Skip to content

Commit

Permalink
Add cache unification and hypothetical field coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed Apr 23, 2024
1 parent 6aed193 commit b866639
Show file tree
Hide file tree
Showing 3 changed files with 683 additions and 634 deletions.
48 changes: 42 additions & 6 deletions nuztf/base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ def wrap_around_180(ra_deg: float):
ra_deg = np.rad2deg(ra_rad)
return ra_deg

def in_contour(self, ra, dec):
raise NotImplementedError

def ampel_object_search(self, ztf_ids: list) -> list:
""" """
all_results = []
Expand Down Expand Up @@ -843,14 +846,40 @@ def text_summary(self):
return text

def calculate_overlap_with_observations(
self, first_det_window_days=3.0, min_sep=0.01
self, first_det_window_days=3.0, min_sep=0.01, fields=None
):
mns = get_obs_summary(t_min=self.t_min, max_days=first_det_window_days)

if mns is None:
return None, None, None
if fields is not None:
new = []
for i, field in enumerate(fields):
new.append(
pd.DataFrame(
{
"filter_id": [1 for _ in range(64)],
"exposure_time": [300.0 for _ in range(64)],
"qid": [i for i in range(64)],
"field_id": [field for _ in range(64)],
"maglim": [21.0 for _ in range(64)],
"obsjd": [
self.t_min.jd + (0.02 * (i + 1)) for _ in range(64)
],
"status": [0 for _ in range(64)],
"date": [
(self.t_min + (0.02 * (i + 1) * u.day)).isot
for _ in range(64)
],
}
)
)
data = pd.concat(new)

data = mns.data.copy()
else:
mns = get_obs_summary(t_min=self.t_min, max_days=first_det_window_days)

if mns is None:
return None, None, None

data = mns.data.copy()

mask = data["status"] == 0
self.logger.info(
Expand Down Expand Up @@ -984,12 +1013,18 @@ def calculate_overlap_with_observations(
overlapping_fields,
)

def plot_overlap_with_observations(self, first_det_window_days=None, min_sep=0.01):
def plot_overlap_with_observations(
self,
first_det_window_days=None,
min_sep=0.01,
fields=None,
):
"""
Function to plot the overlap of the field with observations.
:param first_det_window_days: Window of time in days to consider for the first detection.
:param min_sep: Minimum separation between observations to consider them as separate.
:param fields: Fields to consider.
"""

Expand All @@ -1000,6 +1035,7 @@ def plot_overlap_with_observations(self, first_det_window_days=None, min_sep=0.0
) = self.calculate_overlap_with_observations(
first_det_window_days=first_det_window_days,
min_sep=min_sep,
fields=fields,
)

if coverage_df is None:
Expand Down
19 changes: 15 additions & 4 deletions nuztf/skymap_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_alerts(self):
time_healpix_end = time.time()
time_healpix = time_healpix_end - time_healpix_start

cache_file = self.get_cache_dir().joinpath("all_alerts.json")
cache_file = self.get_cache_dir().joinpath("initial_stage.json")

with open(cache_file, "w") as outfile:
json.dump(self.queue, outfile)
Expand Down Expand Up @@ -287,6 +287,16 @@ def remove_variability_line():
"variability prior to the merger time"
)

def in_contour(self, ra, dec):
"""
Whether a given coordinate is within the skymap contour
:param ra: right ascension
:param dec: declination
:return: bool
"""
return self.skymap.in_contour(ra, dec)

def candidate_text(
self, ztf_id: str, first_detection: float, lul_lim: float, lul_jd: float
):
Expand Down Expand Up @@ -350,7 +360,7 @@ def filter_f_no_prv(self, res: dict, t_max_jd=None) -> bool:
pass

# Check contour
if not self.skymap.in_contour(res["candidate"]["ra"], res["candidate"]["dec"]):
if not self.in_contour(res["candidate"]["ra"], res["candidate"]["dec"]):
self.logger.debug(f"❌ {res['objectId']}: Outside of event contour.")
return False

Expand Down Expand Up @@ -499,10 +509,11 @@ def plot_skymap(self):

return fig

def plot_coverage(self, plot_candidates: bool = True):
def plot_coverage(self, plot_candidates: bool = True, fields: list = None):
"""Plot ZTF coverage of skymap region"""
fig, message = self.plot_overlap_with_observations(
first_det_window_days=self.n_days
first_det_window_days=self.n_days,
fields=fields,
)

if plot_candidates:
Expand Down
Loading

0 comments on commit b866639

Please sign in to comment.