-
Notifications
You must be signed in to change notification settings - Fork 10
fix wrong graupel tuning parameter config in data test #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
a108dc1
4ba05e2
ad39c68
e01367c
c8f0021
0f13ca0
200ac17
f24fb9b
de5ef7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,30 +38,27 @@ | |
| @pytest.mark.embedded_static_args | ||
| @pytest.mark.datatest | ||
| @pytest.mark.parametrize( | ||
| "experiment, model_top_height", | ||
| "experiment", | ||
| [ | ||
| (definitions.Experiments.WEISMAN_KLEMP_TORUS, 30000.0), | ||
| definitions.Experiments.WEISMAN_KLEMP_TORUS, | ||
| ], | ||
| ) | ||
|
||
| @pytest.mark.parametrize( | ||
| "date", ["2008-09-01T01:59:48.000", "2008-09-01T01:59:52.000", "2008-09-01T01:59:56.000"] | ||
| ) | ||
| def test_graupel( | ||
| experiment: definitions.Experiments, | ||
| model_top_height: ta.wpfloat, | ||
| date: str, | ||
| *, | ||
| data_provider: sb.IconSerialDataProvider, | ||
| grid_savepoint: sb.IconGridSavepoint, | ||
| metrics_savepoint: sb.MetricSavepoint, | ||
| icon_grid: icon_grid.IconGrid, | ||
| lowest_layer_thickness: ta.wpfloat, | ||
| model_top_height: ta.wpfloat, | ||
| backend: gtx_typing.Backend, | ||
| ): | ||
| pytest.xfail("Tolerances have increased with new ser_data, need to check with @ongchia") | ||
| vertical_config = v_grid.VerticalGridConfig( | ||
| icon_grid.num_levels, | ||
| lowest_layer_thickness=lowest_layer_thickness, | ||
| model_top_height=model_top_height, | ||
| ) | ||
| vertical_params = v_grid.VerticalGrid( | ||
|
|
@@ -103,16 +100,7 @@ def test_graupel( | |
| v=None, | ||
| ) | ||
|
|
||
| graupel_config = graupel.SingleMomentSixClassIconGraupelConfig( | ||
| liquid_autoconversion_option=mphys_options.LiquidAutoConversionType.SEIFERT_BEHENG, | ||
| ice_stickeff_min=0.01, | ||
| power_law_coeff_for_ice_mean_fall_speed=1.25, | ||
| exponent_for_density_factor_in_ice_sedimentation=0.3, | ||
| power_law_coeff_for_snow_fall_speed=20.0, | ||
| rain_mu=0.0, | ||
| rain_n0=1.0, | ||
| snow2graupel_riming_coeff=0.5, | ||
| ) | ||
| graupel_config = definitions.construct_gscp_graupel_config(experiment) | ||
|
|
||
| graupel_microphysics = graupel.SingleMomentSixClassIconGraupel( | ||
| graupel_config=graupel_config, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ | |
|
|
||
| import pathlib | ||
| import urllib.parse | ||
| import ast | ||
| import re | ||
|
|
||
|
|
||
| import gt4py.next.typing as gtx_typing | ||
|
|
||
|
|
@@ -72,3 +75,85 @@ def create_icon_serial_data_provider( | |
| mpi_rank=rank, | ||
| do_print=True, | ||
| ) | ||
|
|
||
|
|
||
| def read_namelist(path: pathlib.Path) -> dict: | ||
| """ICON NAMELIST_ICON_output_atm reader. | ||
| Returns a dictionary of dictionaries, where the keys are the namelist names | ||
| and the values are dictionaries of key-value pairs from the namelist. | ||
|
|
||
| Use as: | ||
| namelists = read_namelist("/path/to/NAMELIST_ICON_output_atm") | ||
| print(namelists["NWP_TUNING_NML"]["TUNE_ZCEFF_MIN"]) | ||
| """ | ||
| with path.open() as f: | ||
| txt = f.read() | ||
| namelist_set = re.findall(r"&(\w+)(.*?)\/", txt, re.S) | ||
| full_namelist = {} | ||
| for namelist_name, namelist_content in namelist_set: | ||
| full_namelist[namelist_name] = _parse_namelist_content(namelist_content) | ||
| return full_namelist | ||
|
|
||
|
|
||
| def _parse_namelist_content(namelist_content): | ||
| """ | ||
| Parse the contents of a single namelist group to a Python dictionary. | ||
| """ | ||
| result = {} | ||
| current_variable = None | ||
|
|
||
| # Remove comments | ||
| namelist_content = re.sub(r"!.*", "", namelist_content) | ||
|
|
||
| # Split into lines | ||
| lines = namelist_content.splitlines() | ||
|
|
||
| for line in lines: | ||
| line = line.strip() | ||
| # skip any non-meaningful empty line | ||
| if not line: | ||
| continue | ||
|
|
||
| # Remove trailing comma | ||
| if line.endswith(","): | ||
| line = line[:-1] | ||
|
|
||
| if "=" in line: | ||
| # New variable-value pair | ||
| variable, value = line.split("=", 1) | ||
| current_variable = variable.strip() | ||
| result[current_variable] = _parse_value(value) | ||
| # TODO(Chia Rui): check if continuation lines is irrelevant in our tests | ||
| # else: | ||
| # # Continuation line (array or multi-line string) | ||
| # if current_variable is not None: | ||
| # val = _parse_value(line) | ||
| # # convert to a list if we have multiple values for the same variable | ||
| # if not isinstance(result[current_variable], list): | ||
| # result[current_variable] = [result[current_variable]] | ||
| # result[current_variable].append(val) | ||
|
||
|
|
||
| return result | ||
|
|
||
|
|
||
| def _parse_value(value): | ||
| """ | ||
| Convert Fortran-style values to Python types. | ||
| """ | ||
| value = value.strip() | ||
|
|
||
| # Fortran logical | ||
| if value in ("T", ".T."): | ||
| return True | ||
| if value in ("F", ".F."): | ||
| return False | ||
|
|
||
| # Quoted string | ||
| if value.startswith("'") and value.endswith("'"): | ||
| return value[1:-1].rstrip() | ||
|
|
||
| # Try numeric conversion | ||
| try: | ||
| return ast.literal_eval(value) | ||
| except Exception: | ||
| return value | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@havogt is this correct? otherwise, mypy complained about wrong type