From d35e0815242dea317be0dd6e448fc6753112d977 Mon Sep 17 00:00:00 2001 From: Brian Healy Date: Fri, 5 Jan 2024 12:56:58 -0500 Subject: [PATCH 1/4] Add tool to convert skyportal lightcurves to nmma format --- tools/convert_skyportal_lcs.py | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tools/convert_skyportal_lcs.py diff --git a/tools/convert_skyportal_lcs.py b/tools/convert_skyportal_lcs.py new file mode 100755 index 00000000..e45622a4 --- /dev/null +++ b/tools/convert_skyportal_lcs.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +from astropy.table import Table +import numpy as np +from astropy.time import Time +import pathlib +import argparse + +BASE_DIR = pathlib.Path(__file__).parent.parent.absolute() + + +def main( + filepath, +): + data_path = BASE_DIR / filepath + try: + data = Table.read(data_path, format="ascii.csv", header_start=1) + except Exception as e: + raise ValueError(f"input data is not in the expected format {e}") + + try: + local_data_path = str(data_path.with_suffix(".dat")) + with open(local_data_path, "w") as f: + # output the data in the format desired by NMMA: + # remove rows where mag and magerr are missing, or not float, or negative + data = data[ + np.isfinite(data["mag"]) + & np.isfinite(data["magerr"]) + & (data["mag"] > 0) + & (data["magerr"] > 0) + ] + for row in data: + tt = Time(row["mjd"], format="mjd").isot + filt = row["filter"] + mag = row["mag"] + magerr = row["magerr"] + f.write(f"{tt} {filt} {mag} {magerr}\n") + print(f"Wrote reformatted lightcurve to {local_data_path}") + except Exception as e: + raise ValueError(f"failed to format data {e}") + + +def get_parser(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--filepath", + type=str, + required=True, + help="path/name of lightcurve file (including extension) within base nmma directory", + ) + + return parser + + +if __name__ == "__main__": + parser = get_parser() + args = parser.parse_args() + main(**vars(args)) From 7a0d7cf71e6d0b7269d6221c85df574bb4d7ca4c Mon Sep 17 00:00:00 2001 From: Brian Healy Date: Fri, 5 Jan 2024 16:10:22 -0500 Subject: [PATCH 2/4] Change header start --- tools/convert_skyportal_lcs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/convert_skyportal_lcs.py b/tools/convert_skyportal_lcs.py index e45622a4..97cd12ff 100755 --- a/tools/convert_skyportal_lcs.py +++ b/tools/convert_skyportal_lcs.py @@ -13,10 +13,13 @@ def main( ): data_path = BASE_DIR / filepath try: - data = Table.read(data_path, format="ascii.csv", header_start=1) + data = Table.read(data_path, format="ascii.csv") except Exception as e: raise ValueError(f"input data is not in the expected format {e}") + import code + + code.interact(local=locals()) try: local_data_path = str(data_path.with_suffix(".dat")) with open(local_data_path, "w") as f: From 3136cf9eb9be8cbefabcc86b308d7df2190508a5 Mon Sep 17 00:00:00 2001 From: Brian Healy Date: Fri, 12 Jan 2024 14:58:57 -0500 Subject: [PATCH 3/4] Update inj/obj docs with skyportal lc format --- doc/data_inj_obs.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/data_inj_obs.md b/doc/data_inj_obs.md index 7d63be05..a3608fdb 100644 --- a/doc/data_inj_obs.md +++ b/doc/data_inj_obs.md @@ -72,3 +72,12 @@ Example: AT2017gfo data excerpt 2017-08-18T18:11:31.200 2massk 17.91000 0.05000 The first column represents the ISOT time, followed by the filter or spectral band in the second column, the measured AB magnitude and its respective error are given in the third and fourth column. This data structure detailed above is also applicable for other astrophysical sources (SNe, GRBs) or models implemented in NMMA. + +Example: transient data downloaded from [SkyPortal](https://github.com/skyportal/skyportal)/fritz: + + "id","mjd","mag","magerr","limiting_mag","filter","instrument_name","instrument_id","snr","magsys","origin","altdata","ra","dec","ra_unc","dec_unc","created_at","annotations","owner","Edit","Delete" + "518817455","60257.28104169993","","","19.30739974975586","ztfr","ZTF","1","","ab","None","","","","","","2023-12-07T05:49:42.369500","","[object Object]","","" + "518817456","60257.282500000205","","","19.347900390625","ztfr","ZTF","1","","ab","None","","","","","","2023-12-07T05:49:42.369555","","[object Object]","","" + "518817457","60257.36459490005","","","20.112499237060547","ztfg","ZTF","1","","ab","None","","","","","","2023-12-07T05:49:42.369574","","[object Object]","","" + +Data downloaded from a source's photometry table on SkyPortal take the comma-separated format above. These files must be converted to NMMA format (see first example above) before running analyses. Run `tools/convert_skyportal_lcs.py --filepath ` to perform the conversion. From f40f2454c03cee1db1071fc9a08a0d7d4590676a Mon Sep 17 00:00:00 2001 From: Brian Healy Date: Fri, 12 Jan 2024 15:01:54 -0500 Subject: [PATCH 4/4] Remove code.interact --- tools/convert_skyportal_lcs.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/convert_skyportal_lcs.py b/tools/convert_skyportal_lcs.py index 97cd12ff..fbb38231 100755 --- a/tools/convert_skyportal_lcs.py +++ b/tools/convert_skyportal_lcs.py @@ -17,9 +17,6 @@ def main( except Exception as e: raise ValueError(f"input data is not in the expected format {e}") - import code - - code.interact(local=locals()) try: local_data_path = str(data_path.with_suffix(".dat")) with open(local_data_path, "w") as f: