Skip to content

Commit

Permalink
refactor(repoe): resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
steob92 committed May 27, 2024
2 parents 094d055 + ba7bd0a commit 0ac4b83
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 105 deletions.
7 changes: 0 additions & 7 deletions .cz.toml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
push:
branches:
# disabling it for now
- _main
- main
- *_rc

jobs:
bump_version:
Expand Down
51 changes: 42 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
## Unreleased

### Feat

- **background_models**: adding a user defined smoothing sigma
## 1.0.1 (2024-05-09)

### Fix

- **gammapy_tools/analysis/rbm.py**: removing hard coded map size values
- **pyproject.toml**: fixing versioning
- **gammapy_tools/make_background/prepare_data.py**: adding overwrite option

### Refactor

- **analysis_notebook**: updating example
- **data_products**: removing plt.show
- **gammapy_tools/__version__.py**: post test update
- **__version__**: switching to __version__ for the version number

## 1.0.0 (2024-05-07)

## 0.1.3 (2024-02-07)
### Feat

- **utils/exclusion_finder.py**: adding exclusion finder
- **gammapy_tools/fake_source_coordinates/process.py**: adding mimic_data
- **make_background**: parallel reduction of background and mimic search
- **gammapy_tools/make_background**: implementing a parallel + reduction method to spead up background generation
- **make_background**: implementation of closed N background runs
- **background_models**: adding a user defined smoothing sigma

### Fix

- **pyproject.toml**: changing gammapy version
- **gammapy_tools/make_background/background_models.py**: updating to gammapy1.2
- **gammapy_tools/utils/exclusion_finder.py**: adding a check for gammacat and hawc
- **gammapy_tools/utils/exclusion_finder.py**: correcting path
- **gammapy_tools/utils/exclusion_finder.py**: correcting imports and file paths
- **fake_source_coordinates/process.py**: adding safety check
- **gammapy_tools/fake_source_coordinates/process.py**: fixing print and removing target
- **process.py**: correcting background
- **make_background**: storing kl_div table
- **background_tools.py**: exposure searching
- **prepare_data.py**: adding more info
- **prepare_data.py**: raise error when no runs are found
- **gammapy_tools/analysis/rbm.py**: removing hard coded map size values
- **Hipparcos_MAG8_1997.dat**: updated hipparcos file to have correct colour column
- **analysis**: update the analysis scripts to work with config files

### Refactor

- **gammapy_tools/fake_source_coordinates/process.py**: adding more robust file finder
- **fake_source_coordinates/process.py**: reincluding source when scrambling
- **gammapy_tools/fake_source_coordinates/fake_location.py**: popping exisiting background
- **make_background**: removing ignore warnings
- **make_background.py**: removing additional background and allow previous method
- **templates/config.py**: adding KL_DIV
- **utils**: moving functions to utils
- **analysis_notebook**: updating example
- **data_products**: removing plt.show
- **_version.**: bumping version
- **analysis_notebook**: migrating analysis notebook
- **fake_source_coordinates**: adding __all__
- **pyproject.toml**: changing required to minimum python version

### Perf

- **gammapy_tools/utils/run_details.py**: Changed the mimic selection to perform a nested search

## 0.1.2 (2024-01-30)

### Fix
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM jupyter/minimal-notebook AS base

# Install gammapy
RUN mamba install gcc jupyterlab --yes
RUN mamba install gcc jupyterlab "gammapy==1.2" --yes
WORKDIR /gammapy-tools


Expand All @@ -28,14 +28,17 @@ COPY --from=base /opt/conda /opt/conda
WORKDIR /gammapy-tools/tmp_build

# RUN gammapy download datasets
ENV GAMMAPY_DATA=/gammapy-tools/gammapy-datasets/1.1/
ENV GAMMAPY_DATA=/gammapy-tools/gammapy-datasets/1.2/
RUN mkdir -p $GAMMAPY_DATA
WORKDIR /gammapy-tools/
RUN gammapy download datasets

# Add package
ADD --chown=1000:100 . /gammapy-tools/tmp_build/gammapy-tools
WORKDIR /gammapy-tools/tmp_build/gammapy-tools



# RUN ls -lah
RUN pip install .
# RUN ./gammapy_tools/Hipparcos_MAG8_1997.dat $GAMMAPY_DATA/catalogs/
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ services:
- JUPYTER_TOKEN=letmein
volumes:
# Replace with where your data is located
- /path/to/data:/local_data
- $GAMMAPY_DATA:/gammapy-tools/gammapy-datasets/1.1/
- /home/obriens/DataAnalysis/Veritas/Gammapy:/local_data
# - $GAMMAPY_DATA:/gammapy-tools/gammapy-datasets/1.1/
Empty file modified docker_build.sh
100644 → 100755
Empty file.
29 changes: 17 additions & 12 deletions gammapy-tools.def
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ Stage: build
# Port for jupyter lab
export JPORT=8000
export GAMMAPY_DATA=/gamma-tools/gammapy-datasets/1.2/
. "/opt/conda/etc/profile.d/conda.sh"
. /opt/conda/bin/activate
export PATH=/opt/conda/bin/:$PATH

#. "/opt/conda/etc/profile.d/conda.sh"
#. /opt/conda/bin/activate
#export PATH=/opt/conda/bin/:$PATH
. /opt/gammapy_tools/bin/activate


%post

apt update
apt upgrade -y
apt install curl bash git gcc btop emacs -y
apt install curl bash git gcc btop emacs python3 python3-pip python3.12-venv -y

# Install mamba and base env
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh -b -p /opt/conda
. /opt/conda/bin/activate

mamba install -c conda-forge iminuit cmasher pip papermill matplotlib pip "jupyterlab==4.0.12" notebook ipykernel ipython ipywidgets --yes
#curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
#bash Miniforge3-$(uname)-$(uname -m).sh -b -p /opt/conda
#. /opt/conda/bin/activate

python3 -m venv /opt/gammapy_tools
. /opt/gammapy_tools/bin/activate
pip install iminuit cmasher pip papermill matplotlib pip "jupyterlab==4.0.12" notebook ipykernel ipython ipywidgets
#mamba install -c conda-forge iminuit cmasher pip papermill matplotlib pip "jupyterlab==4.0.12" notebook ipykernel ipython ipywidgets --yes


# Install v2dl3
Expand All @@ -41,7 +46,7 @@ Stage: build

# Because its an env install of requirements
# Note the python version in the latest test throws issues with pytest
grep -A 100 "dependencies:" environment-eventdisplay.yml | grep "-" | grep -v "python" | awk '{print $2}' | xargs mamba install --yes
grep -A 100 "dependencies:" environment-eventdisplay.yml | grep "-" | grep -v "python" | awk '{print $2}' | xargs pip install

# root_numpy throws issues too. Only VEGAS uses it
mv setup.py _setup.py && grep -v "root_numpy" _setup.py > setup.py && pip install .
Expand All @@ -59,7 +64,7 @@ Stage: build

cd /gamma-tools ; rm -r /gamma-tools/tmp_build

mamba clean -a --yes
#mamba clean -a --yes
python -m pip cache purge


Expand Down
4 changes: 3 additions & 1 deletion gammapy_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from . import make_background
from . import templates
from . import fake_source_coordinates

from .__version__ import __version__
__all__ = (
analysis.__all__
+ make_background.__all__
+ templates.__all__
+ fake_source_coordinates.__all__
+ ["__version__"]
)

File renamed without changes.
66 changes: 40 additions & 26 deletions gammapy_tools/analysis/data_products_LOCAL_4133777.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pathlib import Path
import numpy as np
import astropy.units as u
from astropy.coordinates import Angle, SkyCoord
Expand All @@ -11,7 +10,6 @@

# %matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import display

# gammapy imports
from gammapy.data import DataStore
Expand All @@ -35,10 +33,9 @@
SkyModel,
)
from gammapy.estimators import LightCurveEstimator
from gammapy.analysis import Analysis, AnalysisConfig
from gammapy.catalog import SourceCatalogGammaCat, SourceCatalog3HWC
from gammapy.visualization import plot_spectrum_datasets_off_regions


def make_spectrum_RE(config, plot=True, return_stacked=False):
"""Make a RE spectrum
Expand Down Expand Up @@ -67,8 +64,12 @@ def make_spectrum_RE(config, plot=True, return_stacked=False):
observations = datastore.get_observations()

if config["run_selection"]["pos_from_DL3"]: # get position from DL3 header
hdul = fits.open(config["io"]["out_dir"]+os.listdir(config["io"]["out_dir"])[0])
source_pos = SkyCoord(hdul[1].header["RA_OBJ"]*u.deg, hdul[1].header["DEC_OBJ"]*u.deg)
hdul = fits.open(
config["io"]["out_dir"] + os.listdir(config["io"]["out_dir"])[0]
)
source_pos = SkyCoord(
hdul[1].header["RA_OBJ"] * u.deg, hdul[1].header["DEC_OBJ"] * u.deg
)
else: # get position from ra/dec [deg]
source_pos = SkyCoord(
config["run_selection"]["source_ra"],
Expand Down Expand Up @@ -148,7 +149,9 @@ def make_spectrum_RE(config, plot=True, return_stacked=False):
< 2.0
)
# star_mask &= (star_cat["mag"] + star_cat["colour"]) < 8
star_mask &= (star_cat["mag"]+star_cat["colour"])< config["sky_map"]["min_star_brightness"]
star_mask &= (star_cat["mag"] + star_cat["colour"]) < config["sky_map"][
"min_star_brightness"
]

for src in star_cat[star_mask]:
exclusion_regions.append(
Expand Down Expand Up @@ -192,13 +195,15 @@ def make_spectrum_RE(config, plot=True, return_stacked=False):
info_table = datasets.info_table(cumulative=True)
time = info_table["livetime"].to("h")
sig = info_table["sqrt_ts"]
#plot exclusion regions and reflected regions
if len(exclusion_regions) > 0 and plot:
plt.figure(figsize=(8,8))

# plot exclusion regions and reflected regions
if len(exclusion_regions) > 0 and plot:
plt.figure(figsize=(8, 8))
ax = exclusion_mask.plot()
on_region.to_pixel(ax.wcs).plot(ax=ax, edgecolor="magenta",label='ON')
plot_spectrum_datasets_off_regions(ax=ax, datasets=datasets) #add legend=True to plot run numbers associated w/ OFF regions
on_region.to_pixel(ax.wcs).plot(ax=ax, edgecolor="magenta", label="ON")
plot_spectrum_datasets_off_regions(
ax=ax, datasets=datasets
) # add legend=True to plot run numbers associated w/ OFF regions
plt.show()

# make spectrum model from user input
Expand Down Expand Up @@ -272,25 +277,32 @@ def get_flux_lc(config, type="flux"):

theta = config["sky_map"]["theta"]
datastore = DataStore.from_dir(config["io"]["out_dir"])

if config["io"]["from_runlist"]:
observations = datastore.get_observations(obs_id=np.genfromtxt(config["io"]["runlist"],unpack=True),required_irf="all-optional")
observations = datastore.get_observations(
obs_id=np.genfromtxt(config["io"]["runlist"], unpack=True),
required_irf="all-optional",
)
else:
observations = datastore.get_observations(required_irf="all-optional")

amp, idx = config["spectrum"]["params"]

if config["run_selection"]["pos_from_DL3"]: # get position from DL3 header
hdul = fits.open(config["io"]["out_dir"]+os.listdir(config["io"]["out_dir"])[0])
source_pos = SkyCoord(hdul[1].header["RA_OBJ"]*u.deg, hdul[1].header["DEC_OBJ"]*u.deg)
hdul = fits.open(
config["io"]["out_dir"] + os.listdir(config["io"]["out_dir"])[0]
)
source_pos = SkyCoord(
hdul[1].header["RA_OBJ"] * u.deg, hdul[1].header["DEC_OBJ"] * u.deg
)
else: # get position from ra/dec [deg]
source_pos = SkyCoord(
config["run_selection"]["source_ra"],
config["run_selection"]["source_dec"],
frame="icrs",
unit="deg",
)

e_min = config["spectrum"]["e_min"]
e_max = config["spectrum"]["e_max"]
nbin = config["spectrum"]["e_bins"]
Expand All @@ -315,13 +327,13 @@ def get_flux_lc(config, type="flux"):

# exclusion regions
exclusion_regions = []

exclusion_regions.append(
CircleSkyRegion(
center=source_pos, radius=config["sky_map"]["on_exclusion_region"] * u.deg
)
)

if (
len(config["sky_map"]["exclusion_regions"]) > 0
): # should be a list of CircleSkyRegions
Expand Down Expand Up @@ -358,7 +370,7 @@ def get_flux_lc(config, type="flux"):
"dec": star_data[:, 1],
"id": star_data[:, 2],
"mag": star_data[:, 3],
"colour": star_data[:,4],
"colour": star_data[:, 4],
}
)
star_mask = (
Expand All @@ -369,8 +381,10 @@ def get_flux_lc(config, type="flux"):
< 2.0
)

star_mask &= (star_cat["mag"]+star_cat["colour"])< config["sky_map"]["min_star_brightness"]

star_mask &= (star_cat["mag"] + star_cat["colour"]) < config["sky_map"][
"min_star_brightness"
]

for src in star_cat[star_mask]:
exclusion_regions.append(
CircleSkyRegion(
Expand Down Expand Up @@ -404,7 +418,7 @@ def get_flux_lc(config, type="flux"):
if type == "flux":
time_intervals = [Time([start, stop])]
lc_maker_1d = LightCurveEstimator(
energy_edges=[e_min,e_max] * u.TeV,
energy_edges=[e_min, e_max] * u.TeV,
time_intervals=time_intervals,
n_sigma_ul=2,
reoptimize=False,
Expand Down
Loading

0 comments on commit 0ac4b83

Please sign in to comment.