-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated for enums * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * tried another form of import * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * moved import constants to bottom; it's something like this * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * I've fixed this before, but I can't remember how * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * I added a note to my old one, hopefully this does the trick * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * testing this works * hopefully fixed the type error problems * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * updated test to fix one error * figuring it out * fixed no method error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * removed NotImplementedError * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * missed one * fixed flake8 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed flake8 again * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed flake8 the third * updated to include a checker function in constants, with necessary tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed flake8 conflicts * missed one: fixed another flake8 conflict * more flake8 * flake8 2: electric imperativemoodaloo * more flake8 * fixed test failure * fixed test failure * fixed error messages to use enums * hasn't this been a journey. Fixed error message * actioned review comments * fixed precommit and error message * corrected constants error message * corrected docstring --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
be33a81
commit e83b7be
Showing
18 changed files
with
303 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Holds all enums created for esmf-regrid.""" | ||
|
||
from enum import Enum | ||
|
||
from . import esmpy | ||
|
||
|
||
class Constants: | ||
"""Encompassing class for best practice import.""" | ||
|
||
class Method(Enum): | ||
"""holds enums for Method values.""" | ||
|
||
CONSERVATIVE = esmpy.RegridMethod.CONSERVE | ||
BILINEAR = esmpy.RegridMethod.BILINEAR | ||
NEAREST = esmpy.RegridMethod.NEAREST_STOD | ||
|
||
class NormType(Enum): | ||
"""holds enums for norm types.""" | ||
|
||
FRACAREA = esmpy.api.constants.NormType.FRACAREA | ||
DSTAREA = esmpy.api.constants.NormType.DSTAREA | ||
|
||
|
||
method_dict = { | ||
"conservative": Constants.Method.CONSERVATIVE, | ||
"bilinear": Constants.Method.BILINEAR, | ||
"nearest": Constants.Method.NEAREST, | ||
} | ||
|
||
norm_dict = { | ||
"fracarea": Constants.NormType.FRACAREA, | ||
"dstarea": Constants.NormType.DSTAREA, | ||
} | ||
|
||
|
||
def check_method(method): | ||
"""Check that method is a member of the `Constants.Method` enum or raise an error.""" | ||
if method in method_dict.keys(): | ||
result = method_dict[method] | ||
elif method in method_dict.values(): | ||
result = method | ||
else: | ||
raise ValueError( | ||
f"Method must be a member of `Constants.Method` enum, instead got {method}" | ||
) | ||
return result | ||
|
||
|
||
def check_norm(norm): | ||
"""Check that normtype is a member of the `Constants.NormType` enum or raise an error.""" | ||
if norm in norm_dict.keys(): | ||
result = norm_dict[norm] | ||
elif norm in norm_dict.values(): | ||
result = norm | ||
else: | ||
raise ValueError( | ||
f"NormType must be a member of `Constants.NormType` enum, instead got {norm}" | ||
) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.