Skip to content

Merge in changes for v0.4.0#74

Merged
davewhipp merged 24 commits into
mainfrom
develop
Apr 17, 2026
Merged

Merge in changes for v0.4.0#74
davewhipp merged 24 commits into
mainfrom
develop

Conversation

@davewhipp

Copy link
Copy Markdown
Member

No description provided.

davewhipp and others added 24 commits November 13, 2025 13:05
…ams (BG)

Summary:
- Added new command-line options for NA inversion: --na-ns, --na-nr, --na-ni, --na-n, --na-n-resample, --na-n-walkers.
- Each parameter can now be modified directly from tc1d-cli for flexible NA runs.
- Implemented: default values inside init_params()
- Updated batch_run_na() to read NA parameters from the unified params dict.
- Ensured backward compatibility: default behavior remains unchanged if no NA flags are provided.
- Updated help message automatically through argparse groups.

Notes: These changes make the NA inversion fully configurable from command line and keep default values centralized in init_params().
…arams (BG)

Summary:
- Added new command-line options for MCMC inversion: --mcmc-nwalkers, --mcmc-nsteps, --mcmc-discard, --mcmc-thin.
- Each MCMC parameter can now be modified directly from tc1d-cli for flexible emcee runs.
- Implemented: default MCMC values inside init_params(), keeping configuration centralized.
- Updated batch_run_mcmc() to read MCMC parameters from the unified params dict (same pattern as NA).
- Ensured backward compatibility: default behavior remains unchanged if no MCMC flags are provided.

Notes:
These changes make the MCMC inversion configurable from the command line, while keeping the defaults defined in init_params(). The MPI/emcee parallelization logic is unchanged; only the hyper-parameters are now exposed and controlled via the CLI.
…nt/linear/exponential laws

Summary
-	Added ero_type=0 to support multi-stage erosion histories defined in an external CSV file (--ero-file).
-	Implemented read_ero_file() with validation of stage type, unit, duration_myr, and required parameters, and a unified internal rate-based representation.
-	Added stage erosion laws used by the forward model:
   - constant: erosion_constant()
   - linear: erosion_linear()
   - exponential: erosion_exponential()
-	Added a CLI summary table echoing CSV-defined multi-stage erosion inputs (p1/p2/p3 with explicit units and conventions)

Thickness parameterization
-	Introduced dual parameterization per stage:
   - erosion_rate mode: rates prescribed directly in CSV.
   - thickness mode: total thickness is prescribed and internal rates are reconstructed to strictly conserve area over the stage duration.
-	Linear + thickness:
   - replaced rate input by a dimensionless shape factor s ∈ [-1,1] to control the temporal trend while conserving total thickness.
-	Exponential + thickness:
   - replaced rate input by a baseline thickness M_base (asymptotic baseline), enabling fully thickness-driven exponential stages with strict area conservation.
   - thickness mode uses (M_total, tau, M_base) with internal reconstruction of r_start and r_target=r_base.

Forward integration
-	Integrated ero_type=0 into calculate_erosion_rate() with explicit stage selection by time and automatic drop to zero erosion rate after the last stage when sum(durations) < t_total.
-	Preloaded erosion stages in run_model() (params["ero_stages"]) to avoid repeated CSV parsing during timestepping.

Exhumation magnitude
-	Integrated ero_type=0 into calculate_exhumation_magnitude() by integrating each stage law consistently up to t_total (no erosion beyond the final stage).
-	Changed strict duration checks (sum(durations) > t_total) to RuntimeWarning; forward runs proceed using only the portion of stages within t_total, and reported exhumation is computed consistently for truncated runs.

Tests / validation
-	Added unit tests for ero_type=0 to ensure numerical and logical consistency.
   - CSV parsing and validation (erosion_rate and thickness modes, error handling)
   - Stage law implementations (constant, linear, exponential)
   - User-facing CSV echo table formatting
   - Exhumation magnitude integration (constant and linear laws, truncation at t_total)
   - Erosion-rate time handling (stage switching and tail-to-zero behavior)
   - All new erosion functionalities are now covered by pytest-based unit tests.
Summary
- Added support for YAML-based input files via a new --input-file option.
- Implemented a structured override of argparse parameters from YAML.
- Added a warning when CLI flags conflict with YAML-defined keys (YAML remains authoritative).
- Preserved backward compatibility with existing CLI workflows.
- Enabled YAML-driven configuration for forward, batch, NA, and MCMC runs.
- Supported both fixed values and inversion ranges using YAML list syntax.

Notes
- YAML acts as a configuration layer on top of CLI defaults.
- All existing erosion models (ero_type 0–7) are supported.
- If a parameter is provided both in YAML and on the CLI, Tc1D warns that the CLI value is ignored and uses the YAML value.
- MPI parallelism remains controlled at runtime (e.g. mpiexec).
… ero_file dependency)

- Replace CSV-based ero_file input with YAML-defined erosion stages for ero_type=0.
- Require erosion_model.ero_stages in YAML input file when ero_type=0 is selected.
- Preserve existing erosion laws (constant, linear, exponential) and parameterizations
(erosion_rate and thickness).
- Parse and cache erosion stages once, and apply them consistently throughout runtime.
- Leave all other erosion models (ero_type > 0) and CLI workflows unchanged.
- Update tests/test_tc1d.py to cover YAML-based ero_type=0 stages.
…tions and parameters

This commit extends the YAML-based multi-stage erosion model (ero_type=0)
to support Neighbourhood Algorithm (NA) inversion of both stage durations
and stage-specific parameters directly from the YAML input file (p1, p2, p3).

Key features:
- Allow NA inversion of stage durations via `duration_myr` ranges in YAML.
- Allow NA inversion of stage parameters (‘p1`, `p2`, `p3`) for each erosion stage.
- Support mixed fixed and inverted stages within the same erosion history.
- Preserve strict parameter ordering to ensure robust NA parameter mapping.
- Rebuild erosion stages on-the-fly during NA evaluations from the raw YAML template.
- Apply optional duration balancing to ensure total erosion time matches `t_total`.
- Reject invalid duration combinations gracefully (penalized misfit, no crash).

Implementation details:
- Introduce helper functions to apply NA-sampled values to YAML erosion stages
  (`_apply_na_stage_durations`, `_apply_na_stage_params`).
- Collect NA bounds for stage durations and parameters directly from YAML lists.
- Cache parsed erosion stages (`ero_stages`) and total stage duration in seconds
  to avoid repeated parsing during forward model execution.
- Keep forward erosion physics unchanged; only the YAML/NA interface is extended.

This makes ero_type=0 compatible with NA-based inversion workflows
using a single YAML configuration file.
This commit extends the MCMC inverse mode to support YAML-defined multi-stage erosion histories (ero_type=0), in a way consistent with the existing NA logic and without modifying forward-model behavior.

Changes:
Add helper function ‘_rebuild_ero_stages_from_sample()’ to rebuild erosion stages on-the-fly during MCMC evaluations from sampled parameters (stage durations and/or p1/p2/p3).
Preserve conservative behavior for stage timing:
- if sum(stage durations) > total model time, erosion is naturally truncated
- if sum(stage durations) < total model time, erosion drops to zero after the last stage.
- Update `log_prior()` to: skip ero_option* cumulative constraints for ero_type=0, apply a generic constraint on the sum of sampled stage durations (sum(durations) <= t_total).
- Update `log_likelihood()` to:
   - enforce MCMC/inverse context explicitly
   - rebuild ero_type=0 stages per sample before calling the forward model
   - reject invalid samples cleanly
- Extend `batch_run_mcmc()` to:
   - automatically extract bounds for stage durations and p1/p2/p3 from the YAML erosion template
   - expose them as MCMC parameters using the same naming scheme as NA,
   - isolate global MCMC state from the base parameter dictionary
@davewhipp davewhipp merged commit a151e98 into main Apr 17, 2026
8 checks passed
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