1- from copy import copy , deepcopy
1+ from copy import deepcopy
22import numpy as np
33import xarray as xr
44from .utils import _set_attrs_on_all_vars
@@ -72,30 +72,30 @@ def __init__(
7272 if ds .metadata ["keep_xboundaries" ]:
7373 xbndry = ds .metadata ["MXG" ]
7474 if self .connection_inner_x is None :
75- self .nx -= xbndry
75+ self .nx = self . nx - xbndry
7676
7777 # used to calculate x-coordinate of inner side (self.xinner)
78- xinner_ind += xbndry
78+ xinner_ind = xinner_ind + xbndry
7979
8080 if self .connection_outer_x is None :
81- self .nx -= xbndry
81+ self .nx = self . nx - xbndry
8282
8383 # used to calculate x-coordinate of outer side (self.xouter)
84- xouter_ind -= xbndry
84+ xouter_ind = xouter_ind - xbndry
8585
8686 if ds .metadata ["keep_yboundaries" ]:
8787 ybndry = ds .metadata ["MYG" ]
8888 if self .connection_lower_y is None :
89- self .ny -= ybndry
89+ self .ny = self . ny - ybndry
9090
9191 # used to calculate y-coordinate of lower side (self.ylower)
92- ylower_ind += ybndry
92+ ylower_ind = ylower_ind + ybndry
9393
9494 if self .connection_upper_y is None :
95- self .ny -= ybndry
95+ self .ny = self . ny - ybndry
9696
9797 # used to calculate y-coordinate of upper side (self.yupper)
98- yupper_ind -= ybndry
98+ yupper_ind = yupper_ind - ybndry
9999
100100 # calculate start and end coordinates
101101 #####################################
@@ -145,9 +145,6 @@ def __repr__(self):
145145 result += f"\t { attr } \t { val } \n "
146146 return result
147147
148- def __eq__ (self , other ):
149- return vars (self ) == vars (other )
150-
151148 def get_slices (self , mxg = 0 , myg = 0 ):
152149 """
153150 Return x- and y-dimension slices that select this region from the global
@@ -159,19 +156,19 @@ def get_slices(self, mxg=0, myg=0):
159156 """
160157 xi = self .xinner_ind
161158 if self .connection_inner_x is not None and xi is not None :
162- xi -= mxg
159+ xi = xi - mxg
163160
164161 xo = self .xouter_ind
165162 if self .connection_outer_x is not None and xo is not None :
166- xi += mxg
163+ xo = xo + mxg
167164
168165 yl = self .ylower_ind
169166 if self .connection_lower_y is not None and yl is not None :
170- yl -= myg
167+ yl = yl - myg
171168
172169 yu = self .yupper_ind
173170 if self .connection_upper_y is not None and yu is not None :
174- yu += myg
171+ yu = yu + myg
175172
176173 return {self .xcoord : slice (xi , xo ), self .ycoord : slice (yl , yu )}
177174
@@ -189,10 +186,10 @@ def get_inner_guards_slices(self, *, mxg, myg=0):
189186 """
190187 ylower = self .ylower_ind
191188 if self .connection_lower_y is not None :
192- ylower -= myg
189+ ylower = ylower - myg
193190 yupper = self .yupper_ind
194191 if self .connection_upper_y is not None :
195- yupper += myg
192+ yupper = yupper + myg
196193 return {
197194 self .xcoord : slice (self .xinner_ind - mxg , self .xinner_ind ),
198195 self .ycoord : slice (ylower , yupper ),
@@ -212,10 +209,10 @@ def get_outer_guards_slices(self, *, mxg, myg=0):
212209 """
213210 ylower = self .ylower_ind
214211 if self .connection_lower_y is not None :
215- ylower -= myg
212+ ylower = ylower - myg
216213 yupper = self .yupper_ind
217214 if self .connection_upper_y is not None :
218- yupper += myg
215+ yupper = yupper + myg
219216 return {
220217 self .xcoord : slice (self .xouter_ind , self .xouter_ind + mxg ),
221218 self .ycoord : slice (ylower , yupper ),
@@ -235,10 +232,10 @@ def get_lower_guards_slices(self, *, myg, mxg=0):
235232 """
236233 xinner = self .xinner_ind
237234 if self .connection_inner_x is not None :
238- xinner -= mxg
235+ xinner = xinner - mxg
239236 xouter = self .xouter_ind
240237 if self .connection_outer_x is not None :
241- xouter += mxg
238+ xouter = xouter + mxg
242239
243240 ystart = self .ylower_ind - myg
244241 ystop = self .ylower_ind
@@ -270,10 +267,10 @@ def get_upper_guards_slices(self, *, myg, mxg=0):
270267 """
271268 xinner = self .xinner_ind
272269 if self .connection_inner_x is not None :
273- xinner -= mxg
270+ xinner = xinner - mxg
274271 xouter = self .xouter_ind
275272 if self .connection_outer_x is not None :
276- xouter += mxg
273+ xouter = xouter + mxg
277274
278275 # wrap around to the beginning of the grid if necessary
279276 ystart = self .yupper_ind
@@ -1189,15 +1186,15 @@ def _create_regions_toroidal(ds):
11891186 # Adjust for boundary cells
11901187 # keep_xboundaries is 1 if there are x-boundaries and 0 if there are not
11911188 if not ds .metadata ["keep_xboundaries" ]:
1192- ixs1 -= mxg
1193- ixs2 -= mxg
1194- nx -= 2 * mxg
1195- jys11 += ybndry
1196- jys21 += ybndry
1197- ny_inner += ybndry + ybndry_upper
1198- jys12 += ybndry + 2 * ybndry_upper
1199- jys22 += ybndry + 2 * ybndry_upper
1200- ny += 2 * ybndry + 2 * ybndry_upper
1189+ ixs1 = ixs1 - mxg
1190+ ixs2 = ixs2 - mxg
1191+ nx = nx - 2 * mxg
1192+ jys11 = jys11 + ybndry
1193+ jys21 = jys21 + ybndry
1194+ ny_inner = ny_inner + ybndry + ybndry_upper
1195+ jys12 = jys12 + ybndry + 2 * ybndry_upper
1196+ jys22 = jys22 + ybndry + 2 * ybndry_upper
1197+ ny = ny + 2 * ybndry + 2 * ybndry_upper
12011198
12021199 # Note, include guard cells in the created regions, fill them later
12031200 if topology in topologies :
@@ -1220,6 +1217,7 @@ def _create_regions_toroidal(ds):
12201217 _check_connections (regions )
12211218
12221219 ds = _set_attrs_on_all_vars (ds , "regions" , regions )
1220+ ds .metadata ["topology" ] = topology
12231221
12241222 return ds
12251223
@@ -1228,11 +1226,6 @@ def _create_single_region(ds, periodic_y=True):
12281226 nx = ds .metadata ["nx" ]
12291227 ny = ds .metadata ["ny" ]
12301228
1231- mxg = ds .metadata ["MXG" ]
1232- myg = ds .metadata ["MYG" ]
1233- # keep_yboundaries is 1 if there are y-boundaries and 0 if there are not
1234- ybndry = ds .metadata ["keep_yboundaries" ] * myg
1235-
12361229 connection = "all" if periodic_y else None
12371230
12381231 regions = {
0 commit comments