Skip to content

Clean up cosmo_inference folder#236

Open
LisaGoh wants to merge 11 commits into
developfrom
235-clean-up-cosmo_inference-folder
Open

Clean up cosmo_inference folder#236
LisaGoh wants to merge 11 commits into
developfrom
235-clean-up-cosmo_inference-folder

Conversation

@LisaGoh

@LisaGoh LisaGoh commented Jul 8, 2026

Copy link
Copy Markdown
Member

Addresses #235. So far I have:

  1. Converted all the plotting notebooks in the folder to the relevant papers/ subfolder and converted them to .py scripts to save space
  2. Removed all but the cosmosis_fitting.py and chain_postprocessing.py scripts since they were overlapping/obsolete.
  3. Cleaned up the cosmosis_config subfolder to only include the template ini files (and separated the ini files into templates and ouput, whereby the contents of output are only generated per user and not included in the repo to keep things lean)
  4. Removed the cosmocov_config subfolder (in preparation for our switch to OneCovariance adoption instead)
  5. Edited the chain_postprocessing.py script to use the cs_util.cosmo functionalities when computing the bestfit $\xi_\pm$ from the $C_\ell$'s

I have not yet run the inference.smk workflow myself, but per Claude the logic should not have been broken with these changes. I hope this helps!

@LisaGoh LisaGoh requested review from cailmdaley and sachaguer July 8, 2026 10:44
@LisaGoh LisaGoh self-assigned this Jul 8, 2026
@LisaGoh LisaGoh linked an issue Jul 8, 2026 that may be closed by this pull request
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

🔴 ruff found lint / format issues

@LisaGoh — these block the merge into develop. Full list below (also surfaced as annotations in the CI run):

ruff check .

✅ clean

ruff format --check .

Would reformat: cosmo_inference/scripts/k_analysis.py
Would reformat: papers/realspace/best_fit_xipm.py
Would reformat: papers/realspace/cov_masking.py
Would reformat: papers/realspace/get_prior_psf_leakage.py
Would reformat: papers/realspace/nonlin_k_analysis.py
5 files would be reformatted, 211 files already formatted

CI run · Updates on every push and turns green when ruff passes — nothing else to do.

@cailmdaley

Copy link
Copy Markdown
Collaborator

Wow I love to see -17k lines :) and i think this is the first time we've seen the new ruff auto-check. Will review in a bit! I think we can leave inference.smk un-tested and fix any bugs when we start running chains on the GLASS mocks

@cailmdaley

Copy link
Copy Markdown
Collaborator

hmm, @martinkilbinger could you please add Lisa as a maintainer to sp_validation so that the workflows run automatically and don't have to be approved manually each time? or you can make me an owner and i can do it :)

@cailmdaley cailmdaley left a comment

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.

Thanks Lisa — this is a great cleanup, and the structure of it is exactly right: the templates/ + output/ split, the .gitignore, inference.smk, and cosmosis_fitting.py changes are all internally consistent, and −17k lines speaks for itself. 🎉

We did the light testing pass discussed in the thread (no full inference.smk run): py_compile on all 12 changed .py files passes, and we checked the new cs_util.cosmo calls against the cs_util source. That turned up two real bugs in the new chain_postprocessing.py logic (inline comments below) — both quick fixes — plus a few smaller things:

Deletion fallout (worth fixing in this PR):

  • workflow/rules/covariance.smk:256 still invokes the deleted scripts/cosmocov_process.py, and papers/bmodes/scripts/run_cov_sweep.sh:68 calls the deleted workflow/scripts/run_cosmocov_chain.sh. Since CosmoCov is being retired for OneCovariance anyway, I'd say drop/update those callers here so nothing dangles. (We checked the 2pt_like_xi_sys.py / xi_sys_psf.py references too — those resolve via %(COSMOSIS_DIR)s into the CosmoSIS install, so they're fine.)

Dependency note (not this PR's fault, but it bites here first):

  • get_cosmo / c_ell_to_xi only exist on cs_util's development branch — released cs_util 0.2.1 (what the container has and what sp_validation pins) doesn't have them, so the import fails until a new cs_util release is cut. Worth coordinating with Martin on a release before merging, or at least noting it.

Optional / non-blocking:

  • The converted papers/realspace/*.py scripts still carry some notebook artifacts — live get_ipython() / display() calls (glass_mock_hist.py, get_chi2.py:562, unblinding_party_plots.py), two plt.savefig("/Plots/…") paths in contours.py (632, 745) that would try to write to the filesystem root, and hardcoded /home/guerrini paths throughout. Since these are archival figure scripts that's fine — maybe just a one-line header note that they document the 2D analysis rather than being re-runnable as-is.
  • cosmosis_fitting.py's module docstring still says products land in cosmosis_config/; they now go to output/.

Once the two inline fixes are in, this looks good to us — and per the thread, we'll shake out any remaining inference.smk wiring when we start running chains on the GLASS mocks.

— Claude (Fable) on behalf of Cail

Comment thread cosmo_inference/scripts/chain_postprocessing.py
theta_deg = np.rad2deg(theta_rad)
xi_p = ccl.correlation(cosmo, ell=ell, C_ell=shear_cl, theta=theta_deg, type="GG+")
xi_m = ccl.correlation(cosmo, ell=ell, C_ell=shear_cl, theta=theta_deg, type="GG-")
xi_p, xi_m = cs_cosmo.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl)

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.

Units bug: c_ell_to_xi expects theta in arcminutes (it converts with theta / 60 internally), but theta_rad here is in radians — so the correlation functions get evaluated at angles ~3438× too small. The previously-deleted code did the np.rad2deg conversion explicitly.

xi_p, xi_m = cs_cosmo.c_ell_to_xi(cosmo, np.rad2deg(theta_rad) * 60, ell, shear_cl)

Keep saving theta_rad to theta.txt as you do below — the reader at L627 multiplies by 180/π·60, i.e. it expects radians there.

@sachaguer

Copy link
Copy Markdown
Contributor

Regarding cs_util an earlier PR on the develop branch pins the cs_util dependency to the develop branch. While still relevant to tag a version soonish, you could also merge the recent PR's of the develop branch in your branch.

Note also that the API of cs_util.cosmo has changed since this PR #223 and CosmoStat/cs_util#79

@LisaGoh

LisaGoh commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

Thank you for the review! I've updated this branch to match develop, so I'll keep referencing the develop branch of cs_util !

I've also added the k_analysis.py script that I used to calculate the k contributions to the correlation function for each theta.

@cailmdaley

Copy link
Copy Markdown
Collaborator

Thanks Lisa! One more ruff pass and I think this is good to go

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.

Clean up cosmo_inference folder

4 participants