Skip to content

Commit

Permalink
atmos_scalar data now works- case8! this case works with only time co…
Browse files Browse the repository at this point in the history
…ordinate-depdendent data!
  • Loading branch information
ilaflott committed Nov 15, 2024
1 parent 5fb52ce commit 30adf0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 45 deletions.
17 changes: 7 additions & 10 deletions fre/cmor/cmor_mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,
var_dim = len(var.shape)
print(f"(rewrite_netcdf_file_var) var_dim = {var_dim}, local_var = {local_var}")

# Check var_dim
if var_dim not in [3, 4]:
raise ValueError(f"var_dim == {var_dim} != 3 nor 4. stop.")
## Check var_dim
#if var_dim not in [3, 4]:
# raise ValueError(f"var_dim == {var_dim} != 3 nor 4. stop.")

# determine the vertical dimension by looping over netcdf variables
vert_dim = get_vertical_dimension(ds, target_var) # returns int( 0 ) if not present
Expand All @@ -265,8 +265,6 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,
# Check var_dim and vert_dim and assign lev if relevant.
# error if vert_dim wrong given var_dim
lev = None
#if var_dim == 4:
# if vert_dim not in [ "plev30", "plev19", "plev8",
if vert_dim != 0:
if vert_dim not in [ "plev39", "plev30", "plev19", "plev8",
"height2m", "level", "lev", "levhalf"] :
Expand Down Expand Up @@ -297,21 +295,19 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,


# setup cmor latitude axis if relevant
#cmor_lat = cmor.axis("latitude", coord_vals = lat, cell_bounds = lat_bnds, units = "degrees_N")
#cmor_lon = cmor.axis("longitude", coord_vals = lon, cell_bounds = lon_bnds, units = "degrees_E")
print(f'(rewrite_netcdf_file_var) assigning cmor_lat')
cmor_lat = None
if any( [ lat is None, lat_bnds is None ] ):
print(f'(rewrite_netcdf_file_var) WARNING: lat or lat_bnds is None, skipping assigning cmor_lat')
else:
print(f'(rewrite_netcdf_file_var) assigning cmor_lat')
cmor_lat = cmor.axis("latitude", coord_vals = lat, cell_bounds = lat_bnds, units = "degrees_N")

# setup cmor longitude axis if relevant
print(f'(rewrite_netcdf_file_var) assigning cmor_lon')
cmor_lon = None
if any( [ lon is None, lon_bnds is None ] ):
print(f'(rewrite_netcdf_file_var) WARNING: lon or lon_bnds is None, skipping assigning cmor_lon')
else:
print(f'(rewrite_netcdf_file_var) assigning cmor_lon')
cmor_lon = cmor.axis("longitude", coord_vals = lon, cell_bounds = lon_bnds, units = "degrees_E")

# setup cmor time axis if relevant
Expand All @@ -320,15 +316,16 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,
print( f"(rewrite_netcdf_file_var) Executing cmor.axis('time', \n"
f" coord_vals = \n{time_coords}, \n"
f" cell_bounds = time_bnds, units = {time_coord_units}) ")
print(f'(rewrite_netcdf_file_var) assigning cmor_time using time_bnds...')
cmor_time = cmor.axis("time", coord_vals = time_coords,
cell_bounds = time_bnds, units = time_coord_units)
except ValueError as exc:
print(f"(rewrite_netcdf_file_var) WARNING exception raised... exc={exc}\n"
" cmor_time = cmor.axis('time', \n"
" coord_vals = time_coords, units = time_coord_units)")
print(f'(rewrite_netcdf_file_var) assigning cmor_time WITHOUT time_bnds...')
cmor_time = cmor.axis("time", coord_vals = time_coords, units = time_coord_units)



# other vertical-axis-relevant initializations
save_ps = False
Expand Down
66 changes: 31 additions & 35 deletions run_test_file_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,23 @@ def run_cmor_RUN(filename, table, opt_var_name):
return FOO_return


# 8) FAIL (no latitude nor longitude coordinates cases)
# atmos, Amon / ch4global
# Result - error,
# File "src/netCDF4/_netCDF4.pyx", line 2519, in netCDF4._netCDF4.Dataset.__getitem__ IndexError:
# lat not found in /
testfile_atmos_scalar_gn_Amon_nolon_nolat = \
'/arch0/cm6/ESM4/DECK/ESM4_historical_D1/gfdl.ncrc4-intel16-prod-openmp/' + \
'pp/atmos_scalar/ts/monthly/5yr/' + \
'atmos_scalar.197001-197412.ch4global.nc'
try:
some_return = run_cmor_RUN(testfile_atmos_scalar_gn_Amon_nolon_nolat, 'Amon', opt_var_name = 'ch4global')
except Exception as exc:
print(f'exception caught: exc=\n{exc}')
some_return=-1
pass
print_the_outcome(some_return,'atmos_scalar_gn_Amon_nolon_nolat / ch4global')


sys.exit()
## 9) FAIL (4 dimensional data with no vertical)
## Result - error,
## File "/home/Ian.Laflotte/Working/fre-cli/fre/cmor/cmor_mixer.py",
## line 134, in get_vertical_dimension if not (ds[dim].axis and ds[dim].axis == "Z"):
## AttributeError: NetCDF: Attribute not found
#testfile_LUmip_refined_gr1_Emon_landusedim = \
# '/arch0/cm6/ESM4/DECK/ESM4_historical_D1/gfdl.ncrc4-intel16-prod-openmp/' + \
# 'pp/LUmip_refined/ts/monthly/5yr/' + \
# 'LUmip_refined.185001-185412.gppLut.nc'
#try:
# some_return = run_cmor_RUN(testfile_LUmip_refined_gr1_Emon_landusedim, 'Emon', opt_var_name = 'gppLut')
#except Exception as exc:
# print(f'exception caught: exc=\n{exc}')
# some_return=-1
# pass
#print_the_outcome(some_return,'LUmip_refined_gr1_Emon_langusedim / gppLut')
#sys.exit()


# 1) SUCCEEDs
Expand Down Expand Up @@ -197,22 +195,20 @@ def run_cmor_RUN(filename, table, opt_var_name):
#print_the_outcome(some_return,'ocean_monthly_z_1x1deg_gr / so')


## 9) FAIL (4 dimensional data with no vertical)
## Result - error,
## File "/home/Ian.Laflotte/Working/fre-cli/fre/cmor/cmor_mixer.py",
## line 134, in get_vertical_dimension if not (ds[dim].axis and ds[dim].axis == "Z"):
## AttributeError: NetCDF: Attribute not found
#testfile_LUmip_refined_gr1_Emon_landusedim = \
# '/arch0/cm6/ESM4/DECK/ESM4_historical_D1/gfdl.ncrc4-intel16-prod-openmp/' + \
# 'pp/LUmip_refined/ts/monthly/5yr/' + \
# 'LUmip_refined.185001-185412.gppLut.nc'
#try:
# some_return = run_cmor_RUN(testfile_LUmip_refined_gr1_Emon_landusedim, 'Emon', opt_var_name = 'gppLut')
#except Exception as exc:
# print(f'exception caught: exc=\n{exc}')
# some_return=-1
# pass
#print_the_outcome(some_return,'LUmip_refined_gr1_Emon_langusedim / gppLut')
# 8) SUCCEEDs (no latitude, nor longitude, nor vertical coordinates cases)
# atmos, Amon / ch4global
testfile_atmos_scalar_gn_Amon_nolon_nolat = \
'/arch0/cm6/ESM4/DECK/ESM4_historical_D1/gfdl.ncrc4-intel16-prod-openmp/' + \
'pp/atmos_scalar/ts/monthly/5yr/' + \
'atmos_scalar.197001-197412.ch4global.nc'
try:
some_return = run_cmor_RUN(testfile_atmos_scalar_gn_Amon_nolon_nolat, 'Amon', opt_var_name = 'ch4global')
except Exception as exc:
print(f'exception caught: exc=\n{exc}')
some_return=-1
pass
print_the_outcome(some_return,'atmos_scalar_gn_Amon_nolon_nolat / ch4global')




Expand Down

0 comments on commit 30adf0f

Please sign in to comment.