From fbf6d5d4fb06f532e05415c5a6aca8b077377f80 Mon Sep 17 00:00:00 2001 From: Brian Healy Date: Thu, 14 Sep 2023 11:00:18 -0500 Subject: [PATCH 1/2] Move Fritz instrument_id request to upload script --- doc/usage.md | 1 + scope/fritz.py | 12 +----------- tools/scope_upload_classification.py | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/doc/usage.md b/doc/usage.md index 95d6929b..a8b00459 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -443,6 +443,7 @@ inputs: 24. --post_phot_as_comment: flag to post photometry as a comment on the source (bool) 25. --post_phasefolded_phot: flag to post phase-folded photometry as comment in addition to time series (bool) 26. --phot_dirname: name of directory in which to save photometry plots (str) +27. --instrument_name: name of instrument used for observations (str) process: 0. include Kowalski host, port, protocol, and token or username+password in config.yaml diff --git a/scope/fritz.py b/scope/fritz.py index c74112d0..5fdb9a1f 100755 --- a/scope/fritz.py +++ b/scope/fritz.py @@ -60,12 +60,6 @@ def api( return response -# Get up-to-date ZTF instrument id -name = 'ZTF' -response_instruments = api('GET', 'api/instrument', max_attempts=MAX_ATTEMPTS) -instrument_data = response_instruments.json().get('data') - - def radec_to_iau_name(ra: float, dec: float, prefix: str = "ZTFJ"): """Transform R.A./Decl. in degrees to IAU-style hexadecimal designations.""" if not 0.0 <= ra < 360.0: @@ -281,6 +275,7 @@ def save_newsource( return_id=False, return_phot=False, skip_phot=False, + instrument_id=1, ): # get the lightcurves @@ -325,11 +320,6 @@ def save_newsource( df_photometry.dropna().drop_duplicates('uexpid').reset_index(drop=True) ) - for instrument in instrument_data: - if instrument['name'] == name: - instrument_id = instrument['id'] - break - photometry = { "obj_id": obj_id, "instrument_id": instrument_id, diff --git a/tools/scope_upload_classification.py b/tools/scope_upload_classification.py index dbf61e38..8b4a0822 100755 --- a/tools/scope_upload_classification.py +++ b/tools/scope_upload_classification.py @@ -179,6 +179,7 @@ def upload_classification( post_phot_as_comment: bool = False, post_phasefolded_phot: bool = False, phot_dirname: str = 'phot_plots', + instrument_name: str = 'ZTF', ): """ Upload labels to Fritz @@ -208,6 +209,7 @@ def upload_classification( :post_phot_as_comment: if True, post photometry as a comment on the source (bool) :post_phasefolded_phot: if True, post phase-folded photometry as comment in addition to time series (bool) :phot_dirname: Name of directory in which to save photometry plots (str) + :instrument_name: Name of instrument used for observations (str) """ # read in file to csv @@ -256,6 +258,16 @@ def upload_classification( classes = [key for key in tax_map.keys()] # define list of columns to examine + # Get up-to-date ZTF instrument id + name = instrument_name + response_instruments = api('GET', 'api/instrument') + instrument_data = response_instruments.json().get('data') + + for instrument in instrument_data: + if instrument['name'] == name: + instrument_id = instrument['id'] + break + dict_list = [] obj_id_dict = {} for index, row in sources.iterrows(): @@ -395,6 +407,7 @@ def upload_classification( radius=radius_arcsec, post_source=post_source, skip_phot=skip_phot, + instrument_id=instrument_id, ) else: obj_id, photometry = save_newsource( @@ -409,6 +422,7 @@ def upload_classification( radius=radius_arcsec, post_source=post_source, skip_phot=skip_phot, + instrument_id=instrument_id, ) data_groups = [] @@ -855,6 +869,12 @@ def upload_classification( default='phot_plots', help="Name of directory in which to save photometry plots", ) + parser.add_argument( + "--instrument_name", + type=str, + default='ZTF', + help="Name of instrument used for observations", + ) args = parser.parse_args() @@ -887,4 +907,5 @@ def upload_classification( args.post_phot_as_comment, args.post_phasefolded_phot, args.phot_dirname, + args.instrument_name, ) From 2510c9ed1b82bcf195b1fb2b758c529080f836e8 Mon Sep 17 00:00:00 2001 From: Brian Healy Date: Thu, 14 Sep 2023 11:08:46 -0500 Subject: [PATCH 2/2] Simplify code --- tools/scope_upload_classification.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/scope_upload_classification.py b/tools/scope_upload_classification.py index 8b4a0822..ab40433e 100755 --- a/tools/scope_upload_classification.py +++ b/tools/scope_upload_classification.py @@ -259,12 +259,11 @@ def upload_classification( classes = [key for key in tax_map.keys()] # define list of columns to examine # Get up-to-date ZTF instrument id - name = instrument_name response_instruments = api('GET', 'api/instrument') instrument_data = response_instruments.json().get('data') for instrument in instrument_data: - if instrument['name'] == name: + if instrument['name'] == instrument_name: instrument_id = instrument['id'] break