Skip to content

Commit

Permalink
Update example to allow for more than 1 analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoughlin committed Sep 5, 2023
1 parent b4fd564 commit 0755ef1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
29 changes: 26 additions & 3 deletions example_files/yaml/doc_example.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Me2017:
Me2017_1:
model: Me2017
svd-path: ./svdmodels
outdir: outdir2
outdir: outdir_1
label: injection
prior: priors/Me2017.prior
tmin: 0.1
Expand All @@ -12,7 +12,30 @@ Me2017:
Ebv-max: 0
injection: ./injection.json
injection-num: 0
injection-outfile: outdir/lc.csv
injection-outfile: outdir_1/lc.csv
generation-seed: 42
filters: ztfg,ztfr,ztfi
plot: True
remove-nondetections: True
ztf-uncertainties: True
ztf-sampling: True
ztf-ToO: 180

Me2017_2:
model: Me2017
svd-path: ./svdmodels
outdir: outdir_2
label: injection
prior: priors/Me2017.prior
tmin: 0.1
tmax: 20
dt: 0.5
error-budget: 1
nlive: 512
Ebv-max: 0
injection: ./injection.json
injection-num: 0
injection-outfile: outdir_2/lc.csv
generation-seed: 42
filters: ztfg,ztfr,ztfi
plot: True
Expand Down
38 changes: 22 additions & 16 deletions nmma/em/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,7 @@ def get_parser():
return parser


def main(args=None):
if args is None:
parser = get_parser()
args = parser.parse_args()
if args.config is not None:
yaml_dict = yaml.safe_load(Path(args.config).read_text())
if not len(yaml_dict.keys()) == 1:
print("WARNING: yaml file can only contain one model for now.")
exit()
params = yaml_dict[list(yaml_dict.keys())[0]]
for key, value in params.items():
key = key.replace("-", "_")
if key not in args:
print(f"{key} not a known argument... please remove")
exit()
setattr(args, key, value)
def analysis(args):

if args.sampler == "pymultinest":
if len(args.outdir) > 64:
Expand Down Expand Up @@ -903,3 +888,24 @@ def main(args=None):
plt.tight_layout()
plt.savefig(plotName)
plt.close()


def main(args=None):
if args is None:
parser = get_parser()
args = parser.parse_args()
if args.config is not None:
yaml_dict = yaml.safe_load(Path(args.config).read_text())
for analysis_set in yaml_dict.keys():
params = yaml_dict[analysis_set]
for key, value in params.items():
key = key.replace("-", "_")
if key not in args:
print(f"{key} not a known argument... please remove")
exit()
setattr(args, key, value)
analysis(args)
else:
analysis(args)
else:
analysis(args)

0 comments on commit 0755ef1

Please sign in to comment.