Skip to content

surveycodex.filter

Filter dataclass

A dataclass containing the main filter parameters

Source code in surveycodex/filter.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
71
@dataclass(frozen=True)
class Filter:
    """A dataclass containing the main filter parameters"""

    name: str
    "The filter name"
    psf_fwhm: Quantity
    "The full-width at half maximum of the PSF"
    zeropoint: Quantity
    "The zeropoint magnitude computed with the speclite library"
    sky_brightness: Quantity
    "Mean sky brightness"
    full_exposure_time: Quantity
    "Mean time spent on the sky on a random survey location"
    effective_wavelength: Optional[Quantity] = None
    "Filter effective wavelength computed from the complete throughput information"

    @classmethod
    def from_dict(cls, filter_info):
        """Constructor for the Filter dataclass

        Makes sure each of the filter attributes gets the appropriate units
        to improve definition and avoid confusion and conversion issues.

        Parameters
        ----------
        filter_info: dict
            Dictionary with the filter informations

        Returns
        -------
        Filter
            A Filter object filled with the given information

        """
        name = filter_info["name"]
        psf_fwhm = filter_info["psf_fwhm"] * u.arcsec
        zeropoint = filter_info["zeropoint"] * u.mag
        sky_brightness = filter_info["sky_brightness"] * (u.mag / u.arcsec**2)
        full_exposure_time = filter_info["full_exposure_time"] * u.s
        wavelength = filter_info.get("effective_wavelength")
        wavelength = wavelength if wavelength is None else wavelength * u.nm

        return cls(
            name,
            psf_fwhm,
            zeropoint,
            sky_brightness,
            full_exposure_time,
            wavelength,
        )

    def __str__(self):
        filter_repr = f"-= {self.name} filter =-\n"
        printed_params = [
            f"  {key:<20} = {val}"
            for key, val in self.__dict__.items()
            if key not in ("name",)
        ]
        filter_repr += "\n".join(printed_params)
        return filter_repr

    def __repr__(self):
        return f"Filter {self.name}"

effective_wavelength: Optional[Quantity] = None class-attribute instance-attribute

Filter effective wavelength computed from the complete throughput information

full_exposure_time: Quantity instance-attribute

Mean time spent on the sky on a random survey location

name: str instance-attribute

The filter name

psf_fwhm: Quantity instance-attribute

The full-width at half maximum of the PSF

sky_brightness: Quantity instance-attribute

Mean sky brightness

zeropoint: Quantity instance-attribute

The zeropoint magnitude computed with the speclite library

from_dict(filter_info) classmethod

Constructor for the Filter dataclass

Makes sure each of the filter attributes gets the appropriate units to improve definition and avoid confusion and conversion issues.

Parameters

filter_info: dict Dictionary with the filter informations

Returns

Filter A Filter object filled with the given information

Source code in surveycodex/filter.py
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
@classmethod
def from_dict(cls, filter_info):
    """Constructor for the Filter dataclass

    Makes sure each of the filter attributes gets the appropriate units
    to improve definition and avoid confusion and conversion issues.

    Parameters
    ----------
    filter_info: dict
        Dictionary with the filter informations

    Returns
    -------
    Filter
        A Filter object filled with the given information

    """
    name = filter_info["name"]
    psf_fwhm = filter_info["psf_fwhm"] * u.arcsec
    zeropoint = filter_info["zeropoint"] * u.mag
    sky_brightness = filter_info["sky_brightness"] * (u.mag / u.arcsec**2)
    full_exposure_time = filter_info["full_exposure_time"] * u.s
    wavelength = filter_info.get("effective_wavelength")
    wavelength = wavelength if wavelength is None else wavelength * u.nm

    return cls(
        name,
        psf_fwhm,
        zeropoint,
        sky_brightness,
        full_exposure_time,
        wavelength,
    )