mfouesneau / pyphot

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

leff and lphot do not convert wavelength units #45

Open christophra opened 2 years ago

christophra commented 2 years ago

Steps to reproduce

  1. Get a transmission curve in nanometers
  2. Pass it to the constructor of Filter
  3. Get that new filter's leff and lphot

Expected behaviour: Like the other derived quantities, lphot and leff are also in nanometers and fall within the filter's band.

Observed behaviour: The leff and lphot are a factor 10 too large; in other words, the value is in Ångström but the Quantity has units nanometer.

Minimal example

(using filters from the library as an example, although of course the point is that this can happen when creating new filters)

import pyphot

# would work with any filters, these are available for the example
lib = pyphot.get_library()

for filter_name in ['ZTF_g', # in nanometers
                    'SDSS_g', # in Angstrom
                   ]:
    print(filter_name)

    # In the HDF5 file, lphot and leff are correct
    original = lib[filter_name]

    # Now construct a new filter based on this
    reloaded = pyphot.phot.Filter(
        # all arguments the constructor accepts:
        original.wavelength,
        original.transmit,
        name = 'test_Filter_constructor',
        dtype='photon',
        unit=original.wavelength_unit,
    )
    print(f'lphot {original.lpivot:.2f} turns to {reloaded.lphot:.2f}')
    print(f'leff {original.leff:.2f} turns to {reloaded.leff:.2f}')
christophra commented 2 years ago

I now found out about pyphot.sandbox and its parallel Unit classes. The bug appears also in pyphot.sandbox.UnitFilter.