diff --git a/docs/check.html b/docs/check.html index 8a2a488..545ba02 100644 --- a/docs/check.html +++ b/docs/check.html @@ -53,7 +53,7 @@
deeplenstronomy.check
deeplenstronomy.check
deeplenstronomy.check
deeplenstronomy.input_reader
deeplenstronomy.input_reader
deeplenstronomy.input_reader
deeplenstronomy.input_reader
configuration
: str
nites
: List[int]
nites
: List[int]
or str
objects
: List[str]
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
deeplenstronomy.timeseries
-def gen_cc(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_cc(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
Generate a SN-CC light curve
@@ -1050,8 +1184,7 @@redshift
: float
nites
: List[int]
sed
: None
or pandas.DataFrame
, optional, default=None
sed_filename
: str
def gen_cc(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_cc(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a SN-CC light curve
Args:
redshift (float): the redshift of the source
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed (None or pandas.DataFrame, optional, default=None): a dataframe containing the sed of the SN
sed_filename (str): filename containing the time-series sed you want to use
cosmo (astropy.cosmology): an astropy.cosmology instance used for distance calculations
@@ -1090,22 +1223,31 @@ Returns
"""
# If sed not specified, choose sed based on weight map
- if not sed:
- if sed_filename:
- sed = self._read_sed('seds/cc/' + sed_filename)
- else:
+ if sed is None:
+ if sed_filename is None:
sed_filename = random.choices(self.cc_sed_files, weights=self.cc_weights, k=1)[0]
+
+ if sed_filename.startswith('seds/cc/'):
+ attr_name = sed_filename.split('.')[0]
+ else:
+ attr_name = 'seds/cc/' + sed_filename.split('.')[0]
+ sed_filename = 'seds/cc/' + sed_filename
+
+ if hasattr(self, attr_name):
+ sed = getattr(self, attr_name)
+ else:
sed = self._read_sed(sed_filename)
+ setattr(self, attr_name, sed)
# Get the type of SN-CC
obj_type = self.cc_info_df['SNTYPE'].values[self.cc_info_df['SED'].values == sed_filename.split('/')[-1].split('.')[0]][0]
# Trigger the lc generation function on this sed
- return self.gen_lc_from_sed(redshift, nites, sed, obj_type, sed_filename, cosmo=cosmo)
+ return self.gen_lc_from_sed(redshift, nite_dict, sed, obj_type, sed_filename, cosmo=cosmo)
-def gen_flat(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_flat(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
Generate a random flat light curve.
@@ -1113,8 +1255,7 @@redshift
: float
nites
: List[int]
sed_filename
: str
cosmo
: astropy.cosmology
def gen_flat(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_flat(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a random flat light curve.
Args:
redshift (float): ignored
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename (str): ignored
cosmo (astropy.cosmology): ignored
@@ -1152,8 +1293,8 @@ Returns
central_mag = random.uniform(12.0, 23.0)
mags = {band: mag for band, mag in zip(self.bands, central_mag + np.random.uniform(low=-2.0, high=2.0, size=len(self.bands)))}
output_data = []
- for nite in nites:
- for band in self.bands:
+ for band in self.bands:
+ for nite in nite_dict[band]:
output_data.append([nite, band, mags[band]])
return {'lc': pd.DataFrame(data=output_data, columns=output_data_cols),
@@ -1162,7 +1303,7 @@ Returns
-def gen_flatnoise(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_flatnoise(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Generate a flat light curve will small random noise
@@ -1170,8 +1311,7 @@ Args
redshift
: float
- ignored
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename
: str
- ignored
cosmo
: astropy.cosmology
@@ -1189,13 +1329,13 @@ Returns
Expand source code
-def gen_flatnoise(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_flatnoise(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a flat light curve will small random noise
Args:
redshift (float): ignored
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename (str): ignored
cosmo (astropy.cosmology): ignored
@@ -1205,7 +1345,7 @@ Returns
- 'obj_type' contains a string for the type of object. Will always be 'FlatNoise' here
- 'sed' contains the filename of the sed used. Will always be 'FlatNoise' here
"""
- noiseless_lc_dict = self.gen_flat(redshift, nites)
+ noiseless_lc_dict = self.gen_flat(redshift, nite_dict)
noise = np.random.normal(loc=0, scale=0.25, size=noiseless_lc_dict['lc'].shape[0])
noiseless_lc_dict['lc']['MAG'] = noiseless_lc_dict['lc']['MAG'].values + noise
noiseless_lc_dict['obj_type'] = 'FlatNoise'
@@ -1214,7 +1354,7 @@ Returns
-def gen_ia(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_ia(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Generate a SN-Ia light curve.
@@ -1222,8 +1362,7 @@ Args
redshift
: float
- the redshift of the source
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed
: None
or pandas.DataFrame
, optional, default=None
- a dataframe containing the sed of the SN
sed_filename
: str
@@ -1243,14 +1382,13 @@ Returns
Expand source code
-def gen_ia(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_ia(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a SN-Ia light curve.
-
Args:
redshift (float): the redshift of the source
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed (None or pandas.DataFrame, optional, default=None): a dataframe containing the sed of the SN
sed_filename (str): filename containing the time-series sed you want to use
cosmo (astropy.cosmology): an astropy.cosmology instance used for distance calculations
@@ -1263,19 +1401,28 @@ Returns
"""
# Read rest-frame sed if not supplied as argument
- if not sed:
- if sed_filename:
- sed = self._read_sed('seds/ia/' + sed_filename)
- else:
+ if sed is None:
+ if sed_filename is None:
sed_filename = random.choice(self.ia_sed_files)
+
+ if sed_filename.startswith('seds/ia/'):
+ attr_name = sed_filename.split('.')[0]
+ else:
+ attr_name = 'seds/ia/' + sed_filename.split('.')[0]
+ sed_filename = 'seds/ia/' + sed_filename
+
+ if hasattr(self, attr_name):
+ sed = getattr(self, attr_name)
+ else:
sed = self._read_sed(sed_filename)
+ setattr(self, attr_name, sed)
# Trigger the lc generation function on this sed
- return self.gen_lc_from_sed(redshift, nites, sed, 'Ia', sed_filename, cosmo=cosmo)
+ return self.gen_lc_from_sed(redshift, nite_dict, sed, 'Ia', sed_filename, cosmo=cosmo)
-def gen_kn(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_kn(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Generate a GW170817-like light curve.
@@ -1283,8 +1430,7 @@ Args
redshift
: float
- the redshift of the source
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed
: None
or pandas.DataFrame
, optional, default=None
- a dataframe containing the sed of the SN
sed_filename
: str
@@ -1304,13 +1450,13 @@ Returns
Expand source code
-def gen_kn(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_kn(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a GW170817-like light curve.
Args:
redshift (float): the redshift of the source
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed (None or pandas.DataFrame, optional, default=None): a dataframe containing the sed of the SN
sed_filename (str): filename containing the time-series sed you want to use
cosmo (astropy.cosmology): an astropy.cosmology instance used for distance calculations
@@ -1323,14 +1469,19 @@ Returns
"""
sed_filename = 'seds/kn/kn.SED'
- if not sed:
- sed = self._read_sed(sed_filename)
-
- return self.gen_lc_from_sed(redshift, nites, sed, 'KN', sed_filename, cosmo=cosmo)
+ if sed is None:
+ attr_name = sed_filename.split('.')[0]
+ if hasattr(self, attr_name):
+ sed = getattr(self, attr_name)
+ else:
+ sed = self._read_sed(sed_filename)
+ setattr(self, attr_name, sed)
+
+ return self.gen_lc_from_sed(redshift, nite_dict, sed, 'KN', sed_filename, cosmo=cosmo)
-def gen_lc_from_sed(self, redshift, nites, sed, obj_type, sed_filename, cosmo=None)
+def gen_lc_from_sed(self, redshift, nite_dict, sed, obj_type, sed_filename, cosmo=None)
-
Generate a light curve based on a time-series sed.
@@ -1338,8 +1489,7 @@ Args
redshift
: float
- the redshift of the source
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed
: None
or pandas.DataFrame
, optional, default=None
- a dataframe containing the sed of the SN
sed_filename
: str
@@ -1359,13 +1509,13 @@ Returns
Expand source code
-def gen_lc_from_sed(self, redshift, nites, sed, obj_type, sed_filename, cosmo=None):
+def gen_lc_from_sed(self, redshift, nite_dict, sed, obj_type, sed_filename, cosmo=None):
"""
Generate a light curve based on a time-series sed.
Args:
redshift (float): the redshift of the source
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed (None or pandas.DataFrame, optional, default=None): a dataframe containing the sed of the SN
sed_filename (str): filename containing the time-series sed you want to use
cosmo (astropy.cosmology): an astropy.cosmology instance used for distance calculations
@@ -1377,15 +1527,17 @@ Returns
- 'sed' contains the filename of the sed used
"""
- # If nite not in the sed, set nite to the closest nite in the sed
- useable_nites = []
+ # Adjust nites
+ nites = {}
sed_nites = np.unique(sed['NITE'].values)
- for nite in nites:
- if nite not in sed_nites:
- useable_nites.append(self._get_closest_nite(sed_nites, nite))
- else:
- useable_nites.append(nite)
- nites = useable_nites
+ for band, cad_nites in nite_dict.items():
+ useable_nites = []
+ for nite in cad_nites:
+ if nite not in sed_nites:
+ useable_nites.append(self._get_closest_nite(sed_nites, nite))
+ else:
+ useable_nites.append(nite)
+ nites[band] = useable_nites
# Redshift the sed frequencies and wavelengths
sed['WAVELENGTH_OBS'] = (1.0 + redshift) * sed['WAVELENGTH_REST'].values
@@ -1398,37 +1550,37 @@ Returns
distance_modulus = self._get_distance_modulus(redshift, cosmo=cosmo)
# Calculate k-correction at peak
- peak_sed = sed[sed['NITE'].values == self._get_closest_nite(np.unique(sed['NITE'].values), 0)].copy().reset_index(drop=True)
- k_corrections = [self._get_kcorrect(peak_sed, band, redshift) for band in self.bands]
+ k_corrections = self._get_kcorrections(sed, sed_filename, redshift)
# On each nite, in each band, calculate the absolute mag
output_data = []
output_data_cols = ['NITE', 'BAND', 'MAG']
- for nite in nites:
- nite_sed = sed[sed['NITE'].values == nite].copy().reset_index(drop=True)
-
- # Apply factors to calculate absolute mag
- nite_sed['FLUX'] = (cosmo.luminosity_distance(redshift).value * 10 ** 6 / 10) ** 2 / (1 + redshift) * nite_sed['FLUX'].values
- nite_sed['FREQUENCY_REST'] = nite_sed['FREQUENCY_REST'].values / (1. + redshift)
-
- # Convert to AB Magnitude system
- norm_sed = nite_sed.copy()
- norm_sed['FLUX'] = 3631.0
+
+ for band, k_correction in zip(self.bands, k_corrections):
- for band, k_correction in zip(self.bands, k_corrections):
+ for nite in nites[band]:
+ nite_sed = sed[sed['NITE'].values == nite].copy().reset_index(drop=True)
+
+ # Flux is zero if requested nite is noe in sed
+ if len(nite_sed) == 0:
+ output_data.append([nite, band, 99.0])
+ continue
+ # Apply factors to calculate absolute mag
+ nite_sed['FLUX'] = (cosmo.luminosity_distance(redshift).value * 10 ** 6 / 10) ** 2 / (1 + redshift) * nite_sed['FLUX'].values
+ nite_sed['FREQUENCY_REST'] = nite_sed['FREQUENCY_REST'].values / (1. + redshift)
+
# Calculate the apparent magnitude
- norm = self._integrate_through_band(norm_sed, band, redshift, frame='REST')
- absolute_ab_mag = self._integrate_through_band(nite_sed, band, redshift, frame='REST') / norm
+ absolute_ab_mag = self._integrate_through_band(nite_sed, band, redshift, frame='REST') / self.norm_dict[band]
output_data.append([nite, band, -2.5 * np.log10(absolute_ab_mag) + distance_modulus + k_correction])
- return {'lc': pd.DataFrame(data=output_data, columns=output_data_cols).replace(np.nan, 30.0, inplace=False),
+ return {'lc': pd.DataFrame(data=output_data, columns=output_data_cols).replace(np.nan, 99.0, inplace=False),
'obj_type': obj_type,
'sed': sed_filename}
-def gen_static(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_static(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Make a static source capable of having time-series data by introducing a mag=99 source
@@ -1437,8 +1589,7 @@
Args
redshift
: float
- ignored
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename
: str
- ignored
@@ -1458,27 +1609,28 @@ Returns
Expand source code
-def gen_static(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_static(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Make a static source capable of having time-series data by introducing a mag=99 source
on each NITE of the simulation.
Args:
redshift (float): ignored
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename (str): ignored
cosmo (astropy.cosmology): ignored
Returns:
lc_dict: a dictionary with keys ['lc, 'obj_type', 'sed']
- 'lc' contains a dataframe of the light from the object
- 'obj_type' contains a string for the type of object. Will always be 'Static' here
- - 'sed' contains the filename of the sed used. Will always be 'Flat' here """
+ - 'sed' contains the filename of the sed used. Will always be 'Flat' here
+ """
output_data_cols = ['NITE', 'BAND', 'MAG']
central_mag = 99.0
mags = {band: central_mag for band in self.bands}
output_data = []
- for nite in nites:
- for band in self.bands:
+ for band in self.bands:
+ for nite in nite_dict[band]:
output_data.append([nite, band, mags[band]])
return {'lc': pd.DataFrame(data=output_data, columns=output_data_cols),
@@ -1487,7 +1639,7 @@ Returns
-def gen_user(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_user(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Generate a light curve from a user-specidied SED
@@ -1495,8 +1647,7 @@ Args
redshift
: float
- the redshift of the source
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed
: None
or pandas.DataFrame
, optional, default=None
- a dataframe containing the sed of the SN
sed_filename
: str
@@ -1516,13 +1667,13 @@ Returns
Expand source code
-def gen_user(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_user(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a light curve from a user-specidied SED
Args:
redshift (float): the redshift of the source
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed (None or pandas.DataFrame, optional, default=None): a dataframe containing the sed of the SN
sed_filename (str): filename containing the time-series sed you want to use
cosmo (astropy.cosmology): an astropy.cosmology instance used for distance calculations
@@ -1533,14 +1684,24 @@ Returns
- 'obj_type' contains a string for the type of object. Will always be <sed_filename> here
- 'sed' contains the filename of the sed used
"""
- if not sed:
- sed = self._read_sed('seds/user/' + sed_filename)
+ if sed is None:
+ if sed_filename.startswith('seds/user/'):
+ attr_name = sed_filename.split('.')[0]
+ else:
+ attr_name = 'seds/user/' + sed_filename.split('.')[0]
+ sed_filename = 'seds/user/' + sed_filename
+
+ if hasattr(self, attr_name):
+ sed = getattr(self, attr_name)
+ else:
+ sed = self._read_sed(sed_filename)
+ setattr(self, attr_name, sed)
- return self.gen_lc_from_sed(redshift, nites, sed, sed_filename, sed_filename, cosmo=cosmo)
+ return self.gen_lc_from_sed(redshift, nite_dict, sed, sed_filename, sed_filename, cosmo=cosmo)
-def gen_variable(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_variable(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Generate a random variable light curve
@@ -1548,9 +1709,7 @@ Args
redshift
: float
- ignored
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
-
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename
: str
- ignored
cosmo
: astropy.cosmology
@@ -1569,13 +1728,13 @@ Returns
Expand source code
-def gen_variable(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_variable(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a random variable light curve
Args:
redshift (float): ignored
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename (str): ignored
cosmo (astropy.cosmology): ignored
@@ -1589,9 +1748,9 @@ Returns
output_data = []
central_mag = random.uniform(12.0, 23.0)
colors = {band: mag for band, mag in zip(self.bands, np.random.uniform(low=-2.0, high=2.0, size=len(self.bands)))}
- for nite in nites:
- central_mag = random.uniform(central_mag - 1.0, central_mag + 1.0)
- for band in self.bands:
+ for band in self.bands:
+ for nite in nite_dict[band]:
+ central_mag = random.uniform(central_mag - 1.0, central_mag + 1.0)
output_data.append([nite, band, central_mag + colors[band]])
return {'lc': pd.DataFrame(data=output_data, columns=output_data_cols),
@@ -1600,7 +1759,7 @@ Returns
-def gen_variablenoise(self, redshift, nites, sed=None, sed_filename=None, cosmo=None)
+def gen_variablenoise(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None)
-
Generate a variable light curve with small random noise
@@ -1608,8 +1767,7 @@ Args
redshift
: float
- ignored
-nites
: List[int]
-- a list of night relative to peak you want to obtain a magnitude for
+- nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename
: str
- ignored
cosmo
: astropy.cosmology
@@ -1627,13 +1785,13 @@ Returns
Expand source code
-def gen_variablenoise(self, redshift, nites, sed=None, sed_filename=None, cosmo=None):
+def gen_variablenoise(self, redshift, nite_dict, sed=None, sed_filename=None, cosmo=None):
"""
Generate a variable light curve with small random noise
Args:
redshift (float): ignored
- nites (List[int]): a list of night relative to peak you want to obtain a magnitude for
+ nite_dict (dict[str: List[int]]): (band, list of night relative to peak you want to obtain a magnitude for) pair for each band in survey
sed_filename (str): ignored
cosmo (astropy.cosmology): ignored
@@ -1643,7 +1801,7 @@ Returns
- 'obj_type' contains a string for the type of object. Will always be 'VariableNoise' here
- 'sed' contains the filename of the sed used. Will always be 'VariableNoise' here
"""
- noiseless_lc_dict = self.gen_variable(redshift, nites)
+ noiseless_lc_dict = self.gen_variable(redshift, nite_dict)
noise = np.random.normal(loc=0, scale=0.25, size=noiseless_lc_dict['lc'].shape[0])
noiseless_lc_dict['lc']['MAG'] = noiseless_lc_dict['lc']['MAG'].values + noise
noiseless_lc_dict['obj_type'] = 'VariableNoise'
diff --git a/docs/utils.html b/docs/utils.html
index 85a1a3b..0328001 100644
--- a/docs/utils.html
+++ b/docs/utils.html
@@ -31,6 +31,7 @@ Module deeplenstronomy.utils
import os
import sys
+import yaml
from astropy.io import fits
import numpy as np
@@ -331,7 +332,26 @@ Module deeplenstronomy.utils
image_indices = np.argmin(np.sum(np.abs(im_param_array - map_param_array) / im_stds, axis=2), axis=0)
return image_indices
-
+
+
+def read_cadence_file(filename):
+ """
+ Parse a cadence file.
+
+ Args:
+ filename (str): Name of cadence file
+
+ Returns:
+ cadence_dict: dictionary containing cadence file contents
+ """
+ with open(filename, 'r') as f:
+ cadence_dict = yaml.safe_load(f)
+
+ # Set reference mjd to the default value of 0
+ if 'REFERENCE_MJD' not in cadence_dict:
+ cadence_dict['REFERENCE_MJD'] = 0
+
+ return cadence_dict
@@ -589,6 +609,45 @@ Returns
return image_indices
+
+def read_cadence_file(filename)
+
+-
+
Parse a cadence file.
+Args
+
+filename
: str
+- Name of cadence file
+
+Returns
+
+cadence_dict
+- dictionary containing cadence file contents
+
+
+
+Expand source code
+
+def read_cadence_file(filename):
+ """
+ Parse a cadence file.
+
+ Args:
+ filename (str): Name of cadence file
+
+ Returns:
+ cadence_dict: dictionary containing cadence file contents
+ """
+ with open(filename, 'r') as f:
+ cadence_dict = yaml.safe_load(f)
+
+ # Set reference mjd to the default value of 0
+ if 'REFERENCE_MJD' not in cadence_dict:
+ cadence_dict['REFERENCE_MJD'] = 0
+
+ return cadence_dict
+
+
def read_distribution_file(filename)
@@ -871,6 +930,7 @@ Index
dict_select_choose
draw_from_user_dist
organize_image_backgrounds
+read_cadence_file
read_distribution_file
read_images
select_params
diff --git a/docs/visualize.html b/docs/visualize.html
index f72813e..18e56e1 100644
--- a/docs/visualize.html
+++ b/docs/visualize.html
@@ -32,6 +32,7 @@ Module deeplenstronomy.visualize
from astropy.visualization import make_lupton_rgb
import matplotlib.pyplot as plt
import numpy as np
+import pandas as pd
def _no_stretch(val):
return val
@@ -92,7 +93,58 @@ Module deeplenstronomy.visualize
plt.show(block=True)
plt.close()
- return
+ return
+
+def view_corner(metadata, labels, hist_kwargs={}, hist2d_kwargs={}, label_kwargs={}):
+ """
+ Show a corner plot of the columns in a DataFrame.
+
+ Args:
+ metadata (pd.DataFrame): A pandas DataFrame containing the metadata to visualize
+ labels (dict): A dictionary mapping column names to axis labels
+ hist_kwargs (dict): keyword arguments to pass to matplotlib.pyplot.hist
+ hist2d_kwargs (dict): keyword arguments to pass to matplotlib.pyplot.hist2d
+ label_kwargs (dict): keyword arguments to pass to matplotlib.axes.Axes.set_xlabel (and ylabel)
+
+ Raises:
+ KeyError: if one or more of the columns are not present in the metadata
+ TypeError: if metadata is not a pandas DataFrame
+ TypeError: if labels is not a dict
+ """
+ if not isinstance(metadata, pd.DataFrame):
+ raise TypeError("first argument must be a pandas DataFrame")
+
+ if not isinstance(labels, dict):
+ raise TypeError("second argument must be a list")
+
+ if any([x not in metadata.columns for x in labels]):
+ raise KeyError("One or more passed columns is not present in the metadata")
+
+ fig, axs = plt.subplots(len(labels), len(labels), figsize=(14,14))
+
+ for row, row_label in enumerate(labels.keys()):
+ for col, col_label in enumerate(labels.keys()):
+
+ if row == col:
+ # hist
+ axs[row, col].hist(metadata[row_label].values, **hist_kwargs)
+
+ elif row > col:
+ # hist2d
+ axs[row, col].hist2d(metadata[col_label].values,
+ metadata[row_label].values, **hist2d_kwargs)
+ else:
+ axs[row, col].set_visible(False)
+
+ if row == len(labels) -1:
+ axs[row, col].set_xlabel(labels[col_label], **label_kwargs)
+
+ if col == 0 and row != 0:
+ axs[row, col].set_ylabel(labels[row_label], **label_kwargs)
+
+ fig.tight_layout()
+ plt.show()
+ plt.close()
@@ -102,6 +154,89 @@ Module deeplenstronomy.visualize
Functions
+
+def view_corner(metadata, labels, hist_kwargs={}, hist2d_kwargs={}, label_kwargs={})
+
+-
+
Show a corner plot of the columns in a DataFrame.
+Args
+
+metadata
: pd.DataFrame
+- A pandas DataFrame containing the metadata to visualize
+labels
: dict
+- A dictionary mapping column names to axis labels
+hist_kwargs
: dict
+- keyword arguments to pass to matplotlib.pyplot.hist
+hist2d_kwargs
: dict
+- keyword arguments to pass to matplotlib.pyplot.hist2d
+label_kwargs
: dict
+- keyword arguments to pass to matplotlib.axes.Axes.set_xlabel (and ylabel)
+
+Raises
+
+KeyError
+- if one or more of the columns are not present in the metadata
+TypeError
+- if metadata is not a pandas DataFrame
+TypeError
+- if labels is not a dict
+
+
+
+Expand source code
+
+def view_corner(metadata, labels, hist_kwargs={}, hist2d_kwargs={}, label_kwargs={}):
+ """
+ Show a corner plot of the columns in a DataFrame.
+
+ Args:
+ metadata (pd.DataFrame): A pandas DataFrame containing the metadata to visualize
+ labels (dict): A dictionary mapping column names to axis labels
+ hist_kwargs (dict): keyword arguments to pass to matplotlib.pyplot.hist
+ hist2d_kwargs (dict): keyword arguments to pass to matplotlib.pyplot.hist2d
+ label_kwargs (dict): keyword arguments to pass to matplotlib.axes.Axes.set_xlabel (and ylabel)
+
+ Raises:
+ KeyError: if one or more of the columns are not present in the metadata
+ TypeError: if metadata is not a pandas DataFrame
+ TypeError: if labels is not a dict
+ """
+ if not isinstance(metadata, pd.DataFrame):
+ raise TypeError("first argument must be a pandas DataFrame")
+
+ if not isinstance(labels, dict):
+ raise TypeError("second argument must be a list")
+
+ if any([x not in metadata.columns for x in labels]):
+ raise KeyError("One or more passed columns is not present in the metadata")
+
+ fig, axs = plt.subplots(len(labels), len(labels), figsize=(14,14))
+
+ for row, row_label in enumerate(labels.keys()):
+ for col, col_label in enumerate(labels.keys()):
+
+ if row == col:
+ # hist
+ axs[row, col].hist(metadata[row_label].values, **hist_kwargs)
+
+ elif row > col:
+ # hist2d
+ axs[row, col].hist2d(metadata[col_label].values,
+ metadata[row_label].values, **hist2d_kwargs)
+ else:
+ axs[row, col].set_visible(False)
+
+ if row == len(labels) -1:
+ axs[row, col].set_xlabel(labels[col_label], **label_kwargs)
+
+ if col == 0 and row != 0:
+ axs[row, col].set_ylabel(labels[row_label], **label_kwargs)
+
+ fig.tight_layout()
+ plt.show()
+ plt.close()
+
+
def view_image(image, stretch_func=<function _no_stretch>, **imshow_kwargs)
@@ -215,6 +350,7 @@ Index
Functions