16
16
17
17
from .field import EmptyFieldList
18
18
from .flavour import CoordinateGuesser
19
+ from .patch import patch_dataset
19
20
from .time import Time
20
21
from .variable import FilteredVariable
21
22
from .variable import Variable
@@ -49,7 +50,11 @@ def __getitem__(self, i):
49
50
raise IndexError (k )
50
51
51
52
@classmethod
52
- def from_xarray (cls , ds , flavour = None ):
53
+ def from_xarray (cls , ds , * , flavour = None , patch = None ):
54
+
55
+ if patch is not None :
56
+ ds = patch_dataset (ds , patch )
57
+
53
58
variables = []
54
59
55
60
if isinstance (flavour , str ):
@@ -83,6 +88,8 @@ def _skip_attr(v, attr_name):
83
88
_skip_attr (variable , "bounds" )
84
89
_skip_attr (variable , "grid_mapping" )
85
90
91
+ LOG .debug ("Xarray data_vars: %s" , ds .data_vars )
92
+
86
93
# Select only geographical variables
87
94
for name in ds .data_vars :
88
95
@@ -97,13 +104,15 @@ def _skip_attr(v, attr_name):
97
104
c = guess .guess (ds [coord ], coord )
98
105
assert c , f"Could not guess coordinate for { coord } "
99
106
if coord not in variable .dims :
107
+ LOG .debug ("%s: coord=%s (not a dimension): dims=%s" , variable , coord , variable .dims )
100
108
c .is_dim = False
101
109
coordinates .append (c )
102
110
103
111
grid_coords = sum (1 for c in coordinates if c .is_grid and c .is_dim )
104
112
assert grid_coords <= 2
105
113
106
114
if grid_coords < 2 :
115
+ LOG .debug ("Skipping %s (not 2D): %s" , variable , [(c , c .is_grid , c .is_dim ) for c in coordinates ])
107
116
continue
108
117
109
118
v = Variable (
0 commit comments