7
7
8
8
logger = logging .getLogger (__name__ )
9
9
10
- from .traj import Traj
10
+ from .traj import Traj , detect_tx_variable
11
11
from .traj1d import Traj1d
12
12
from .traj2d import Traj2d
13
13
from .ragged import ContiguousRagged
14
14
15
15
16
- def detect_tx_dim (ds ):
17
- if 'lon' in ds :
18
- return ds .lon
19
- elif 'longitude' in ds :
20
- return ds .longitude
21
- elif 'x' in ds :
22
- return ds .x
23
- elif 'X' in ds :
24
- return ds .X
25
- else :
26
- raise ValueError ("Could not determine x / lon variable" )
27
-
28
-
29
- def detect_time_dim (ds , obs_dim ):
30
- logger .debug (f'Detecting time-dimension for "{ obs_dim } "..' )
16
+ def detect_time_variable (ds , obs_dim ):
17
+ logger .debug (f'Detecting time-variable for "{ obs_dim } "..' )
18
+ # TODO: should use cf-xarray here
31
19
for v in ds .variables :
32
20
if obs_dim in ds [v ].dims and 'time' in v :
33
21
return v
34
22
35
- raise ValueError ("no time dimension detected" )
23
+ raise ValueError ("No time variable detected" )
36
24
37
25
38
26
@xr .register_dataset_accessor ("traj" )
@@ -50,7 +38,7 @@ def __new__(cls, ds):
50
38
obs_dim = None
51
39
time_varname = None
52
40
53
- tx = detect_tx_dim (ds )
41
+ tx = detect_tx_variable (ds )
54
42
55
43
# if we have a 1D dims, this is most likely some contiguous data
56
44
# there may be a few exceptions though, so be ready to default to the classical 2D parser below
@@ -106,11 +94,11 @@ def __new__(cls, ds):
106
94
# there may also be some slightly unusual cases where these Traj1d and Traj2d classes will be used on data with 1D arrays
107
95
if 'obs' in tx .dims :
108
96
obs_dim = 'obs'
109
- time_varname = detect_time_dim (ds , obs_dim )
97
+ time_varname = detect_time_variable (ds , obs_dim )
110
98
111
99
elif 'index' in tx .dims :
112
100
obs_dim = 'obs'
113
- time_varname = detect_time_dim (ds , obs_dim )
101
+ time_varname = detect_time_variable (ds , obs_dim )
114
102
115
103
elif 'time' in tx .dims :
116
104
obs_dim = 'time'
@@ -123,7 +111,7 @@ def __new__(cls, ds):
123
111
None ) == 'trajectory_id' and not 'traj' in d :
124
112
125
113
obs_dim = d
126
- time_varname = detect_time_dim (ds , obs_dim )
114
+ time_varname = detect_time_variable (ds , obs_dim )
127
115
128
116
break
129
117
0 commit comments