diff --git a/flows/api/catalogs.py b/flows/api/catalogs.py index 7fa84e8..6657b89 100644 --- a/flows/api/catalogs.py +++ b/flows/api/catalogs.py @@ -58,8 +58,8 @@ def get_catalog(target, radius=None, output='table'): dict_tables = {} tab = Table( - names=('targetid', 'target_name', 'target_status', 'ra', 'decl', 'redshift', 'redshift_error', 'discovery_mag', 'catalog_downloaded', 'pointing_model_created', 'inserted', 'discovery_date', 'project', 'host_galaxy', 'ztf_id'), - dtype=('int32', 'str', 'str', 'float64', 'float64', 'float32', 'float32', 'float32', 'bool', 'bool', 'object', 'object', 'str', 'str', 'str'), + names=('targetid', 'target_name', 'target_status', 'ra', 'decl', 'redshift', 'redshift_error', 'discovery_mag', 'catalog_downloaded', 'pointing_model_created', 'inserted', 'discovery_date', 'project', 'host_galaxy', 'ztf_id', 'sntype'), + dtype=('int32', 'str', 'str', 'float64', 'float64', 'float32', 'float32', 'float32', 'bool', 'bool', 'object', 'object', 'str', 'str', 'str', 'str'), rows=[jsn['target']]) tab['ra'].description = 'Right ascension' diff --git a/flows/api/targets.py b/flows/api/targets.py index 21a1e02..4d04216 100644 --- a/flows/api/targets.py +++ b/flows/api/targets.py @@ -62,7 +62,8 @@ def get_targets(): #-------------------------------------------------------------------------------------------------- def add_target(name, coord, redshift=None, redshift_error=None, discovery_date=None, - discovery_mag=None, host_galaxy=None, ztf=None, status='candidate', project='flows'): + discovery_mag=None, host_galaxy=None, ztf=None, sntype=None, status='candidate', + project='flows'): """ Add new candidate or target. @@ -95,6 +96,7 @@ def add_target(name, coord, redshift=None, redshift_error=None, discovery_date=N discovery_date (:class:`astropy.time.Time`, :class:`datetime.datetime` or str, optional): discovery_mag (float, optional): Magnitude at time of discovery. host_galaxy (str, optional): Host galaxy name. + sntype (str, optional): Supernovae type (e.g. Ia, Ib, II). ztf (str, optional): ZTF identifier. status (str, optional): project (str, optional): @@ -142,7 +144,8 @@ def add_target(name, coord, redshift=None, redshift_error=None, discovery_date=N 'host_galaxy': host_galaxy, 'project': project, 'ztf_id': ztf, - 'target_status': status + 'target_status': status, + 'sntype': sntype } # Post the request to the API: diff --git a/flows/tns.py b/flows/tns.py index 1c7c4a8..df3f190 100644 --- a/flows/tns.py +++ b/flows/tns.py @@ -130,6 +130,11 @@ def tns_get_obj(name): if 'reply' in data: reply = data['reply'] + if not reply: + return None + if 'objname' not in reply: # Bit of a cheat, but it is simple and works + return None + reply['internal_names'] = [name.strip() for name in reply['internal_names'].split(',') if name.strip()] return reply return None diff --git a/run_querytns.py b/run_querytns.py index 01ce398..1b11a3c 100644 --- a/run_querytns.py +++ b/run_querytns.py @@ -109,6 +109,10 @@ def main(): discovery_date = Time(reply['discoverydate'], format='iso', scale='utc') ztf = list(filter(regex_ztf.match, reply['internal_names'])) ztf = None if not ztf else ztf[0] + if 'object_type' in reply and 'name' in reply['object_type']: + sntype = regex_sn.sub('', reply['object_type']['name']) + else: + sntype = None # Try to upload to FLOWS newtargetid = api.add_target(reply['objname'], coord, @@ -117,6 +121,7 @@ def main(): discovery_mag=reply['discoverymag'], host_galaxy=reply['hostname'], ztf=ztf, + sntype=sntype, status='candidate', project='flows') logger.debug('Uploaded to FLOWS with targetid=%d', newtargetid) diff --git a/tests/test_tns.py b/tests/test_tns.py index c16d2fd..98103c5 100644 --- a/tests/test_tns.py +++ b/tests/test_tns.py @@ -39,6 +39,13 @@ def test_tns_get_obj(SETUP_CONFIG): assert res['objname'] == '2019yvr' assert res['name_prefix'] == 'SN' +#-------------------------------------------------------------------------------------------------- +@pytest.mark.skipif(os.environ.get('CI') == 'true', reason="Disabled on GitHub Actions to avoid too many requests HTTP error") +def test_tns_get_obj_noexist(SETUP_CONFIG): + res = tns.tns_get_obj('1892doesnotexist') + print(res) + assert res is None + #-------------------------------------------------------------------------------------------------- @pytest.mark.skipif(os.environ.get('CI') == 'true', reason="Disabled on GitHub Actions to avoid too many requests HTTP error") @pytest.mark.parametrize('date_begin,date_end', [