From ac21c99a3027409a1afb16cbd32814d7735b082a Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Tue, 5 May 2026 19:31:32 -0500 Subject: [PATCH 1/3] Update lightcone_generators.py and other code according to naming conventions in diffhalos for the weights: lc_data.nhalos --> lc_data.cen_weights, and lc_data.nhalos_host --> lc_data.sat_weight. Note that these are not straight search-and-replace changes, due to changes in the meaning of the variables. See PR notes for details. --- .github/workflows/test_diffhalos_pr.yaml | 97 +++++++++++++++++++ .../test_dbk_specphot_kernels_merging.py | 3 +- .../tests/test_phot_kernels_merging.py | 3 +- .../kernels/tests/test_sed_kernels_merging.py | 6 +- .../tests/test_specphot_kernels_merging.py | 3 +- diffsky/experimental/lightcone_generators.py | 27 +++--- diffsky/experimental/mc_phot.py | 3 +- 7 files changed, 118 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/test_diffhalos_pr.yaml diff --git a/.github/workflows/test_diffhalos_pr.yaml b/.github/workflows/test_diffhalos_pr.yaml new file mode 100644 index 00000000..710b5b4b --- /dev/null +++ b/.github/workflows/test_diffhalos_pr.yaml @@ -0,0 +1,97 @@ +name: pytest against diffhalos:namedtuple_names + +on: + push: + branches: + - main + pull_request: null + +jobs: + tests: + name: pytest with diffmah/diffstar/dsps@main + runs-on: "ubuntu-latest" + + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - uses: conda-incubator/setup-miniconda@v4 + with: + python-version: 3.12 + channels: conda-forge,defaults + channel-priority: strict + show-channel-urls: true + miniforge-version: latest + + - name: configure conda and install code + # Test against current main branch of all diff+ dependencies + shell: bash -l {0} + env: + GITHUB_TOKEN: ${{ secrets.CPAC_PRIVATE_REPO_TOKEN }} + GITHUB_USER: ${{ secrets.GH_USR_TESTING_TOKEN }} + + # Test against conda-forge for all dependencies except use main branch for dsps + run: | + conda config --set always_yes yes + conda install --quiet \ + --file=requirements.txt + conda install -y -q \ + flake8 \ + pytest \ + pytest-xdist \ + pytest-cov \ + pip \ + setuptools \ + "setuptools_scm>=7,<8" \ + matplotlib \ + scipy \ + python-build + pip uninstall diffmah --yes + pip uninstall diffstar --yes + pip uninstall dsps --yes + pip uninstall diffhalos --yes + pip install --no-deps git+https://github.com/ArgonneCPAC/diffmah.git + pip install --no-deps git+https://github.com/ArgonneCPAC/diffstar.git + pip install --no-deps git+https://github.com/ArgonneCPAC/dsps.git + pip install --no-deps git+https://github.com/ArgonneCPAC/diffhalos.git@refs/pull/39/head + python -m pip install --no-build-isolation --no-deps -e . + + - name: check numpy version + shell: bash -l {0} + run: | + python -c "import numpy; print(numpy.__version__)" + + - name: test + shell: bash -l {0} + run: | + pytest -v diffsky --cov --cov-report=xml + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v6 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + - name: test versions + shell: bash -el {0} + run: | + pip uninstall diffsky --yes + [[ $(python setup.py --version) != "0.0.0" ]] || exit 1 + + rm -rf dist/* + python setup.py sdist + pip install --no-deps --no-build-isolation dist/*.tar.gz + pushd .. + python -c "import diffsky; assert diffsky.__version__ != '0.0.0'" + popd + pip uninstall diffsky --yes + + rm -rf dist/* + python -m build --sdist . --outdir dist + pip install --no-deps --no-build-isolation dist/*.tar.gz + pushd .. + python -c "import diffsky; assert diffsky.__version__ != '0.0.0'" + popd + pip uninstall diffsky --yes + + python -m pip install -v --no-deps --no-build-isolation -e . diff --git a/diffsky/experimental/kernels/tests/test_dbk_specphot_kernels_merging.py b/diffsky/experimental/kernels/tests/test_dbk_specphot_kernels_merging.py index cb40f80a..8c98fd64 100644 --- a/diffsky/experimental/kernels/tests/test_dbk_specphot_kernels_merging.py +++ b/diffsky/experimental/kernels/tests/test_dbk_specphot_kernels_merging.py @@ -114,7 +114,6 @@ def test_mc_dbk_specphot_kern_merging(mc_merge, num_halos=150): ) fb = 0.13 - sat_weights = np.where(lc_data.is_central == 1, 1.0, lc_data.nhalos) args = ( ran_key, lc_data.z_obs, @@ -132,7 +131,7 @@ def test_mc_dbk_specphot_kern_merging(mc_merge, num_halos=150): lc_data.logmhost_infall, lc_data.t_infall, lc_data.is_central, - sat_weights, + lc_data.sat_weight, lc_data.halo_indx, mc_merge, ) diff --git a/diffsky/experimental/kernels/tests/test_phot_kernels_merging.py b/diffsky/experimental/kernels/tests/test_phot_kernels_merging.py index 4f342dea..d6af337c 100644 --- a/diffsky/experimental/kernels/tests/test_phot_kernels_merging.py +++ b/diffsky/experimental/kernels/tests/test_phot_kernels_merging.py @@ -64,7 +64,6 @@ def test_mc_phot_kern_merging(mc_merge, num_halos=250): ) fb = 0.176 - sat_weights = np.where(lc_data.is_central == 1, 1.0, lc_data.nhalos) phot_kern_results, phot_randoms, merging_randoms = pkm._mc_phot_kern_merging( ran_key, lc_data.z_obs, @@ -81,7 +80,7 @@ def test_mc_phot_kern_merging(mc_merge, num_halos=250): lc_data.logmhost_infall, lc_data.t_infall, lc_data.is_central, - sat_weights, + lc_data.sat_weight, lc_data.halo_indx, mc_merge, ) diff --git a/diffsky/experimental/kernels/tests/test_sed_kernels_merging.py b/diffsky/experimental/kernels/tests/test_sed_kernels_merging.py index 841a8368..7ba1837b 100644 --- a/diffsky/experimental/kernels/tests/test_sed_kernels_merging.py +++ b/diffsky/experimental/kernels/tests/test_sed_kernels_merging.py @@ -25,8 +25,6 @@ def test_sed_kern(mc_merge, num_halos=5, return_results=False): ) fb = 0.176 - sat_weights = np.where(lc_data.is_central == 1, 1.0, lc_data.nhalos) - phot_kern_results, phot_randoms, merging_randoms = pkm._mc_phot_kern_merging( ran_key, lc_data.z_obs, @@ -43,7 +41,7 @@ def test_sed_kern(mc_merge, num_halos=5, return_results=False): lc_data.logmhost_infall, lc_data.t_infall, lc_data.is_central, - sat_weights, + lc_data.sat_weight, lc_data.halo_indx, mc_merge, ) @@ -66,7 +64,7 @@ def test_sed_kern(mc_merge, num_halos=5, return_results=False): lc_data.logmhost_infall, lc_data.t_infall, lc_data.is_central, - sat_weights, + lc_data.sat_weight, lc_data.halo_indx, mc_merge, ) diff --git a/diffsky/experimental/kernels/tests/test_specphot_kernels_merging.py b/diffsky/experimental/kernels/tests/test_specphot_kernels_merging.py index 55f5912e..d73b3acd 100644 --- a/diffsky/experimental/kernels/tests/test_specphot_kernels_merging.py +++ b/diffsky/experimental/kernels/tests/test_specphot_kernels_merging.py @@ -53,7 +53,6 @@ def test_mc_specphot_kern_merging(mc_merge, num_halos=141): ssp_data = lemi.get_subset_emline_data(lc_data.ssp_data, emline_names) lc_data = lc_data._replace(ssp_data=ssp_data) - sat_weights = np.where(lc_data.is_central == 1, 1.0, lc_data.nhalos) phot_kern_results, phot_randoms, spec_kern_results = ( sppkm._mc_specphot_kern_merging( ran_key, @@ -73,7 +72,7 @@ def test_mc_specphot_kern_merging(mc_merge, num_halos=141): lc_data.logmhost_infall, lc_data.t_infall, lc_data.is_central, - sat_weights, + lc_data.sat_weight, lc_data.halo_indx, mc_merge, ) diff --git a/diffsky/experimental/lightcone_generators.py b/diffsky/experimental/lightcone_generators.py index 572a5134..8230d6bc 100644 --- a/diffsky/experimental/lightcone_generators.py +++ b/diffsky/experimental/lightcone_generators.py @@ -81,8 +81,8 @@ def weighted_lc_halos_photdata( lc_data: namedtuple Population of num_halos halos along with data needed to compute photometry - nhalos: ndarray of shape (num_halos, ) - weight of the (sub)halo + cen_weight: ndarray of shape (n_halos_tot, ) + For centrals, cen_weight is determined by the halo mass function (HMF) z_obs: ndarray of shape (num_halos, ) redshift values @@ -127,7 +127,7 @@ def weighted_lc_halos_photdata( wave_eff_table = get_wave_eff_table(z_phot_table, tcurves) lc_data = LCHalosData( - halopop.nhalos, + halopop.cen_weight, halopop.z_obs, halopop.t_obs, halopop.logmp_obs, @@ -234,12 +234,15 @@ def weighted_lc_photdata( logt0: float Base-10 log of z=0 age of the Universe for the input cosmology - nhalos: ndarray of shape (n_halos_tot, ) - weight of the (sub)halo + cen_weight: ndarray of shape (n_halos_tot, ) - nhalos_host: ndarray of shape (n_halos_tot, ) - weight of the host halo - Equal to nhalos for central halos + For centrals, cen_weight is determined by the halo mass function (HMF) + For satellites, cen_weight is HMF weight of the associated central + + sat_weight: ndarray of shape (n_halos_tot, ) + Multiplicity factor of the subhalo richness + Equals 1 for central halos + For subhalos, halopop.sat_weight = nsub_per_host: int number of subhalos per host halo @@ -298,7 +301,7 @@ def weighted_lc_photdata( wave_eff_table = get_wave_eff_table(z_phot_table, tcurves) lc_data = LCData( - halopop.nhalos, + halopop.cen_weight, halopop.z_obs, halopop.t_obs, halopop.logmp_obs, @@ -309,7 +312,7 @@ def weighted_lc_photdata( precomputed_ssp_mag_table, z_phot_table, wave_eff_table, - halopop.nhalos_host, + halopop.sat_weight, t_infall, logmp_infall, logmhost_infall, @@ -349,7 +352,7 @@ def passively_add_emlines_to_lc_data(ssp_data, lc_data): _LCDHKEYS = ( - "nhalos", + "cen_weight", "z_obs", "t_obs", "logmp_obs", @@ -365,7 +368,7 @@ def passively_add_emlines_to_lc_data(ssp_data, lc_data): _LCDKEYS = ( *_LCDHKEYS, - "nhalos_host", + "sat_weight", "t_infall", "logmp_infall", "logmhost_infall", diff --git a/diffsky/experimental/mc_phot.py b/diffsky/experimental/mc_phot.py index 3ff89b53..625974b1 100644 --- a/diffsky/experimental/mc_phot.py +++ b/diffsky/experimental/mc_phot.py @@ -100,7 +100,6 @@ def mc_lc_phot_merging( if not skip_param_check: assert dpwm.check_param_collection_is_ok(param_collection) - sat_weights = jnp.where(lc_data.is_central == 1, 1.0, lc_data.nhalos) _res = mcpk._mc_phot_kern_merging( ran_key, lc_data.z_obs, @@ -122,7 +121,7 @@ def mc_lc_phot_merging( lc_data.logmhost_infall, lc_data.t_infall, lc_data.is_central, - sat_weights, + lc_data.sat_weight, lc_data.halo_indx, mc_merge, ) From ac23e2f58784889c7b20ddec2c1b300636e4c52a Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 6 May 2026 10:11:25 -0500 Subject: [PATCH 2/3] Remove obsolete test_diffhalos_pr.yaml workflow --- .github/workflows/test_diffhalos_pr.yaml | 97 ------------------------ 1 file changed, 97 deletions(-) delete mode 100644 .github/workflows/test_diffhalos_pr.yaml diff --git a/.github/workflows/test_diffhalos_pr.yaml b/.github/workflows/test_diffhalos_pr.yaml deleted file mode 100644 index 710b5b4b..00000000 --- a/.github/workflows/test_diffhalos_pr.yaml +++ /dev/null @@ -1,97 +0,0 @@ -name: pytest against diffhalos:namedtuple_names - -on: - push: - branches: - - main - pull_request: null - -jobs: - tests: - name: pytest with diffmah/diffstar/dsps@main - runs-on: "ubuntu-latest" - - steps: - - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - uses: conda-incubator/setup-miniconda@v4 - with: - python-version: 3.12 - channels: conda-forge,defaults - channel-priority: strict - show-channel-urls: true - miniforge-version: latest - - - name: configure conda and install code - # Test against current main branch of all diff+ dependencies - shell: bash -l {0} - env: - GITHUB_TOKEN: ${{ secrets.CPAC_PRIVATE_REPO_TOKEN }} - GITHUB_USER: ${{ secrets.GH_USR_TESTING_TOKEN }} - - # Test against conda-forge for all dependencies except use main branch for dsps - run: | - conda config --set always_yes yes - conda install --quiet \ - --file=requirements.txt - conda install -y -q \ - flake8 \ - pytest \ - pytest-xdist \ - pytest-cov \ - pip \ - setuptools \ - "setuptools_scm>=7,<8" \ - matplotlib \ - scipy \ - python-build - pip uninstall diffmah --yes - pip uninstall diffstar --yes - pip uninstall dsps --yes - pip uninstall diffhalos --yes - pip install --no-deps git+https://github.com/ArgonneCPAC/diffmah.git - pip install --no-deps git+https://github.com/ArgonneCPAC/diffstar.git - pip install --no-deps git+https://github.com/ArgonneCPAC/dsps.git - pip install --no-deps git+https://github.com/ArgonneCPAC/diffhalos.git@refs/pull/39/head - python -m pip install --no-build-isolation --no-deps -e . - - - name: check numpy version - shell: bash -l {0} - run: | - python -c "import numpy; print(numpy.__version__)" - - - name: test - shell: bash -l {0} - run: | - pytest -v diffsky --cov --cov-report=xml - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v6 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - - name: test versions - shell: bash -el {0} - run: | - pip uninstall diffsky --yes - [[ $(python setup.py --version) != "0.0.0" ]] || exit 1 - - rm -rf dist/* - python setup.py sdist - pip install --no-deps --no-build-isolation dist/*.tar.gz - pushd .. - python -c "import diffsky; assert diffsky.__version__ != '0.0.0'" - popd - pip uninstall diffsky --yes - - rm -rf dist/* - python -m build --sdist . --outdir dist - pip install --no-deps --no-build-isolation dist/*.tar.gz - pushd .. - python -c "import diffsky; assert diffsky.__version__ != '0.0.0'" - popd - pip uninstall diffsky --yes - - python -m pip install -v --no-deps --no-build-isolation -e . From d6de6237c2c0c78eba7d35410c0568614bef7b28 Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 6 May 2026 11:17:59 -0500 Subject: [PATCH 3/3] Update docstrings in lightcone_generators.py --- diffsky/experimental/lightcone_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsky/experimental/lightcone_generators.py b/diffsky/experimental/lightcone_generators.py index 8230d6bc..59a97417 100644 --- a/diffsky/experimental/lightcone_generators.py +++ b/diffsky/experimental/lightcone_generators.py @@ -161,7 +161,7 @@ def weighted_lc_photdata( logmp_cutoff=11.0, ): """ - Generate a weighted lightcone of host halos, + Generate a weighted lightcone of host halos and subhalos, and additional data needed for photometry calculations. This function is a wrapper around