Skip to content

Commit

Permalink
Merge pull request #315 from SNEWS2/JostMigenda/Cleanup
Browse files Browse the repository at this point in the history
Various bits of cleanup
  • Loading branch information
JostMigenda authored Apr 26, 2024
2 parents ef94617 + fc03661 commit 1e1f520
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Set up the Python environment and dependencies
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions python/snewpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ._version import __version__
from pathlib import Path
from sys import exit
import os

try:
Expand Down
7 changes: 2 additions & 5 deletions python/snewpy/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
from scipy.integrate import cumulative_trapezoid
from scipy.interpolate import interp1d
from enum import IntEnum

from copy import copy
from functools import wraps

#list of units which will be used as units for decomposition inside the Container
Expand Down Expand Up @@ -285,16 +283,15 @@ def integrate(self, axis:Union[Axes,str], limits:np.ndarray=None)->'Container':
yc = cumulative_trapezoid(self.array, x=ax, axis=axis, initial=0)
#get first and last value to use as the fill values
yc_limits = (yc.take(0,axis=axis), yc.take(-1,axis=axis))
#this will make the _intergal constant if it gets out of bounds,
#this will make the _integral constant if it gets out of bounds,
# i.e. effectively the flux outside of bounds is zero
_integral = interp1d(x=ax, y=yc, fill_value=yc_limits, axis=axis, bounds_error=False)
array = np.diff(_integral(limits),axis=axis) << (self.array.unit*ax.unit)
axes = list(self.axes)
axes[axis] = limits
#choose the proper class
return Container(array, *axes, integrable_axes=self._integrable_axes.difference({axis}))
return result


def integrate_or_sum(self, axis:Union[Axes,str])->'Container':
if self.can_integrate(axis):
return self.integrate(axis)
Expand Down
4 changes: 2 additions & 2 deletions python/snewpy/models/presn_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Odrzywolek_2010(SupernovaModel):
def __init__(self, filename:str):
df = pd.read_csv(
self.request_file(filename),
delim_whitespace=True,
sep='\s+',
skiprows=1,
usecols=[1,6,7,8],
names=["time","a","alpha","b"],
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(self, filename:str):
df = pd.read_csv(
self.request_file(filename),
comment="#",
delim_whitespace=True,
sep='\s+',
names=["time","Enu",Flavor.NU_E,Flavor.NU_E_BAR,Flavor.NU_X,Flavor.NU_X_BAR],
usecols=range(6),
)
Expand Down
1 change: 0 additions & 1 deletion python/snewpy/rate_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from astropy import units as u
from warnings import warn
from typing import Dict
from dataclasses import dataclass
from typing import Callable
import scipy.stats as st

Expand Down
10 changes: 5 additions & 5 deletions python/snewpy/snowglobes_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, base_dir:Path='', detectors:str="all", detector_effects=True)
self._load_smearing_matrices(self.base_dir/'smear')

def _load_detectors(self, path:Path, detectors:str):
df = pd.read_table(path,names=['name','mass','factor'], delim_whitespace=True, comment='#')
df = pd.read_table(path, names=['name', 'mass', 'factor'], sep='\s+', comment='#')
df['tgt_mass']=df.mass*df.factor

if detectors == 'all':
Expand All @@ -108,17 +108,17 @@ def _load_channels(self, chan_dir):
if l.startswith('%'):
# Format 1: explicit binning, same for all channels
tokens = l.split()[1:]
df = pd.read_table(f, delim_whitespace=True, index_col=1, comment='%', names=['name','n','parity','flavor','weight'])
df = pd.read_table(f, sep='\s+', index_col=1, comment='%', names=['name','n','parity','flavor','weight'])
elif l.startswith('SN_nu'):
# Format 2: explicit binning, differs per channel
tokens = l.split()[6:]
df = pd.read_table(f, delim_whitespace=True, index_col=1, comment='%', names=['name','n','parity','flavor','weight'], usecols=range(1,6))
df = pd.read_table(f, sep='\s+', index_col=1, comment='%', names=['name','n','parity','flavor','weight'], usecols=range(1,6))
# drop coherent scattering channels, which have different binning
df = df[df["name"].str.startswith('coh_') == False]
else:
# Format 3: no binning specified, use SNOwGLoBES default values
tokens = '% 200 0.0005 0.100 200 0.0005 0.100'.split()[1:]
df = pd.read_table(f, delim_whitespace=True, index_col=1, comment='%', names=['name','n','parity','flavor','weight'])
df = pd.read_table(f, sep='\s+', index_col=1, comment='%', names=['name','n','parity','flavor','weight'])

self.channels[material] = df

Expand All @@ -136,7 +136,7 @@ def _load_efficiency_vectors(self, path):
for detector in self.detectors:
res_det = {}
for file in (path/str(detector)).glob(f'effic_*_{detector}.dat'):
channel = file.stem[len('effic_'):-len(detector)-1]
channel = file.stem[len('effic_'):-len(detector)-1]
logger.debug(f'Reading file ({detector},{channel}): {file}')
with open(file) as f:
effs = np.fromiter(f.readlines()[0].split("{")[-1].split("}")[0].split(","), float)
Expand Down

0 comments on commit 1e1f520

Please sign in to comment.