From a307fc6b52b6740ebd65b256ecf861e971bc30b5 Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 01:22:51 -0500 Subject: [PATCH 01/10] Changing photometry dtype to be np.float32. --- sedkit/sed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sedkit/sed.py b/sedkit/sed.py index b6c33d3..52b2755 100644 --- a/sedkit/sed.py +++ b/sedkit/sed.py @@ -200,7 +200,7 @@ def __init__(self, name='My Target', verbose=True, method_list=None, substellar= # Make empty photometry table self.mag_system = 'Vega' phot_cols = ('band', 'eff', 'app_magnitude', 'app_magnitude_unc', 'app_flux', 'app_flux_unc', 'abs_magnitude', 'abs_magnitude_unc', 'abs_flux', 'abs_flux_unc', 'bandpass', 'ref') - phot_typs = ('U16', np.float16, np.float16, np.float16, float, float, np.float16, np.float16, float, float, 'O', 'O') + phot_typs = ('U16', np.float16, np.float32, np.float32, float, float, np.float32, np.float32, float, float, 'O', 'O') self._photometry = at.QTable(names=phot_cols, dtype=phot_typs) for col in ['app_flux', 'app_flux_unc', 'abs_flux', 'abs_flux_unc']: self._photometry[col].unit = self._flux_units @@ -310,7 +310,7 @@ def add_photometry(self, band, mag, mag_unc=None, system='Vega', ref=None, **kwa # Make a dict for the new point mag = round(mag, 3) mag_unc = mag_unc if np.isnan(mag_unc) else round(mag_unc, 3) - eff = bp.wave_eff.astype(np.float16) + eff = bp.wave_eff.astype(np.float32) new_photometry = {'band': band, 'eff': eff, 'app_magnitude': mag, 'app_magnitude_unc': mag_unc, 'bandpass': bp, 'ref': ref} # Add the kwargs @@ -361,8 +361,8 @@ def add_photometry_row(self, row, bands=None, rename=None, unc_wildcard='e_*', r # Add photometry to phot table for idx, band in enumerate(bands): if band in row.colnames: - goodmag = isinstance(row[band], (float, np.float16, np.float32)) - goodunc = isinstance(row[unc_wildcard.replace('*', band)], (float, np.float16, np.float32)) + goodmag = isinstance(row[band], (float, np.float32, np.float32)) + goodunc = isinstance(row[unc_wildcard.replace('*', band)], (float, np.float32, np.float32)) if goodmag: mag = row[band] unc = row[unc_wildcard.replace('*', band)] if goodunc else np.nan From 7c37bb0d2246f143076bfe5fa7df651cbbc6240f Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:36:59 -0500 Subject: [PATCH 02/10] Adding test to check if photometry values input stay the same when added. --- tests/test_sed.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_sed.py b/tests/test_sed.py index c4fb4a3..ab2d298 100644 --- a/tests/test_sed.py +++ b/tests/test_sed.py @@ -31,6 +31,15 @@ def setUp(self): self.spec2 = sp.Spectrum(*SPEC2) self.sed = sed.SED(verbose=True, foo=123) + def test_compare_photometry(self): + """Test that photometry is the same as input values""" + s = copy.copy(self.sed) + # Add the photometry + mag = 23.93 + mag_unc = 0.3 + s.add_photometry('2MASS.J', mag, mag_unc) + self.assertEqual(s.photometry['app_magnitude'], mag) + self.assertEqual(s.photometry['app_magnitude_unc'], mag_unc) def test_add_photometry(self): """Test that photometry is added properly""" From ee5ffdc35131d5f84672b0c45d711aa70cdd0d67 Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:37:11 -0500 Subject: [PATCH 03/10] Revert "Changing photometry dtype to be np.float32." This reverts commit a307fc6b52b6740ebd65b256ecf861e971bc30b5. --- sedkit/sed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sedkit/sed.py b/sedkit/sed.py index 52b2755..b6c33d3 100644 --- a/sedkit/sed.py +++ b/sedkit/sed.py @@ -200,7 +200,7 @@ def __init__(self, name='My Target', verbose=True, method_list=None, substellar= # Make empty photometry table self.mag_system = 'Vega' phot_cols = ('band', 'eff', 'app_magnitude', 'app_magnitude_unc', 'app_flux', 'app_flux_unc', 'abs_magnitude', 'abs_magnitude_unc', 'abs_flux', 'abs_flux_unc', 'bandpass', 'ref') - phot_typs = ('U16', np.float16, np.float32, np.float32, float, float, np.float32, np.float32, float, float, 'O', 'O') + phot_typs = ('U16', np.float16, np.float16, np.float16, float, float, np.float16, np.float16, float, float, 'O', 'O') self._photometry = at.QTable(names=phot_cols, dtype=phot_typs) for col in ['app_flux', 'app_flux_unc', 'abs_flux', 'abs_flux_unc']: self._photometry[col].unit = self._flux_units @@ -310,7 +310,7 @@ def add_photometry(self, band, mag, mag_unc=None, system='Vega', ref=None, **kwa # Make a dict for the new point mag = round(mag, 3) mag_unc = mag_unc if np.isnan(mag_unc) else round(mag_unc, 3) - eff = bp.wave_eff.astype(np.float32) + eff = bp.wave_eff.astype(np.float16) new_photometry = {'band': band, 'eff': eff, 'app_magnitude': mag, 'app_magnitude_unc': mag_unc, 'bandpass': bp, 'ref': ref} # Add the kwargs @@ -361,8 +361,8 @@ def add_photometry_row(self, row, bands=None, rename=None, unc_wildcard='e_*', r # Add photometry to phot table for idx, band in enumerate(bands): if band in row.colnames: - goodmag = isinstance(row[band], (float, np.float32, np.float32)) - goodunc = isinstance(row[unc_wildcard.replace('*', band)], (float, np.float32, np.float32)) + goodmag = isinstance(row[band], (float, np.float16, np.float32)) + goodunc = isinstance(row[unc_wildcard.replace('*', band)], (float, np.float16, np.float32)) if goodmag: mag = row[band] unc = row[unc_wildcard.replace('*', band)] if goodunc else np.nan From db30091e37564290c35fa79262eb4b355cecb324 Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:50:17 -0500 Subject: [PATCH 04/10] Changing test to use np equal --- tests/test_sed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_sed.py b/tests/test_sed.py index ab2d298..0b442cb 100644 --- a/tests/test_sed.py +++ b/tests/test_sed.py @@ -38,8 +38,8 @@ def test_compare_photometry(self): mag = 23.93 mag_unc = 0.3 s.add_photometry('2MASS.J', mag, mag_unc) - self.assertEqual(s.photometry['app_magnitude'], mag) - self.assertEqual(s.photometry['app_magnitude_unc'], mag_unc) + assert np.equal(s.photometry['app_magnitude'], mag) + assert np.equal(s.photometry['app_magnitude_unc'], mag_unc) def test_add_photometry(self): """Test that photometry is added properly""" From 8949b4c7c22ceeacec78f3fc14567b89afc532bf Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:33:28 -0500 Subject: [PATCH 05/10] Test which test if the input photometry is the same as the one shown in the resulting sed. --- tests/test_sed.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/test_sed.py b/tests/test_sed.py index 0b442cb..b510e12 100644 --- a/tests/test_sed.py +++ b/tests/test_sed.py @@ -14,6 +14,7 @@ class TestSED(unittest.TestCase): """Tests for the SED class""" + def setUp(self): # Make Blackbody @@ -31,15 +32,17 @@ def setUp(self): self.spec2 = sp.Spectrum(*SPEC2) self.sed = sed.SED(verbose=True, foo=123) + def test_compare_photometry(self): """Test that photometry is the same as input values""" s = copy.copy(self.sed) + # Add the photometry - mag = 23.93 - mag_unc = 0.3 - s.add_photometry('2MASS.J', mag, mag_unc) - assert np.equal(s.photometry['app_magnitude'], mag) - assert np.equal(s.photometry['app_magnitude_unc'], mag_unc) + mag, mag_unc = 23.93, 0.3 + s.add_photometry('UKIRT/UFTI.J', mag, mag_unc) + + assert (np.equal(s.photometry['app_magnitude'], mag)) is True + assert (np.equal(s.photometry['app_magnitude_unc'], mag_unc)) is True def test_add_photometry(self): """Test that photometry is added properly""" @@ -58,7 +61,7 @@ def test_add_photometry_table(self): s = copy.copy(self.sed) # Add the photometry - f = str(importlib.resources.files('sedkit')/ 'data/L3_photometry.txt') + f = str(importlib.resources.files('sedkit') / 'data/L3_photometry.txt') s.add_photometry_table(f) self.assertEqual(len(s.photometry), 8) @@ -82,7 +85,7 @@ def test_add_spectrum(self): self.assertEqual(len(s.spectra), 1) # Test new spectrum array - SPEC1 = [self.WAVE1, self.FLUX1, self.FLUX1/100.] + SPEC1 = [self.WAVE1, self.FLUX1, self.FLUX1 / 100.] s.add_spectrum(SPEC1) self.assertEqual(len(s.spectra), 2) @@ -101,7 +104,7 @@ def test_attributes(self): s.age = 4 * q.Gyr, 0.1 * q.Gyr, 'reference' self.assertRaises(TypeError, setattr, s, 'age', 'foo') self.assertRaises(TypeError, setattr, s, 'age', (4, 0.1)) - self.assertRaises(TypeError, setattr, s, 'age', (4*q.Jy, 0.1*q.Jy)) + self.assertRaises(TypeError, setattr, s, 'age', (4 * q.Jy, 0.1 * q.Jy)) # Sky coords s.sky_coords = 1.2345 * q.deg, 1.2345 * q.deg @@ -142,7 +145,7 @@ def test_attributes(self): self.assertRaises(ValueError, setattr, s, 'evo_model', 'foo') # Flux units - s.flux_units = q.erg/q.s/q.cm**2/q.AA + s.flux_units = q.erg / q.s / q.cm ** 2 / q.AA self.assertRaises(TypeError, setattr, s, 'flux_units', q.cm) # Wave units @@ -157,9 +160,9 @@ def test_attributes(self): def test_no_spectra(self): """Test that a purely photometric SED can be creted""" s = copy.copy(self.sed) - s.age = 455*q.Myr, 13*q.Myr - s.radius = 2.362*q.Rsun, 0.02*q.Rjup, 0.02*q.Rjup - s.parallax = 130.23*q.mas, 0.36*q.mas + s.age = 455 * q.Myr, 13 * q.Myr + s.radius = 2.362 * q.Rsun, 0.02 * q.Rjup, 0.02 * q.Rjup + s.parallax = 130.23 * q.mas, 0.36 * q.mas s.spectral_type = 'A0V' s.add_photometry('2MASS.J', -0.177, 0.206) s.add_photometry('2MASS.H', -0.029, 0.146) @@ -174,7 +177,7 @@ def test_no_spectra(self): self.assertIsNotNone(s.fbol) # Make Wein tail - s.make_wein_tail(teff=2000*q.K) + s.make_wein_tail(teff=2000 * q.K) # Radius from spectral type s.results @@ -199,9 +202,9 @@ def test_plot(self): def test_no_photometry(self): """Test that a purely photometric SED can be created""" s = copy.copy(self.sed) - s.age = 455*q.Myr, 13*q.Myr - s.radius = 2.362*q.Rsun, 0.02*q.Rjup,0.02*q.Rjup - s.parallax = 130.23*q.mas, 0.36*q.mas + s.age = 455 * q.Myr, 13 * q.Myr + s.radius = 2.362 * q.Rsun, 0.02 * q.Rjup, 0.02 * q.Rjup + s.parallax = 130.23 * q.mas, 0.36 * q.mas s.spectral_type = 'A0V' s.add_spectrum(self.spec1) @@ -303,6 +306,7 @@ def test_fit_modelgrid(self): # # self.assertTrue(isinstance(s.Teff_bb, (int, float))) + def test_VegaSED(): """Test the VegaSED class""" vega = sed.VegaSED() From db95b8812cab6ea622846e68e729e0d4dc37eb32 Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:38:37 -0500 Subject: [PATCH 06/10] Changing dtype to np.float32 for the provided magnitudes --- sedkit/sed.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sedkit/sed.py b/sedkit/sed.py index b6c33d3..540da0c 100644 --- a/sedkit/sed.py +++ b/sedkit/sed.py @@ -200,7 +200,7 @@ def __init__(self, name='My Target', verbose=True, method_list=None, substellar= # Make empty photometry table self.mag_system = 'Vega' phot_cols = ('band', 'eff', 'app_magnitude', 'app_magnitude_unc', 'app_flux', 'app_flux_unc', 'abs_magnitude', 'abs_magnitude_unc', 'abs_flux', 'abs_flux_unc', 'bandpass', 'ref') - phot_typs = ('U16', np.float16, np.float16, np.float16, float, float, np.float16, np.float16, float, float, 'O', 'O') + phot_typs = ('U16', np.float16, np.float32, np.float32, float, float, np.float16, np.float16, float, float, 'O', 'O') self._photometry = at.QTable(names=phot_cols, dtype=phot_typs) for col in ['app_flux', 'app_flux_unc', 'abs_flux', 'abs_flux_unc']: self._photometry[col].unit = self._flux_units @@ -361,8 +361,8 @@ def add_photometry_row(self, row, bands=None, rename=None, unc_wildcard='e_*', r # Add photometry to phot table for idx, band in enumerate(bands): if band in row.colnames: - goodmag = isinstance(row[band], (float, np.float16, np.float32)) - goodunc = isinstance(row[unc_wildcard.replace('*', band)], (float, np.float16, np.float32)) + goodmag = isinstance(row[band], (float, np.float32, np.float32)) + goodunc = isinstance(row[unc_wildcard.replace('*', band)], (float, np.float32, np.float32)) if goodmag: mag = row[band] unc = row[unc_wildcard.replace('*', band)] if goodunc else np.nan From 350d56c97cea4bc0c31a7242b5e9afa92de4d164 Mon Sep 17 00:00:00 2001 From: Sherelyn Alejandro <80668767+SherelynA@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:54:19 -0500 Subject: [PATCH 07/10] Fixing Test --- tests/test_sed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_sed.py b/tests/test_sed.py index b510e12..01912fe 100644 --- a/tests/test_sed.py +++ b/tests/test_sed.py @@ -41,8 +41,8 @@ def test_compare_photometry(self): mag, mag_unc = 23.93, 0.3 s.add_photometry('UKIRT/UFTI.J', mag, mag_unc) - assert (np.equal(s.photometry['app_magnitude'], mag)) is True - assert (np.equal(s.photometry['app_magnitude_unc'], mag_unc)) is True + assert np.equal(s.photometry['app_magnitude'][0], mag) + assert np.equal(s.photometry['app_magnitude_unc'][0], mag_unc) def test_add_photometry(self): """Test that photometry is added properly""" From 69f9efa1e6df0613293768cad8f81efebe6894c2 Mon Sep 17 00:00:00 2001 From: kelle Date: Fri, 15 Nov 2024 11:37:06 +0100 Subject: [PATCH 08/10] float tests --- tests/test_sed.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_sed.py b/tests/test_sed.py index 01912fe..52238bd 100644 --- a/tests/test_sed.py +++ b/tests/test_sed.py @@ -49,11 +49,20 @@ def test_add_photometry(self): s = copy.copy(self.sed) # Add the photometry - s.add_photometry('2MASS.J', -0.177, 0.206) + s.add_photometry('2MASS.J', 13.123, 0.206) self.assertEqual(len(s.photometry), 1) + assert s.photometry[0]['band'] == '2MASS.J' + assert s.photometry[0]['app_magnitude'] == np.float32(13.123) + assert s.photometry[0]['app_magnitude_unc'] == np.float32(0.206) + + mag, mag_unc = 23.93, 0.3 + s.add_photometry('UKIRT/UFTI.J', mag, mag_unc) + assert s.photometry['app_magnitude'][1] == np.float32(23.93) + assert s.photometry['app_magnitude_unc'][1] == np.float32(0.3) # Now remove it - s.drop_photometry(0) + s.drop_photometry('UKIRT/UFTI.J') + s.drop_photometry('2MASS.J') self.assertEqual(len(s.photometry), 0) def test_add_photometry_table(self): @@ -241,7 +250,7 @@ def test_find_SDSS_spectra(self): s.sky_coords = SkyCoord('0h8m05.63s +14d50m23.3s', frame='icrs') s.find_SDSS_spectra(search_radius=20 * q.arcsec) s.find_SDSS() - s.plot() + # s.plot() def test_run_methods(self): """Test that the method_list argument works""" From 61c32955849ae14cc6bce58f5f2faae2231114ae Mon Sep 17 00:00:00 2001 From: kelle Date: Fri, 15 Nov 2024 11:37:25 +0100 Subject: [PATCH 09/10] make float32s --- sedkit/sed.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sedkit/sed.py b/sedkit/sed.py index 540da0c..8dbe48b 100644 --- a/sedkit/sed.py +++ b/sedkit/sed.py @@ -27,7 +27,6 @@ from bokeh.plotting import figure, show from bokeh.models import HoverTool, Range1d, ColumnDataSource from bokeh.palettes import Category10 -import itertools from dustmaps.bayestar import BayestarWebQuery from svo_filters import svo @@ -191,16 +190,16 @@ def __init__(self, name='My Target', verbose=True, method_list=None, substellar= self.best_fit = {} # Make empty spectra table - spec_cols = ('name', 'spectrum', 'wave_min', 'wave_max', 'wave_bins', 'resolution', 'history', 'ref') - spec_typs = ('O', 'O', np.float16, np.float16, int, int, 'O', 'O') - self._spectra = at.QTable(names=spec_cols, dtype=spec_typs) + spec_col_names = ('name', 'spectrum', 'wave_min', 'wave_max', 'wave_bins', 'resolution', 'history', 'ref') + spec_dtypes = ('O', 'O', np.float32, np.float32, int, int, 'O', 'O') + self._spectra = at.QTable(names=spec_col_names, dtype=spec_dtypes) for col in ['wave_min', 'wave_max']: self._spectra[col].unit = self._wave_units # Make empty photometry table self.mag_system = 'Vega' phot_cols = ('band', 'eff', 'app_magnitude', 'app_magnitude_unc', 'app_flux', 'app_flux_unc', 'abs_magnitude', 'abs_magnitude_unc', 'abs_flux', 'abs_flux_unc', 'bandpass', 'ref') - phot_typs = ('U16', np.float16, np.float32, np.float32, float, float, np.float16, np.float16, float, float, 'O', 'O') + phot_typs = ('U16', np.float32, np.float32, np.float32, float, float, np.float32, np.float32, float, float, 'O', 'O') self._photometry = at.QTable(names=phot_cols, dtype=phot_typs) for col in ['app_flux', 'app_flux_unc', 'abs_flux', 'abs_flux_unc']: self._photometry[col].unit = self._flux_units @@ -310,7 +309,7 @@ def add_photometry(self, band, mag, mag_unc=None, system='Vega', ref=None, **kwa # Make a dict for the new point mag = round(mag, 3) mag_unc = mag_unc if np.isnan(mag_unc) else round(mag_unc, 3) - eff = bp.wave_eff.astype(np.float16) + eff = bp.wave_eff.astype(np.float32) new_photometry = {'band': band, 'eff': eff, 'app_magnitude': mag, 'app_magnitude_unc': mag_unc, 'bandpass': bp, 'ref': ref} # Add the kwargs @@ -444,8 +443,8 @@ def add_spectrum(self, spectrum, **kwargs): spec.flux_units = self.flux_units # Add the spectrum object to the list of spectra - mn = spec.wave_min#.astype(np.float16) - mx = spec.wave_max#.astype(np.float16) + mn = spec.wave_min + mx = spec.wave_max res = int(((mx - mn) / np.nanmean(np.diff(spec.wave))).value) # Make sure it's not a duplicate @@ -688,7 +687,7 @@ def calculate_synthetic_photometry(self, bandpasses=None): if mag is not None and not np.isnan(mag): # Make a dict for the new point - new_photometry = {'band': band, 'eff': bp.wave_eff.astype(np.float16), 'bandpass': bp, 'app_magnitude': mag, 'app_magnitude_unc': mag_unc, 'ref': 'sedkit'} + new_photometry = {'band': band, 'eff': bp.wave_eff.astype(np.float32), 'bandpass': bp, 'app_magnitude': mag, 'app_magnitude_unc': mag_unc, 'ref': 'sedkit'} # Add it to the table self._synthetic_photometry.add_row(new_photometry) From d69f9c0508235d6de2e96d4df072aa26e0310f8c Mon Sep 17 00:00:00 2001 From: kelle Date: Fri, 15 Nov 2024 11:39:12 +0100 Subject: [PATCH 10/10] remove duplicate test --- tests/test_sed.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_sed.py b/tests/test_sed.py index 52238bd..4f19ae3 100644 --- a/tests/test_sed.py +++ b/tests/test_sed.py @@ -33,16 +33,6 @@ def setUp(self): self.sed = sed.SED(verbose=True, foo=123) - def test_compare_photometry(self): - """Test that photometry is the same as input values""" - s = copy.copy(self.sed) - - # Add the photometry - mag, mag_unc = 23.93, 0.3 - s.add_photometry('UKIRT/UFTI.J', mag, mag_unc) - - assert np.equal(s.photometry['app_magnitude'][0], mag) - assert np.equal(s.photometry['app_magnitude_unc'][0], mag_unc) def test_add_photometry(self): """Test that photometry is added properly"""