@@ -197,6 +197,129 @@ def create_mock_ocean_dataset(
197197 return ds
198198
199199
200+ def create_mock_2d_ocean_dataset (
201+ nt = 12 , ny = 300 , nx = 360 , variables = ["surface_temp" ], start_date = "2000-01-01" , freq = "M"
202+ ):
203+ """
204+ Create a mock xarray Dataset mimicking ACCESS-ESM ocean surface temperature output.
205+
206+ Returns a dataset with 12 monthly time steps, matching the structure from ncdump.
207+ """
208+ # Dimensions
209+ nt , ny , nx = 12 , 300 , 360
210+
211+ # Coordinates
212+ xt_ocean = np .linspace (0.5 , 359.5 , nx )
213+ yt_ocean = np .linspace (- 89.5 , 89.5 , ny )
214+ nv = np .array ([1.0 , 2.0 ])
215+
216+ # Time: 12 months starting from year 1444
217+ days_per_month = [31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]
218+ base_days = (1444 - 1 ) * 365
219+
220+ # time = []
221+ time_bnds = np .zeros ((12 , 2 ))
222+ cumulative = base_days
223+
224+ for i in range (12 ):
225+ time_bnds [i , 0 ] = cumulative
226+ time_bnds [i , 1 ] = cumulative + days_per_month [i ]
227+ cumulative += days_per_month [i ]
228+
229+ time = pd .date_range (start = start_date , periods = nt , freq = freq )
230+ average_T1 = time_bnds [:, 0 ]
231+ average_T2 = time_bnds [:, 1 ]
232+ average_DT = average_T2 - average_T1
233+
234+ # Surface temperature data (K)
235+ np .random .seed (42 )
236+ data_var = np .random .uniform (273.0 , 303.0 , (nt , ny , nx )).astype (np .float32 )
237+
238+ # Create dataset
239+ ds = xr .Dataset (
240+ data_vars = {
241+ variables [0 ]: (
242+ ["time" , "yt_ocean" , "xt_ocean" ],
243+ data_var ,
244+ {
245+ "long_name" : "Conservative temperature" ,
246+ "units" : "K" ,
247+ "valid_range" : np .array ([- 10.0 , 500.0 ], dtype = np .float32 ),
248+ "missing_value" : np .float32 (- 1e20 ),
249+ "_FillValue" : np .float32 (- 1e20 ),
250+ "cell_methods" : "time: mean" ,
251+ "standard_name" : "sea_surface_conservative_temperature" ,
252+ },
253+ ),
254+ "average_T1" : (
255+ ["time" ],
256+ average_T1 ,
257+ {
258+ "long_name" : "Start time for average period" ,
259+ "units" : "days since 0001-01-01 00:00:00" ,
260+ },
261+ ),
262+ "average_T2" : (
263+ ["time" ],
264+ average_T2 ,
265+ {
266+ "long_name" : "End time for average period" ,
267+ "units" : "days since 0001-01-01 00:00:00" ,
268+ },
269+ ),
270+ "average_DT" : (
271+ ["time" ],
272+ average_DT ,
273+ {"long_name" : "Length of average period" , "units" : "days" },
274+ ),
275+ "time_bnds" : (
276+ ["time" , "nv" ],
277+ time_bnds ,
278+ {"long_name" : "time axis boundaries" , "units" : "days" },
279+ ),
280+ },
281+ coords = {
282+ "xt_ocean" : (
283+ "xt_ocean" ,
284+ xt_ocean ,
285+ {
286+ "long_name" : "tcell longitude" ,
287+ "units" : "degrees_E" ,
288+ "cartesian_axis" : "X" ,
289+ },
290+ ),
291+ "yt_ocean" : (
292+ "yt_ocean" ,
293+ yt_ocean ,
294+ {
295+ "long_name" : "tcell latitude" ,
296+ "units" : "degrees_N" ,
297+ "cartesian_axis" : "Y" ,
298+ },
299+ ),
300+ "time" : (
301+ "time" ,
302+ time ,
303+ {
304+ "long_name" : "time" ,
305+ "units" : "days since 0001-01-01 00:00:00" ,
306+ "calendar" : "PROLEPTIC_GREGORIAN" ,
307+ "bounds" : "time_bnds" ,
308+ },
309+ ),
310+ "nv" : ("nv" , nv , {"long_name" : "vertex number" }),
311+ },
312+ attrs = {
313+ "filename" : "ocean-2d-surface_temp-1monthly-mean-ym_2000_01.nc" ,
314+ "title" : "ACCESS-ESM_CMIP6" ,
315+ "grid_type" : "mosaic" ,
316+ "grid_tile" : "1" ,
317+ },
318+ )
319+
320+ return ds
321+
322+
200323def create_chunked_dataset (chunks = None , ** kwargs ):
201324 """Create a chunked dataset for testing dask operations."""
202325 if chunks is None :
0 commit comments