Skip to content

traj: add trajectories method to iterate over trajectories (rather than groupby which expects unique traj ids)#188

Merged
gauteh merged 4 commits intoOpenDrift:mainfrom
gauteh:add_trajectories
Feb 4, 2026
Merged

traj: add trajectories method to iterate over trajectories (rather than groupby which expects unique traj ids)#188
gauteh merged 4 commits intoOpenDrift:mainfrom
gauteh:add_trajectories

Conversation

@gauteh
Copy link
Member

@gauteh gauteh commented Feb 4, 2026

No description provided.

polygon = Polygon([(lon[0], lat[0]), (lon[1], lat[1]), (lon[2], lat[2]), (lon[3], lat[3])])
lon = [
lons[i, j], lons[i, j + 1], lons[i + 1, j + 1], lons[i + 1, j]
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veit ikkje om eg heilt likar denne automatiske lintinga :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nei.. det kan du sei, hadde nok valgt annleis sjølv, men det er betre å halde seg til auto-formatering og standardane.. ellers vil ein ikkje kunne bruke det automatisk og konsistent andre stadar i fila uten at det alltid blir oppdatert.

warnings.simplefilter("ignore", category=DeprecationWarning)
azimuth_forward, a2, distance = geod.inv(lonfrom, latfrom, lonto, latto)
azimuth_forward, a2, distance = geod.inv(lonfrom, latfrom, lonto,
latto)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ikkje akkurat meir lesbart....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikkje so veldig mykje mindre heller, og då held ein seg innafor linjelengda. lange linjer er vanskeligare å lese. Men ja, eg meiner det heilt klart er betre å halde seg til automatisk standard slik at ein berre kan køyre gjennom eit konsistent verktøy og det blir null sjarm og forskjellige preferansar :)

>>> import lzma
>>> b = lzma.open('examples/barents.nc.xz')
>>> ds = xr.open_dataset(b)
>>> p = ds.traj.trajectories().map(lambda t: t.mean('obs'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this different from p = ds.traj.mean(dim='obs') ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no.. not the best example, couldn't think of a better one right now.

@gauteh gauteh merged commit b7d0b43 into OpenDrift:main Feb 4, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants