forked from OpenDrift/trajan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_parcels.py
More file actions
67 lines (58 loc) · 2.3 KB
/
Copy pathexample_parcels.py
File metadata and controls
67 lines (58 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Analysing output from Parcels (Zarr format)
===========================================
"""
import matplotlib.pyplot as plt
import xarray as xr
import trajan as ta
ds = xr.open_dataset('../tests/test_data/parcels.zarr', engine='zarr')
#%%
# Print Xarray dataset
print(ds)
#%%
# Print trajectory specific information about dataset
print(ds.traj)
#%%
# Basic plot
ds.traj.plot(land='mask', margin=1)
# TODO: we must allow no time dimension for the below to work
#ds.mean('trajectory', skipna=True).traj.plot(color='r', label='Mean trajectory')
# In the meantime, we regrid to a regular 1D dataset to allow plotting a mean trajectory
ds = ds.traj.gridtime('4h')
ds.mean('trajectory').traj.plot(color='r', label='Mean trajectory')
plt.legend()
plt.show()
#%%
# Calculating and plotting the concentration of elements, after 6 and 24 hours
grid = ds.traj.make_grid(dx=3000)
ds_conc = ds.traj.concentration(grid)
plt.subplot(1,2,1)
ds_conc.number.isel(time=6).plot(vmin=0, vmax=20)
plt.scatter(ds.isel(time=6).lon, ds.isel(time=6).lat, s=1, color='black')
plt.subplot(1,2,2)
ds_conc.number.isel(time=24).plot(vmin=0, vmax=20)
plt.scatter(ds.isel(time=24).lon, ds.isel(time=24).lat, s=1, color='black')
plt.show()
#%%
# Calculating skillscore
# Defining the first trajectory to be the "true"
ds_true = ds.isel(trajectory=0)
skillscore = ds.traj.skill(expected=ds_true, method='liu-weissberg', tolerance_threshold=1)
#%%
# Plotting trajectories, colored by their skillscore, compared to the "true" trajectory (black)
mappable = ds.traj.plot(land='mask', color=skillscore)
ds_true.traj.plot(color='k', linewidth=3, label='"True" trajectory')
plt.colorbar(mappable=mappable, orientation='horizontal', label='Skillscore per trajectory')
plt.legend()
plt.show()
#%%
# Illustration of cumulative skillscore:
# Plotting another random trajectory ("modeled"), colored by the cumulative skillscore
# where the first trajectory is regarded as truth
ds_model = ds.isel(trajectory=4)
skillscore = ds_model.traj.skill(expected=ds_true, method='liu-weissberg', cumulative=True)
ds_true.traj.plot(color='k', linewidth=3, label='"True" trajectory', land='mask')
mappable = ds_model.traj.plot(linewidth=3, color=skillscore, label='"Modeled" trajectory')
plt.colorbar(mappable=mappable, orientation='horizontal', label='Cumulative skillscore')
plt.legend()
plt.show()