Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WD Hubeny models #123

Merged
merged 9 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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, ``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
<https://www.python.org/psf/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 <https://docs.astropy.org/en/latest/development/workflow/development_workflow.html>`_

* `Coding Guidelines <https://docs.astropy.org/en/latest/development/codeguide.html>`_

* `Developer Documentation <https://docs.astropy.org/en/latest/index_dev.html>`_
`Astropy`_. Take a look at the astropy
`developer <https://docs.astropy.org/en/latest/index_dev.html>`_ documentation for
guidelines.

For the complete list of contributors please see the `measure_extinction
contributors page on Github
Expand Down
2 changes: 1 addition & 1 deletion measure_extinction/plotting/plot_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
77 changes: 63 additions & 14 deletions measure_extinction/stardata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
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
----------
Expand All @@ -105,12 +105,21 @@

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"))

Check warning on line 122 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L122

Added line #L122 was not covered by tests
band_name = line[0:eqpos].strip()

save_band = False
Expand All @@ -127,6 +136,8 @@
# units
if line.find("mJy") >= 0:
self.band_units[band_name] = "mJy"
elif line.find("ABmag") >= 0:
self.band_units[band_name] = "ABmag"

Check warning on line 140 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L140

Added line #L140 was not covered by tests
else:
self.band_units[band_name] = "mag"

Expand Down Expand Up @@ -183,32 +194,47 @@
_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):
_wfpc2_band_zeromag_fluxes[i] = _wfpc2_photflam[i] * (
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 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):
Expand Down Expand Up @@ -464,6 +490,28 @@
0.5 * (_flux2 - _flux1),
)
self.band_waves[pband_name] = poss_bands[pband_name][1]
elif _mag_vals[2] == "ABmag":
_flux1_nu = np.power(

Check warning on line 494 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L493-L494

Added lines #L493 - L494 were not covered by tests
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(

Check warning on line 498 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L497-L498

Added lines #L497 - L498 were not covered by tests
fluxunit,
equivalencies=u.spectral_density(poss_bands[pband_name][1] * u.micron),
)
_flux2_nu = np.power(

Check warning on line 502 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L502

Added line #L502 was not covered by tests
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(

Check warning on line 506 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L505-L506

Added lines #L505 - L506 were not covered by tests
fluxunit,
equivalencies=u.spectral_density(poss_bands[pband_name][1] * u.micron),
)
self.band_fluxes[pband_name] = (

Check warning on line 510 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L510

Added line #L510 was not covered by tests
0.5 * (_flux1.value + _flux2.value),
0.5 * (_flux2.value - _flux1.value),
)
self.band_waves[pband_name] = poss_bands[pband_name][1]

Check warning on line 514 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L514

Added line #L514 was not covered by tests
elif _mag_vals[2] == "mJy":
self.band_waves[pband_name] = poss_bands[pband_name][1]
mfac = (
Expand Down Expand Up @@ -821,9 +869,10 @@
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="./"):
"""
Expand Down
23 changes: 13 additions & 10 deletions measure_extinction/utils/fit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
fits the model.

Parameters
``
----------
params : floats
parameters of the model
Expand Down Expand Up @@ -99,10 +100,12 @@
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)

Expand Down Expand Up @@ -238,14 +241,14 @@
(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 params_best
return fit_params_best

Check warning on line 251 in measure_extinction/utils/fit_model.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/fit_model.py#L251

Added line #L251 was not covered by tests


def get_percentile_params(samples):
Expand Down
50 changes: 46 additions & 4 deletions measure_extinction/utils/make_all_tlusty_obsdata.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -61,20 +62,61 @@
return model_params


def decode_params_wd(filename):
"""
Decode the tlusty filenames for the model parameters
"""
model_params = {}

Check warning on line 69 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L69

Added line #L69 was not covered by tests

slashpos = filename.rfind("/")
periodpos = filename.rfind(".spec")

Check warning on line 72 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L71-L72

Added lines #L71 - L72 were not covered by tests

tpos = filename.find("t", slashpos)
gpos = filename.find("g", slashpos)

Check warning on line 75 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L74-L75

Added lines #L74 - L75 were not covered by tests

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"] = 1.0 # ratio to solar

Check warning on line 80 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L77-L80

Added lines #L77 - L80 were not covered by tests

if model_params["Teff"] < 10000.0:
model_params["Teff"] *= 100.0

Check warning on line 83 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L82-L83

Added lines #L82 - L83 were not covered by tests

return model_params

Check warning on line 85 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L85

Added line #L85 was not covered by tests


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(

Check warning on line 92 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L91-L92

Added lines #L91 - L92 were not covered by tests
"--grid",
choices=["tlusty", "wd_hubeny"],
default="tlusty",
help="Grid to use",
)
args = parser.parse_args()

Check warning on line 98 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L98

Added line #L98 was not covered by tests

if args.grid == "wd_hubeny":
mfilestr = "/home/kgordon/Python/extstar_data/Models/WD_Hubeny/*.spec"
decodefunc = decode_params_wd
outbase = "wd_hubeny"

Check warning on line 103 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L100-L103

Added lines #L100 - L103 were not covered by tests
else:
mfilestr = "/home/kgordon/Python/extstar_data/Models/Tlusty_2023/*v10.spec.gz"
decodefunc = decode_params
outbase = "tlusty"

Check warning on line 107 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L105-L107

Added lines #L105 - L107 were not covered by tests

tlusty_models = glob.glob(mfilestr)

Check warning on line 109 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L109

Added line #L109 was not covered by tests

for cfname in tlusty_models:
# parse the filename to get the model parameters
model_params = decode_params(cfname)
model_params = decodefunc(cfname)

Check warning on line 113 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L113

Added line #L113 was not covered by tests

# 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]}"

Check warning on line 119 in measure_extinction/utils/make_all_tlusty_obsdata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/make_all_tlusty_obsdata.py#L119

Added line #L119 was not covered by tests

print(cfname)
print(basename)
Expand Down
2 changes: 2 additions & 0 deletions measure_extinction/utils/make_obsdata_from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions measure_extinction/utils/merge_stis_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

if args.ralph:
sfilename = "%s/%s/%s.mrg" % (args.inpath, args.waveregion, args.starname)
sfilename = f"{args.inpath}{args.starname}.mrg"

Check warning on line 59 in measure_extinction/utils/merge_stis_spec.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/utils/merge_stis_spec.py#L59

Added line #L59 was not covered by tests

# determine the line for the 1st data (can vary between files)
f = open(sfilename, "r")
Expand Down
Loading