Skip to content

Commit

Permalink
remove/update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Shotaro committed Jun 21, 2024
1 parent 3c996f1 commit b279143
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 103 deletions.
33 changes: 0 additions & 33 deletions src/pybkgmodel/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,6 @@
from astropy.coordinates.erfa_astrom import erfa_astrom, ErfaAstromInterpolator


# def find_run_neighbours(target_run, run_list, time_delta, pointing_delta):
# """
# Returns the neighbours of the specified run.

# Parameters
# ----------
# target_run: RunSummary
# Run for which to find the neighbours.
# run_list: iterable
# Runs where to look for the "target_run" neighbours.
# time_delta: astropy.units.quantity.Quantity
# Maximal time difference between either
# (1) the start of the target run and the end of its "neighbour" or
# (2) the end of the target run and the start of its "neighbour"
# pointing_delta: astropy.units.quantity.Quantity
# Maximal pointing difference between the target and the "neibhbour" runs.
# """

# neihbours = filter(
# lambda run_: (abs(run_.mjd_start - target_run.mjd_stop)*u.d < time_delta) or
# (abs(run_.mjd_stop - target_run.mjd_start)*u.d < time_delta),
# run_list
# )

# neihbours = filter(
# lambda run_: target_run.tel_pointing_start.icrs.separation(run_.tel_pointing_start.icrs)
# < pointing_delta,
# neihbours
# )

# return tuple(neihbours)


def load_file(file_name, cuts):

if MagicRootEventFile.is_compatible(file_name):
Expand Down
128 changes: 58 additions & 70 deletions src/pybkgmodel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from astropy.coordinates import SkyCoord

from pybkgmodel.data import load_file
# from pybkgmodel.data import find_run_neighbours

from pybkgmodel.camera import RectangularCameraImage
from pybkgmodel.matching import LazyFinder, SimpleFinder
Expand All @@ -18,56 +17,6 @@ class BaseMap:
procedures for all background methods.
"""

def __init__(self):
pass

# def read_runs(self, target_run, neighbours, cuts):
# """Function loading the event from the run file into event file objects.

# Parameters
# ----------
# target_run : str
# Run for which the file shall be read.
# neighbours : tuple
# Neighbouring runs selected.
# cuts : str
# Event selection cuts.

# Returns
# -------
# evtfiles : list
# List of the event files objects is returned.

# Raises
# ------
# RuntimeError
# Raise if a run in an unsupported format is provided.
# Currenttly supported formats are DL3 according to GADF, DL2 for LST and ROOT for MAGIC.
# """
# if MagicRootEventFile.is_compatible(target_run.file_name):
# evtfiles = [
# MagicRootEventFile(run.file_name, cuts=cuts)
# for run in (target_run,) + neighbours
# ]
# return evtfiles
# elif LstDL2EventFile.is_compatible(target_run.file_name):
# evtfiles = [
# LstDL2EventFile(run.file_name, cuts=cuts)
# for run in (target_run,) + neighbours
# ]
# return evtfiles
# elif DL3EventFile.is_compatible(target_run.file_name):
# evtfiles = [
# DL3EventFile(run.file_name)
# for run in (target_run,) + neighbours
# ]
# return evtfiles
# else:
# raise RuntimeError(f"Unsupported file format for '{target_run.file_name}'.")


class Map(BaseMap):

def __init__(
self,
runs,
Expand Down Expand Up @@ -116,6 +65,19 @@ def get_single_run_map(self,):

def find_neighbours(self, target_run):

"""
Find neighbouring runs that are used to cover the masked regions in the target run.
Parameters
----------
target_run : RunSummary
Run for which the background map shall be generated.
Returns
-------
runs : tuple of RectangularCameraImage
"""

# specify the run-matching mode
if self.neighbouring_mode == 'lazy':
finder = LazyFinder(runs = self.runs)
Expand All @@ -125,6 +87,8 @@ def find_neighbours(self, target_run):
time_delta = self.time_delta,
pointing_delta = self.pointing_delta,
)
elif self.neighbouring_mode == 'horizontally_closest':
raise NotImplementedError
elif self.neighbouring_mode == 'rectangle':
raise NotImplementedError
elif self.neighbouring_mode == 'circle':
Expand Down Expand Up @@ -154,7 +118,7 @@ def stack_images(images, *args, **kwargs) -> RectangularCameraImage:

# check the geometry consistency
# TODO: this functionality should be in the CameraImage class?
# TODO: check the same CameraImage class or not (e.g. RectangularCameraImage)
# TODO: check the same CameraImage class or not (e.g. RectangularCameraImage or Circular?)
if len(images) < 2:
pass
else:
Expand All @@ -174,7 +138,7 @@ def stack_images(images, *args, **kwargs) -> RectangularCameraImage:
counts = numpy.sum([im.counts for im in images], axis=0)
exposure = numpy.sum(u.Quantity([im.exposure for im in images]), axis=0)

# ToDo: automatically use the same class with the input images
# TODO: automatically use the same class with the input images
stacked_map = RectangularCameraImage(
counts = counts,
exposure = exposure,
Expand All @@ -187,7 +151,7 @@ def stack_images(images, *args, **kwargs) -> RectangularCameraImage:
return stacked_map


class WobbleMap(Map):
class WobbleMap(BaseMap):
"""
Class for generating runwise background maps using the wobble map algorithm.
Expand All @@ -211,7 +175,7 @@ class WobbleMap(Map):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# self.src_coord = None # TODO: maybe better that users can specify the source in the config file?
self.src_coord = None # TODO: better that users can specify the source in the config file


def get_single_run_map(self, evtfile, src_coord) -> RectangularCameraImage:
Expand All @@ -226,10 +190,41 @@ def get_single_run_map(self, evtfile, src_coord) -> RectangularCameraImage:
image.mask_half(src_cam)

return image

@staticmethod
def guess_src_coord(evtfiles):

"""
Guess the position of the source of interest based on the wobbling.
Parameters
----------
evtfiles : list of EventFile
Runs that will be used for the wobble-map technique
Returns
-------
src_coord : SkyCoord
the source position in the Ra/Dec coordinates
"""

pointing_ra = u.Quantity([
event_file.pointing_ra.mean() for event_file in evtfiles
])
pointing_dec = u.Quantity([
event_file.pointing_dec.mean() for event_file in evtfiles
])
src_coord = SkyCoord(
ra = pointing_ra.mean(),
dec = pointing_dec.mean()
)

return src_coord


def get_runwise_bkg(self, target_run)->RectangularCameraImage:
"""Function for obtaining runwise background maps using the Wobble
"""
Function for obtaining runwise background maps using the Wobble
map method.
Parameters
Expand All @@ -255,17 +250,10 @@ def get_runwise_bkg(self, target_run)->RectangularCameraImage:
]

# guess the position of the source of interest
# TODO: maybe better that users can specify the source in config?
pointing_ra = u.Quantity([
event_file.pointing_ra.mean() for event_file in evtfiles
])
pointing_dec = u.Quantity([
event_file.pointing_dec.mean() for event_file in evtfiles
])
src_coord = SkyCoord(
ra = pointing_ra.mean(),
dec = pointing_dec.mean()
)
if self.src_coord is None:
src_coord = self.guess_src_coord(evtfiles)
else:
src_coord = self.src_coord

# get the wobble maps (half masked)
images = [self.get_single_run_map(evtfile, src_coord) for evtfile in evtfiles]
Expand All @@ -276,8 +264,7 @@ def get_runwise_bkg(self, target_run)->RectangularCameraImage:
return image



class ExclusionMap(Map):
class ExclusionMap(BaseMap):
"""
Class for generating runwise background maps using the exclusion map
algorithm.
Expand Down Expand Up @@ -323,7 +310,8 @@ def get_single_run_map(self, evtfile) -> RectangularCameraImage:


def get_runwise_bkg(self, target_run) -> RectangularCameraImage:
"""Function for obtaining runwise background maps using the Exclusion
"""
Function for obtaining runwise background maps using the Exclusion
map method.
Parameters
Expand Down

0 comments on commit b279143

Please sign in to comment.