Skip to content

Commit

Permalink
Add cache paths and extra loading option (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein authored Mar 28, 2024
1 parent 2fca013 commit a2862f3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
54 changes: 49 additions & 5 deletions nuztf/base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,41 @@ def query_ampel(

return query_res

def get_initial_cache_path(self) -> Path:
"""
Get the path to the initial cache file
:return: Cache file path
"""
return self.get_cache_dir().joinpath("initial_stage.json")

def get_final_cache_path(self) -> Path:
"""
Get the path to the final cache file
:return: Cache file path
"""
return self.get_cache_dir().joinpath("final_stage.json")

def load_from_cache(self):
"""
Load the cache from the final cache file
:return: None
"""
if not self.get_final_cache_path().exists():
err = (
f"Final cache file {self.get_final_cache_path()} does not exist. "
f"Run scan_area first."
)
self.logger.error(err)
raise FileNotFoundError(err)

with open(self.get_final_cache_path(), "r") as infile:
results = json.load(infile)

self.add_results(results)

def scan_area(
self,
t_min=None,
Expand All @@ -329,9 +364,7 @@ def scan_area(
"""
query_res = self.query_ampel(t_min=t_min, t_max=t_max)

cache_file_initial_stage = self.get_cache_dir().joinpath("initial_stage.json")

with open(cache_file_initial_stage, "w") as outfile:
with open(self.get_initial_cache_path(), "w") as outfile:
json.dump(query_res, outfile)

ztf_ids_first_stage = []
Expand All @@ -350,13 +383,24 @@ def scan_area(

results = self.ampel_object_search(ztf_ids=ztf_ids_first_stage)

with open(self.get_final_cache_path(), "w") as outfile:
json.dump(results, outfile)

self.add_results(results)
self.create_candidate_summary()

def add_results(self, results):
"""
Add the results to the cache and create a summary
:param results: Results from the AMPEL API
:return: None
"""
for res in results:
self.add_res_to_cache(res)

self.logger.info(f"Found {len(self.cache)} candidates")

self.create_candidate_summary()

def filter_f_no_prv(self, res):
raise NotImplementedError

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nuztf"
version = "2.7.2"
version = "2.8.0"
description = "Package for multi-messenger correlation searches with ZTF"
authors = ["Robert Stein <[email protected]>", "Simeon Reusch <[email protected]>", "Jannis Necker <[email protected]>"]
repository = "https://github.com/desy-multimessenger/nuztf"
Expand Down

0 comments on commit a2862f3

Please sign in to comment.