Skip to content
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ pip install trajan
TrajAn exposes a `.traj` accessor on xarray Datasets:

```python
import lzma
import xarray as xr
import trajan as ta

# Open a CF-trajectory dataset (e.g. from drifting buoys)
with lzma.open("barents.nc.xz") as f:
ds = xr.open_dataset(f)
ds.load()
ds = xr.open_dataset('barents.nc')

# Basic map plot — geographic projection is chosen automatically
ds.traj.plot()
Expand Down
Binary file modified examples/data_dir/test.nc
Binary file not shown.
1 change: 0 additions & 1 deletion examples/example_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
``.show()`` to display interactively or ``.save()`` to write a file.
"""
import logging
import lzma
import numpy as np
import xarray as xr
import coloredlogs
Expand Down
3 changes: 0 additions & 3 deletions examples/example_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
==============================
"""
import numpy as np
import lzma
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import xarray as xr
import pandas as pd
import trajan as ta

#%%
Expand Down
2 changes: 0 additions & 2 deletions examples/example_drifter_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Read a position log from a CSV file and convert it to a CF-compatible dataset
=============================================================================
"""
import pandas as pd
import trajan as ta
import matplotlib.pyplot as plt

Expand All @@ -14,4 +13,3 @@
ds.traj.plot(color=None, label=ds.trajectory.values)
plt.legend()
plt.show()

1 change: 0 additions & 1 deletion examples/example_drifters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
============================
"""
import numpy as np
import lzma
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import xarray as xr
Expand Down
16 changes: 5 additions & 11 deletions examples/example_nc_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@
ds = xr.open_dataset(ta.DATA_DIR + 'gnome_nc_particles.nc')
print(ds)

print(ds.traj)

#%%
# Basic plot
ds.traj.plot(land='mask')
# Displaying what is detected by TrajAn
print(ds.traj)

#%%
# Convert from Ragged to Orthogonal
ds_ortho = ds.traj.gridtime('1h')
# Plotting

#%%
# Plotting a mean trajectory
ds.traj.plot(land='mask') # plotting all trajectories
ds_ortho = ds.traj.gridtime('1h') # convert from Ragged to Orthogonal
ds_ortho.mean('trajectory').traj.plot(color='r', label='Mean trajectory')

#%%
# Plotting initial and final element locations, and a convex hull
ds_ortho.isel(time=0).traj.plot.scatter(color='k', s=80, zorder=100, label='Initial positions')
ds_ortho.isel(time=-1).traj.plot.scatter(color='b', s=80, zorder=100, label='Final positions')
ds_ortho.isel(time=-1).traj.plot.convex_hull(color='g', label='Convex hull of final positions')
#ds_ortho.isel(time=10).traj.plot.convex_hull(color='y', label='Convex hull after 10 hours')

plt.legend()
plt.title('Sample trajectory dataset from nc_particles repository')
plt.show()
Expand Down
1 change: 0 additions & 1 deletion examples/example_opendrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Analysing output from OpenDrift
===============================
"""
import lzma
import matplotlib.pyplot as plt
import xarray as xr
import trajan as ta
Expand Down
1 change: 0 additions & 1 deletion tests/test_seltime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import xarray as xr
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


def test_seltime(barents):
Expand Down
2 changes: 1 addition & 1 deletion trajan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def trajectory_dict_to_dataset(trajectory_dict,
else:
variable_attributes[var] = {}
time = np.empty((num_drifters, num_times), dtype='datetime64[s]')
time[:] = np.datetime64('nat')
time[:] = np.datetime64('NaT', 's')

# Fill arrays with data from dictionaries
for drifter_num, (drifter_name,
Expand Down
Loading