Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #87

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ output/*
*.swp
build/*
dist/*
resources/
*.egg-info*
.cache
docs/api
Expand Down
5 changes: 5 additions & 0 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ Running tests

.. code-block:: bash

# download test datasets
cd pocean/tests
python download_test_data.py
ocefpaf marked this conversation as resolved.
Show resolved Hide resolved

# run test suite
pytest
8 changes: 7 additions & 1 deletion pocean/dsg/trajectory/im.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ def from_dataframe(cls, df, output, **kwargs):
def ts(t_index, size):
return np.s_[0:size]
default_dimensions = (daxes.sample,)
trajectory = nc.createVariable(axes.trajectory, get_dtype(df[axes.trajectory]))
# To support the IOOS netCDF specification, if traj_strlen is specified
# use a char array for the trajectory variable with a dimension traj_strlen.
if 'traj_strlen' in kwargs:
nc.createDimension('traj_strlen', kwargs['traj_strlen'])
trajectory = nc.createVariable(axes.trajectory, 'S1', ('traj_strlen',))
else:
trajectory = nc.createVariable(axes.trajectory, get_dtype(df[axes.trajectory]))
else:
def ts(t_index, size):
return np.s_[t_index, 0:size]
Expand Down
4 changes: 2 additions & 2 deletions pocean/dsg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def get_temporal_attributes(df, axes=None):
'attributes': {
'time_coverage_start': mint.strftime('%Y-%m-%dT%H:%M:%SZ'),
'time_coverage_end': maxt.strftime('%Y-%m-%dT%H:%M:%SZ'),
'time_coverage_duration': (maxt - mint).round('1S').isoformat(),
'time_coverage_resolution': mode_value.round('1S').isoformat()
'time_coverage_duration': (maxt - mint).round('1s').isoformat(),
'time_coverage_resolution': mode_value.round('1s').isoformat()
}
}

Expand Down
16 changes: 8 additions & 8 deletions pocean/tests/dsg/trajectory/test_trajectory_im.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ def test_imt_calculated_metadata_single(self):

with IncompleteMultidimensionalTrajectory(filepath) as ncd:
s = ncd.calculated_metadata()
assert s.min_t.round('S') == dtparse('1990-01-01 00:00:00')
assert s.max_t.round('S') == dtparse('1990-01-05 03:00:00')
assert s.min_t.round('s') == dtparse('1990-01-01 00:00:00')
assert s.max_t.round('s') == dtparse('1990-01-05 03:00:00')
traj1 = s.trajectories["Trajectory1"]
assert traj1.min_z == 0
assert traj1.max_z == 99
assert traj1.min_t.round('S') == dtparse('1990-01-01 00:00:00')
assert traj1.max_t.round('S') == dtparse('1990-01-05 03:00:00')
assert traj1.min_t.round('s') == dtparse('1990-01-01 00:00:00')
assert traj1.max_t.round('s') == dtparse('1990-01-05 03:00:00')
first_loc = traj1.geometry.coords[0]
assert np.isclose(first_loc[0], -7.9336)
assert np.isclose(first_loc[1], 42.00339)
Expand All @@ -180,17 +180,17 @@ def test_imt_calculated_metadata_multi(self):
traj0 = m.trajectories["Trajectory0"]
assert traj0.min_z == 0
assert traj0.max_z == 35
assert traj0.min_t.round('S') == dtparse('1990-01-01 00:00:00')
assert traj0.max_t.round('S') == dtparse('1990-01-02 11:00:00')
assert traj0.min_t.round('s') == dtparse('1990-01-01 00:00:00')
assert traj0.max_t.round('s') == dtparse('1990-01-02 11:00:00')
first_loc = traj0.geometry.coords[0]
assert np.isclose(first_loc[0], -35.07884)
assert np.isclose(first_loc[1], 2.15286)

traj3 = m.trajectories["Trajectory3"]
assert traj3.min_z == 0
assert traj3.max_z == 36
assert traj3.min_t.round('S') == dtparse('1990-01-01 00:00:00')
assert traj3.max_t.round('S') == dtparse('1990-01-02 12:00:00')
assert traj3.min_t.round('s') == dtparse('1990-01-01 00:00:00')
assert traj3.max_t.round('s') == dtparse('1990-01-02 12:00:00')
first_loc = traj3.geometry.coords[0]
assert np.isclose(first_loc[0], -73.3026)
assert np.isclose(first_loc[1], 1.95761)
Expand Down
24 changes: 12 additions & 12 deletions pocean/tests/dsg/trajectoryProfile/test_trajectoryProfile_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def test_crtp_calculated_metadata_single(self):

with ContiguousRaggedTrajectoryProfile(self.single) as st:
s = st.calculated_metadata(axes=axes)
assert s.min_t.round('S') == dtparse('2014-11-25 18:57:30')
assert s.max_t.round('S') == dtparse('2014-11-27 07:10:30')
assert s.min_t.round('s') == dtparse('2014-11-25 18:57:30')
assert s.max_t.round('s') == dtparse('2014-11-27 07:10:30')
assert len(s.trajectories) == 1
traj = s.trajectories["sp025-20141125T1730"]
assert traj.min_z == 0
assert np.isclose(traj.max_z, 504.37827)
assert traj.min_t.round('S') == dtparse('2014-11-25 18:57:30')
assert traj.max_t.round('S') == dtparse('2014-11-27 07:10:30')
assert traj.min_t.round('s') == dtparse('2014-11-25 18:57:30')
assert traj.max_t.round('s') == dtparse('2014-11-27 07:10:30')

first_loc = traj.geometry.coords[0]
assert np.isclose(first_loc[0], -119.79025)
Expand All @@ -131,34 +131,34 @@ def test_crtp_calculated_metadata_multi(self):

with ContiguousRaggedTrajectoryProfile(self.multi) as mt:
m = mt.calculated_metadata(axes=axes)
assert m.min_t.round('S') == dtparse('1990-01-01 00:00:00')
assert m.max_t.round('S') == dtparse('1990-01-03 02:00:00')
assert m.min_t.round('s') == dtparse('1990-01-01 00:00:00')
assert m.max_t.round('s') == dtparse('1990-01-03 02:00:00')
assert len(m.trajectories) == 5
# First trajectory
traj0 = m.trajectories[0]
assert traj0.min_z == 0
assert traj0.max_z == 43
assert traj0.min_t.round('S') == dtparse('1990-01-02 05:00:00')
assert traj0.max_t.round('S') == dtparse('1990-01-03 01:00:00')
assert traj0.min_t.round('s') == dtparse('1990-01-02 05:00:00')
assert traj0.max_t.round('s') == dtparse('1990-01-03 01:00:00')
first_loc = traj0.geometry.coords[0]
assert first_loc[0] == -60
assert first_loc[1] == 53
assert len(traj0.profiles) == 4
assert traj0.profiles[0].t.round('S') == dtparse('1990-01-03 01:00:00')
assert traj0.profiles[0].t.round('s') == dtparse('1990-01-03 01:00:00')
assert traj0.profiles[0].x == -60
assert traj0.profiles[0].y == 49

# Last trajectory
traj4 = m.trajectories[4]
assert traj4.min_z == 0
assert traj4.max_z == 38
assert traj4.min_t.round('S') == dtparse('1990-01-02 14:00:00')
assert traj4.max_t.round('S') == dtparse('1990-01-02 15:00:00')
assert traj4.min_t.round('s') == dtparse('1990-01-02 14:00:00')
assert traj4.max_t.round('s') == dtparse('1990-01-02 15:00:00')
first_loc = traj4.geometry.coords[0]
assert first_loc[0] == -67
assert first_loc[1] == 47
assert len(traj4.profiles) == 4
assert traj4.profiles[19].t.round('S') == dtparse('1990-01-02 14:00:00')
assert traj4.profiles[19].t.round('s') == dtparse('1990-01-02 14:00:00')
assert traj4.profiles[19].x == -44
assert traj4.profiles[19].y == 47

Expand Down