pz-rail-astro-tools 1.0.6__tar.gz → 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pz-rail-astro-tools might be problematic. Click here for more details.

Files changed (52) hide show
  1. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/PKG-INFO +1 -1
  2. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/pz_rail_astro_tools.egg-info/PKG-INFO +1 -1
  3. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/pz_rail_astro_tools.egg-info/SOURCES.txt +1 -0
  4. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/astro_tools/_version.py +2 -2
  5. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/degraders/unrec_bl_model.py +50 -8
  6. pz_rail_astro_tools-1.0.7/src/rail/pipelines/degradation/truth_to_observed.py +83 -0
  7. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/tests/astro_tools/test_degraders.py +10 -2
  8. pz_rail_astro_tools-1.0.7/tests/astro_tools/test_pipline.py +17 -0
  9. pz_rail_astro_tools-1.0.6/tests/astro_tools/test_pipline.py +0 -16
  10. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.copier-answers.yml +0 -0
  11. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/ISSUE_TEMPLATE/0-general_issue.md +0 -0
  12. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/ISSUE_TEMPLATE/1-bug_report.md +0 -0
  13. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/ISSUE_TEMPLATE/2-feature_request.md +0 -0
  14. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/pull_request_template.md +0 -0
  15. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/workflows/add-issue-to-project-tracker.yml +0 -0
  16. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/workflows/linting.yml +0 -0
  17. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/workflows/publish-to-pypi.yml +0 -0
  18. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/workflows/smoke-test.yml +0 -0
  19. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.github/workflows/testing-and-coverage.yml +0 -0
  20. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.gitignore +0 -0
  21. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/.pre-commit-config.yaml +0 -0
  22. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/LICENSE +0 -0
  23. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/README.md +0 -0
  24. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/environment.yml +0 -0
  25. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/pyproject.toml +0 -0
  26. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/setup.cfg +0 -0
  27. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/setup.py +0 -0
  28. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/pz_rail_astro_tools.egg-info/dependency_links.txt +0 -0
  29. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/pz_rail_astro_tools.egg-info/requires.txt +0 -0
  30. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/pz_rail_astro_tools.egg-info/top_level.txt +0 -0
  31. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/astro_tools/__init__.py +0 -0
  32. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/degraders/grid_selection.py +0 -0
  33. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/degraders/observing_condition_degrader.py +0 -0
  34. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/degraders/photometric_errors.py +0 -0
  35. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/degraders/spectroscopic_degraders.py +0 -0
  36. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/degraders/spectroscopic_selections.py +0 -0
  37. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/creation/engines/gcr_engine.py +0 -0
  38. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/creation_data/data/HSC_grid_settings.pkl +0 -0
  39. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/creation_data/data/hsc_ratios_and_specz.hdf5 +0 -0
  40. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/creation_data/data/survey_conditions/DC2-dr6-galcounts-i20-i25.3-nside-128.fits +0 -0
  41. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/creation_data/data/survey_conditions/DC2-mask-neg-nside-128.fits +0 -0
  42. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/creation_data/data/survey_conditions/minion_1016_dc2_Median_airmass_i_and_nightlt1825_HEAL.fits +0 -0
  43. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/creation_data/data/survey_conditions/minion_1016_dc2_Median_fiveSigmaDepth_i_and_nightlt1825_HEAL.fits +0 -0
  44. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/examples_data/testdata/rubin_dm_dc2_example2.pq +0 -0
  45. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/pipelines/degradation/apply_phot_errors.py +0 -0
  46. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/pipelines/degradation/blending.py +0 -0
  47. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/pipelines/degradation/spectroscopic_selection_pipeline.py +0 -0
  48. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/src/rail/tools/photometry_tools.py +0 -0
  49. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/tests/astro_tools/gcr_test_data/schema.yaml +0 -0
  50. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/tests/astro_tools/gcr_test_data/test_object_tract_4850.hdf5 +0 -0
  51. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/tests/astro_tools/test_core.py +0 -0
  52. {pz_rail_astro_tools-1.0.6 → pz_rail_astro_tools-1.0.7}/tests/astro_tools/test_gcr_engine.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pz-rail-astro-tools
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Author-email: "LSST Dark Energy Science Collaboration (DESC)" <lsst-desc-rail-admin@slac.stanford.edu>
5
5
  License: MIT License
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pz-rail-astro-tools
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Author-email: "LSST Dark Energy Science Collaboration (DESC)" <lsst-desc-rail-admin@slac.stanford.edu>
5
5
  License: MIT License
6
6
 
@@ -39,6 +39,7 @@ src/rail/examples_data/testdata/rubin_dm_dc2_example2.pq
39
39
  src/rail/pipelines/degradation/apply_phot_errors.py
40
40
  src/rail/pipelines/degradation/blending.py
41
41
  src/rail/pipelines/degradation/spectroscopic_selection_pipeline.py
42
+ src/rail/pipelines/degradation/truth_to_observed.py
42
43
  src/rail/tools/photometry_tools.py
43
44
  tests/astro_tools/test_core.py
44
45
  tests/astro_tools/test_degraders.py
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.0.6'
16
- __version_tuple__ = version_tuple = (1, 0, 6)
15
+ __version__ = version = '1.0.7'
16
+ __version_tuple__ = version_tuple = (1, 0, 7)
@@ -3,6 +3,7 @@
3
3
  from ceci.config import StageParameter as Param
4
4
  from rail.creation.degrader import Degrader
5
5
  from rail.core.data import PqHandle
6
+ from rail.core.common_params import SHARED_PARAMS
6
7
  import numpy as np, pandas as pd
7
8
  import FoFCatalogMatching
8
9
 
@@ -20,7 +21,9 @@ class UnrecBlModel(Degrader):
20
21
  config_options.update(ra_label=Param(str, 'ra', msg='ra column name'),
21
22
  dec_label=Param(str, 'dec', msg='dec column name'),
22
23
  linking_lengths=Param(float, 1.0, msg='linking_lengths for FoF matching'),
23
- bands=Param(str, 'ugrizy', msg='name of filters'),
24
+ bands=SHARED_PARAMS,
25
+ ref_band=SHARED_PARAMS,
26
+ redshift_col=SHARED_PARAMS,
24
27
  match_size=Param(bool, False, msg='consider object size for finding blends'),
25
28
  match_shape=Param(bool, False, msg='consider object shape for finding blends'),
26
29
  obj_size=Param(str, 'obj_size', msg='object size column name'),
@@ -30,6 +33,8 @@ class UnrecBlModel(Degrader):
30
33
 
31
34
  outputs = [("output", PqHandle), ("compInd", PqHandle)]
32
35
 
36
+ blend_info_cols = ['group_id', 'n_obj', 'brightest_flux', 'total_flux', 'z_brightest', 'z_weighted', 'z_mean', 'z_stdev']
37
+
33
38
  def __call__(self, sample, seed: int = None):
34
39
  """The main interface method for ``Degrader``.
35
40
 
@@ -89,32 +94,70 @@ class UnrecBlModel(Degrader):
89
94
  def __merge_bl__(self, data):
90
95
 
91
96
  """Merge sources within a group into unrecognized blends."""
92
-
97
+
93
98
  group_id = data['group_id']
94
99
  unique_id = np.unique(group_id)
95
100
 
96
101
  ra_label, dec_label = self.config.ra_label, self.config.dec_label
97
- cols = [ra_label, dec_label] + [b for b in self.config.bands] + ['group_id']
102
+ cols = [ra_label, dec_label] + [b for b in self.config.bands] + self.blend_info_cols
98
103
 
99
104
  N_rows = len(unique_id)
100
105
  N_cols = len(cols)
101
106
 
107
+ # compute the fluxes once for all the galaxies
108
+ fluxes = {b:10**(-data[b]/2.5) for b in self.config.bands}
109
+
110
+ # pull the column indices
111
+ idx_ra = cols.index(ra_label)
112
+ idx_dec = cols.index(dec_label)
113
+ idx_n_obj = cols.index('n_obj')
114
+ idx_brightest_flux = cols.index('brightest_flux')
115
+ idx_total_flux = cols.index('total_flux')
116
+ idx_z_brightest = cols.index('z_brightest')
117
+ idx_z_mean = cols.index('z_mean')
118
+ idx_z_weighted = cols.index('z_weighted')
119
+ idx_z_stdev = cols.index('z_stdev')
120
+
102
121
  mergeData = np.zeros((N_rows, N_cols))
103
122
  for i, id in enumerate(unique_id):
104
123
 
105
- this_group = data.query(f'group_id=={id}')
124
+ # Get the mask for this grouping
125
+ mask = data['group_id'] == id
126
+
127
+ # Get the data and fluxes for this grouping
128
+ this_group = data[mask]
129
+ these_fluxes = {b:fluxes[b][mask] for b in self.config.bands}
130
+
131
+ # Pull put some useful stuff
132
+ n_obj = len(this_group)
133
+ ref_fluxes = these_fluxes[self.config.ref_band]
134
+ these_redshifts = this_group[self.config.redshift_col]
106
135
 
107
136
  ## take the average position for the blended source
108
- mergeData[i, cols.index(ra_label)] = this_group[ra_label].mean()
109
- mergeData[i, cols.index(dec_label)] = this_group[dec_label].mean()
137
+ mergeData[i, idx_ra] = this_group[ra_label].mean()
138
+ mergeData[i, idx_dec] = this_group[dec_label].mean()
110
139
 
111
140
  ## sum up the fluxes into the blended source
112
141
  for b in self.config.bands:
113
- mergeData[i, cols.index(b)] = -2.5*np.log10(np.sum(10**(-this_group[b]/2.5)))
142
+ mergeData[i, cols.index(b)] = -2.5*np.log10(np.sum(these_fluxes[b]))
143
+
144
+ brighest_idx = np.argmax(ref_fluxes)
145
+
146
+ mergeData[i, idx_n_obj] = n_obj
147
+ mergeData[i, idx_brightest_flux] = ref_fluxes.max()
148
+ mergeData[i, idx_total_flux] = np.sum(ref_fluxes)
149
+ mergeData[i, idx_z_brightest] = these_redshifts.iloc[brighest_idx]
150
+ mergeData[i, idx_z_mean] = np.mean(these_redshifts)
151
+ mergeData[i, idx_z_weighted] = np.sum(these_redshifts*ref_fluxes)/np.sum(ref_fluxes)
152
+ if n_obj > 1:
153
+ mergeData[i, idx_z_stdev] = np.std(these_redshifts)
154
+ else:
155
+ mergeData[i, idx_z_stdev] = 0.
114
156
 
115
157
  mergeData[:,cols.index('group_id')] = unique_id
116
158
  mergeData_df = pd.DataFrame(data=mergeData, columns=cols)
117
159
  mergeData_df['group_id'] = mergeData_df['group_id'].astype(int)
160
+ mergeData_df['n_obj'] = mergeData_df['n_obj'].astype(int)
118
161
 
119
162
  return mergeData_df
120
163
 
@@ -133,4 +176,3 @@ class UnrecBlModel(Degrader):
133
176
  # Return the new catalog and component index in original catalog
134
177
  self.add_data("output", blData)
135
178
  self.add_data("compInd", compInd)
136
-
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # Prerquisites, os, and numpy
5
+ import os
6
+ import numpy as np
7
+
8
+ # Various rail modules
9
+ from rail.tools.photometry_tools import Dereddener, Reddener
10
+
11
+ from rail.core.stage import RailStage, RailPipeline
12
+
13
+ import ceci
14
+
15
+ from rail.core.utils import RAILDIR
16
+
17
+ from rail.creation.degraders.unrec_bl_model import UnrecBlModel
18
+
19
+ from .spectroscopic_selection_pipeline import SELECTORS, CommonConfigParams
20
+ from .apply_phot_errors import ERROR_MODELS
21
+
22
+
23
+ if 'PZ_DUSTMAP_DIR' not in os.environ: # pragma: no cover
24
+ os.environ['PZ_DUSTMAP_DIR'] = '.'
25
+
26
+ dustmap_dir = os.path.expandvars("${PZ_DUSTMAP_DIR}")
27
+
28
+
29
+ class TruthToObservedPipeline(RailPipeline):
30
+
31
+ default_input_dict = dict(input='dummy.in')
32
+
33
+ def __init__(self, error_models=None, selectors=None, blending=False):
34
+ RailPipeline.__init__(self)
35
+
36
+ DS = RailStage.data_store
37
+ DS.__class__.allow_overwrite = True
38
+
39
+ if error_models is None:
40
+ error_models = ERROR_MODELS.copy()
41
+
42
+ if selectors is None:
43
+ selectors = SELECTORS.copy()
44
+
45
+ config_pars = CommonConfigParams.copy()
46
+
47
+ self.reddener = Reddener.build(
48
+ dustmap_dir=dustmap_dir,
49
+ copy_all_cols=True,
50
+ )
51
+ previous_stage = self.reddener
52
+
53
+ if blending:
54
+ self.unrec_bl = UnrecBlModel.build()
55
+ previous_stage = self.unrec_bl
56
+
57
+ for key, val in error_models.items():
58
+ error_model_class = ceci.PipelineStage.get_stage(val['ErrorModel'], val['Module'])
59
+ the_error_model = error_model_class.make_and_connect(
60
+ name=f'error_model_{key}',
61
+ connections=dict(input=previous_stage.io.output),
62
+ hdf5_groupname='',
63
+ )
64
+ self.add_stage(the_error_model)
65
+ previous_stage = the_error_model
66
+
67
+ dereddener_errors = Dereddener.make_and_connect(
68
+ name=f"deredden_{key}",
69
+ dustmap_dir=dustmap_dir,
70
+ connections=dict(input=previous_stage.io.output),
71
+ copy_all_cols=True,
72
+ )
73
+ self.add_stage(dereddener_errors)
74
+ previous_stage = dereddener_errors
75
+
76
+ for key2, val2 in selectors.items():
77
+ the_class = ceci.PipelineStage.get_stage(val2['Select'], val2['Module'])
78
+ the_selector = the_class.make_and_connect(
79
+ name=f'select_{key}_{key2}',
80
+ connections=dict(input=previous_stage.io.output),
81
+ **config_pars,
82
+ )
83
+ self.add_stage(the_selector)
@@ -83,13 +83,14 @@ def data_for_bl():
83
83
  DS.__class__.allow_overwrite = True
84
84
 
85
85
  # generate random normal data
86
- columns=['ra', 'dec', 'u', 'g', 'r', 'i', 'z', 'y']
86
+ columns=['ra', 'dec', 'u', 'g', 'r', 'i', 'z', 'y', 'redshift']
87
87
  rng = np.random.default_rng(0)
88
88
  x = rng.normal(loc=23, scale=3, size=(1000, len(columns)))
89
89
 
90
90
  # replace positions with constrained values
91
91
  x[:, 0] = np.random.uniform(low=0, high=0.02, size=1000)
92
92
  x[:, 1] = np.random.uniform(low=0, high=0.02, size=1000)
93
+ x[:, 8] = np.random.uniform(low=0, high=3.00, size=1000)
93
94
 
94
95
  # return data in handle wrapping a pandas DataFrame
95
96
  df = pd.DataFrame(x, columns=columns)
@@ -421,7 +422,14 @@ def test_EucliErrorModel(data):
421
422
  def test_BLModel(data_for_bl):
422
423
  # Setup the stage
423
424
 
424
- degrader = UnrecBlModel.make_stage(name='unrec_bl_model', ra_label='ra', dec_label='dec', linking_lengths=1.0, bands='ugrizy', seed=1234)
425
+ degrader = UnrecBlModel.make_stage(
426
+ name='unrec_bl_model',
427
+ ra_label='ra',
428
+ dec_label='dec',
429
+ linking_lengths=1.0,
430
+ bands='ugrizy',
431
+ ref_band='i',
432
+ seed=1234)
425
433
 
426
434
  # Apply the degrader and get the data out
427
435
  outputs = degrader(data_for_bl)
@@ -0,0 +1,17 @@
1
+ import os
2
+ from rail.utils.testing_utils import build_and_read_pipeline
3
+
4
+ import pytest
5
+
6
+ @pytest.mark.parametrize(
7
+ "pipeline_class, options",
8
+ [
9
+ ('rail.pipelines.degradation.apply_phot_errors.ApplyPhotErrorsPipeline', {}),
10
+ ('rail.pipelines.degradation.blending.BlendingPipeline', {}),
11
+ ('rail.pipelines.degradation.spectroscopic_selection_pipeline.SpectroscopicSelectionPipeline', {}),
12
+ ('rail.pipelines.degradation.truth_to_observed.TruthToObservedPipeline', {'blending':True}),
13
+ ]
14
+ )
15
+ def test_build_and_read_pipeline(pipeline_class, options):
16
+ build_and_read_pipeline(pipeline_class, **options)
17
+
@@ -1,16 +0,0 @@
1
- import os
2
- from rail.utils.testing_utils import build_and_read_pipeline
3
-
4
- import pytest
5
-
6
- @pytest.mark.parametrize(
7
- "pipeline_class",
8
- [
9
- 'rail.pipelines.degradation.apply_phot_errors.ApplyPhotErrorsPipeline',
10
- 'rail.pipelines.degradation.blending.BlendingPipeline',
11
- 'rail.pipelines.degradation.spectroscopic_selection_pipeline.SpectroscopicSelectionPipeline',
12
- ]
13
- )
14
- def test_build_and_read_pipeline(pipeline_class):
15
- build_and_read_pipeline(pipeline_class)
16
-