Skip to content

Commit

Permalink
Merge pull request #366 from ContactEngineering/24_April_fixes
Browse files Browse the repository at this point in the history
BUG: Assorted fixes for April
  • Loading branch information
pastewka committed Apr 16, 2024
2 parents 3c7f395 + 5d220f7 commit c09e042
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 14 deletions.
7 changes: 7 additions & 0 deletions SurfaceTopography/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change log for SurfaceTopography
================================

v1.13.13 (16Apr24)
------------------

- BUG: Fixed reader for MetroPro v3 files, close #364
- BUG: Wrong data layout in SUR files
- TST: scipy.signal.triang -> scipy.signal.windows.triang, closes #365

v1.13.12 (21Mar24)
------------------

Expand Down
14 changes: 7 additions & 7 deletions SurfaceTopography/IO/MetroPro.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@

import numpy as np

from ..Exceptions import (CorruptFile, FileFormatMismatch,
MetadataAlreadyFixedByFile)
from ..UniformLineScanAndTopography import Topography
from .binary import decode
from .common import OpenFromAny
from .Reader import ReaderBase, ChannelInfo
from ..Exceptions import CorruptFile, FileFormatMismatch, MetadataAlreadyFixedByFile
from ..UniformLineScanAndTopography import Topography
from .Reader import ChannelInfo, ReaderBase


class MetroProReader(ReaderBase):
Expand Down Expand Up @@ -256,10 +257,10 @@ class MetroProReader(ReaderBase):
('asphere_att8', '>f'),
('asphere_aperture_pct', '>f'),
('asphere_optimized_r0', '>f'),
('iff_state', 'gint16_le'),
('iff_state', '<i'),
('iff_idr_filename', '42s'),
('iff_ise_filename', '42s'),
(None, '2s'),
(None, '2b'),
('asphere_eqn_r0', '>f'),
('asphere_eqn_k', '>f'),
('asphere_eqn_coef', '>21f'),
Expand Down Expand Up @@ -289,7 +290,7 @@ class MetroProReader(ReaderBase):
('field_stop_name', '12s'),
('apert_stop_name', '12s'),
('illum_filt_name', '12s'),
(None, '2606b')
(None, '2608b')
]

# Reads in the positions of all the data and metadata
Expand Down Expand Up @@ -318,7 +319,6 @@ def __init__(self, file_path):
else:
if self._header['header_size'] != self._HEADER_SIZE3:
raise CorruptFile('Reported header size does not match expected header size.')
# TODO: We have no example file to actually test this code
header, size3 = decode(f, self._header_structure3, return_size=True)
assert size + size3 == self._HEADER_SIZE3
self._header.update(header)
Expand Down
12 changes: 7 additions & 5 deletions SurfaceTopography/IO/SUR.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@

import numpy as np

from .binary import BinaryArray, BinaryStructure, Convert, Validate
from .Reader import DeclarativeReaderBase, ChannelInfo, CompoundLayout
from ..Exceptions import CorruptFile, FileFormatMismatch, UnsupportedFormatFeature
from ..Exceptions import (CorruptFile, FileFormatMismatch,
UnsupportedFormatFeature)
from ..Support.UnitConversion import get_unit_conversion_factor
from .binary import BinaryArray, BinaryStructure, Convert, Validate
from .Reader import ChannelInfo, CompoundLayout, DeclarativeReaderBase


class SURReader(DeclarativeReaderBase):
Expand Down Expand Up @@ -115,8 +116,9 @@ class SURReader(DeclarativeReaderBase):
], name='header'),
BinaryArray(
'data',
lambda context: (context.header.nb_grid_pts_x, context.header.nb_grid_pts_y),
lambda context: np.dtype('<i2') if context.header.itemsize == 16 else np.dtype('<i4')
lambda context: (context.header.nb_grid_pts_y, context.header.nb_grid_pts_x),
lambda context: np.dtype('<i2') if context.header.itemsize == 16 else np.dtype('<i4'),
conversion_fun=lambda arr: arr.T
)
])

Expand Down
49 changes: 48 additions & 1 deletion test/IO/test_sur.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import numpy as np
import pytest

from NuMPI import MPI

from SurfaceTopography import read_topography
Expand Down Expand Up @@ -88,3 +87,51 @@ def test_sur3_metadata(file_format_examples):
assert t.unit == 'm'

np.testing.assert_allclose(t.rms_height_from_area(), 0.0019200491394179297, rtol=1e-6)


def test_sur4_metadata(file_format_examples, plot=False):
file_path = os.path.join(file_format_examples, 'sur-4.sur')

r = SURReader(file_path)
t = r.topography()

if plot:
import matplotlib.pyplot as plt
t.plot()
plt.show()

nx, ny = t.nb_grid_pts
assert nx == 1232
assert ny == 1028

sx, sy = t.physical_sizes
np.testing.assert_allclose(sx, 0.3400320075452328, rtol=1e-6)
np.testing.assert_allclose(sy, 0.2837280062958598, rtol=1e-6)

assert t.unit == 'mm'

np.testing.assert_allclose(t.rms_height_from_area(), 0.1269314744701442, rtol=1e-6)


def test_sur5_metadata(file_format_examples, plot=False):
file_path = os.path.join(file_format_examples, 'sur-5.sur')

r = SURReader(file_path)
t = r.topography()

if plot:
import matplotlib.pyplot as plt
t.plot()
plt.show()

nx, ny = t.nb_grid_pts
assert nx == 2560
assert ny == 2560

sx, sy = t.physical_sizes
np.testing.assert_allclose(sx, 0.631917268037796, rtol=1e-6)
np.testing.assert_allclose(sy, 0.631917268037796, rtol=1e-6)

assert t.unit == 'mm'

np.testing.assert_allclose(t.rms_height_from_area(), 0.007327675492217414, rtol=1e-6)
Binary file added test/file_format_examples/sur-4.sur
Binary file not shown.
Binary file added test/file_format_examples/sur-5.sur
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test_bearing_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_bearing_area_nonuniform(plot=False):
hm = 0.1
X = np.arange(n) # n+1 because we need the endpoint
# sinsurf = np.sin(2 * np.pi * X / L) * hm
trisurf = hm * scipy.signal.triang(n)
trisurf = hm * scipy.signal.windows.triang(n)

t = NonuniformLineScan(X, trisurf)

Expand Down

0 comments on commit c09e042

Please sign in to comment.