Skip to content

[FIX] round trip of measurements through .pytta files - #60

Open
aguirreSL wants to merge 4 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-fix_pytta_files
Open

aguirreSL wants to merge 4 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-fix_pytta_files

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

This PR builds on #52, whose two commits come first, since the tests of tests/test_pyttasave.py create their sweeps with pytta.generate. The change proposed here is the last commit. With it, every test in tests/ passes (18 of 18 on development plus #52), and this addresses #23.

Saving and loading a RecMeasure, PlayRecMeasure or FRFMeasure with pytta.save and pytta.load failed or lost data. Each cause is fixed where it starts:

  1. json.dump failed on NumPy scalars (fftDegree is an np.int64). Every json.dump now converts them with .item().
  2. ChannelsList refused NumPy integers, which load passes. It now accepts any NumPy number.
  3. load renumbered a channel and then looked it up again by its old number, which raised IndexError as soon as the saved numbers differed from 1, 2, 3, and so on. Channels are now restored by position.
  4. RecMeasure was loaded with a channel 0, and the output channels of PlayRecMeasure and FRFMeasure were saved but never restored.
  5. _to_dict of the measurements did not call the base one, so the sampling rate, frequency limits, length domain and comment were not saved. The channel code was neither saved nor restored. Files written before this change load with the default code.

A second commit restores the coordinates and orientation of the channels, which were saved but not restored; files without them keep the defaults. While testing it, setting an orientation along the y axis raised ZeroDivisionError, because CoordinateObj took the azimuth as arctan(y / x). It now uses arctan2(y, x), which also gives the right quadrant for x < 0. tests/test_pytta_channels.py saves and loads a channel with coordinates and orientation.

Checked with Python 3.12, numpy 1.26 and scipy 1.17.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

aguirreSL and others added 3 commits October 31, 2026 19:44
The name given to generated objects was read by a block copied in 20
places that walked the stack with traceback.walk_stack(None). Since
Python 3.12 it starts four frames up instead of two, so in a plain
script it walks past the end of the stack and pytta.generate.sweep()
raises AttributeError at module level and UnboundLocalError inside a
function. One helper, _instanceinfo.caller_name, replaces the copies: it
walks from the caller explicitly and returns an empty name when the
source line is not available (python -c).

Tests run real scripts in a subprocess, since under pytest the stack is
deep enough to hide the failure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
scipy.signal.hann and scipy.signal.tukey were removed in SciPy 1.13. The
five calls now use scipy.signal.windows, the same functions with the
same defaults.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Saving and loading a RecMeasure, PlayRecMeasure or FRFMeasure with
pytta.save and pytta.load failed or lost data:

- json.dump failed on NumPy scalars (fftDegree is np.int64); every
  json.dump now converts them with .item().
- ChannelsList refused NumPy integers, which load passes; it now accepts
  any NumPy number.
- load renumbered a channel and then looked it up again by its old
  number; channels are now restored by position.
- RecMeasure was loaded with channel 0, and the output channels of
  PlayRecMeasure and FRFMeasure were never restored.
- the base fields of a measurement (sampling rate, frequency limits,
  length domain, comment) were not saved, since _to_dict of the
  measurements did not call the base one, and the channel code was
  neither saved nor restored.

With this, all tests in tests/test_pyttasave.py and tests/test_h5io.py
pass. The coordinates and orientation of channels are saved but still
not restored.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The coordinates and orientation of each channel were saved but not
restored on load; they now are, and files without them keep the
defaults. Setting a point with x = 0, such as an orientation along the
y axis, raised ZeroDivisionError because the azimuth was arctan(y / x);
it is now arctan2(y, x), which also gives the right quadrant for x < 0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

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.

1 participant