@@ -60,8 +60,13 @@ def get_variables_with_anonymous_dims(
60
60
return set (
61
61
variable
62
62
for variable in variables
63
- if (len (varinfo .get_variable (variable ).dimensions ) == 0 )
64
- or (any_absent_dimension_variables (varinfo , variable ))
63
+ if (
64
+ varinfo .get_variable (variable )
65
+ and (
66
+ (len (varinfo .get_variable (variable ).dimensions ) == 0 )
67
+ or (any_absent_dimension_variables (varinfo , variable ))
68
+ )
69
+ )
65
70
)
66
71
67
72
@@ -70,42 +75,56 @@ def any_absent_dimension_variables(varinfo: VarInfoFromDmr, variable: str) -> bo
70
75
that have been created by opendap, but are not really
71
76
dimension variables
72
77
"""
78
+
73
79
return any (
74
80
varinfo .get_variable (dimension ) is None
75
81
for dimension in varinfo .get_variable (variable ).dimensions
76
82
)
77
83
78
84
79
- def get_dimension_array_names_from_coordinate_variables (
85
+ def get_dimension_array_names (
80
86
varinfo : VarInfoFromDmr ,
81
87
variable_name : str ,
82
88
) -> list [str ]:
83
89
"""
84
- Returns the dimensions names from coordinate variables
90
+ Returns the dimensions names from coordinate variables or from
91
+ configuration
85
92
"""
93
+ variable = varinfo .get_variable (variable_name )
94
+ dimension_names = varinfo .get_variable (variable_name ).dimensions
95
+
96
+ if len (dimension_names ) >= 2 :
97
+ # if the dimension is not a variable, was added as a
98
+ # configuration entry,
99
+ if variable is not None :
100
+ return dimension_names
86
101
87
102
latitude_coordinates , longitude_coordinates = get_coordinate_variables (
88
103
varinfo , [variable_name ]
89
104
)
90
105
91
106
# for one variable, the coordinate array length will always be 1 or 0
92
107
if len (latitude_coordinates ) == 1 and len (longitude_coordinates ) == 1 :
93
- dimension_array_names = get_dimension_array_names (
108
+ dimension_array_names = get_dimension_array_names_from_coordinates (
94
109
varinfo , latitude_coordinates [0 ]
95
110
)
96
111
# if variable does not have coordinates (len = 0)
97
112
elif (
98
113
varinfo .get_variable (variable_name ).is_latitude ()
99
114
or varinfo .get_variable (variable_name ).is_longitude ()
100
115
):
101
- dimension_array_names = get_dimension_array_names (varinfo , variable_name )
116
+ dimension_array_names = get_dimension_array_names_from_coordinates (
117
+ varinfo , variable_name
118
+ )
102
119
else :
103
120
dimension_array_names = []
104
121
105
122
return dimension_array_names
106
123
107
124
108
- def get_dimension_array_names (varinfo : VarInfoFromDmr , variable_name : str ) -> str :
125
+ def get_dimension_array_names_from_coordinates (
126
+ varinfo : VarInfoFromDmr , variable_name : str
127
+ ) -> str :
109
128
"""returns the x-y variable names that would
110
129
match the group of the input variable. The 'dim_y' dimension
111
130
and 'dim_x' names are returned with the group pathname
@@ -172,13 +191,19 @@ def create_dimension_arrays_from_coordinates(
172
191
col_dim_values , np .transpose (col_indices )[1 ], col_size
173
192
)
174
193
175
- projected_y , projected_x = tuple (projected_dimension_names )
194
+ if len (projected_dimension_names ) >= 2 :
195
+ projected_y , projected_x = (
196
+ projected_dimension_names [- 2 ],
197
+ projected_dimension_names [- 1 ],
198
+ )
199
+
200
+ if dim_order_is_y_x :
201
+ return {projected_y : y_dim , projected_x : x_dim }
202
+ raise UnsupportedDimensionOrder ('x,y' )
203
+ # this is not currently supported in the calling function in spatial.py
204
+ # return {projected_x: x_dim, projected_y: y_dim}
176
205
177
- if dim_order_is_y_x :
178
- return {projected_y : y_dim , projected_x : x_dim }
179
- raise UnsupportedDimensionOrder ('x,y' )
180
- # this is not currently supported in the calling function in spatial.py
181
- # return {projected_x: x_dim, projected_y: y_dim}
206
+ raise UnsupportedDimensionOrder (projected_dimension_names )
182
207
183
208
184
209
def get_2d_coordinate_array (
@@ -322,8 +347,16 @@ def get_dimension_order_and_dim_values(
322
347
projected spatial dimension. The input lat lon arrays and dimension
323
348
indices are assumed to be 2D in this implementation of the function.
324
349
"""
325
- lat_arr_values = [lat_array_points [i ][j ] for i , j in grid_dimension_indices ]
326
- lon_arr_values = [lon_array_points [i ][j ] for i , j in grid_dimension_indices ]
350
+ if lat_array_points .ndim == 1 and lon_array_points .ndim == 1 :
351
+ lat_arr_values = lat_array_points
352
+ lon_arr_values = lon_array_points
353
+ elif lat_array_points .ndim == 2 and lon_array_points .ndim == 2 :
354
+ lat_arr_values = [lat_array_points [i ][j ] for i , j in grid_dimension_indices ]
355
+ lon_arr_values = [lon_array_points [i ][j ] for i , j in grid_dimension_indices ]
356
+ else :
357
+ # assuming a nominal z,y,x order
358
+ lat_arr_values = [lat_array_points [0 ][i ][j ] for i , j in grid_dimension_indices ]
359
+ lon_arr_values = [lon_array_points [0 ][i ][j ] for i , j in grid_dimension_indices ]
327
360
328
361
from_geo_transformer = Transformer .from_crs (4326 , crs )
329
362
x_values , y_values = ( # pylint: disable=unpacking-non-sequence
0 commit comments