Commit 8ec3987e authored by Médéric Boquien's avatar Médéric Boquien

Do not store anymore the filter type as all the filters are now assumed to be...

Do not store anymore the filter type as all the filters are now assumed to be in units of energy. The conversion from photon to energy is carried out by the import procedure as needed.
parent 6eff2254
......@@ -149,14 +149,21 @@ def build_filters(base):
# The table is transposed to have table[0] containing the wavelength
# and table[1] containing the transmission.
filter_table = filter_table.transpose()
# We convert the wavelength from Å to nm.
filter_table[0] *= 0.1
# We convert to energy if needed
if filter_type == 'photon':
filter_table[1] *= filter_table[0]
elif filter_type != 'energy':
raise ValueError("Filter transmission type can only be "
"'energy' or 'photon'.")
print("Importing %s... (%s points)" % (filter_name,
filter_table.shape[1]))
new_filter = Filter(filter_name, filter_description,
filter_type, filter_table)
new_filter = Filter(filter_name, filter_description, filter_table)
# We normalise the filter and compute the effective wavelength.
# If the filter is a pseudo-filter used to compute line fluxes, it
......@@ -188,14 +195,21 @@ def build_filters_gazpar(base):
# The table is transposed to have table[0] containing the wavelength
# and table[1] containing the transmission.
filter_table = filter_table.transpose()
# We convert the wavelength from Å to nm.
filter_table[0] *= 0.1
# We convert to energy if needed
if filter_type == 'photon':
filter_table[1] *= filter_table[0]
elif filter_type != 'energy':
raise ValueError("Filter transmission type can only be "
"'energy' or 'photon'.")
print("Importing %s... (%s points)" % (filter_name,
filter_table.shape[1]))
new_filter = Filter(filter_name, filter_desc, filter_type,
filter_table)
new_filter = Filter(filter_name, filter_desc, filter_table)
# We normalise the filter and compute the effective wavelength.
# If the filter is a pseudo-filter used to compute line fluxes, it
......
......@@ -61,14 +61,12 @@ class _Filter(BASE):
name = Column(String, primary_key=True)
description = Column(String)
trans_type = Column(String)
trans_table = Column(PickleType)
effective_wavelength = Column(Float)
def __init__(self, f):
self.name = f.name
self.description = f.description
self.trans_type = f.trans_type
self.trans_table = f.trans_table
self.effective_wavelength = f.effective_wavelength
......@@ -968,8 +966,7 @@ class Database(object):
filter(_Filter.name == name).
first())
if result:
return Filter(result.name, result.description,
result.trans_type, result.trans_table,
return Filter(result.name, result.description, result.trans_table,
result.effective_wavelength)
else:
raise DatabaseLookupError(
......@@ -988,8 +985,8 @@ class Database(object):
def parse_filters(self):
"""Generator to parse the filter database."""
for filt in self.session.query(_Filter):
yield Filter(filt.name, filt.description, filt.trans_type,
filt.trans_table, filt.effective_wavelength)
yield Filter(filt.name, filt.description, filt.trans_table,
filt.effective_wavelength)
def parse_m2005(self):
"""Generator to parse the Maraston 2005 SSP database."""
......
......@@ -10,8 +10,8 @@ class Filter(object):
"""A photometric filter with associated transmission data.
"""
def __init__(self, name, description=None, trans_type=None,
trans_table=None, effective_wavelength=None):
def __init__(self, name, description=None, trans_table=None,
effective_wavelength=None):
"""Create a new filter. If the transmission type, the description
the transmission table or the effective wavelength are not specified,
their value is set to None.
......@@ -22,8 +22,6 @@ class Filter(object):
Name of the filter
description: string
Description of the filter
trans_type: string
Type of transmission table ('energy' or 'photon')
trans_table: array
trans_table[0] is the wavelength in nm,
trans_table[1] is the transmission)
......@@ -33,34 +31,15 @@ class Filter(object):
self.name = name
self.description = description
self.trans_type = trans_type
self.trans_table = trans_table
self.effective_wavelength = effective_wavelength
if self.trans_type == 'photon':
self.trans_table[1] *= self.trans_table[0]
self.trans_type = 'energy'
# Check that the trans_type is correct
@property
def trans_type(self):
return self._trans_type
@trans_type.setter
def trans_type(self, value):
if value in ['energy', 'photon']:
self._trans_type = value
else:
raise ValueError("Filter transmission type can only be "
"'energy' or 'photon'.")
def __str__(self):
"""Pretty print the filter information
"""
result = ""
result += ("Filter name: %s\n" % self.name)
result += ("Description: %s\n" % self.description)
result += ("Transmission type: %s\n" % self.trans_type)
result += ("Effective wavelength: %s nm\n" %
self.effective_wavelength)
return result
......
......@@ -29,13 +29,11 @@ def list_filters():
name='Description')
wl = Column(data=[filters[f].effective_wavelength for f in filters],
name='Effective Wavelength', unit=u.nm, format='%d')
filter_type = Column(data=[filters[f].trans_type for f in filters],
name='Type')
samples = Column(data=[filters[f].trans_table[0].size for f in filters],
name="Points")
t = Table()
t.add_columns([name, description, wl, filter_type, samples])
t.add_columns([name, description, wl, samples])
t.sort(['Effective Wavelength'])
t.pprint(max_lines=-1, max_width=-1)
......@@ -53,14 +51,21 @@ def add_filters(fnames):
# The table is transposed to have table[0] containing the
# wavelength and table[1] containing the transmission.
filter_table = filter_table.transpose()
# We convert the wavelength from Å to nm.
filter_table[0] *= 0.1
# We convert to energy if needed
if filter_type == 'photon':
filter_table[1] *= filter_table[0]
elif filter_type != 'energy':
raise ValueError("Filter transmission type can only be "
"'energy' or 'photon'.")
print("Importing {}... ({} points)".format(filter_name,
filter_table.shape[1]))
new_filter = Filter(filter_name, filter_description, filter_type,
filter_table)
new_filter = Filter(filter_name, filter_description, filter_table)
# We normalise the filter and compute the effective wavelength.
# If the filter is a pseudo-filter used to compute line fluxes, it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment