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

traj: allow specifying the trajectory, observation and time dimensions/variables #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions tests/test_dims.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ def test_no_time_dim(barents):
# can we use trajan without

print(b.traj)

def test_custom_dims(barents: xr.DataArray):
# b = barents.expand_dims('campaign')
b = barents.rename(trajectory='campaign')
print(b)

g = b.traj(trajectory_dim='campaign').gridtime('1H')
print(g)
33 changes: 33 additions & 0 deletions trajan/traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,39 @@ def __init__(self, ds, trajectory_dim, obs_dim, time_varname):
self.obs_dim = obs_dim # dimension along which time increases
self.time_varname = time_varname

def __call__(self, trajectory_dim=None, obs_dim=None, time_varname=None):
"""
Specify the trajectory, observation and time dimensions or variable names.


Parameters
----------
trajectory_dim : string
Name of trajectory dimension (usually `trajectory` or `drifter`).

obs_dim : string
Name of observation dimension (usually `obs` or `time`).

time_varname : string
Name of time variable or dimension coordinate (usually `time`).


Returns
-------
traj : Traj
Traj accessor with manually specified coordinates and dimensions.
"""
if trajectory_dim is not None:
self.trajectory_dim = trajectory_dim

if obs_dim is not None:
self.obs_dim = obs_dim

if time_varname is not None:
self.time_varname = time_varname

return self

def __repr__(self):
output = '=======================\n'
output += 'TrajAn info:\n'
Expand Down
Loading