File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Finding the closeset or interpolated positions at given times (e.g. wave observations).
3
+ =======================================================================================
4
+ """
5
+
6
+ from pathlib import Path
7
+ from trajan .readers .omb import read_omb_csv
8
+ import xarray as xr
9
+ import coloredlogs
10
+
11
+ coloredlogs .install (level = 'debug' )
12
+
13
+ #%%
14
+ # Read the data
15
+ data = Path .cwd ().parent / "tests" / "test_data" / "csv" / "omb3.csv"
16
+ ds = read_omb_csv (data )
17
+ print (ds )
18
+
19
+ #%%
20
+ # The wave data in the variable `pHs0` is given along a different observation dimension.
21
+ # Because it is also a observation, i.e. in the style of 2D trajectory
22
+ # datasets, we need to iterate over the trajectories:
23
+
24
+
25
+ def gridwaves (tds ):
26
+ t = tds [['lat' , 'lon' ,
27
+ 'time' ]].traj .gridtime (tds ['time_waves_imu' ].squeeze ())
28
+ return t .traj .to_2d (obsdim = 'obs_waves_imu' )
29
+
30
+
31
+ dsw = ds .groupby ('trajectory' ).map (gridwaves )
32
+
33
+ print (dsw )
34
+
35
+ #%%
36
+ # We now have the positions interpolated to the IMU (wave) observations. We
37
+ # could also merge these together to one dataset again:
38
+
39
+ ds = xr .merge ((ds , dsw .rename ({
40
+ 'lon' : 'lon_waves' ,
41
+ 'lat' : 'lat_waves'
42
+ }).drop ('time' )))
43
+ print (ds )
You can’t perform that action at this time.
0 commit comments