mfouesneau / pyphot

suite to deal with passband photometry
https://mfouesneau.github.io/pyphot/
MIT License
57 stars 18 forks source link

ZTF filters are broken #23

Closed karpov-sv closed 4 years ago

karpov-sv commented 4 years ago

It seems ZTF filters are currently broken.

For ZTF_g, the problem is missing TAB between 'WAVELENGTH_UNIT' and 'nanometer' in ASCII file, which prevents correct reading of wavelength units.

For ZTF_i, the entries in ASCII file are in descending order, which breaks numerical integration. It may be either fixed on a file level, or more generically - in Filter class constructor like that:

diff --git a/pyphot/phot.py b/pyphot/phot.py
index 8cfb2f0..120ca21 100644
--- a/pyphot/phot.py
+++ b/pyphot/phot.py
@@ -129,6 +129,11 @@ class Filter(object):
             self._wavelength = wavelength
         self.set_wavelength_unit(unit)
         self.transmit   = np.clip(transmit, 0., np.nanmax(transmit))
+
+        aidx = np.argsort(self._wavelength)
+        self._wavelength = self._wavelength[aidx]
+        self.transmit = self.transmit[aidx]
+
         self.norm       = trapz(self.transmit, self._wavelength)
         self._lT        = trapz(self._wavelength * self.transmit, self._wavelength)
         self._lpivot    = self._calculate_lpivot()

Both of these errors are propagated to default new_filters.hd5 library.

ZTF_r loads correctly, but its effective wavelength is order of magnitude larger than it should be (which seems to be a generic problem for all filters defined with 'nanometer' units - at least for Gaia_MAW_G it is the same)

Filter object information:
    name:                 ZTF_r
    detector type:        photon
    wavelength units:     nanometer
    central wavelength:   643.692086 nanometer
    pivot wavelength:     642.116699 nanometer
    effective wavelength: 6339.593128 nanometer
    photon wavelength:    6370.971519 nanometer
    minimum wavelength:   560.080000 nanometer
    maximum wavelength:   731.660000 nanometer
    norm:                 14739.212505
    effective width:      151.525747 nanometer
    fullwidth half-max:   155.710000 nanometer
    definition contains 3201 points
mfouesneau commented 4 years ago

Thanks for reporting the bugs. Note that the effective wavelength issue only affects the base version of pyphot using pint units, it does not affect the astropy version.

Filter object information:
    name:                 ZTF_r
    detector type:        photon
    wavelength units:     nanometer
    central wavelength:   643.692086 nm
    pivot wavelength:     642.116699 nm
    effective wavelength: 633.959313 nm
    photon wavelength:    637.097152 nm
    minimum wavelength:   560.080000 nm
    maximum wavelength:   731.660000 nm
    norm:                 14739.212505
    effective width:      151.525747 nm
    fullwidth half-max:   155.710000 nm
    definition contains 3201 points

    Zeropoints
        Vega: 21.626994 mag,
              2.2346125681876647e-09 erg / (Angstrom cm2 s),
              3073.3318967140135 Jy
              70286.39164596281 ph / (Angstrom cm2 s)
          AB: 21.446018 mag,
              2.639932202863843e-09 erg / (Angstrom cm2 s),
              3630.7805477009956 Jy
          ST: 21.100000 mag,
              3.6307805477010028e-09 erg / (Angstrom cm2 s),
              4993.524974339604 Jy
mfouesneau commented 4 years ago

revision 55d7076 implements the ordering correction.

mfouesneau commented 4 years ago

Units corrected in revision ba206e3.

The bug came from the wrong default library objects. Corrected for using the unit aware classes instead.

mfouesneau commented 4 years ago

ZTF filter ascii file corrected in rev. 40e82c0

mfouesneau commented 4 years ago

Correction of the libraries done. Version 1.1 -- rev. 943b2a5

Let me know if you still have issues

karpov-sv commented 4 years ago

Yes, I confirm that now it works as expected. Thanks!