Skip to content

Commit

Permalink
fix test and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oloapinivad committed Mar 15, 2023
1 parent c253289 commit f7a2581
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 162 deletions.
147 changes: 10 additions & 137 deletions ecmean/libs/support.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
'''
Shared functions for XArray ECmean4
Shared functions for Support class for ECmean4
'''

import logging
Expand All @@ -13,10 +13,6 @@
from ecmean.libs.areas import area_cell
from ecmean.libs.units import UnitsHandler

###########################
# INTERPOLATION FUNCTIONS #
###########################


class Supporter():

Expand Down Expand Up @@ -176,10 +172,13 @@ def load_field(self, areafile, comp):
"""Loading files for area and interpolation"""

# loading and examining atmospheric file
logging.info(f'{comp}mareafile is ' + areafile)
if not areafile:
sys.exit(f'ERROR: {comp}reafile cannot be found')
return xr.open_mfdataset(areafile, preprocess=xr_preproc).load()
if areafile:
logging.info(f'{comp}mareafile is ' + areafile)
if not areafile:
sys.exit(f'ERROR: {comp}reafile cannot be found')
return xr.open_mfdataset(areafile, preprocess=xr_preproc).load()
else:
sys.exit('ERROR: Cannot find any file to load! Does your experiment exit?')

def make_areas(self, gridtype, xfield):
"""Create weights for area operations.
Expand All @@ -190,7 +189,7 @@ def make_areas(self, gridtype, xfield):
area = xfield['areacello']
elif 'cell_area' in xfield.data_vars: # as ECE4 NEMO case for nemo-initial-state.nc
area = xfield['cell_area']
elif 'e1t' in xfield.data_vars: # ECE4 NEMO case for domaing_cfg.nc, deprecated
elif 'e1t' in xfield.data_vars: # ECE4 NEMO case for domaing_cfg.nc
area = xfield['e1t'] * xfield['e2t']
else: # automatic solution, wish you luck!
area = area_cell(xfield, gridtype)
Expand Down Expand Up @@ -316,130 +315,4 @@ def identify_grid(xfield):
else:
sys.exit("Cannot find any lon/lat dimension, aborting...")

return gridtype

# def remap_dictionary(component, atmdict, ocedict, target_grid):
# """Create a dicitionary with atmospheric and oceanic weights for
# interpolation. There is an option of fix grid before the real
# interpolation: this is used for Gaussian reduced grids"""

# atmareafile = inifiles_priority(atmdict)
# atmfix, atmremap = _make_atm_interp_weights(
# component['atm'], atmareafile, target_grid)

# # get oceanic areas, assuming AMIP if no oceanic area is found
# oceareafile = inifiles_priority(ocedict)
# if oceareafile:
# ocefix, oceremap = _make_oce_interp_weights(
# component['oce'], oceareafile, target_grid)
# else:
# logging.warning("Ocereafile cannot be found, assuming this is an AMIP run")
# ocefix = None
# oceremap = None

# remap = {
# 'atm_fix': atmfix,
# 'atm_remap': atmremap,
# 'oce_fix': ocefix,
# 'oce_remap': oceremap,
# }

# return remap


# def _make_atm_interp_weights(component, atmareafile, target_grid):
# """Create atmospheric interpolator"""

# logging.debug('Atmareafile is ' + atmareafile)
# if not atmareafile:
# sys.exit("ERROR: Atmareafile cannot be found")

# xfield = xr.open_mfdataset(atmareafile, preprocess=xr_preproc).load()
# gridtype = identify_grid(xfield)
# logging.warning(f'Atmosphere grid is is a {gridtype} grid!')

# if component == 'oifs':

# # this is to get lon and lat from the Equator
# xname = list(xfield.data_vars)[-1]
# m = xfield[xname].isel(time=0).load()
# # g = sorted(list(set(m.lat.data)))
# # f = sorted(list(m.sel(cell=m.lat == g[int(len(g) / 2)]).lon.data))
# # use numpy since it is faster
# g = np.unique(m.lat.data)
# f = np.unique(m.sel(cell=m.lat == g[int(len(g) / 2)]).lon.data)

# # this creates a a gaussian non reduced grid
# ds_out = xr.Dataset({"lon": (["lon"], f), "lat": (["lat"], g)})

# # use nearest neighbour to remap to gaussian regular
# fix = xe.Regridder(
# xfield[xname],
# ds_out,
# method="nearest_s2d",
# locstream_in=True,
# periodic=True)

# # create bilinear interpolator
# interp = xe.Regridder(
# fix(xfield[xname]), target_grid, periodic=True, method="bilinear")

# elif component in ['cmoratm', 'globo']:

# fix = None
# interp = xe.Regridder(
# xfield,
# target_grid,
# periodic=True,
# method="bilinear")

# else:
# sys.exit(
# "ERROR: Atm weights not defined for this component, this cannot be handled!")

# return fix, interp


# def _make_oce_interp_weights(component, oceareafile, target_grid):
# """Create oceanic interpolator weights"""

# logging.debug('Oceareafile is ' + oceareafile)
# if not oceareafile:
# sys.exit("ERROR: Oceareafile cannot be found")

# xfield = xr.open_mfdataset(oceareafile, preprocess=xr_preproc).load()
# gridtype = identify_grid(xfield)
# logging.warning(f'Ocean grid is is a {gridtype} grid!')

# if component in ['nemo', 'cmoroce']:
# if 'areacello' in xfield.data_vars: # CMOR case
# xname = 'areacello'
# elif 'cell_area' in xfield.data_vars: # ECE4 NEMO case for nemo-initial-state.nc
# xname = 'cell_area'
# else:
# xname = list(xfield.data_vars)[-1]
# else:
# sys.exit(
# "ERROR: Oce weights not defined for this component, this cannot be handled!")

# if gridtype in ['unstructured']:
# # print("Detecting a unstructured grid, using nearest neighbour!")
# fix = None
# interp = xe.Regridder(
# xfield[xname],
# target_grid,
# method="nearest_s2d",
# locstream_in=True,
# periodic=True)

# else:
# # print("Detecting regular or curvilinear grid, using bilinear!")
# fix = None
# interp = xe.Regridder(
# xfield[xname],
# target_grid,
# method="bilinear",
# periodic=True,
# ignore_degenerate=True)

# return fix, interp
return gridtype
22 changes: 0 additions & 22 deletions ecmean/libs/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,6 @@ def units_converter(self):
return offset, factor


# def units_wrapper(var, varunit, clim, face):
# """
# Wrapper function for units computation: provides check for integral quantities,
# estimate offset and factor of conversion and check the fluxes direction
# """

# logging.info(var)
# logging.info(varunit + ' ---> ' + clim[var]['units'])

# # adjust integrated quantities
# new_units = _units_are_integrals(varunit, clim[var])

# # unit conversion based on metpy
# offset, factor = units_converter(new_units, clim[var]['units'])

# # sign adjustment (for heat fluxes)
# factor = factor * \
# directions_match(face['variables'][var], clim[var])
# logging.debug('Offset %f, Factor %f', offset, factor)

# return offset, factor


def units_extra_definition():
"""Add units to the pint registry required by ECMean4"""
Expand Down
6 changes: 3 additions & 3 deletions tests/table/global_mean_cpld_1990_1990.ref
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
| toamsfc | TOA - Sfc Net Radiation | W/m2 | 0.301943 | 0 | None | - |
| tos | Sea Surface Temperature | celsius | 18.9061 | 18.754±0.15 | ESA-CCI-L4 | 1991-2020 |
| sos | Sea Surface Salinity | PSU | 34.4368 | 34.814±0.014 | ESA-CCI | 2010-2020 |
| zos | SSH | m | 0.00120879 | 0 | None | - |
| wfo | Net Water Flux into ocean | m/century | -1.40864 | 0 | None | - |
| zos | SSH | m | 0.00120878 | 0 | None | - |
| wfo | Net Water Flux into ocean | m/century | -1.40863 | 0 | None | - |
| siconc_north | Sea Ice Area (Northern Hemisphere) | Mm^2 | 10.6708 | 9.562 | ESA-CCI-L4 | - |
| siconc_south | Sea Ice Area (Southern Hemisphere) | Mm^2 | 3.11233 | 9.66 | ESA-CCI-L4 | - |
| siconc_south | Sea Ice Area (Southern Hemisphere) | Mm^2 | 3.11234 | 9.66 | ESA-CCI-L4 | - |

0 comments on commit f7a2581

Please sign in to comment.