Skip to content

surveycodex.utilities

mag2counts(magnitude, survey, filter, exposure_time=None)

Convert source magnitude to electron counts for a given survey filter

To perform the computation, we use the filter zeropoint computed with speclite at a given airmass under classical atmospheric conditions and by default integrated over the survey lifetime.

An exposure time can be provided to compute the corresponding counts instead of the full filter exposure time.

Expect a rough estimate from this calculation since e.g. it does not take into account the atmospheric extinction. Therefore the result is cast to an integer.

Parameters

magnitude: float magnitude of source survey: str or Survey Name of a given survey or Survey instance filter: str or Filter Name of the survey filter or Filter instance exposure_time: float or Quantity[float] (optional) Exposure time of the filter in seconds. If not provided, the full filter exposure time is used.

Returns

Quantity[int] The corresponding flux in electron counts

Example

from surveycodex.utilities import mag2counts mag2counts(24, "LSST", "g")

References

The WeakLensingDeblending package https://github.com/LSSTDESC/WeakLensingDeblending

Source code in surveycodex/utilities.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def mag2counts(magnitude, survey, filter, exposure_time=None):
    """Convert source magnitude to electron counts for a given survey filter

    To perform the computation, we use the filter zeropoint computed
    with `speclite` at a given airmass under classical atmospheric
    conditions and by default integrated over the survey lifetime.

    An exposure time can be provided to compute the corresponding counts
    instead of the full filter exposure time.

    Expect a rough estimate from this calculation since e.g. it does not
    take into account the atmospheric extinction. Therefore the result
    is cast to an integer.

    Parameters
    ----------
    magnitude: float
        magnitude of source
    survey: str or Survey
        Name of a given survey or Survey instance
    filter: str or Filter
        Name of the survey filter or Filter instance
    exposure_time: float or Quantity[float] (optional)
        Exposure time of the filter in seconds.
        If not provided, the full filter exposure time is used.

    Returns
    -------
    Quantity[int]
        The corresponding flux in electron counts

    Example
    -------
    >>> from surveycodex.utilities import mag2counts
    >>> mag2counts(24, "LSST", "g")
    <Quantity 121397 ct>

    References
    ----------
    The `WeakLensingDeblending` package
    https://github.com/LSSTDESC/WeakLensingDeblending

    """
    if not isinstance(magnitude, u.Quantity):
        magnitude *= u.mag(u.electron / u.s)
    else:
        magnitude = magnitude.value * u.mag(u.electron / u.s)

    if not isinstance(survey, Survey):
        survey = get_survey(survey)

    if not isinstance(filter, Filter):
        filter = survey.get_filter(filter)

    flux = (magnitude - filter.zeropoint).to(u.electron / u.s)

    exposure_time = exposure_time or filter.full_exposure_time
    if not isinstance(exposure_time, u.Quantity):
        exposure_time *= u.s

    counts = flux * exposure_time

    return counts.astype(int)

mean_sky_level(survey, filter)

Computes the mean sky level for a given survey and a filter

This computation uses the sky brightness parameter from surveycodex, expressed as a magnitude per sky area, weights it by the pixel area and converts it to electron counts.

Parameters

survey: str or Survey Name of a given survey or Survey instance filter: str or Filter Name of the survey filter of Filter instance

Returns

Quantity[float] The corresponding mean sky level in electron counts

Example

from surveycodex.utilities import mean_sky_level mean_sky_level("LSST", "g")

Source code in surveycodex/utilities.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def mean_sky_level(survey, filter):
    """Computes the mean sky level for a given survey and a filter

    This computation uses the sky brightness parameter from surveycodex,
    expressed as a magnitude per sky area, weights it by the
    pixel area and converts it to electron counts.

    Parameters
    ----------
    survey: str or Survey
        Name of a given survey or Survey instance
    filter: str or Filter
        Name of the survey filter of Filter instance

    Returns
    -------
    Quantity[float]
        The corresponding mean sky level in electron counts

    Example
    -------
    >>> from surveycodex.utilities import mean_sky_level
    >>> mean_sky_level("LSST", "g")
    <Quantity 23241.84 ct>

    """
    if not isinstance(survey, Survey):
        survey = get_survey(survey)

    if not isinstance(filter, Filter):
        filter = survey.get_filter(filter)

    sky_brightness_counts = mag2counts(filter.sky_brightness, survey, filter)
    pixel_area = survey.pixel_scale.to_value(u.arcsec) ** 2

    mean_sky_level = sky_brightness_counts * pixel_area

    return mean_sky_level