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

Traj2d.timestep is failing #141

Open
knutfrode opened this issue Nov 12, 2024 · 4 comments
Open

Traj2d.timestep is failing #141

knutfrode opened this issue Nov 12, 2024 · 4 comments

Comments

@knutfrode
Copy link
Contributor

I added an xfailing test for this:
https://github.com/OpenDrift/trajan/blob/main/tests/test_read_sfy.py#L33

def timestep(self, average=np.nanmedian):

Traj2d.timestep uses
np.diff(self.ds.time, axis=1)
but we should instead use dimension names here (the failing SFY dataset has only one axis).

Also, would it not be better if Traj1d.timestep and Traj2d.timestep returned timedeltas instead of seconds?

@gauteh
Copy link
Member

gauteh commented Nov 12, 2024

Yes. I also think we should return a multi dimensional array for time steps on 2d datasets.

@knutfrode
Copy link
Contributor Author

knutfrode commented Nov 13, 2024

Ok, I will implement that.

I find those time-things in Python really messy, but I guess we have no better alternative than to use numpy.timedelta64 here ?
I.e. an Xarray DataArray of numpy.timedelta64.

@gauteh
Copy link
Member

gauteh commented Nov 13, 2024

pd.Timedelta, e.g. from pd.to_timedelta are the best. They serialize to np.timedelta64 internally in xarray. The pandas functions for timedelta and datetime are the best of all, can take anything (single value, array) and can convert to anything. They usually figure out the right thing automatically.

@knutfrode
Copy link
Contributor Author

In fact, we already have methods time_to_next for exactly this....
I guess timestep was simply made as a shorthand to get a single timestep (either the constant one, or a mean of the varying timesteps).

def time_to_next(self):

def time_to_next(self):

However, time_to_next() fails for the SFY dataset (bug32), since the method is hardcoded for having a dimension named obs
Thus that should be fixed first, but again raises a more fundamental issue/question:

We have self.obsdim and self.timedim - but in fact those are often not dimensions at all, but rather variables.
Thus I think we need a more precise terminology here, i.e. separating clearly between:

  • dimensions
  • coordinates
  • coordinate variables
  • regular variables

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

No branches or pull requests

2 participants