Skip to content

Warn before overwriting a mismatched isochrone file; fix NaN IMF masses; NumPy scalars in IMF helpers - #173

Merged
jluastro merged 7 commits into
MovingUniverseLab:devfrom
wei-lingfeng:isochrone-mismatch-warning
Nov 13, 2026
Merged

jluastro merged 7 commits into
MovingUniverseLab:devfrom
wei-lingfeng:isochrone-mismatch-warning

Conversation

@wei-lingfeng

@wei-lingfeng wei-lingfeng commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  1. Warn before overwriting a mismatched isochrone file. IsochronePhot regenerates an isochrone when its save file exists but was made with a different evolution model, atmosphere, reddening law or model version. That overwrites the existing file, and with the default verbose=False it happened silently. It now issues a UserWarning listing the mismatched inputs, and the verbose mismatch messages say which value is the file's and which was requested.
  2. NumPy scalars in IMF helpers. theta_closed, theta_open and delta in imf.py now test isinstance(x, (float, np.floating)) like the other IMF helpers, so NumPy scalars return floats instead of one-element arrays.
  3. NaN masses from IMF_broken_powerlaw. When a segment other than the last is steeper than m^-1, dice_star_cl returned NaN for some draws (19% for slopes -2.3, -1.3 with limits 0.08, 0.5, 150 Msun; 0.4% for -2.7, -2.3). Fixed; masses are unchanged wherever they were not NaN.
  4. Quieter ResolvedCluster. The "Remove low mass stars ..." messages are printed only with verbose=True.

Behaviour

Situation Before After
Save file mismatches, recomp=False, no matching legacy file (file is overwritten) silent; details only with verbose=True UserWarning naming the mismatched inputs, regardless of verbose
Save file mismatches, but a matching legacy file is used details with verbose=True unchanged
Save file made before SPISEA 3, or with no SPISEAVERSION (dev now regenerates these) details with verbose=True UserWarning with SPISEAVERSION: file has None, requested 3.1.0
File missing, or recomp=True messages with verbose=True unchanged (no warning)

Example warning:

UserWarning: Isochrone file ./iso_6.70_0.70_04000_p0.00.fits exists, but meta-data does not match:
  REDLAW: file has H18b, requested N09
Regenerating it, which overwrites the file.

The warning uses the same multiline block as the verbose report.

IsochronePhotExternalEvolution gets the same warning.

Changes

  • save_file_mismatches() returns each mismatched input as (key, value in file, requested value), or None if the file does not exist. check_save_file() now uses it; its return values are unchanged (checked on 40 existing isochrone files with two model sets).
  • The SPISEA version check that dev added to check_save_file is now part of save_file_mismatches: a file made before SPISEA 3, or with no SPISEAVERSION, is listed as a SPISEAVERSION mismatch. Whether a file is regenerated is unchanged from dev (checked on 20 Wd1 isochrone files, with and without a v3 version tag: 140 checks, 0 differences). Dev stops at the version check; this lists every mismatched input.
  • Verbose mismatch lines now read REDLAW: file has H18b, requested N09 instead of REDLAW: H18b != N09, and a model-version mismatch is listed with the other keys instead of in a separate sentence. When the warning is issued, the same file is not also reported in the verbose output.
  • theta_closed, theta_open and delta in imf.py now test isinstance(x, (float, np.floating)) like the other IMF helpers, so NumPy scalars return floats instead of one-element arrays.
  • IMF_broken_powerlaw.dice_star_cl evaluated the inverse primitive ((1+p) t)^(1/(1+p)) for every draw at or beyond segment i and then multiplied it by 0 for draws past the segment. For p < -1 the inverse is NaN past the segment, and 0 × NaN stays NaN. It is now evaluated only for draws inside the segment.
  • The two "Remove low mass stars ..." prints in ResolvedCluster are now behind verbose.

Tests

New tests in test_synthetic.py cover save_file_mismatches (including a pre-v3 or missing SPISEAVERSION), the verbose messages, and the warning: issued for a mismatched file with and without verbose, and not issued for a missing file, recomp=True, or a matching legacy file. The isochrone computation is patched out, so they run in seconds. A new test in test_imf.py draws 10,000 masses for slopes -2.3, -1.3 and checks for no NaN and masses within the limits; it fails without the fix. test_imf.py passes.

wei-lingfeng and others added 3 commits October 29, 2026 11:25
The other IMF helpers test isinstance(x, (float, np.floating)); these three
still tested type(x) == float, so a NumPy scalar came back as a one-element
array instead of a float.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With recomp=False, IsochronePhot (and IsochronePhotExternalEvolution)
regenerates an isochrone whose save file exists but was made with a
different evolution model, atmosphere, reddening law or model version,
overwriting that file. This happened silently unless verbose.

- save_file_mismatches() lists each mismatched input as
  (key, value in file, requested value); check_save_file() uses it and
  returns the same results as before.
- Before overwriting a mismatched save file, warn regardless of verbose,
  naming the mismatched inputs. A missing file or recomp=True regenerates
  without a warning, as before.
- Verbose mismatch lines now read "KEY: file has X, requested Y" (was
  "KEY: X != Y"), and a model version mismatch is listed with the others.
  A file that gets the warning is not also reported in the verbose output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The warning now opens with the same multiline block as the verbose output
(one "KEY: file has X, requested Y" line per mismatched input) and ends with
"Regenerating it, which overwrites the file."

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wei-lingfeng wei-lingfeng changed the title Warn before overwriting an isochrone file made with different inputs Warn before overwriting a mismatched isochrone file; NumPy scalars in IMF helpers Oct 29, 2026

@jluastro jluastro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This all looks good to me. I've reviewed all the code changes. Can you confirm that you have run all the tests and that they pass?

wei-lingfeng and others added 2 commits November 10, 2026 16:07
…smatch-warning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dev now regenerates isochrone files made before SPISEA version 3 (or with
no SPISEAVERSION recorded). Fold that check into save_file_mismatches so
it is listed in the verbose report and the overwrite warning like the
other mismatched inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wei-lingfeng

Copy link
Copy Markdown
Contributor Author

Ran the full test suite on the updated branch: 91 passed, 2 skipped (the COSMIC integration tests; the optional cosmic package is not installed here).

wei-lingfeng and others added 2 commits November 12, 2026 18:33
dice_star_cl evaluated the inverse primitive for draws beyond each
segment as well. For a slope steeper than -1 that inverse is NaN there,
and multiplying it by 0 kept the NaN. Evaluate it only for draws inside
the segment. Add a regression test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wei-lingfeng wei-lingfeng changed the title Warn before overwriting a mismatched isochrone file; NumPy scalars in IMF helpers Warn before overwriting a mismatched isochrone file; fix NaN IMF masses; NumPy scalars in IMF helpers Nov 13, 2026
@jluastro
jluastro merged commit 7086d89 into MovingUniverseLab:dev Nov 13, 2026
1 check failed
mwhosek pushed a commit that referenced this pull request Nov 14, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mwhosek added a commit that referenced this pull request Nov 14, 2026
@wei-lingfeng
wei-lingfeng deleted the isochrone-mismatch-warning branch November 18, 2026 01:47
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.

2 participants