From 5cb468be8640cab0ef2e3b4cac32227cf81353d3 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Mon, 9 Sep 2024 11:23:40 -0400 Subject: [PATCH 1/9] adding hubeny WD models --- measure_extinction/plotting/plot_spec.py | 2 +- measure_extinction/stardata.py | 7 +-- .../utils/make_all_tlusty_obsdata.py | 47 +++++++++++++++++-- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/measure_extinction/plotting/plot_spec.py b/measure_extinction/plotting/plot_spec.py index 0e8f873..141fd0c 100755 --- a/measure_extinction/plotting/plot_spec.py +++ b/measure_extinction/plotting/plot_spec.py @@ -397,7 +397,7 @@ def plot_spectrum( plt.rc("ytick.minor", width=2) # create the plot - fig, ax = plt.subplots(figsize=(13, 10)) + fig, ax = plt.subplots(figsize=(10, 8)) # read in and plot all bands and spectra for this star if ".dat" not in star: diff --git a/measure_extinction/stardata.py b/measure_extinction/stardata.py index d3ec30c..1269bc2 100644 --- a/measure_extinction/stardata.py +++ b/measure_extinction/stardata.py @@ -821,9 +821,10 @@ def read_irs(self, line, path="./", use_corfac=True, corfac=None): if len(indxs) > 0: self.npts[indxs] = 0 - # add units - self.fluxes = self.fluxes.value * (u.Jy) - self.uncs = self.uncs.value * (u.Jy) + self.fluxes = self.fluxes.to( + fluxunit, equivalencies=u.spectral_density(self.waves) + ) + self.uncs = self.uncs.to(fluxunit, equivalencies=u.spectral_density(self.waves)) def read_nircam_ss(self, line, path="./"): """ diff --git a/measure_extinction/utils/make_all_tlusty_obsdata.py b/measure_extinction/utils/make_all_tlusty_obsdata.py index 127c8a2..acc8103 100644 --- a/measure_extinction/utils/make_all_tlusty_obsdata.py +++ b/measure_extinction/utils/make_all_tlusty_obsdata.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import glob +import argparse from measure_extinction.utils.make_obsdata_from_model import make_obsdata_from_model @@ -61,20 +62,58 @@ def decode_params(filename): return model_params +def decode_params_wd(filename): + """ + Decode the tlusty filenames for the model parameters + """ + model_params = {} + + slashpos = filename.rfind("/") + periodpos = filename.rfind(".spec") + + tpos = filename.find("t", slashpos) + gpos = filename.find("g", slashpos) + + model_params["Teff"] = float(filename[tpos + 1 : gpos]) + model_params["logg"] = float(filename[gpos + 1 : periodpos - 1]) * 0.01 + model_params["vturb"] = 0.0 + model_params["Z"] = 0.0 + + return model_params + + if __name__ == "__main__": - tlusty_models = glob.glob( - "/home/kgordon/Python/extstar_data/Models/Tlusty_2023/*v10.spec.gz" + + # commandline parser + parser = argparse.ArgumentParser() + parser.add_argument( + "--grid", + choices=["tlusty", "wd_hubeny"], + default="tlusty", + help="Grid to use", ) + args = parser.parse_args() + + if args.grid == "wd_hubeny": + mfilestr = "/home/kgordon/Python/extstar_data/Models/WD_Hubeny/*.spec" + decodefunc = decode_params_wd + outbase = "wd_hubeny" + else: + mfilestr = "/home/kgordon/Python/extstar_data/Models/Tlusty_2023/*v10.spec.gz" + decodefunc = decode_params + outbase = "tlusty" + + tlusty_models = glob.glob(mfilestr) for cfname in tlusty_models: # parse the filename to get the model parameters - model_params = decode_params(cfname) + model_params = decodefunc(cfname) # get the base filename for the output files slashpos = cfname.rfind("/") periodpos = cfname.rfind(".spec") - basename = "tlusty_{}".format(cfname[slashpos + 1 : periodpos]) + basename = f"{outbase}_{cfname[slashpos + 1 : periodpos]}" print(cfname) print(basename) From 4427a25ebacb84ec0aea326901e3339be284ea64 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Mon, 9 Sep 2024 11:45:49 -0400 Subject: [PATCH 2/9] adding in two more WFC3 bands --- measure_extinction/stardata.py | 27 ++++++++++++++----- .../utils/make_obsdata_from_model.py | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/measure_extinction/stardata.py b/measure_extinction/stardata.py index 1269bc2..e2c235e 100644 --- a/measure_extinction/stardata.py +++ b/measure_extinction/stardata.py @@ -183,7 +183,7 @@ def get_poss_bands(): _n_wfpc2_bands = len(_wfpc2_vegamag) _wfpc2_band_zeromag_fluxes = np.zeros(_n_wfpc2_bands) - # zeromag Vega flux not given in standard WFPC2 documenation + # zeromag Vega flux not given in standard WFPC2 documentation # instead the flux and Vega magnitudes are given for 1 DN/sec # the following code coverts these numbers to zeromag Vega fluxes for i in range(_n_wfpc2_bands): @@ -191,24 +191,39 @@ def get_poss_bands(): 10 ** (0.4 * _wfpc2_vegamag[i]) ) - # WFC3 bands + # WFC3 bands - updated for 2020 solutions Assuming UVIS1 _wfc3_band_names = [ "WFC3_F275W", "WFC3_F336W", "WFC3_F475W", + "WFC3_F625W", + "WFC3_F775W", "WFC3_F814W", "WFC3_F110W", "WFC3_F160W", ] - _wfc3_band_waves = np.array([0.2710, 0.3355, 0.4772, 0.8053, 1.1534, 1.5369]) + _wfc3_band_waves = np.array( + [0.2710, 0.3355, 0.4773, 0.6243, 0.7651, 0.8053, 1.1534, 1.5369] + ) _wfc3_photflam = np.array( - [3.186e-18, 1.267e-18, 2.458e-19, 1.477e-19, 1.53e-20, 1.93e-20] + [ + 3.223e-18, + 1.286e-18, + 2.498e-19, + 1.723e-19, + 2.093e-18, + 1.477e-19, + 1.53e-20, + 1.93e-20, + ] + ) + _wfc3_vegamag = np.array( + [22.676, 23.526, 25.809, 25.374, 24.84, 24.712, 26.063, 24.695] ) - _wfc3_vegamag = np.array([22.331, 23.513, 25.809, 24.712, 26.063, 24.695]) _n_wfc3_bands = len(_wfc3_vegamag) _wfc3_band_zeromag_fluxes = np.zeros(_n_wfc3_bands) - # zeromag Vega flux not given in standard WFPC2 documenation + # zeromag Vega flux not given in standard WFP3 documentation # instead the flux and Vega magnitudes are given for 1 DN/sec # the following code coverts these numbers to zeromag Vega fluxes for i in range(_n_wfc3_bands): diff --git a/measure_extinction/utils/make_obsdata_from_model.py b/measure_extinction/utils/make_obsdata_from_model.py index 49a4d0f..cb81a66 100644 --- a/measure_extinction/utils/make_obsdata_from_model.py +++ b/measure_extinction/utils/make_obsdata_from_model.py @@ -399,6 +399,8 @@ def make_obsdata_from_model( "HST_WFC3_UVIS1_F275W", "HST_WFC3_UVIS1_F336W", "HST_WFC3_UVIS1_F475W", + "HST_WFC3_UVIS1_F625W", + "HST_WFC3_UVIS1_F775W", "HST_WFC3_UVIS1_F814W", "HST_WFC3_IR_F110W", "HST_WFC3_IR_F160W", From a74158be125248392f97e41d06553ee16c28e825 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Mon, 9 Sep 2024 11:47:47 -0400 Subject: [PATCH 3/9] fixing doc error --- docs/index.rst | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 07e10f2..6e5c5f3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -50,21 +50,16 @@ trace if it is necessary. Contributing ============ -Like the `Astropy`_ project, the ``measure_extinction`` is made both by and for its +Like the `Astropy`_ project, ``dust_extinction`` is made both by and for its users. We accept contributions at all levels, spanning the gamut from fixing a typo in the documentation to developing a major new feature. We welcome contributors who will abide by the `Python Software Foundation Code of Conduct `_. -``measure_extinction`` follows the same workflow and coding guidelines as -`Astropy`_. The following pages will help you get started with contributing -fixes, code, or documentation (no git or GitHub experience necessary): - -* `How to make a code contribution `_ - -* `Coding Guidelines `_ - -* `Developer Documentation `_ +``dust_extinction`` follows the same workflow and coding guidelines as +`Astropy`_. Take a look at the astropy +`developer `_ documentation for +guidelines. For the complete list of contributors please see the `measure_extinction contributors page on Github From 2528ec4768d3f64eb497e3360fd8e3b7a44b4f73 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Mon, 9 Sep 2024 12:26:20 -0400 Subject: [PATCH 4/9] fix typo --- measure_extinction/stardata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/measure_extinction/stardata.py b/measure_extinction/stardata.py index e2c235e..d311473 100644 --- a/measure_extinction/stardata.py +++ b/measure_extinction/stardata.py @@ -223,7 +223,7 @@ def get_poss_bands(): _n_wfc3_bands = len(_wfc3_vegamag) _wfc3_band_zeromag_fluxes = np.zeros(_n_wfc3_bands) - # zeromag Vega flux not given in standard WFP3 documentation + # zeromag Vega flux not given in standard WFC3 documentation # instead the flux and Vega magnitudes are given for 1 DN/sec # the following code coverts these numbers to zeromag Vega fluxes for i in range(_n_wfc3_bands): From ff1c2d224c2fea3488f4fcf2b072c3178c8cbc0a Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Mon, 9 Sep 2024 16:26:08 -0400 Subject: [PATCH 5/9] adding in ABmag support --- measure_extinction/stardata.py | 43 ++++++++++++++++++--- measure_extinction/utils/merge_stis_spec.py | 2 + 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/measure_extinction/stardata.py b/measure_extinction/stardata.py index d311473..a3ce335 100644 --- a/measure_extinction/stardata.py +++ b/measure_extinction/stardata.py @@ -84,9 +84,9 @@ def __init__(self, type): def read_bands(self, lines, only_bands=None): """ Read the photometric band data from a DAT file - and upate class variables. + and update class variables. Bands are filled in wavelength order to make life - easier in subsequent calcuations (interpolations!) + easier in subsequent calculations (interpolations!) Parameters ---------- @@ -105,12 +105,21 @@ def read_bands(self, lines, only_bands=None): if (eqpos >= 0) & (pmpos >= 0) & (line[0] != "#"): # check for reference or unit - colpos = max((line.find(";"), line.find("#"), line.find("mJy"))) + colpos = max( + ( + line.find(";"), + line.find("#"), + line.find("mJy"), + line.find("ABmag"), + ) + ) if colpos == -1: colpos = len(line) # if there is both a reference and a unit - elif line.find(";") != -1 and line.find("mJy") != -1: - colpos = min(line.find(";"), line.find("mJy")) + elif line.find(";") != -1 and ( + line.find("mJy") != -1 or line.find("ABmag") != -1 + ): + colpos = min(line.find(";"), line.find("mJy"), line.find("ABmag")) band_name = line[0:eqpos].strip() save_band = False @@ -127,6 +136,8 @@ def read_bands(self, lines, only_bands=None): # units if line.find("mJy") >= 0: self.band_units[band_name] = "mJy" + elif line.find("ABmag") >= 0: + self.band_units[band_name] = "ABmag" else: self.band_units[band_name] = "mag" @@ -479,6 +490,28 @@ def get_band_fluxes(self): 0.5 * (_flux2 - _flux1), ) self.band_waves[pband_name] = poss_bands[pband_name][1] + elif _mag_vals[2] == "ABmag": + _flux1_nu = np.power( + 10.0, (-0.4 * (_mag_vals[0] + _mag_vals[1] + 48.60)) + ) + _flux1_nu *= u.erg / (u.cm * u.cm * u.s * u.Hz) + _flux1 = _flux1_nu.to( + fluxunit, + equivalencies=u.spectral_density(poss_bands[pband_name][1] * u.micron), + ) + _flux2_nu = np.power( + 10.0, (-0.4 * (_mag_vals[0] - _mag_vals[1] + 48.60)) + ) + _flux2_nu *= u.erg / (u.cm * u.cm * u.s * u.Hz) + _flux2 = _flux2_nu.to( + fluxunit, + equivalencies=u.spectral_density(poss_bands[pband_name][1] * u.micron), + ) + self.band_fluxes[pband_name] = ( + 0.5 * (_flux1.value + _flux2.value), + 0.5 * (_flux2.value - _flux1.value), + ) + self.band_waves[pband_name] = poss_bands[pband_name][1] elif _mag_vals[2] == "mJy": self.band_waves[pband_name] = poss_bands[pband_name][1] mfac = ( diff --git a/measure_extinction/utils/merge_stis_spec.py b/measure_extinction/utils/merge_stis_spec.py index 0c541cb..c33e367 100644 --- a/measure_extinction/utils/merge_stis_spec.py +++ b/measure_extinction/utils/merge_stis_spec.py @@ -56,6 +56,8 @@ def read_stis_archive_format(filename): if args.ralph: sfilename = "%s/%s/%s.mrg" % (args.inpath, args.waveregion, args.starname) + sfilename = f"{args.inpath}{args.starname}.mrg" + # determine the line for the 1st data (can vary between files) f = open(sfilename, "r") From 805180707526a31d4a3e6e72dc8c9be857e5fdc5 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Mon, 9 Sep 2024 17:04:37 -0400 Subject: [PATCH 6/9] fixing high teff in WD hubeny grid --- measure_extinction/utils/make_all_tlusty_obsdata.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/measure_extinction/utils/make_all_tlusty_obsdata.py b/measure_extinction/utils/make_all_tlusty_obsdata.py index acc8103..3875c22 100644 --- a/measure_extinction/utils/make_all_tlusty_obsdata.py +++ b/measure_extinction/utils/make_all_tlusty_obsdata.py @@ -77,7 +77,10 @@ def decode_params_wd(filename): model_params["Teff"] = float(filename[tpos + 1 : gpos]) model_params["logg"] = float(filename[gpos + 1 : periodpos - 1]) * 0.01 model_params["vturb"] = 0.0 - model_params["Z"] = 0.0 + model_params["Z"] = 1.0 # ratio to solar + + if model_params["Teff"] < 10000.0: + model_params["Teff"] *= 1000.0 return model_params From d2117efb0557da316afb870436a5e1f7d4077eaf Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Tue, 10 Sep 2024 10:39:19 -0400 Subject: [PATCH 7/9] fixing another bug in the likelihood --- measure_extinction/utils/fit_model.py | 9 ++++++--- measure_extinction/utils/make_all_tlusty_obsdata.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/measure_extinction/utils/fit_model.py b/measure_extinction/utils/fit_model.py index 6967d77..1911b68 100755 --- a/measure_extinction/utils/fit_model.py +++ b/measure_extinction/utils/fit_model.py @@ -70,6 +70,7 @@ def lnlike(self, params, obsdata, modeldata): fits the model. Parameters + `` ---------- params : floats parameters of the model @@ -99,10 +100,12 @@ def lnlike(self, params, obsdata, modeldata): gvals = (self.weights[cspec] > 0) & (np.isfinite(hi_ext_modsed[cspec])) chiarr = np.square( ( - obsdata.data[cspec].fluxes[gvals].value - - (hi_ext_modsed[cspec][gvals] * (norm_data / norm_model)) + ( + obsdata.data[cspec].fluxes[gvals].value + - (hi_ext_modsed[cspec][gvals] * (norm_data / norm_model)) + ) + * self.weights[cspec][gvals] ) - * self.weights[cspec][gvals] ) lnl += -0.5 * np.sum(chiarr) diff --git a/measure_extinction/utils/make_all_tlusty_obsdata.py b/measure_extinction/utils/make_all_tlusty_obsdata.py index 3875c22..066b13d 100644 --- a/measure_extinction/utils/make_all_tlusty_obsdata.py +++ b/measure_extinction/utils/make_all_tlusty_obsdata.py @@ -80,7 +80,7 @@ def decode_params_wd(filename): model_params["Z"] = 1.0 # ratio to solar if model_params["Teff"] < 10000.0: - model_params["Teff"] *= 1000.0 + model_params["Teff"] *= 100.0 return model_params From a54ffbc1b613fc0b620945fc18af1179e38aa894 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Thu, 12 Sep 2024 14:51:36 -0400 Subject: [PATCH 8/9] codestyle/typos fix --- docs/index.rst | 4 ++-- measure_extinction/utils/fit_model.py | 16 ++++++++-------- measure_extinction/utils/merge_stis_spec.py | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 6e5c5f3..97d83d2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -50,13 +50,13 @@ trace if it is necessary. Contributing ============ -Like the `Astropy`_ project, ``dust_extinction`` is made both by and for its +Like the `Astropy`_ project, ``measure_extinction`` is made both by and for its users. We accept contributions at all levels, spanning the gamut from fixing a typo in the documentation to developing a major new feature. We welcome contributors who will abide by the `Python Software Foundation Code of Conduct `_. -``dust_extinction`` follows the same workflow and coding guidelines as +``measure_extinction`` follows the same workflow and coding guidelines as `Astropy`_. Take a look at the astropy `developer `_ documentation for guidelines. diff --git a/measure_extinction/utils/fit_model.py b/measure_extinction/utils/fit_model.py index 1911b68..4389260 100755 --- a/measure_extinction/utils/fit_model.py +++ b/measure_extinction/utils/fit_model.py @@ -241,14 +241,14 @@ def get_best_fit_params(sampler): (indxs,) = np.where(sampler.lnprobability[k] == tmax_lnp) fit_params_best = sampler.chain[k, indxs[0], :] - ndim = len(fit_params_best) - params_best = np.zeros((ndim + 3)) - params_best[0:ndim] = fit_params_best - params_best[ndim] = params_best[3] / params_best[4] - params_best[ndim + 1] = (10 ** params_best[10]) / params_best[3] - params_best[ndim + 2] = (10 ** params_best[10]) / params_best[ndim] - - return params_best + #ndim = len(fit_params_best) + #params_best = np.zeros((ndim + 3)) + #params_best[0:ndim] = fit_params_best + #params_best[ndim] = params_best[3] / params_best[4] + #params_best[ndim + 1] = (10 ** params_best[10]) / params_best[3] + #params_best[ndim + 2] = (10 ** params_best[10]) / params_best[ndim] + + return fit_params_best def get_percentile_params(samples): diff --git a/measure_extinction/utils/merge_stis_spec.py b/measure_extinction/utils/merge_stis_spec.py index c33e367..93bc27e 100644 --- a/measure_extinction/utils/merge_stis_spec.py +++ b/measure_extinction/utils/merge_stis_spec.py @@ -58,7 +58,6 @@ def read_stis_archive_format(filename): sfilename = "%s/%s/%s.mrg" % (args.inpath, args.waveregion, args.starname) sfilename = f"{args.inpath}{args.starname}.mrg" - # determine the line for the 1st data (can vary between files) f = open(sfilename, "r") k = 0 From ac6280e9a0cc25a39a1f713389cc2e24ebcef334 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Thu, 12 Sep 2024 14:58:22 -0400 Subject: [PATCH 9/9] codestyle error --- measure_extinction/utils/fit_model.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/measure_extinction/utils/fit_model.py b/measure_extinction/utils/fit_model.py index 4389260..76cc9bb 100755 --- a/measure_extinction/utils/fit_model.py +++ b/measure_extinction/utils/fit_model.py @@ -241,12 +241,12 @@ def get_best_fit_params(sampler): (indxs,) = np.where(sampler.lnprobability[k] == tmax_lnp) fit_params_best = sampler.chain[k, indxs[0], :] - #ndim = len(fit_params_best) - #params_best = np.zeros((ndim + 3)) - #params_best[0:ndim] = fit_params_best - #params_best[ndim] = params_best[3] / params_best[4] - #params_best[ndim + 1] = (10 ** params_best[10]) / params_best[3] - #params_best[ndim + 2] = (10 ** params_best[10]) / params_best[ndim] + # ndim = len(fit_params_best) + # params_best = np.zeros((ndim + 3)) + # params_best[0:ndim] = fit_params_best + # params_best[ndim] = params_best[3] / params_best[4] + # params_best[ndim + 1] = (10 ** params_best[10]) / params_best[3] + # params_best[ndim + 2] = (10 ** params_best[10]) / params_best[ndim] return fit_params_best