@@ -97,8 +97,28 @@ def plot_matplotlib(self,lon_min,lon_max,lat_min,lat_max):
9797 # cropping coastline to area of interest
9898 rec = land .cx [lon_min :lon_max , lat_min :lat_max ]
9999
100- # selecting simulation domain
101- curr = curr .sel (lon = slice (lon_min , lon_max ), lat = slice (lat_min , lat_max ))
100+ # Get the full coordinate arrays from the dataset
101+ lon_arr = curr .lon .values
102+ lat_arr = curr .lat .values
103+
104+ # Find indices for the outward slice
105+ # For the lower bound - the grid value that is <= the lon_min or lat_min.
106+ i_min = np .searchsorted (lon_arr , lon_min , side = "right" ) - 1
107+ j_min = np .searchsorted (lat_arr , lat_min , side = "right" ) - 1
108+
109+ # For the upper bound - the grid value that is >= the lon_max or lat_max.
110+ i_max = np .searchsorted (lon_arr , lon_max , side = "left" )
111+ j_max = np .searchsorted (lat_arr , lat_max , side = "left" )
112+
113+ # Make sure indices are within bounds
114+ i_min = max (i_min , 0 )
115+ j_min = max (j_min , 0 )
116+ i_max = min (i_max , len (lon_arr ) - 1 )
117+ j_max = min (j_max , len (lat_arr ) - 1 )
118+
119+ ### Subset the current data to the plot boundaries ###
120+ # Slice the dataset using these indices
121+ curr = curr .isel (lon = slice (i_min , i_max + 1 ), lat = slice (j_min , j_max + 1 ))
102122
103123 min_concentration = 0.0
104124 max_concentration = (ds_particles .concentration * 1000 ).max ().values
@@ -782,9 +802,9 @@ def __init__(self, x, y):
782802 self .width = x [- 1 ] - x [0 ]
783803 self .height = y [- 1 ] - y [0 ]
784804
785- if not np .allclose (np .diff (x ), self .width / (self .nx - 1 ), atol = 1e-5 ):
805+ if not np .allclose (np .diff (x ), self .width / (self .nx - 1 ), atol = 1e-4 ):
786806 raise ValueError ("'x' values must be equally spaced" )
787- if not np .allclose (np .diff (y ), self .height / (self .ny - 1 ), atol = 1e-5 ):
807+ if not np .allclose (np .diff (y ), self .height / (self .ny - 1 ), atol = 1e-4 ):
788808 raise ValueError ("'y' values must be equally spaced" )
789809
790810 @property
0 commit comments