diff --git a/docs/synphot/filter_par.rst b/docs/synphot/filter_par.rst index 5883ca69..313d1837 100644 --- a/docs/synphot/filter_par.rst +++ b/docs/synphot/filter_par.rst @@ -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 @@ -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 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 diff --git a/synphot/compat.py b/synphot/compat.py index c0a23d1e..6c5b2818 100644 --- a/synphot/compat.py +++ b/synphot/compat.py @@ -2,6 +2,7 @@ """Module to handle backward-compatibility.""" import astropy +import numpy from astropy.utils.introspection import minversion try: @@ -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') diff --git a/synphot/filter_parameterization/filter_fft.py b/synphot/filter_parameterization/filter_fft.py index 9e7a73af..909ec889 100644 --- a/synphot/filter_parameterization/filter_fft.py +++ b/synphot/filter_parameterization/filter_fft.py @@ -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 @@ -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