Skip to content

AnaCal ingestion#446

Open
empEvil wants to merge 70 commits into
masterfrom
AnaCal_ingestion
Open

AnaCal ingestion#446
empEvil wants to merge 70 commits into
masterfrom
AnaCal_ingestion

Conversation

@empEvil

@empEvil empEvil commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

This is a pull request for ingesting the DP2 version of AnaCal. currently it is ingesting a DP1 version of the catalog

Comment thread txpipe/ingest/anacal.py Outdated

@mr-superonion mr-superonion left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the preparing the PR, here is my comment

Comment thread examples/Anacal_test/config.yml Outdated
Comment thread txpipe/ingest/anacal.py Outdated
Comment thread txpipe/ingest/anacal.py
Comment thread txpipe/shear_calibration/calibration_calculators.py Outdated
Comment thread txpipe/source_selection/Anacal.py Outdated
Comment thread txpipe/shear_calibration/calibration_calculators.py Outdated
Comment thread txpipe/shear_calibration/calibration_calculators.py Outdated
The indicies of the objects selected from this chunk of data
"""
data = _DataWrapper(data, "")
select = self.selector(data, *args, **kwargs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the select also need a shear response calculation like what is done in self.get_submask()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure what you mean

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mr-superonion The select function is passed to the code that does the shear calibration. The DataWrapper objects pass in different subsets of data - if the select function asks for data["s2n"], for example, then DataWrapper will give it different columns depending on the second argument used when creating it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation

  1. i am implementing it here (e112dea#r3592442390) to create s2n_1p, s2n_1m, s2n_2p, s2n_2m
  2. then the data wrapper is used here (e112dea#r3592459804) to create different shifted version

Comment thread txpipe/ingest/anacal.py
Comment thread examples/anacal/config.yml
Comment thread txpipe/ingest/anacal.py Outdated
Comment thread txpipe/shear_calibration/calibrators.py Outdated
Comment thread txpipe/source_selection/Anacal.py Outdated
Comment thread txpipe/source_selection/Anacal.py Outdated
Comment thread txpipe/ingest/anacal.py Outdated
config: examples/Anacal_test/config.yml

inputs:
anacal_catalog: /pscratch/sd/x/xiangchl/data/DP1/catalogs/anacal_catalog_a360.fits

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the example do the butler version?

Comment thread txpipe/ingest/anacal.py
Comment thread txpipe/ingest/anacal.py
except Exception as e:
raise RuntimeError(error_msg) from e

if self.config["select_field"]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we have anacal for DP2? If so we might code that applies there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean? The plan is to generate an Anacal catalog for DP2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant that all the fields are DP1 fields so it might not be that useful here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh okay, I also added the option of just providing tracts

Comment thread txpipe/ingest/anacal.py Outdated
@mr-superonion

Copy link
Copy Markdown

It seems that i do not have permission to modify the pr here; therefore i opened a pr to correct for some bugs/typo in this pr:
#482

mr-superonion and others added 3 commits July 14, 2026 23:41
Two equivalent bookkeeping conventions give an unbiased shear:

  (A) <e> = Σ(wsel·e) / N
      R   = Σ(de/dg·wsel + dw/dg·e) / N
      → R_sel normalized by count.

  (B) <e> = Σ(wsel·e) / N / <wsel>
      R   = Σ(de/dg·wsel + dw/dg·e) / N / <wsel>
      → R_sel normalized by sum(wsel).

The rest of the code — R_shape, R_weight, and every mean-e
computation — uses convention (B), so R_sel must match with a
sum_weights denominator, not count.

Also: nanojansky_err_to_mag_ab returns NaN for flux <= 0 via
np.divide(where=flux>0) instead of producing negative sigma_mag
and RuntimeWarnings.
@joezuntz

Copy link
Copy Markdown
Collaborator

@mr-superonion I've added you to the team that gives you permissions for future things.

   as a second stage after ingest, with a matching config.yml block:
   delta_gamma: 0.01, mask_threshold: 40, s2n_cut: 5.0, T_cut: 0.1,
   5-bin source_zbin_edges, input_pz: true.
2. Ingested photo-z point estimates. TXIngestAnacal now reads
   zmode_{0,1p,1m,2p,2m} from the merged catalog and exposes them on the
   shear catalog as mean_z, mean_z_{1p,1m,2p,2m} — baseline for
   tomographic binning, the four variants for the R_sel bin-migration
   term.
3. Built ±γ variants of every quantity the selector cuts on. In
   TXSourceSelectorAnaCal.apply_simple_redshift_cut, injected
   s2n_{1p,1m,2p,2m} = s2n ± δγ · ds2n_dg{1,2}, and analogous variants
   of m00, m20 (from dm00_dg, dm20_dg) and zbin (from mean_z_*). All
   four cut quantities now respond to shear via a single uniform
   injection step.
4. Unified the calculator's cut logic under _DataWrapper. Deleted the
   ad-hoc get_submask size-cut machinery in AnaCalCalculator.add_data.
   The selector now applies mask + s2n + size + zbin in one place; the
   calculator just runs the same selector on five wrappers (baseline +
   _1p/_1m/_2p/_2m), and the wrapper's suffix-lookup routes the shifted
   columns automatically. AnaCalCalculator.__init__ dropped its
   mask_threshold argument as a consequence.
5. Consistent response formulae. Rewrote R_shape, R_weight, R_sel_{1,2}
   in the calculator so all three share the same code shape: Σ(w · X) /
   sum_weights for R_shape and R_weight, and [Σ(w·e)|sel_+ −
   Σ(w·e)|sel_−] / (2 δγ · sum_weights) for R_sel. R_shape switched from
   a ParallelMean to a plain scalar sum for parity; det_response_*
   renamed to weight_response_* to match the "R_weight" label; a small
   _reduce helper replaced 30 lines of MPI reduce boilerplate.
6. Promoted the size threshold to config. The AnaCal size cut,
   previously hard-coded as (m00 + m20) / m00 > 0.1, is now > T_cut —
   driven by the base selector's T_cut config option that was previously
   unused for AnaCal. TXSourceSelectorAnaCal.config_options gives it a
   default of 0.1 alongside a new s2n_cut default of 5.0, so a minimal
   yaml block still runs; both can be overridden in the yaml for
   tighter/looser cuts.

@mr-superonion mr-superonion left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few update to include the selection bias correction for s2n and add selection stage into the example. I will check over the dp1 data to see whether i can get consistent result to the hsc code.

pz_data["s2n_1m"] = s2n - dg * shear_data["ds2n_dg1"]
pz_data["s2n_2p"] = s2n + dg * shear_data["ds2n_dg2"]
pz_data["s2n_2m"] = s2n - dg * shear_data["ds2n_dg2"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the code to create shifted columns for s2n.

shear_cols += ["mean_z"]
# Baseline photo-z + the four shifted variants used to derive
# zbin_{1p,1m,2p,2m} for the selection-response calculation.
shear_cols += ["mean_z", "mean_z_1p", "mean_z_1m", "mean_z_2p", "mean_z_2m"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need columns for the shifted redshifts to get the selection bias due to the binning.

data_1p = _DataWrapper(data, "_1p")
data_1m = _DataWrapper(data, "_1m")
data_2p = _DataWrapper(data, "_2p")
data_2m = _DataWrapper(data, "_2m")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data wrapper is used here to get different shifted version of the catalog

The indicies of the objects selected from this chunk of data
"""
data = _DataWrapper(data, "")
select = self.selector(data, *args, **kwargs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation

  1. i am implementing it here (e112dea#r3592442390) to create s2n_1p, s2n_1m, s2n_2p, s2n_2m
  2. then the data wrapper is used here (e112dea#r3592459804) to create different shifted version

# (zmode_{1p,1m,2p,2m}) in xlens' photoZPipe (currently ±0.01 in
# DISTORTIONS).
delta_gamma: 0.01

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i add the selection stage in the example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we don't want to run them at the same time. Sadly from how things are set up on NERSC, we want to run the ingestion stage in one environment and then the rest of the pipeline should be run in a dedicated environment for TXPipe. But we want to be able to run the Selection stage later, where we might be able to use different photo-z's for example

@empEvil

empEvil commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@mr-superonion Thank you for the additions, I however do not think we should move away from parallel mean if we can avoid it! I am a little confused about what has been moved from the calibration stage to the source-selection, and why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants