Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Fritz instrument_id request to upload script #489

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions scope/fritz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -281,6 +275,7 @@ def save_newsource(
return_id=False,
return_phot=False,
skip_phot=False,
instrument_id=1,
):

# get the lightcurves
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions tools/scope_upload_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -256,6 +258,15 @@ def upload_classification(

classes = [key for key in tax_map.keys()] # define list of columns to examine

# Get up-to-date ZTF instrument id
response_instruments = api('GET', 'api/instrument')
instrument_data = response_instruments.json().get('data')

for instrument in instrument_data:
if instrument['name'] == instrument_name:
instrument_id = instrument['id']
break

dict_list = []
obj_id_dict = {}
for index, row in sources.iterrows():
Expand Down Expand Up @@ -395,6 +406,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(
Expand All @@ -409,6 +421,7 @@ def upload_classification(
radius=radius_arcsec,
post_source=post_source,
skip_phot=skip_phot,
instrument_id=instrument_id,
)

data_groups = []
Expand Down Expand Up @@ -855,6 +868,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()

Expand Down Expand Up @@ -887,4 +906,5 @@ def upload_classification(
args.post_phot_as_comment,
args.post_phasefolded_phot,
args.phot_dirname,
args.instrument_name,
)