Skip to content

Commit

Permalink
Refactor filters_to_fft_table internals.
Browse files Browse the repository at this point in the history
Add NUMPY_LT_1_17 compat.
  • Loading branch information
pllim committed Feb 3, 2021
1 parent b570f52 commit 09a3414
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
10 changes: 7 additions & 3 deletions docs/synphot/filter_par.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ By default, 10 FFT parameters are returned as complex numbers::
(38.635087381362396-13.02803811279449j)]

.. TODO: Only skipping the fft_pars comparison above because output is very
different for Numpy 1.16. Unskip it and replace with +FLOAT_CMP when
different for NUMPY_LT_1_17. Unskip it and replace with +FLOAT_CMP when
Numpy minversion is 1.17.
It is up to you to decide how to store this data, though storing it in a
Expand All @@ -70,15 +70,19 @@ will store the results in a table for you::
>>> from synphot.filter_parameterization import filters_to_fft_table
>>> mapping = {'HST/ACS/HRC/F555W': (bp, None)}
>>> filter_pars_table = filters_to_fft_table(mapping)
>>> filter_pars_table # doctest: +FLOAT_CMP +ELLIPSIS
>>> filter_pars_table # doctest: +SKIP
<Table length=1>
filter n_lambda ... fft_9
...
str17 int32 ... complex128
str17 int... ... complex128
----------------- -------- ... ---------------------------------------
HST/ACS/HRC/F555W 10000 ... (38.635087381362396-13.02803811279449j)
>>> filter_pars_table.write('my_filter_pars.fits') # doctest: +SKIP

.. TODO: Only skipping the filter_pars_table comparison above because output
is slightly different for NUMPY_LT_1_17. Unskip it and replace with
+FLOAT_CMP +ELLIPSIS when Numpy minversion is 1.17.
.. _filter_fft_construction:

Reconstructing Filter from FFT
Expand Down
6 changes: 4 additions & 2 deletions synphot/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Module to handle backward-compatibility."""

import astropy
import numpy
from astropy.utils.introspection import minversion

try:
Expand All @@ -19,8 +20,9 @@
HAS_DUST_EXTINCTION = True


__all__ = ['ASTROPY_LT_4_1', 'ASTROPY_LT_4_0', 'HAS_SPECUTILS',
'HAS_DUST_EXTINCTION']
__all__ = ['ASTROPY_LT_4_1', 'ASTROPY_LT_4_0', 'NUMPY_LT_1_17',
'HAS_SPECUTILS', 'HAS_DUST_EXTINCTION']

ASTROPY_LT_4_1 = not minversion(astropy, '4.1')
ASTROPY_LT_4_0 = not minversion(astropy, '4.0')
NUMPY_LT_1_17 = not minversion(numpy, '1.17')
24 changes: 15 additions & 9 deletions synphot/filter_parameterization/filter_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from astropy.modeling.models import custom_model, Sine1D
from astropy.table import Table

from synphot.compat import NUMPY_LT_1_17
from synphot.models import Empirical1D
from synphot.spectrum import SpectralElement
from synphot.units import validate_quantity
Expand Down Expand Up @@ -210,18 +211,23 @@ def filters_to_fft_table(filters_mapping, n_terms=10):
""" # noqa
wave_unit = SpectralElement._internal_wave_unit

fft_table = Table(names=['filter', 'n_lambda', 'lambda_0', 'delta_lambda',
'tr_max'] + [f'fft_{i}' for i in range(n_terms)],
dtype=[np.str, np.int32, np.float32, np.float32,
np.float32] + [np.complex] * n_terms)
fft_table['lambda_0'].unit = wave_unit
fft_table['delta_lambda'].unit = wave_unit
colnames = ['filter', 'n_lambda', 'lambda_0', 'delta_lambda',
'tr_max'] + [f'fft_{i}' for i in range(n_terms)]
rows = []

for key, (bp, wavelengths) in filters_mapping.items():
n_lambda, lambda_0, delta_lambda, tr_max, fft_pars = filter_to_fft(
bp, wavelengths=wavelengths, n_terms=n_terms)
fft_table.add_row(tuple(
[key, n_lambda, lambda_0, delta_lambda, tr_max] + fft_pars))
if not NUMPY_LT_1_17:
rows.append(tuple(
[key, n_lambda, lambda_0, delta_lambda, tr_max] + fft_pars))
else: # Numpy 1.16 cannot handle unit here
rows.append(tuple(
[key, n_lambda, lambda_0.value, delta_lambda.value,
tr_max.value] + fft_pars))

fft_table = Table(rows=rows, names=colnames)
fft_table['lambda_0'].unit = wave_unit
fft_table['delta_lambda'].unit = wave_unit

return fft_table

0 comments on commit 09a3414

Please sign in to comment.