geoprior.models.subsidence.utils#
GeoPrior subsidence model utilities.
Functions
|
Return (a,b) for y_si = y_model*a + b. |
|
Check dynamic_feature_names length matches Xh. |
|
Return a canonicalized scaling dict. |
|
Return (tR,xR,yR) if coords_normalized. |
|
Return coordinate spans in SI (t in seconds; x/y in meters). |
|
Meters per degree factor for lon/lat coords. |
|
Enforce that canonical keys and aliases agree. |
Add derived SI conversion constants to |
|
|
Inverse of to_si_subsidence: s_model = (s_si - b) / a. |
|
Cache gwl_dyn_index on model after first resolve. |
|
Return head (or depth) history in SI meters. |
|
Return h_ref in SI meters, broadcast to like. |
|
Return initial settlement (cumulative subsidence) in SI meters. |
|
Fetch a key from scaling_kwargs with aliases + default. |
|
Cache subs_dyn_index on model after first resolve. |
|
Convert depth-bgs to head if possible. |
|
Infer per-step dt in time_units from time tensor t(B,H,1). |
|
Load scaling kwargs from a dict-like object or JSON. |
|
Return a scalar gate in |
|
Resolve GWL channel index for dynamic_features. |
|
Resolve subsidence channel index for dynamic_features. |
|
Slice (B,T,F) -> (B,T,1) at idx. |
|
Convert head/depth to SI meters. |
|
Convert subsidence to SI meters. |
|
Convert thickness to SI. |
|
Basic scaling sanity checks. |
- geoprior.models.subsidence.utils.enforce_scaling_alias_consistency(scaling_kwargs, *, where='validate')[source]#
Enforce that canonical keys and aliases agree.
If both canonical and an alias exist and their values differ, apply the scaling error policy.
- geoprior.models.subsidence.utils.canonicalize_scaling_kwargs(scaling_kwargs, *, copy=True)[source]#
Return a canonicalized scaling dict.
If a canonical key is missing, but one of its aliases exists, copy alias -> canonical.
Keeps existing canonical values unchanged.
- geoprior.models.subsidence.utils.load_scaling_kwargs(scaling_kwargs, *, copy=True)[source]#
Load scaling kwargs from a dict-like object or JSON.
- geoprior.models.subsidence.utils.get_sk(scaling_kwargs, key, *aliases, default=None, required=False, cast=None)[source]#
Fetch a key from scaling_kwargs with aliases + default.
Tries: key -> built-in aliases -> explicit aliases
Treats None and blank strings as “missing” and keeps searching.
- geoprior.models.subsidence.utils.validate_scaling_kwargs(scaling_kwargs)[source]#
Basic scaling sanity checks.
This includes policy-controlled heuristic checks for common “silent fallback” cases.
- geoprior.models.subsidence.utils.affine_from_cfg(scaling_kwargs, *, scale_key, bias_key, meta_keys=(), unit_key=None)[source]#
Return (a,b) for y_si = y_model*a + b.
- geoprior.models.subsidence.utils.to_si_thickness(H_model, scaling_kwargs)[source]#
Convert thickness to SI.
- geoprior.models.subsidence.utils.to_si_head(h_model, scaling_kwargs)[source]#
Convert head/depth to SI meters.
- geoprior.models.subsidence.utils.to_si_subsidence(s_model, scaling_kwargs)[source]#
Convert subsidence to SI meters.
- geoprior.models.subsidence.utils.from_si_subsidence(s_si, scaling_kwargs)[source]#
Inverse of to_si_subsidence: s_model = (s_si - b) / a.
- geoprior.models.subsidence.utils.deg_to_m(axis, scaling_kwargs)[source]#
Meters per degree factor for lon/lat coords.
If coords_in_degrees=True and deg_to_m_lon/lat are missing, we try to compute them from lat0_deg (recommended).
- geoprior.models.subsidence.utils.coord_ranges(scaling_kwargs)[source]#
Return (tR,xR,yR) if coords_normalized.
- geoprior.models.subsidence.utils.resolve_gwl_dyn_index(scaling_kwargs)[source]#
Resolve GWL channel index for dynamic_features.
- geoprior.models.subsidence.utils.get_gwl_dyn_index_cached(model)[source]#
Cache gwl_dyn_index on model after first resolve.
- Return type:
- geoprior.models.subsidence.utils.resolve_subs_dyn_index(scaling_kwargs)[source]#
Resolve subsidence channel index for dynamic_features.
This is optional: v3.2 can use historical subsidence as a dynamic driver to provide a physics-friendly initial condition for the mean settlement path.
- geoprior.models.subsidence.utils.get_subs_dyn_index_cached(model)[source]#
Cache subs_dyn_index on model after first resolve.
- Return type:
- geoprior.models.subsidence.utils.slice_dynamic_channel(Xh, idx)[source]#
Slice (B,T,F) -> (B,T,1) at idx.
- Parameters:
Xh (Tensor)
idx (int)
- Return type:
Tensor
- geoprior.models.subsidence.utils.assert_dynamic_names_match_tensor(Xh, scaling_kwargs)[source]#
Check dynamic_feature_names length matches Xh.
- geoprior.models.subsidence.utils.gwl_to_head_m(v_m, scaling_kwargs, *, inputs=None)[source]#
Convert depth-bgs to head if possible.
- geoprior.models.subsidence.utils.get_h_hist_si(model, inputs, *, want_head=True)[source]#
Return head (or depth) history in SI meters.
- Parameters:
- Returns:
(B,T,1) tensor in SI meters.
- Return type:
Tensor
- geoprior.models.subsidence.utils.get_s_init_si(model, inputs, like)[source]#
Return initial settlement (cumulative subsidence) in SI meters.
Priority: 1) explicit keys in inputs (s_init_si/subs_hist_last_si/…) 2) last historical value from dynamic_features if subs_dyn_index exists 3) zeros (broadcast)
- geoprior.models.subsidence.utils.get_h_ref_si(model, inputs, like)[source]#
Return h_ref in SI meters, broadcast to like.
- geoprior.models.subsidence.utils.infer_dt_units_from_t(t_BH1, scaling_kwargs, *, eps=1e-12)[source]#
Infer per-step dt in time_units from time tensor t(B,H,1).
- geoprior.models.subsidence.utils.policy_gate(step, policy, *, warmup_steps=0, ramp_steps=0, dtype=tf.float32)[source]#
Return a scalar gate in
[0,1]based on a policy + step.- Parameters:
step (
Tensor) – Global step counter (typicallyoptimizer.iterations).policy (
{"always_on","always_off","warmup_off"}) – Gating behavior.always_onreturns 1,always_offreturns 0, andwarmup_offreturns 0 forstep < warmup_stepsbefore ramping to 1 overramp_stepswhenramp_steps > 0or switching immediately atwarmup_stepsotherwise.warmup_steps (
int, default0) – Number of steps to keep the gate at 0 (only forwarmup_off).ramp_steps (
int, default0) – Number of steps for a linear ramp from 0->1 after warmup. If 0, the gate is a hard step.dtype (
dtype, defaulttf_float32) – Output dtype.
- Return type:
Tensor
- geoprior.models.subsidence.utils.finalize_scaling_kwargs(sk)[source]#
Add derived SI conversion constants to
scaling_kwargs.Adds (when possible): -
seconds_per_time_unit: float -coord_ranges_si: dict with keyst(seconds),x/y(meters) -coord_inv_ranges_si: inverse of the above (safe floor).Notes
This helper is designed to be called once when assembling
scaling_kwargs(e.g., in your stage2 script) so the model can reuse those constants without recomputing unit conversions in the hot training loop.