Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/black-22.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonreusch committed Jul 11, 2022
2 parents a28f13e + 19ad5d0 commit 65cec27
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion nuztf/cat_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding: utf-8

from astropy.coordinates import SkyCoord
from astroquery.ned import Ned
from astroquery.ipac.ned import Ned
from astroquery.exceptions import RemoteServiceError
from astropy import units as u
from nuztf.ampel_api import ampel_api_catalog, ampel_api_name
Expand Down
17 changes: 12 additions & 5 deletions nuztf/irsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from nuztf.parse_nu_gcn import find_gcn_no, parse_gcn_circular

logger = logging.getLogger(__name__)
logger.setLevel("DEBUG")


def format_date(t, atel=True):
Expand All @@ -45,11 +44,17 @@ def format_date(t, atel=True):


def load_irsa(ra_deg: float, dec_deg: float, radius_arcsec: float = 0.5, **kwargs):
"""
Get lightcuve from IPAC
"""

logger.debug("Querying IPAC")
df = LCQuery.from_position(ra_deg, dec_deg, radius_arcsec, **kwargs).data

print(len(df))
logger.debug(f"Found {len(df)} datapoints")

if len(df) == 0:
logger.info("No data found.")
return None

else:
Expand Down Expand Up @@ -84,7 +89,8 @@ def plot_irsa_lightcurve(
expanded_labels: bool = True,
ylim: tuple = None,
radius_arcsec: float = 0.5,
):
query_irsa_for_logs: bool = True,
) -> None:
plot_title = source_name

# If there are no coordinates, try name resolve to get coordinates!
Expand Down Expand Up @@ -163,13 +169,13 @@ def plot_irsa_lightcurve(
source_redshift = result_table["Redshift"]

logger.info(
f"Using Astropy NED query result for name {source_name} ({source_coords})"
f"Using AStroquery NED query result for name {source_name} ({source_coords})"
)

if source_coords is None:
sc = SkyCoord.from_name(source_name)
logger.info(
f"Using Astropy CDS query result for name {source_name} (RA={sc.ra}, Dec={sc.dec})"
f"Using Astroquery CDS query result for name {source_name} (RA={sc.ra}, Dec={sc.dec})"
)
source_coords = (sc.ra.value, sc.dec.value)

Expand Down Expand Up @@ -317,6 +323,7 @@ def plot_irsa_lightcurve(
ra=source_coords[0],
dec=source_coords[1],
lookback_weeks_max=check_obs_lookback_weeks,
query_irsa_for_logs=query_irsa_for_logs,
)

if mro is not None:
Expand Down
31 changes: 21 additions & 10 deletions nuztf/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_coverage(jds: [int]) -> pd.DataFrame:
return df


def get_obs_summary(t_min, t_max=None, max_days: int = None):
def get_obs_summary(t_min, t_max=None, max_days: int = None, query_irsa_for_logs=True):

if t_max is None:
if max_days is None:
Expand All @@ -147,15 +147,22 @@ def get_obs_summary(t_min, t_max=None, max_days: int = None):

jds = np.arange(int(t_min.jd), int(t_max.jd) + 1)

df = get_coverage(jds)
if len(df) == 0:
get_obs_summary_skyvision(t_min, t_max, max_days=max_days)
if query_irsa_for_logs:
logger.debug("Getting coverage")
df = get_coverage(jds)
mns = MNS(df)
mns.data.query(f"obsjd >= {t_min.jd} and obsjd <= {t_max.jd}", inplace=True)
mns.data.reset_index(inplace=True)
mns.data.drop(columns=["index"], inplace=True)
logger.debug("Done")

mns = MNS(df)
if len(df) == 0:
logger.debug("Empty observation log, try skyvision instead.")
mns = get_obs_summary_skyvision(t_min, t_max, max_days=max_days)

mns.data.query(f"obsjd >= {t_min.jd} and obsjd <= {t_max.jd}", inplace=True)
mns.data.reset_index(inplace=True)
mns.data.drop(columns=["index"], inplace=True)
else:
logger.info("Getting observation log from skyvision.")
mns = get_obs_summary_skyvision(t_min, t_max, max_days=max_days)

logger.debug(f"Found {len(mns.data)} observations in total.")

Expand Down Expand Up @@ -211,7 +218,9 @@ def get_obs_summary_skyvision(t_min, t_max=None, max_days: int = None):
return mns


def get_most_recent_obs(ra: float, dec: float, lookback_weeks_max: int = 12):
def get_most_recent_obs(
ra: float, dec: float, lookback_weeks_max: int = 12, query_irsa_for_logs=True
):
""" """

fields = get_fields_containing_target(ra, dec)._data
Expand Down Expand Up @@ -240,7 +249,9 @@ def get_most_recent_obs(ra: float, dec: float, lookback_weeks_max: int = 12):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)

mns = get_obs_summary(t_min=t_min, t_max=t_max)
mns = get_obs_summary(
t_min=t_min, t_max=t_max, query_irsa_for_logs=query_irsa_for_logs
)

mask = np.array([x in fields for x in mns.data["field"]])

Expand Down
12 changes: 8 additions & 4 deletions tests/test_irsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@

import unittest
import logging
import nuztf
from nuztf.irsa import plot_irsa_lightcurve, load_irsa


class TestIrsa(unittest.TestCase):
def setUp(self):
logging.getLogger("irsa").setLevel(logging.INFO)
logging.getLogger("nuztf.irsa").setLevel(logging.DEBUG)
logging.getLogger("nuztf.observations").setLevel(logging.DEBUG)

self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.INFO)
self.logger.setLevel(logging.DEBUG)

def test_lightcurve(self):
self.logger.info("\n\n Testing IRSA \n\n")
self.logger.info("Getting lightcurve from IPAC.")

res = load_irsa(77.358185, 5.693148, 0.5, TIME=[58204.1, 59678.9])
res = load_irsa(77.358185, 5.693148, 0.5, TIME=[59204.1, 59210.9])

res = res[res["programid"] == 1]
expected = 374
expected = 2

self.logger.info(f"Found {len(res)} entries. Expected: {expected}")

Expand All @@ -35,4 +38,5 @@ def test_lightcurve(self):
nu_name=nu_names[i],
check_obs=True,
check_obs_lookback_weeks=1,
query_irsa_for_logs=False,
)
2 changes: 0 additions & 2 deletions tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,3 @@ def test_lightcurve(self):

for (name, val) in expected_2.items():
self.assertEqual(res2.data.iloc[0][name], val)

# get_obs_summary(Time.now() - 1.0 * u.day, Time.now())
4 changes: 4 additions & 0 deletions tests/test_skymap_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ def test_gw_scan(self):

self.assertEqual(n_retrieved_candidates, n_expected_candidates)

self.logger.info("Creating overview table")

scanner.create_overview_table()

self.logger.info("Creating candidate summary")

scanner.create_candidate_summary()

fig, coverage_summary = scanner.plot_coverage()
Expand Down

0 comments on commit 65cec27

Please sign in to comment.