Skip to content

Commit

Permalink
Merge pull request #46 from LSSTDESC/fix_numpy_error
Browse files Browse the repository at this point in the history
Fix error with new numpy version
  • Loading branch information
ztq1996 authored Jul 31, 2024
2 parents 60d6359 + 064be05 commit 89d3ca8
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing-and-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"deprecated",
"pz-rail-base",
"pz-rail-base>=1.0.3",
"numpy",
"pandas>=2.2.2",
"astropy",
"healpy",
"photerr",
Expand Down
4 changes: 2 additions & 2 deletions src/rail/creation/degraders/grid_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class GridSelection(Selector):
random_seed=Param(int, 12345, msg="random seed for reproducibility"),
scaling_factor=Param(float, 1.588, msg="multiplicative factor for ratios to adjust number of galaxies kept"))

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):

Selector.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)

if self.config.redshift_cut < 0:
raise ValueError("redshift cut must be positive")
Expand Down
4 changes: 2 additions & 2 deletions src/rail/creation/degraders/lsst_error_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class LSSTErrorModel(Degrader):
required=False,
)

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):
"""
Constructor
Does standard Degrader initialization and sets up the error model.
"""
Degrader.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)
self.error_model = PhotErrErrorModel(
**{key: self.config[key] for key in self._photerr_params}
)
Expand Down
4 changes: 2 additions & 2 deletions src/rail/creation/degraders/observing_condition_degrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class ObsCondition(Noisifier):
}


def __init__(self, args, comm=None):
Noisifier.__init__(self, args, comm=comm)
def __init__(self, args, **kwargs):
super().__init__(args, **kwargs)

# store a list of keys relevant for
# survey conditions;
Expand Down
20 changes: 6 additions & 14 deletions src/rail/creation/degraders/photometric_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ def set_params(self, peparams):
required=False,
)

def __init__(self, args, comm=None):
"""
Constructor
Does standard Degrader initialization and sets up the error model.
"""
Noisifier.__init__(self, args, comm=comm)

def _initNoiseModel(self):
"""
Initialize the noise model by the peNoiseModel
Expand Down Expand Up @@ -93,9 +85,9 @@ class LSSTErrorModel(PhotoErrorModel):

name = "LSSTErrorModel"

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):

PhotoErrorModel.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)

self.set_params(peLsstErrorParams)
self.peNoiseModel = peLsstErrorModel
Expand All @@ -111,9 +103,9 @@ class RomanErrorModel(PhotoErrorModel):

name = "RomanErrorModel"

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):

PhotoErrorModel.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)

self.set_params(peRomanErrorParams)
self.peNoiseModel = peRomanErrorModel
Expand All @@ -128,9 +120,9 @@ class EuclidErrorModel(PhotoErrorModel):

name = "EuclidErrorModel"

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):

PhotoErrorModel.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)

self.set_params(peEuclidErrorParams)
self.peNoiseModel = peEuclidErrorModel
8 changes: 4 additions & 4 deletions src/rail/creation/degraders/spectroscopic_degraders.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class LineConfusion(Noisifier):
wrong_wavelen=float,
frac_wrong=float)

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):
"""
"""
Noisifier.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)
# validate parameters
if self.config.true_wavelen < 0:
raise ValueError("true_wavelen must be positive, not {self.config.true_wavelen}")
Expand Down Expand Up @@ -115,10 +115,10 @@ class InvRedshiftIncompleteness(Selector):
config_options = Selector.config_options.copy()
config_options.update(pivot_redshift=float)

def __init__(self, args, comm=None):
def __init__(self, args, **kwargs):
"""
"""
Selector.__init__(self, args, comm=comm)
super().__init__(args, **kwargs)
if self.config.pivot_redshift < 0:
raise ValueError("pivot redshift must be positive, not {self.config.pivot_redshift}")

Expand Down
6 changes: 3 additions & 3 deletions src/rail/creation/degraders/spectroscopic_selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class SpecSelection(Selector):
random_seed=Param(int, 42, msg="random seed for reproducibility"),
)

def __init__(self, args, comm=None):
Selector.__init__(self, args, comm=comm)
def __init__(self, args, **kwargs):
super().__init__(args, **kwargs)
self._validate_settings()
self.mask = None
self.rng = None
Expand Down Expand Up @@ -155,7 +155,7 @@ def _select(self):
# get the bands and bandNames present in the data
data = self.get_data("input", allow_missing=True)
self.validate_colnames(data)
self.mask = np.product(~np.isnan(data.to_numpy()), axis=1)
self.mask = np.prod(~np.isnan(data.to_numpy()), axis=1)
self.invalid_cut(data)
self.selection(data)
if self.config.downsample is True:
Expand Down
4 changes: 2 additions & 2 deletions src/rail/creation/engines/gcr_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class GCRCreator(Creator):
),
)

def __init__(self, args, comm=None):
Creator.__init__(self, args, comm=comm)
def __init__(self, args, **kwargs):
super().__init__(args, **kwargs)

# Provides override for unit test
self._catalog_override = None
Expand Down
10 changes: 2 additions & 8 deletions src/rail/tools/photometry_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class PhotometryManipulator(RailStage, ABC):
inputs = [('input', PqHandle)]
outputs = [('output', PqHandle)]

def __init__(self, args, comm=None):
super().__init__(args, comm)
def __init__(self, args, **kwargs):
super().__init__(args, **kwargs)
self._check_config()
# convenience remapping of parameters
self.value_columns = self.config.value_columns
Expand Down Expand Up @@ -371,9 +371,6 @@ class LSSTFluxToMagConverter(RailStage):
inputs = [('input', PqHandle)]
outputs = [('output', Hdf5Handle)]

def __init__(self, args, comm=None):
RailStage.__init__(self, args, comm=comm)

def _flux_to_mag(self, flux_vals):
return -2.5*np.log10(flux_vals) + self.config.mag_offset

Expand Down Expand Up @@ -452,9 +449,6 @@ def fetch_map(self):
fetch_func = dust_map_submod.fetch
fetch_func()


def __init__(self, args, comm=None):
RailStage.__init__(self, args, comm=comm)

def run(self):
data = self.get_data('input', allow_missing=True)
Expand Down
20 changes: 20 additions & 0 deletions tests/astro_tools/test_degraders.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ def test_InvRedshiftIncompleteness_returns_correct_shape(data):
assert degraded_data.shape[1] == data.data.shape[1]
os.remove(degrader.get_output(degrader.get_aliased_tag("output"), final_name=True))


def test_LineConfusion_returns_correct_shape(data):
"""Make sure returns same number of columns, fewer rows"""
OII = 3727
OIII = 5007

lc_2p_0II_0III = LineConfusion.make_stage(
name="lc_2p_0II_0III", true_wavelen=OII, wrong_wavelen=OIII, frac_wrong=0.02
)
lc_1p_0III_0II = LineConfusion.make_stage(
name="lc_1p_0III_0II", true_wavelen=OIII, wrong_wavelen=OII, frac_wrong=0.01
)
degraded_data = lc_1p_0III_0II(
lc_2p_0II_0III(data)
).data
assert degraded_data.shape[0] <= data.data.shape[0]
assert degraded_data.shape[1] == data.data.shape[1]
os.remove(lc_2p_0II_0III.get_output(lc_2p_0II_0III.get_aliased_tag("output"), final_name=True))
os.remove(lc_1p_0III_0II.get_output(lc_1p_0III_0II.get_aliased_tag("output"), final_name=True))


@pytest.mark.parametrize(
"percentile_cut,redshift_cut,errortype",
Expand Down

0 comments on commit 89d3ca8

Please sign in to comment.