Skip to content

Commit

Permalink
Add core.load_target_source_coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
HealthyPear committed Dec 16, 2024
1 parent 811fbdc commit 8dab0fc
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/iact_estimator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import importlib

import astropy.units as u
from astropy.coordinates import SkyCoord
from astroplan import FixedTarget
from gammapy.stats import WStatCountsStatistic
import numpy as np
from scipy import interpolate
Expand Down Expand Up @@ -32,6 +34,35 @@
logger = logging.getLogger(__name__)


def load_target_source_coordinates(config):
"""Load target source using celestial coordinates.
Parameters
----------
config : dict
Loaded configuration file.
Returns
-------
target_source : `~astroplan.FixedTarget`
"""
source_name = (
config["target_source"]["name"]
if config["target_source"]["name"]
else "test_source"
)

try:
coords = config["target_source"]["coordinates"]
target_source_coordinates = SkyCoord(
coords["ra_l"], coords["dec_b"], frame=coords["frame"].lower()
)
target_source = FixedTarget(coord=target_source_coordinates, name=source_name)
except ValueError:
logging.exception("Invalid target source coordinates.")
return target_source


def setup_logging(log_level, source_name):
"""
Create a logger.
Expand Down Expand Up @@ -213,17 +244,15 @@ def initialize_model(config):
initialized_model : `~gammapy.modeling.models.SpectralModel`
Initialized instance of a spectral model.
"""
model_name = config["assumed_model"]["name"]
assumed_model_cfg = config["target_source"]["assumed_model"]
model_name = assumed_model_cfg["name"]
module_name = ".".join(model_name.split(".")[:-1])
class_name = model_name.split(".")[-1]
module = importlib.import_module(module_name)
model = getattr(module, class_name)
model_parameters = config["assumed_model"]["parameters"]
model_parameters = assumed_model_cfg["parameters"]

if (
class_name == "LogParabolaSpectralModel"
and config["assumed_model"]["from_log10"]
):
if class_name == "LogParabolaSpectralModel" and assumed_model_cfg["from_log10"]:
initialized_model = model.from_log10(**model_parameters)
else:
initialized_model = model(**model_parameters)
Expand Down

0 comments on commit 8dab0fc

Please sign in to comment.