Skip to content

Commit 6754419

Browse files
committed
update Om3
1 parent 4545bf5 commit 6754419

2 files changed

Lines changed: 190 additions & 40 deletions

File tree

src/access_mopper/configurations.py

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def cmorise_ocean(self, file_paths, compound_name, cmor_dataset_json, mip_table)
263263
# Write data to CMOR
264264
data = np.moveaxis(data, 0, -1)
265265
cmor.write(cmorVar, data, ntimes_passed=len(time_numeric))
266+
266267

267268
# Finalize and save the file
268269
filename = cmor.close(cmorVar, file_name=True)
@@ -330,7 +331,7 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
330331
# Not all variable have a time component (e.g. fx, Ofx)
331332
time_axis = axes.pop("time", None)
332333
if time_axis:
333-
time_axis = axes.pop("time")
334+
# time_axis = axes.pop("time")
334335
time_numeric = ds[time_axis].values
335336
time_units = ds[time_axis].attrs["units"]
336337
time_bnds = ds[ds[time_axis].attrs["bounds"]].values
@@ -344,8 +345,13 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
344345
inpath=ipth,
345346
set_verbosity=cmor.CMOR_NORMAL,
346347
netcdf_file_action=cmor.CMOR_REPLACE,
348+
logfile="cmor_debug.log"
347349
)
348350

351+
out_dir = "/g/data/tm70/yz9299/MOPPeR_outputs"
352+
os.makedirs(out_dir, exist_ok=True)
353+
# cmor.set_cur_dataset_attribute("outpath", out_dir)
354+
349355
cmor.dataset_json(cmor_dataset_json)
350356
current_dir = os.path.dirname(os.path.abspath(__file__))
351357
grid_table_id = cmor.load_table(
@@ -369,7 +375,7 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
369375
latitude_vertices=lat_bnds,
370376
longitude_vertices=lon_bnds,
371377
)
372-
cmor_axes.append(grid_id)
378+
# cmor_axes.append(grid_id)
373379

374380
# Now, load the Omon table to set up the time axis and variable
375381
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -381,31 +387,48 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
381387
cmorTime = cmor.axis(
382388
"time", coord_vals=time_numeric, cell_bounds=time_bnds, units=time_units
383389
)
384-
cmor_axes.append(cmorTime)
390+
# cmor_axes.append(cmorTime)
385391

386-
if axes:
387-
for axis, dim in axes.items():
388-
coord_vals = var[dim].values
389-
try:
390-
cell_bounds = var[var[dim].attrs["bounds"]].values
391-
except KeyError:
392-
cell_bounds = None
393-
axis_units = var[dim].attrs["units"]
394-
cmor_axis = cmor.axis(
395-
axis,
396-
coord_vals=coord_vals,
397-
cell_bounds=cell_bounds,
398-
units=axis_units,
399-
)
400-
cmor_axes.append(cmor_axis)
392+
# Append coordinates and transpose data axes
393+
if data.ndim == 3:
394+
cmor_axes.append(grid_id)
395+
cmor_axes.append(cmorTime)
396+
data = np.transpose(data, (1, 2, 0))
397+
398+
elif data.ndim == 4:
399+
cmor_axes.append(grid_id)
400+
if axes:
401+
for axis, dim in axes.items():
402+
coord_vals = var[dim].values
403+
try:
404+
cell_bounds = var[var[dim].attrs["bounds"]].values
405+
except KeyError:
406+
cell_bounds = None
407+
print(axis, dim)
408+
if axis == "depth_coord":
409+
depth = coord_vals
410+
bounds = np.zeros((len(depth), 2))
411+
bounds[1:, 0] = 0.5 * (depth[1:] + depth[:-1])
412+
bounds[:-1, 1] = 0.5 * (depth[1:] + depth[:-1])
413+
bounds[0, 0] = max(0.0, depth[0] - (depth[1] - depth[0]) / 2)
414+
bounds[-1, 1] = depth[-1] + (depth[-1] - depth[-2]) / 2
415+
cell_bounds = bounds
416+
axis_units = "m"
417+
cmor_axis = cmor.axis(
418+
axis,
419+
coord_vals=coord_vals,
420+
cell_bounds=cell_bounds,
421+
units=axis_units,
422+
)
423+
cmor_axes.append(cmor_axis)
424+
cmor_axes.append(cmorTime)
425+
data = np.transpose(data,(2, 3, 1, 0))
401426

402427
# Define CMOR variable
403428
cmorVar = cmor.variable(cmor_name, variable_units, cmor_axes, positive=positive)
404429

405430
# Write data to CMOR
406-
data = np.moveaxis(data, 0, -1)
407-
ntimes_passed = len(time_numeric) if time_axis else 0
408-
cmor.write(cmorVar, data, ntimes_passed=ntimes_passed)
431+
cmor.write(cmorVar, data, ntimes_passed=len(time_numeric))
409432

410433
# Finalize and save the file
411434
filename = cmor.close(cmorVar, file_name=True)

src/access_mopper/mappings/Mappings_OM3_Omon.json

Lines changed: 146 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"dimensions": {
123123
"time": "time",
124124
"yh": "latitude",
125-
"xh": "longitude"
125+
"xq": "longitude"
126126
},
127127
"units": "N m-2",
128128
"positive": "down",
@@ -203,23 +203,6 @@
203203
}
204204
},
205205

206-
"hfsifrazil": {
207-
"dimensions": {
208-
"time": "time",
209-
"yh": "latitude",
210-
"xh": "longitude"
211-
},
212-
"units": "W m-2",
213-
"positive": null,
214-
"model_variables": [
215-
"hfsifrazil"
216-
],
217-
"calculation": {
218-
"type": "direct",
219-
"formula": "hfsifrazil"
220-
}
221-
},
222-
223206
"evs": {
224207
"dimensions": {
225208
"time": "time",
@@ -325,7 +308,7 @@
325308
"tauvo": {
326309
"dimensions": {
327310
"time": "time",
328-
"yh": "latitude",
311+
"yq": "latitude",
329312
"xh": "longitude"
330313
},
331314
"units": "N m-2",
@@ -354,6 +337,150 @@
354337
"type": "direct",
355338
"formula": "sfdsi"
356339
}
340+
},
341+
342+
"vo": {
343+
"dimensions": {
344+
"time": "time",
345+
"zl": "depth_coord",
346+
"yq": "latitude",
347+
"xh": "longitude"
348+
},
349+
"units": "m s-1",
350+
"positive": null,
351+
"model_variables": [
352+
"vo"
353+
],
354+
"calculation": {
355+
"type": "direct",
356+
"formula": "vo"
357+
}
358+
},
359+
360+
"uo": {
361+
"dimensions": {
362+
"time": "time",
363+
"zl": "depth_coord",
364+
"yh": "latitude",
365+
"xq": "longitude"
366+
},
367+
"units": "m s-1",
368+
"positive": null,
369+
"model_variables": [
370+
"uo"
371+
],
372+
"calculation": {
373+
"type": "direct",
374+
"formula": "uo"
375+
}
376+
},
377+
378+
"vmo": {
379+
"dimensions": {
380+
"time": "time",
381+
"zl": "depth_coord",
382+
"yq": "latitude",
383+
"xh": "longitude"
384+
},
385+
"units": "kg s-1",
386+
"positive": null,
387+
"model_variables": [
388+
"vmo"
389+
],
390+
"calculation": {
391+
"type": "direct",
392+
"formula": "vmo"
393+
}
394+
},
395+
396+
"umo": {
397+
"dimensions": {
398+
"time": "time",
399+
"zl": "depth_coord",
400+
"yh": "latitude",
401+
"xq": "longitude"
402+
},
403+
"units": "kg s-1",
404+
"positive": null,
405+
"model_variables": [
406+
"umo"
407+
],
408+
"calculation": {
409+
"type": "direct",
410+
"formula": "umo"
411+
}
412+
},
413+
414+
"thkcello": {
415+
"dimensions": {
416+
"time": "time",
417+
"zl": "depth_coord",
418+
"yh": "latitude",
419+
"xh": "longitude"
420+
},
421+
"units": "m",
422+
"positive": null,
423+
"model_variables": [
424+
"thkcello"
425+
],
426+
"calculation": {
427+
"type": "direct",
428+
"formula": "thkcello"
429+
}
430+
},
431+
432+
"agessc": {
433+
"dimensions": {
434+
"time": "time",
435+
"zl": "depth_coord",
436+
"yh": "latitude",
437+
"xh": "longitude"
438+
},
439+
"units": "yr",
440+
"positive": null,
441+
"model_variables": [
442+
"agessc"
443+
],
444+
"calculation": {
445+
"type": "direct",
446+
"formula": "agessc"
447+
}
448+
},
449+
450+
"thetao": {
451+
"dimensions": {
452+
"time": "time",
453+
"zl": "depth_coord",
454+
"yh": "latitude",
455+
"xh": "longitude"
456+
},
457+
"units": "degC",
458+
"positive": null,
459+
"model_variables": [
460+
"thetao"
461+
],
462+
"calculation": {
463+
"type": "direct",
464+
"formula": "thetao"
465+
}
466+
},
467+
468+
"so": {
469+
"dimensions": {
470+
"time": "time",
471+
"zl": "depth_coord",
472+
"yh": "latitude",
473+
"xh": "longitude"
474+
},
475+
"units": "0.001",
476+
"positive": null,
477+
"model_variables": [
478+
"so"
479+
],
480+
"calculation": {
481+
"type": "direct",
482+
"formula": "so"
483+
}
357484
}
358485

359486
}

0 commit comments

Comments
 (0)