Skip to content

Fix the row order of H4 parameter files in MKZ_Param_Multi_Layer - #116

Open
jsh9 wants to merge 2 commits into
2026-10-10-parametrize-testsfrom
2026-10-11-fix-mkz-file-row-order
Open

jsh9 wants to merge 2 commits into
2026-10-10-parametrize-testsfrom
2026-10-11-fix-mkz-file-row-order

Conversation

@jsh9

@jsh9 jsh9 commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Fixes #79. One of the four P0 fixes from #114, based on #74's branch (2026-10-10-parametrize-tests).

Problem

H4 parameter files (H4_G_*.txt, H4_x_*.txt) store each layer as gamma_ref, b (always 0), s, beta.

  • Reading: MKZ_Param_Multi_Layer() read files and 2D arrays without from_files=True, so every layer got s = 0, beta = the file's s, and Gmax = the file's beta. With s = 0, G/Gmax is a constant (0.5296 for every strain in layer 1 of H4_G_IWTH04.txt), and damping is about 0.
  • Writing: save_txt() and get_all_H4_x_params(save_txt=True) wrote gamma_ref, s, beta, Gmax instead of the file layout.

Reading and writing were wrong in the same way, so a file written by the library loaded back unchanged. That is why the existing round-trip tests passed.

Changes

  • PySeismoSoil/class_parameters.py:
    • MKZ_Param_Multi_Layer.__init__() reads files and 2D arrays with from_files=True. The class docstring already said the array has the file format; its table now shows the actual rows.
    • New MKZ_Param_Multi_Layer.serialize_to_2D_array() writes the file layout (to_files=True), so save_txt() does too.
    • The file layout has no Gmax: reading sets Gmax = 1.0 and writing drops it. This is now in the docstrings. Gmax does not affect the G/Gmax or damping curves.
  • PySeismoSoil/class_curves.py:
    • get_all_H4_x_params() serializes with functools.partial(mkz.serialize_params_to_array, to_files=True).
    • Its docstring said it saves an "HH_x" file of "HH parameters"; it now says H4 and describes the layout.
  • PySeismoSoil/helper_site_response.py: the func_serialize docstring of fit_all_damping_curves() mentions to_files=True for H4 files.
  • CHANGELOG.md: a "Fixed" entry.
  • The example notebooks were re-run (second commit), as CONTRIBUTING.md requires. No notebook loads H4 files or builds MKZ_Param_Multi_Layer from a file or array, so no printed results changed (only timings, folder names, object addresses, and image bytes).

Tests

All of these fail on the old library code (5 failed) and pass with the fix:

  • test_mkz_param_multi_layer__test_contents_of_list_elements: the old benchmark [0.000856, 0, 0.88832, 1.7492] encoded s = 0. The test now expects layer 1 of H4_G_IWTH04.txt read in its file layout: gamma_ref=0.00085636, s=0.88832, beta=1.7492, Gmax=1.0.
  • test_mkz_param_multi_layer__save_txt_and_load_back (new): serialize_to_2D_array() and the save_txt() file have the rows gamma_ref, 0, s, beta, and both load back with the same parameters (Gmax = 1.0).
  • test_construct_curves[from_H4_G_parameters] / [from_H4_x_parameters]: these checked only shapes. They now also compare the values of one layer with the curve from that layer's column read with from_files=True. The HH cases get the same check.
  • tests/test_class_curves.py::test_get_all_H4_x_params__saved_file_loads_back (new): the saved file has the file layout and loads back via MKZ_Param_Multi_Layer().

Testing

CI runs only on PRs into main, so it does not run here. These were run locally on Python 3.13:

  • python -m pytest tests: 243 passed.
  • pre-commit run -a and pydoclint PySeismoSoil: pass.
  • tox -e run-notebooks: all 14 notebooks ran without errors.

Notes for review

🤖 Generated with Claude Code

https://claude.ai/code/session_01W7fK8T2pPLf3tPCnMCKL1T


Generated by Claude Code

- `MKZ_Param_Multi_Layer()` now reads files and 2D arrays with
  `from_files=True`, i.e., in the format of the H4 parameter files
  (gamma_ref, 0, s, beta), as its docstring says. Before, it read them as
  (gamma_ref, s, beta, Gmax), so each layer got s = 0 and flat curves.
  Gmax (not in the files) is set to 1.0, as documented now.
- `MKZ_Param_Multi_Layer.serialize_to_2D_array()` (and so `save_txt()`)
  and `Multiple_Damping_Curves.get_all_H4_x_params(save_txt=True)` now
  write the same format (`to_files=True`), so a saved file loads back
  with the same parameters.
- Tests: fix the expected parameters of layer 1 of H4_G_IWTH04.txt
  (they had s = 0), check the curve values in `test_construct_curves`,
  and add round-trip tests for `save_txt()` and
  `get_all_H4_x_params(save_txt=True)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7fK8T2pPLf3tPCnMCKL1T
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7fK8T2pPLf3tPCnMCKL1T

This branch has not been deployed

No deployments
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