...
 
Commits (13)
This diff is collapsed.
...@@ -277,7 +277,7 @@ def build_m2005(base): ...@@ -277,7 +277,7 @@ def build_m2005(base):
spec_table = spec_table[1:] spec_table = spec_table[1:]
# Extract the wavelength and convert from Å to nm # Extract the wavelength and convert from Å to nm
ssp_wave = spec_table[0][:1221] * 0.1 ssp_wave = spec_table[0][:14501] * 0.1
spec_table = spec_table[1:] spec_table = spec_table[1:]
# Extra the fluxes and convert from erg/s/Å to W/nm # Extra the fluxes and convert from erg/s/Å to W/nm
...@@ -299,18 +299,21 @@ def build_m2005(base): ...@@ -299,18 +299,21 @@ def build_m2005(base):
# To avoid the creation of waves when interpolating, we refine the grid # To avoid the creation of waves when interpolating, we refine the grid
# beyond 10 μm following a log scale in wavelength. The interpolation # beyond 10 μm following a log scale in wavelength. The interpolation
# is also done in log space as the spectrum is power-law-like # is also done in log space as the spectrum is power-law-like
ssp_wave_resamp = np.around(np.logspace(np.log10(10000), #ssp_wave_resamp = np.around(np.logspace(np.log10(10000),
np.log10(160000), 50)) #np.log10(160000), 50))
argmin = np.argmin(10000.-ssp_wave > 0)-1 #argmin = np.argmin(10000.-ssp_wave > 0)-1
ssp_lumin_resamp = 10.**interpolate.interp1d( #ssp_lumin_resamp = 10.**interpolate.interp1d(
np.log10(ssp_wave[argmin:]), #np.log10(ssp_wave[argmin:]),
np.log10(ssp_lumin_interp[argmin:, :]), #np.log10(ssp_lumin_interp[argmin:, :]),
assume_sorted=True, #assume_sorted=True,
axis=0)(np.log10(ssp_wave_resamp)) #axis=0)(np.log10(ssp_wave_resamp))
ssp_wave = np.hstack([ssp_wave[:argmin+1], ssp_wave_resamp]) #ssp_wave = np.hstack([ssp_wave[:argmin+1], ssp_wave_resamp])
ssp_lumin = np.vstack([ssp_lumin_interp[:argmin+1, :], #ssp_lumin = np.vstack([ssp_lumin_interp[:argmin+1, :],
ssp_lumin_resamp]) #ssp_lumin_resamp])
ssp_wave = ssp_wave
ssp_lumin = ssp_lumin_interp
# Use Z value for metallicity, not log([Z/H]) # Use Z value for metallicity, not log([Z/H])
metallicity = {-1.35: 0.001, metallicity = {-1.35: 0.001,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -83,7 +83,6 @@ class _M2005(BASE): ...@@ -83,7 +83,6 @@ class _M2005(BASE):
time_grid = Column(PickleType) time_grid = Column(PickleType)
wavelength_grid = Column(PickleType) wavelength_grid = Column(PickleType)
info_table = Column(PickleType) info_table = Column(PickleType)
spec_table = Column(PickleType)
def __init__(self, ssp): def __init__(self, ssp):
self.imf = ssp.imf self.imf = ssp.imf
...@@ -91,7 +90,6 @@ class _M2005(BASE): ...@@ -91,7 +90,6 @@ class _M2005(BASE):
self.time_grid = ssp.time_grid self.time_grid = ssp.time_grid
self.wavelength_grid = ssp.wavelength_grid self.wavelength_grid = ssp.wavelength_grid
self.info_table = ssp.info_table self.info_table = ssp.info_table
self.spec_table = ssp.spec_table
class _BC03(BASE): class _BC03(BASE):
...@@ -329,6 +327,10 @@ class Database(object): ...@@ -329,6 +327,10 @@ class Database(object):
self.session.add(ssp) self.session.add(ssp)
try: try:
self.session.commit() self.session.commit()
# Save the spec_table to a file
filename = "m2005_%s_%s.npy" % (ssp.imf, ssp.metallicity)
filepath = pkg_resources.resource_filename(__name__, filename)
np.save(filepath, ssp_m2005.spec_table)
except exc.IntegrityError: except exc.IntegrityError:
self.session.rollback() self.session.rollback()
raise DatabaseInsertError('The SSP is already in the base.') raise DatabaseInsertError('The SSP is already in the base.')
...@@ -362,9 +364,13 @@ class Database(object): ...@@ -362,9 +364,13 @@ class Database(object):
.filter(_M2005.metallicity == metallicity)\ .filter(_M2005.metallicity == metallicity)\
.first() .first()
if result: if result:
# Load the spec_table from file
filename = "m2005_%s_%s.npy" % (result.imf, result.metallicity)
filepath = pkg_resources.resource_filename(__name__, filename)
spec_table = np.load(filepath)
return M2005(result.imf, result.metallicity, result.time_grid, return M2005(result.imf, result.metallicity, result.time_grid,
result.wavelength_grid, result.info_table, result.wavelength_grid, result.info_table,
result.spec_table) spec_table)
else: else:
raise DatabaseLookupError( raise DatabaseLookupError(
"The M2005 SSP for imf <{0}> and metallicity <{1}> is not in " "The M2005 SSP for imf <{0}> and metallicity <{1}> is not in "
......