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

Add unit conversion from degrees to radians, address isssue #309 #311

Merged
merged 5 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/ccpp_prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def check_optional_arguments(metadata, arguments, optional_arguments):
# *DH 2020-05-26
for subroutine_name in optional_arguments[module_name].keys():
# If optional arguments are listed individually, check each of them
if type(optional_arguments[module_name][subroutine_name]) is list:
if isinstance(optional_arguments[module_name][subroutine_name], list):
for var_name in optional_arguments[module_name][subroutine_name]:
if not var_name in arguments[module_name][scheme_name][subroutine_name]:
raise Exception("Explicitly requested optional argument '{}' not known to {}/{}".format(
Expand Down
30 changes: 29 additions & 1 deletion scripts/conversion_tools/unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,35 @@ def kg_kg_minus_1__to__g_kg_minus_1():

def g_kg_minus_1__to__kg_kg_minus_1():
"""Convert gram per kilogram to kilogram per kilogram"""
return '{var}/1.0E+3{kind}'
return '1.0E-3{kind}*{var}'

##################
# Plane angle #
##################

def radian__to__degrees():
"""Convert radian to degrees"""
return '57.295779513{kind}*{var}'

def degrees__to__radian():
"""Convert degrees to radian"""
return '{var}/57.295779513{kind}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While correct, this will eventually run afoul of efforts to standardize constants.
We should revisit (e.g., via pi / 180.0{kind} and its inverse) this then (i.e., when a universal value for pi is available to CCPP modules).

Copy link
Collaborator Author

@climbfuji climbfuji Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. I was wondering if I should plug in the value of math.pi and then "calculate" 57.x as 180.0/pi, but that seemed to be unnecessary to me. Rather implement it correctly once pi is defined and available as a Fortran constant through the CCPP framework. Then one can set pi = 1 and the world suddenly looks a lot more familiar ;-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely add that to the physical constants dictionary. What good would it be if there was no version with c == ℏ == 1?
c == ℏ == π == 1 is only for advanced users.


def radian__to__degrees_north():
"""Convert radian to degrees north"""
return radian__to__degrees()

def degrees_north__to__radian():
"""Convert degrees north to radian"""
return degrees__to__radian()

def radian__to__degrees_east():
"""Convert radian to degrees east"""
return radian__to__degrees()

def degrees_east__to__radian():
"""Convert degrees east to radian"""
return degrees__to__radian()

##################
# Composed units #
Expand Down
4 changes: 2 additions & 2 deletions scripts/mkcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def dimensions(self):

@dimensions.setter
def dimensions(self, value):
if not type(value) is list:
if not isinstance(value, list):
raise TypeError('Invalid type for variable property dimensions, must be a list')
self._dimensions = value

Expand Down Expand Up @@ -170,7 +170,7 @@ def actions(self):

@actions.setter
def actions(self, values):
if type(values)==dict:
if isinstance(values, dict):
for key in values.keys():
if key in ['in', 'out'] and isstring(values[key]):
self._actions[key] = values[key]
Expand Down