Skip to content

Commit

Permalink
Merge pull request #47 from alercebroker/feat/fp_query
Browse files Browse the repository at this point in the history
Added border case and doc
  • Loading branch information
AlxEnashi authored Jan 6, 2025
2 parents e7002cc + b9da71d commit e90246f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 12 additions & 8 deletions alerce/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,20 @@ def query_forced_photometry(self, oid, format="json", index=None, sort=None):
new_result.update(extra_fields)
parsed_result.append(new_result)
if format == "pandas" or format == "csv":
extra_fields = complete_result["extra_fields"].copy()
complete_result = complete_result.drop(columns=FIELDS_TO_REMOVE)
# expand
import pandas as pd

extra_fields = pd.json_normalize(extra_fields)
# merge
parsed_result = complete_result.merge(extra_fields)
if format == "csv":
parsed_result = parsed_result.to_csv(index=False)
if len(complete_result) == 0:
# the object dont have any fp
return pd.DataFrame()
else:
extra_fields = complete_result["extra_fields"].copy()
complete_result = complete_result.drop(columns=FIELDS_TO_REMOVE)
# expand
extra_fields = pd.json_normalize(extra_fields)
# merge
parsed_result = complete_result.merge(extra_fields)
if format == "csv":
parsed_result = parsed_result.to_csv(index=False)

return parsed_result

Expand Down
4 changes: 4 additions & 0 deletions docs/source/tutorials/ztf_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Query Lightcurve

To get the lightcurve for an object the method :func:`~alerce.core.Alerce.query_lightcurve` can be used, this will return
a dictionary with Detections and Non-detections for that object, also we can get them separetly with :func:`~alerce.core.Alerce.query_detections` and :func:`~alerce.core.Alerce.query_non_detections`.
Also, there is a method to access the forced photometries of an object :func:`~alerce.core.Alerce.query_forced_photometry`.

.. code-block:: python
Expand All @@ -105,6 +106,9 @@ a dictionary with Detections and Non-detections for that object, also we can get
non_detections = alerce.query_non_detections("ZTF18abbuksn",
format="json")
# Getting forced photometry for an object
non_detections = alerce.query_forced_photometry("ZTF18abbuksn",
format="json")
# Getting lightcurve for an object
lightcurve = alerce.query_lightcurve("ZTF18abbuksn",
format="json")
Expand Down

0 comments on commit e90246f

Please sign in to comment.