-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from lephare-photoz/issue/74/consolidate-infor…
…mer-steps Started work on inform stage and yaml config stuff
- Loading branch information
Showing
103 changed files
with
128,970 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import datetime | ||
import os | ||
|
||
import yaml | ||
|
||
import lephare as lp | ||
|
||
__all__ = ["prepare", "overwrite_config", "read_yaml_config", "write_yaml_config", "write_para_config"] | ||
|
||
|
||
def prepare(config, star_config=None, gal_config=None, qso_config=None): | ||
"""Run the prepare stages of LePHARE | ||
In order to run "zphota" we must create the filter files, run sedtolib to | ||
create the SED libraries, and finally run mag_gal, to create the | ||
magnitude libararies. We abstract these tasks into a single prepare stage. | ||
We overide the config for each type if distinct config set. If no overide | ||
configs are set we use the same for each type. | ||
Parameters | ||
========== | ||
config : dict of lephare.keyword | ||
The config base to run all tasks | ||
star_config : dict of lephare.keyword or None | ||
Config values to override for stars | ||
gal_config : dict of lephare.keyword or None | ||
Config values to override for galaxies | ||
qso_config : dict of lephare.keyword or None | ||
Config values to override for QSO. | ||
""" | ||
object_types = {"STAR": star_config, "GAL": gal_config, "QSO": qso_config} | ||
# Run the filter command | ||
# load filters from config | ||
filter_lib = lp.FilterSvc.from_keymap(config) | ||
# Get location to store filter files | ||
filter_output = os.path.join(os.environ["LEPHAREWORK"], "filt", config["FILTER_FILE"].value) | ||
# Write filter files | ||
lp.write_output_filter(filter_output + ".dat", filter_output + ".doc", filter_lib) | ||
# # Write config to work directory | ||
write_yaml_config(config, f"{filter_output}_config.yaml") | ||
|
||
for object_type in object_types: | ||
updated_config = overwrite_config(config, object_types[object_type]) | ||
# Write the updated config | ||
sed_out_name = f"{updated_config[f'{object_type}_LIB'].value}_{object_type.lower()}_config.yaml" | ||
sed_output = os.path.join(os.environ["LEPHAREWORK"], "lib_bin", sed_out_name) | ||
mag_out_name = f"{updated_config[f'{object_type}_LIB_OUT'].value}_{object_type.lower()}_config.yaml" | ||
mag_output = os.path.join(os.environ["LEPHAREWORK"], "lib_mag", mag_out_name) | ||
# Run sedtolib | ||
sedlib = lp.Sedtolib(config_keymap=updated_config) | ||
list_loc = os.path.join(lp.LEPHAREDIR, updated_config[f"{object_type}_SED"].value) | ||
sedtolib_kwargs = {f"{object_type.lower()}_sed": list_loc} | ||
print(sedtolib_kwargs) | ||
sedlib.run(typ=object_type, **sedtolib_kwargs) | ||
write_yaml_config(updated_config, sed_output) | ||
# Run mag_gal | ||
maglib = lp.MagGal(config_keymap=updated_config) | ||
maglib.run(typ=object_type) | ||
write_yaml_config(updated_config, mag_output) | ||
|
||
|
||
def overwrite_config(config1, config2): | ||
"""Check that two config can be safely broadcast for a joint run""" | ||
if config2 is None: | ||
return config1 | ||
config = config1 | ||
# Redshift grid must be idenitical | ||
# assert True | ||
# filters must be indentical | ||
# assert True | ||
for k in config2: | ||
config[k] = config2[k] | ||
return config | ||
|
||
|
||
def read_yaml_config(yaml_file_path): | ||
"""Open a standard yaml file and render it as a dictionary of keywords | ||
Parameters | ||
========== | ||
yaml_file_path : str | ||
Path to input yaml file. | ||
""" | ||
with open(yaml_file_path, "r") as file: | ||
config = yaml.safe_load(file) | ||
for key in config: | ||
config[key] = lp.keyword(key, config[key]) | ||
return config | ||
|
||
|
||
def write_yaml_config(keymap, yaml_file_path): | ||
"""Write a dictionary of keywords to a yaml file | ||
Parameters | ||
========== | ||
keymap : dict of lephare.keyword | ||
The dictionary of keywords to be written to yaml. | ||
yaml_file_path : str | ||
Path to output yaml file. | ||
""" | ||
config_dict = {} | ||
for k in keymap: | ||
config_dict[keymap[k].name] = keymap[k].value | ||
with open(yaml_file_path, "w") as yaml_file: | ||
yaml.dump(config_dict, yaml_file) | ||
|
||
|
||
def write_para_config(keymap, para_file_path): | ||
"""Write a dictionary of keywords to a para file | ||
Parameters | ||
========== | ||
keymap : dict of lephare.keyword | ||
The dictionary of keywords to be written to yaml. | ||
para_file_path : str | ||
Path to output para file. | ||
""" | ||
now = datetime.datetime.now().strftime("%Y%m%dT%H%M%S") | ||
para_contents = f"# File written automatically at {now}\n" | ||
for k in keymap: | ||
para_contents += f"{k} {keymap[k].value}\n" | ||
with open(para_file_path, "w") as file_handle: | ||
file_handle.write(para_contents) | ||
file_handle.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
IDENT str spec | ||
Z_BEST float zgmin[0] | ||
Z_BEST68_LOW float zgmin[1] | ||
Z_BEST68_HIGH float zgmin[2] | ||
Z_BEST90_LOW float zgmin[3] | ||
Z_BEST90_HIGH float zgmin[4] | ||
Z_BEST99_LOW float zgmin[5] | ||
Z_BEST99_HIGH float zgmin[6] | ||
Z_MED float zgmed[0] | ||
Z_MED68_LOW float zgmed[1] | ||
Z_MED68_HIGH float zgmed[2] | ||
Z_MED90_LOW float zgmed[3] | ||
Z_MED90_HIGH float zgmed[4] | ||
Z_MED99_LOW float zgmed[5] | ||
Z_MED99_HIGH float zgmed[6] | ||
Z_MODE float zgmode[0] | ||
Z_MODE68_LOW float zgmode[1] | ||
Z_MODE68_HIGH float zgmode[2] | ||
Z_MODE90_LOW float zgmode[3] | ||
Z_MODE90_HIGH float zgmode[4] | ||
Z_MODE99_LOW float zgmode[5] | ||
Z_MODE99_HIGH float zgmode[6] | ||
MASS_BEST float results["MASS_BEST"] | ||
SFR_BEST float results["SFR_BEST"] | ||
SSFR_BEST float results["SFR_BEST"] | ||
LDUST_BEST float results["LDUST_BEST"] | ||
AGE_BEST float results["AGE_BEST"] | ||
EBV_BEST float results["EBV_BEST"] | ||
EXTLAW_BEST float results["EXTLAW_BEST"] | ||
LUM_NUV_BEST float results["LUM_NUV_BEST"] | ||
LUM_R_BEST float results["LUM_R_BEST"] | ||
LUM_K_BEST float results["LUM_K_BEST"] | ||
LUM_TIR_BEST float results["LUM_TIR_BEST"] | ||
MOD_BEST int imasmin[0] | ||
#PDZ_BEST | ||
CHI_BEST float chimin[0] | ||
SCALE_BEST float dmmin[0] | ||
CONTEXT long cont | ||
NBAND_USED int nbused | ||
NBAND_ULIM int nbul | ||
ZSPEC float zs | ||
MAG_OBS() float mab | ||
ERR_MAG_OBS() float msab | ||
MAG_MOD() float magm | ||
MAG_PRED() float magPred | ||
ABSMAG_PRED() float absmagPred | ||
ZQ_BEST float zqmin[0] | ||
ZQ_BEST68_LOW float zqmin[1] | ||
ZQ_BEST68_HIGH float zqmin[2] | ||
ZQ_BEST90_LOW float zqmin[3] | ||
ZQ_BEST90_HIGH float zqmin[4] | ||
ZQ_BEST99_LOW float zqmin[5] | ||
ZQ_BEST99_HIGH float zqmin[6] | ||
ZQ_MED float zqmed[0] | ||
ZQ_MED68_LOW float zqmed[1] | ||
ZQ_MED68_HIGH float zqmed[2] | ||
ZQ_MED90_LOW float zqmed[3] | ||
ZQ_MED90_HIGH float zqmed[4] | ||
ZQ_MED99_LOW float zqmed[5] | ||
ZQ_MED99_HIGH float zqmed[6] | ||
ZQ_MODE float zqmode[0] | ||
ZQ_MODE68_LOW float zqmode[1] | ||
ZQ_MODE68_HIGH float zqmode[2] | ||
ZQ_MODE90_LOW float zqmode[3] | ||
ZQ_MODE90_HIGH float zqmode[4] | ||
ZQ_MODE99_LOW float zqmode[5] | ||
ZQ_MODE99_HIGH float zqmode[6] | ||
CHI_QSO float chimin[1] | ||
MOD_QSO int imasmin[1] | ||
CHI_STAR float chimin[2] | ||
MOD_STAR int imasmin[2] | ||
MOD_SEC int zsecMod | ||
EXTLAW_SEC int zsecExtlaw | ||
Z_SEC float zsec | ||
EBV_SEC float zsecEbv | ||
PDZ_SEC float zsecProb | ||
CHI_SEC float zsecChi2 | ||
SCALE_SEC float zsecScale | ||
AGE_SEC float zsecAge | ||
AGE_MED float agemed[0] | ||
AGE_INF float agemed[1] | ||
AGE_SUP float agemed[2] | ||
LDUST_MED float Ldustmed[0] | ||
LDUST_INF float Ldustmed[1] | ||
LDUST_SUP float Ldustmed[2] | ||
LUM_TIR_MED float LIRmed[0] | ||
LUM_TIR_INF float LIRmed[1] | ||
LUM_TIR_SUP float LIRmed[2] | ||
MASS_MED float massmed[0] | ||
MASS_INF float massmed[1] | ||
MASS_SUP float massmed[2] | ||
#EBV_MED float med[0] | ||
#EBV_INF float med[1] | ||
#EBV_SUP float med[2] | ||
SFR_MED float SFRmed[0] | ||
SFR_INF float SFRmed[1] | ||
SFR_SUP float SFRmed[2] | ||
SSFR_MED float sSFRmed[0] | ||
SSFR_INF float sSFRmed[1] | ||
SSFR_SUP float sSFRmed[2] | ||
COL1_MED float col1med[0] | ||
COL1_INF float col1med[1] | ||
COL1_SUP float col1med[2] | ||
COL2_MED float col2med[0] | ||
COL2_INF float col2med[1] | ||
COL2_SUP float col2med[2] | ||
MREF_MED float Mrefmed[0] | ||
MREF_INF float Mrefmed[1] | ||
MREF_SUP float Mrefmed[2] | ||
LIMITS_ZMAX float limits_zmax | ||
LIMITS_MFAINT float limits_Mfaint | ||
EM_FLUX_LYA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_OII float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_HB float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_OIIIA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_OIIIB float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_HA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_SIIIA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX_SIIIB float results_emission_lines["EM_FLUX_LYA"] | ||
EM_FLUX() float fluxEL_SED | ||
EM_EW_LYA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_OII float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_HB float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_OIIIA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_OIIIB float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_HA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_SIIIA float results_emission_lines["EM_FLUX_LYA"] | ||
EM_EW_SIIIB float results_emission_lines["EM_FLUX_LYA"] | ||
#MABS_FLUX | ||
MABS_FILT() float absfilt | ||
K_COR() float kap | ||
MAG_ABS() float mabs | ||
EMAG_ABS() float emabs | ||
STRING_INPUT str str_inp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.