Skip to content
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

Unit converter does not handle a variable with units = 1 #458

Closed
gold2718 opened this issue Dec 22, 2022 · 1 comment · Fixed by #462, NOAA-EMC/fv3atm#634 or ufs-community/ufs-weather-model#1654
Assignees
Labels

Comments

@gold2718
Copy link
Collaborator

Description

If the units converter is invoked because a variable is listed in metadata with the same standard name but a different unit and one of the units is "1", an obscure error is generated as the units converter does not know how to handle units = 1.

Steps to Reproduce

195ee07, no modifications

Please provide detailed steps for reproducing the issue.

  1. Create a metadata file with a scheme variable whose units are not 1
  2. Create another metadata file with a scheme variable that has the same Standard Name but with units = 1.
  3. Create a CCPP suite that includes these two schemes.
  4. Run the framework on the suite created in the previous step.

Additional Context

The problem is that the unit converter attempts to convert each unit into a python identifier and 1 does not cooperate.

@mkavulich
Copy link
Collaborator

Fix implemented in #462

Old (bad) output:

INFO: Comparing metadata for requested and provided variables ...
Traceback (most recent call last):
  File "ccpp/framework/scripts/ccpp_prebuild.py", line 813, in <module>
    main()
  File "ccpp/framework/scripts/ccpp_prebuild.py", line 767, in main
    (success, modules, metadata) = compare_metadata(metadata_define, metadata_request)
  File "ccpp/framework/scripts/ccpp_prebuild.py", line 473, in compare_metadata
    var.convert_to(metadata_define[var_name][0].units)
  File "/glade/work/kavulich/CCPP/workdir/issue_458/ccpp-scm/ccpp/framework/scripts/mkcap.py", line 191, in convert_to
    function_name = '{0}__to__{1}'.format(string_to_python_identifier(self.units), string_to_python_identifier(units))
  File "/glade/work/kavulich/CCPP/workdir/issue_458/ccpp-scm/ccpp/framework/scripts/common.py", line 197, in string_to_python_identifier
    raise Exception("Resulting string '{0}' is not a valid Python identifier".format(string))
Exception: Resulting string '1' is not a valid Python identifier

After fix:

INFO: Comparing metadata for requested and provided variables ...
Traceback (most recent call last):
  File "/glade/work/kavulich/CCPP/workdir/issue_458/ccpp-scm/ccpp/framework/scripts/mkcap.py", line 193, in convert_to
    function = getattr(unit_conversion, function_name)
AttributeError: module 'conversion_tools.unit_conversion' has no attribute 'one__to__none'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ccpp/framework/scripts/ccpp_prebuild.py", line 813, in <module>
    main()
  File "ccpp/framework/scripts/ccpp_prebuild.py", line 767, in main
    (success, modules, metadata) = compare_metadata(metadata_define, metadata_request)
  File "ccpp/framework/scripts/ccpp_prebuild.py", line 473, in compare_metadata
    var.convert_to(metadata_define[var_name][0].units)
  File "/glade/work/kavulich/CCPP/workdir/issue_458/ccpp-scm/ccpp/framework/scripts/mkcap.py", line 196, in convert_to
    raise Exception('Error, automatic unit conversion from {0} to {1} for {2} in {3} not implemented'.format(self.units, units, self.standard_name, self.container))
Exception: Error, automatic unit conversion from 1 to none for ccpp_error_message in MODULE_cu_gf_driver SCHEME_cu_gf_driver SUBROUTINE_cu_gf_driver_init not implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment