Skip to content

Commit

Permalink
Some updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
rigoudyg committed May 30, 2022
1 parent 83fc0c1 commit fa9b574
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 335 deletions.
10 changes: 5 additions & 5 deletions dr2xml/Xwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,12 @@ def is_singleton(sdim):
:param sdim: dimensions characteristics
:return: boolean indicating whether sdim corresponds to a singleton or not
"""
if sdim.axis == '':
if sdim.axis in ['', ]:
# Case of non-spatial dims. Singleton only have a 'value' (except Scatratio has a lot (in DR01.00.21))
return sdim.value != '' and len(sdim.value.strip().split(" ")) == 1
return sdim.value not in ['', ] and " " not in sdim.value.strip()
else:
# Case of space dimension singletons. Should a 'value' and no 'requested'
return ((sdim.value != '') and (sdim.requested.strip() == '')) \
or (sdim.label == "typewetla") # The latter is a bug in DR01.00.21 : typewetla has no value there
return sdim.value not in ['', ] and sdim.requested.strip() in ['', ]


def write_xios_file_def(filename, svars_per_table, year, dummies, skipped_vars_per_table, actually_written_vars,
Expand Down Expand Up @@ -562,6 +561,7 @@ def write_xios_file_def_for_svars_list(vars_list, hgrid, xml_file_definition, fr
found_A = False
found_AH = False
found_begin_A = False
freq_ps = vars_list[0].frequency
for svar in sorted(vars_list):
rep = find_alias(svar, skipped_vars_per_table, debug)
if rep is not None:
Expand All @@ -585,7 +585,7 @@ def write_xios_file_def_for_svars_list(vars_list, hgrid, xml_file_definition, fr
if found_begin_A:
# create a field_def entry for surface pressure
# print "Searching for ps for var %s, freq %s="%(alias,freq)
sv_psol = get_simplevar("ps", table, freq)
sv_psol = get_simplevar("ps", table, freq_ps)

if sv_psol:
# if not sv_psol.cell_measures : sv_psol.cell_measures = "cell measure is not specified in DR "+
Expand Down
2 changes: 1 addition & 1 deletion dr2xml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def generate_file_defs_inner(year, enddate, context, pingfiles=None, dummies='in
if len(warn) > 0:
logger.warning("\nWarnings about cell methods (with var list)")
for w in warn:
logger.warning("\t%s for vars : %s" % (w, print_struct(warn[w])))
logger.warning("\t%s for vars: %s" % (w, print_struct(warn[w])))
if len(warnings_for_optimisation) > 0:
logger.warning("Warning for fields which cannot be optimised (i.e. average before remap)"
" because of an expr with @\n\t",)
Expand Down
24 changes: 12 additions & 12 deletions dr2xml/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def analyze_cell_time_method(cm, label, table):
# albisccp et pctisccp, en emDay et emMon)
add_value_in_list_config_variable("cell_method_warnings",
('Will not explicitly handle time: mean where cloud', label, table))
logger.info("Note : assuming that for %15s in table %s is well handled by 'detect_missing'" % (label, table))
logger.info("Note: assuming that for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
# -------------------------------------------------------------------------------------
Expand All @@ -185,7 +185,7 @@ def analyze_cell_time_method(cm, label, table):
# variables en SImon)
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where sea_ice_melt_pound', label, table))
logger.info("Note : assuming that 'time: mean where sea_ice_melt_pound' "
logger.info("Note: assuming that 'time: mean where sea_ice_melt_pound' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -195,7 +195,7 @@ def analyze_cell_time_method(cm, label, table):
# variables en SImon, sauf sispeed et sithick en SIday)
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where sea_ice', label, table))
logger.info("Note : assuming that 'time: mean where sea_ice' "
logger.info("Note: assuming that 'time: mean where sea_ice' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -212,7 +212,7 @@ def analyze_cell_time_method(cm, label, table):
# variables en Imon, Iyr, sauf sftflt en LImon !?)
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where floating_ice_shelf', label, table))
logger.info("Note : assuming that 'time: mean where floating_ice_shelf' "
logger.info("Note: assuming that 'time: mean where floating_ice_shelf' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -222,7 +222,7 @@ def analyze_cell_time_method(cm, label, table):
# variables en Imon, Iyr)
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where grounded_ice_sheet', label, table))
logger.info("Note : assuming that 'time: mean where grounded_ice_sheet' "
logger.info("Note: assuming that 'time: mean where grounded_ice_sheet' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -232,7 +232,7 @@ def analyze_cell_time_method(cm, label, table):
# variables en Imon, Iyr)
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where ice_sheet', label, table))
logger.info("Note : assuming that 'time: mean where ice_sheet' "
logger.info("Note: assuming that 'time: mean where ice_sheet' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -242,7 +242,7 @@ def analyze_cell_time_method(cm, label, table):
# variables suffixees en 'Lut')
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where land_use', label, table))
logger.info("Note : assuming that 'time: mean where landuse' "
logger.info("Note: assuming that 'time: mean where landuse' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -252,7 +252,7 @@ def analyze_cell_time_method(cm, label, table):
# variables suffixees en 'Crop')
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where crops', label, table))
logger.info("Note : assuming that 'time: mean where crops' "
logger.info("Note: assuming that 'time: mean where crops' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -262,7 +262,7 @@ def analyze_cell_time_method(cm, label, table):
# variables suffixees en 'Grass')
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where natural_grasses', label, table))
logger.info("Note : assuming that 'time: mean where natural_grasses' "
logger.info("Note: assuming that 'time: mean where natural_grasses' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -272,7 +272,7 @@ def analyze_cell_time_method(cm, label, table):
# variables suffixees en 'Shrub')
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where shrubs', label, table))
logger.info("Note : assuming that 'time: mean where shrubs' "
logger.info("Note: assuming that 'time: mean where shrubs' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -282,7 +282,7 @@ def analyze_cell_time_method(cm, label, table):
# variables suffixees en 'Tree')
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where trees', label, table))
logger.info("Note : assuming that 'time: mean where trees' "
logger.info("Note: assuming that 'time: mean where trees' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand All @@ -291,7 +291,7 @@ def analyze_cell_time_method(cm, label, table):
# [amv-twm]: Weighted Time Mean on Vegetation (pas de variables concernees)
add_value_in_list_config_variable("cell_method_warnings",
('time: mean where vegetation', label, table))
logger.info("Note : assuming that 'time: mean where vegetation' "
logger.info("Note: assuming that 'time: mean where vegetation' "
" for %15s in table %s is well handled by 'detect_missing'" % (label, table))
operation = "average"
detect_missing = True
Expand Down
26 changes: 23 additions & 3 deletions dr2xml/dr_interface/CMIP6.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

import re

from logger import get_logger
from .definition import Scope as ScopeBasic

from ..utils import Dr2xmlError

try:
import dreq
Expand Down Expand Up @@ -93,14 +94,29 @@ def get_sectors_list():
return sorted(list(set(rep) - {"typewetla"}))


def get_element_uid(id=None):
def get_element_uid(id=None, error_msg=None, raise_on_error=False, check_print_DR_errors=True,
check_print_stdnames_error=False):
"""
Get the uid of an element if precised, else the list of all elements.
"""
logger = get_logger()
if id is None:
return dq.inx.uid
else:
elif id in dq.inx.uid:
return dq.inx.uid[id]
else:
if error_msg is None:
error_msg = "DR Error: issue with %s" % id
if raise_on_error:
raise Dr2xmlError(error_msg)
elif check_print_DR_errors and print_DR_errors:
logger.error(error_msg)
return None
elif check_print_stdnames_error and print_DR_stdname_errors:
logger.error(error_msg)
return None
else:
return None


def get_experiment_label(experiment):
Expand Down Expand Up @@ -139,9 +155,13 @@ def correct_data_request_dim(dim):
dim.dimsize = 16
if dim.type in ["character", ]:
dim.altLabel = "sector"
# The latter is a bug in DR01.00.21 : typewetla has no value there
if dim.label in ["typewetla", ]:
dim.value = "wetland"


def correct_data_request_variable(variable):
logger = get_logger()
if variable.label is not None:
# DR21 has a bug with tsland : the MIP variable is named "ts"
if variable.label in ["tsland", ]:
Expand Down
3 changes: 2 additions & 1 deletion dr2xml/dr_interface/no.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def get_sectors_list():
return get_list_of_elements_by_id("grids")


def get_element_uid(id=None):
def get_element_uid(id=None, error_msg=None, raise_on_error=False, check_print_DR_errors=True,
check_print_stdnames_error=False):
"""
Get the uid of an element if precised, else the list of all elements.
"""
Expand Down
51 changes: 3 additions & 48 deletions dr2xml/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
# Interface to xml tools
from .xml_interface import find_rank_xml_subelement, DR2XMLElement

# CFsites tools
from .cfsites import cfsites_grid_id, add_cfsites_in_defs, cfsites_domain_id


# Next variable is used to circumvent an Xios 1270 shortcoming. Xios
# should read that value in the datafile. Actually, it did, in some
Expand Down Expand Up @@ -256,7 +253,6 @@ def change_axes_in_grid(grid_id):
grid_def_init = get_grid_def(grid_id)
grid_def = grid_def_init.copy()
output_grid_id = grid_id
axes_to_change = list()
# print "in change_axis for %s "%(grid_id)

# Get settings info about axes normalization
Expand Down Expand Up @@ -293,9 +289,9 @@ def change_axes_in_grid(grid_id):
#
dim_id = 'dim:{}'.format(dr_axis_id)
# print "in change_axis for %s %s"%(grid_id,dim_id)
if dim_id not in get_element_uid(): # This should be a dimension !
raise Dr2xmlError("Value %s in 'non_standard_axes' is not a DR dimension id" % dr_axis_id)
dim = get_element_uid(dim_id)
# dim_id should be a dimension !
dim = get_element_uid(dim_id,
error_msg="Value %s in 'non_standard_axes' is not a DR dimension id" % dr_axis_id)
# We don't process scalars here
if dim.value in ['', ] or dim.label in ["scatratio", ]:
axis_id, axis_name = create_axis_from_dim(dim, alt_labels, axis_ref)
Expand Down Expand Up @@ -385,47 +381,6 @@ def scalar_vertical_dimension(sv):
return None


def create_output_grid(ssh, grid_defs, domain_defs, target_hgrid_id, margs):
"""
Build output grid (stored in grid_defs) by analyzing the spatial shape
Including horizontal operations. Can include horiz re-gridding specification
"""
grid_ref = None

# Compute domain name, define it if needed
if ssh[0:2] in ['Y-', ]: # zonal mean and atm zonal mean on pressure levels
# Grid normally has already been created upstream
grid_ref = margs['src_grid_id']
elif ssh in ['S-na', ]:
# COSP sites. Input field may have a singleton dimension (XIOS scalar component)
grid_ref = cfsites_grid_id
add_cfsites_in_defs()
#
elif ssh[0:3] in ['XY-', 'S-A']:
# this includes 'XY-AH' and 'S-AH' : model half-levels
if ssh[0:3] in ['S-A', ]:
add_cfsites_in_defs()
target_hgrid_id = cfsites_domain_id
if target_hgrid_id:
# Must create and a use a grid similar to the last one defined
# for that variable, except for a change in the hgrid/domain
grid_ref = change_domain_in_grid(target_hgrid_id)
if grid_ref is False or grid_ref is None:
raise Dr2xmlError("Fatal: cannot create grid_def for %s with hgrid=%s" % (alias, target_hgrid_id))
elif ssh in ['TR-na', 'TRS-na']: # transects, oce or SI
pass
elif ssh[0:3] in ['YB-', ]: # basin zonal mean or section
pass
elif ssh in ['na-na', ]: # TBD ? global means or constants - spatial integration is not handled
pass
elif ssh in ['na-A', ]: # only used for rlu, rsd, rsu ... in Efx ????
pass
else:
raise Dr2xmlError(
"Fatal: Issue with un-managed spatial shape %s for variable %s in table %s" % (ssh, sv.label, table))
return grid_ref


def create_standard_domains(domain_defs):
"""
Add to dictionary domain_defs the Xios string representation for DR-standard horizontal grids, such as '1deg'
Expand Down
Loading

0 comments on commit fa9b574

Please sign in to comment.