Skip to content

Commit

Permalink
Add SN Type to API and get it from TNS for candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
rhandberg committed Feb 10, 2022
1 parent 33b4e01 commit c241358
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions flows/api/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 5 additions & 2 deletions flows/api/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions flows/tns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions run_querytns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down

0 comments on commit c241358

Please sign in to comment.