Skip to content

Commit

Permalink
Update main with observability check
Browse files Browse the repository at this point in the history
  • Loading branch information
HealthyPear committed Sep 19, 2024
1 parent a5f8252 commit 1f6da45
Showing 1 changed file with 48 additions and 32 deletions.
80 changes: 48 additions & 32 deletions src/iact_estimator/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
calculate,
)
from ..plots import plot_spectrum, plot_sed, plot_transit, plot_altitude_airmass
from ..observability import define_constraints, check_observability
from .. import RESOURCES_PATH

parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -127,6 +128,53 @@ def main():
seaborn_options = config["seaborn_options"]
sns.set_theme(**seaborn_options)

# Basic observability checks
target_source = FixedTarget.from_name(source_name)
observer = Observer.at_site("Roque de los Muchachos")
time = Time(config["observation_datetime"])

crab = FixedTarget.from_name("Crab")

constraints = define_constraints(config)

time_range = config["observation"]["datetime"] + 1 * u.year

ever_observable, always_observable, best_months = check_observability(
constraints, observer, target_source, time_range
)

if not ever_observable:
logger.info("The source is never observable from this location!")
parser.exit(0)

logger.info(f"The best months to observe the target source are {best_months}.")

with quantity_support():
plot_transit(
config,
source_name,
target_source,
observer,
time,
merge_profiles=config["plotting_options"]["merge_horizon_profiles"],
plot_crab=True if (crab.coord == target_source.coord) else False,
style_kwargs=None,
savefig=True,
output_path=output_path,
)

plot_altitude_airmass(
config,
source_name,
target_source,
observer,
time,
brightness_shading=True,
airmass_yaxis=True,
savefig=True,
output_path=output_path,
)

logger.info("Initializing assumed model")
assumed_spectrum = initialize_model(config)

Expand Down Expand Up @@ -175,38 +223,6 @@ def main():

logger.info("All expected operations have been perfomed succesfully.")

target_source = FixedTarget.from_name(source_name)
observer = Observer.at_site("Roque de los Muchachos")
time = Time(config["observation_datetime"])

crab = FixedTarget.from_name("Crab")

with quantity_support():
plot_transit(
config,
source_name,
target_source,
observer,
time,
merge_profiles=config["plotting_options"]["merge_horizon_profiles"],
plot_crab=True if (crab.coord == target_source.coord) else False,
style_kwargs=None,
savefig=True,
output_path=output_path,
)

plot_altitude_airmass(
config,
source_name,
target_source,
observer,
time,
brightness_shading=True,
airmass_yaxis=True,
savefig=True,
output_path=output_path,
)

if config["plotting_options"]["show"]:
plt.show()

Expand Down

0 comments on commit 1f6da45

Please sign in to comment.