Skip to content

Commit

Permalink
Refs #629 SampleLogs.get_pointlist creates point lists in units of mi…
Browse files Browse the repository at this point in the history
…li-meters

Signed-off-by: Jose Borreguero <[email protected]>
  • Loading branch information
jmborr committed Sep 7, 2020
1 parent df67c33 commit e651dcb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pyrs/dataobjects/sample_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ def get_pointlist(self, subruns=None) -> 'PointList':
r"""
Create a ~pyrs.dataobjects.sample_logs.PointList instance from the vx, vy, and vz logs
Units are converted to mili-meters, if the logs are in meters. If the logs lack units, it's
assumed units are mili-meters
Parameters
----------
subruns: int, list, np.ndarray, ~pyrs.dataobjects.sample_logs.SubRuns
Expand All @@ -522,9 +525,12 @@ def get_pointlist(self, subruns=None) -> 'PointList':
if missing:
raise ValueError('Failed to find positions in logs. Missing {}'.format(', '.join(missing)))

# Check the units are in mili meters
factor = 1000.0 if self._units.get(VX, 'mm') == 'm' else 1.0

# create a PointList on the fly
# passing the subruns down allow for slicing/selecting
return PointList([self[VX, subruns], self[VY, subruns], self[VZ, subruns]])
return PointList([factor * self[vi, subruns] for vi in (VX, VY, VZ)])


class _DirectionExtents(NamedTuple):
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/pyrs/dataobjects/test_sample_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ def test_get_pointlist(self):
np.testing.assert_equal(pointlist.vy, [0, 2, 3])
np.testing.assert_equal(pointlist.vz, [0, 2, 3])

# check unit conversion
sample['vx', 'm'] = np.arange(5, dtype=float)
sample['vy', 'm'] = np.arange(5, dtype=float)
sample['vz', 'm'] = np.arange(5, dtype=float)
pointlist = sample.get_pointlist()
np.testing.assert_allclose(pointlist.vx, 1000 * np.arange(5, dtype=float), atol=0.1)


class TestDirectionExtents:

Expand Down

0 comments on commit e651dcb

Please sign in to comment.