Skip to content

Commit

Permalink
adding in selective reading of bands
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Feb 21, 2024
1 parent 8bed087 commit 7af872e
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions measure_extinction/stardata.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, type):
self.band_waves = OrderedDict()
self.band_fluxes = OrderedDict()

def read_bands(self, lines):
def read_bands(self, lines, only_bands=None):
"""
Read the photometric band data from a DAT file
and upate class variables.
Expand All @@ -92,6 +92,8 @@ def read_bands(self, lines):
----------
lines : list of string
lines from a DAT formatted file
only_bands : list
Only read in the bands given
Returns
-------
Expand All @@ -110,15 +112,23 @@ def read_bands(self, lines):
elif line.find(";") != -1 and line.find("mJy") != -1:
colpos = min(line.find(";"), line.find("mJy"))
band_name = line[0:eqpos].strip()
self.bands[band_name] = (
float(line[eqpos + 1 : pmpos]),
float(line[pmpos + 3 : colpos]),
)
# units
if line.find("mJy") >= 0:
self.band_units[band_name] = "mJy"

save_band = False
if (only_bands is None):
save_band = True
else:
self.band_units[band_name] = "mag"
if band_name in only_bands:
save_band = True

Check warning on line 121 in measure_extinction/stardata.py

View check run for this annotation

Codecov / codecov/patch

measure_extinction/stardata.py#L120-L121

Added lines #L120 - L121 were not covered by tests
if save_band:
self.bands[band_name] = (
float(line[eqpos + 1 : pmpos]),
float(line[pmpos + 3 : colpos]),
)
# units
if line.find("mJy") >= 0:
self.band_units[band_name] = "mJy"
else:
self.band_units[band_name] = "mag"

self.n_bands = len(self.bands)

Expand Down Expand Up @@ -934,7 +944,8 @@ class StarData:
"""

def __init__(
self, datfile, path="", photonly=False, use_corfac=True, deredden=False
self, datfile, path="", photonly=False, use_corfac=True, deredden=False,
only_bands=None,
):
"""
Parameters
Expand All @@ -955,6 +966,9 @@ def __init__(
deredden : boolean [default=False]
Deredden the data based on dereddening parameters given in the DAT file.
Generally used to deredden standards.
only_bands : list
Only read in the bands given
"""
self.file = datfile
self.path = path
Expand All @@ -969,9 +983,9 @@ def __init__(
self.dereddened = deredden

if self.file is not None:
self.read(deredden=deredden)
self.read(deredden=deredden, only_bands=only_bands)

def read(self, deredden=False):
def read(self, deredden=False, only_bands=None):
"""
Populate the object from a DAT file + spectral files
Expand All @@ -980,6 +994,8 @@ def read(self, deredden=False):
deredden : boolean [default=False]
Deredden the data based on dereddening parameters given in the DAT file.
Generally used to deredden standards.
only_bands : list
Only read in the bands given
"""

# open and read all the lines in the file
Expand All @@ -988,7 +1004,7 @@ def read(self, deredden=False):
f.close()
# get the photometric band data
self.data["BAND"] = BandData("BAND")
self.data["BAND"].read_bands(self.datfile_lines)
self.data["BAND"].read_bands(self.datfile_lines, only_bands=only_bands)

# covert the photoemtric band data to fluxes in all possible bands
self.data["BAND"].get_band_fluxes()
Expand Down

0 comments on commit 7af872e

Please sign in to comment.