Skip to content

Commit

Permalink
Added get stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
cvalenzu committed Nov 8, 2019
1 parent 4583a69 commit a3f4bee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
25 changes: 22 additions & 3 deletions alerce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pandas.io.json import json_normalize
from astropy.table import Table, Column
from IPython.display import HTML
from astropy.io.fits import HDUList
from astropy.io.fits import open as fits_open

import warnings
from json.decoder import JSONDecodeError
Expand Down Expand Up @@ -35,6 +37,10 @@ def __init__(self, **kwargs):
if "catsHTM_url" in kwargs.keys():
self.catsHTM_url = kwargs["catsHTM_url"]

self.avro_url = "http://avro.alerce.online"
if "catsHTM_url" in kwargs.keys():
self.avro_url = kwargs["avro_url"]

self.oid = ""


Expand Down Expand Up @@ -588,7 +594,7 @@ def plot_stamp(self, oid, candid=None):
warnings.warn("This method only works on Notebooks", RuntimeWarning)
return

science = "%s/get_stamp?oid=%s&candid=%s&type=science&format=png" % (oid, candid)
science = "%s/get_stamp?oid=%s&candid=%s&type=science&format=png" % (self.avro_url,oid, candid)
images="""
<div>ZTF oid: %s, candid: %s</div>
<div>&emsp;&emsp;&emsp;&emsp;&emsp;
Expand All @@ -612,13 +618,26 @@ def get_stamps(self,oid,candid=None):
----------
oid : :py:class:`str`
object ID in ALeRCE DBs.
candid : :py:class:`int`
candid : :py:class:`int` (default First Stamps)
Candid of the stamp to be displayed, if not set shows the Discovery stamp (first one).
Returns
-------
:class:`astropy.io.fits.HDUList`
Science, Template and Difference stamps for an specific alert.
"""

if candid is None:
candid = min(self.get_detections(oid,format="pandas").index)
detections = self.get_detections(oid,format="pandas")
if detections is None:
return None
candid = min(detections.index)

hdulist = HDUList()
for stamp_type in ["science", "template", "difference"]:
tmp_hdulist = fits_open("%s/get_stamp?oid=%s&candid=%s&type=%s&format=fits"%(self.avro_url,oid,candid,stamp_type))
hdu = tmp_hdulist[0]
hdu.header["TYPE"] = stamp_type
hdulist.append(hdu)
return hdulist
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='alerce',
version='0.1',
version='0.2',
description='Package to access to ALeRCE data',
author='ALeRCE Team',
author_email='[email protected]',
Expand Down
3 changes: 3 additions & 0 deletions tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def test_catsHTM_redshift(self):
redshift = self.api.catsHTM_redshift(self.oid,radius=100)
self.assertEqual(type(redshift),float)

def test_get_stamps(self):
stamps = self.api.get_stamps(self.oid)


if __name__ == '__main__':
unittest.main()

0 comments on commit a3f4bee

Please sign in to comment.