Skip to content

Commit

Permalink
Merge pull request #22 from NoraLoose/preinit-wetfac
Browse files Browse the repository at this point in the history
move computation of wet_fac to post_init
  • Loading branch information
rabernat authored Feb 11, 2021
2 parents 73baa9e + e1427c3 commit 8b92035
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ repos:
- id: black
language_version: python3

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
hooks:
- id: mypy
exclude: docs/source/conf.py
args: [--ignore-missing-imports]
#- repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.770
# hooks:
# - id: mypy
# exclude: docs/source/conf.py
# args: [--ignore-missing-imports]
18 changes: 10 additions & 8 deletions gcm_filters/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,24 @@ class CartesianLaplacianWithLandMask(BaseLaplacian):

wet_mask: ArrayType

def __call__(self, field: ArrayType):
np = get_array_module(field)
def __post_init__(self):
np = get_array_module(self.wet_mask)

out = field.copy() # is this necessary?
out = np.nan_to_num(field) # is this necessary?
out = self.wet_mask * out

fac = (
self.wet_fac = (
np.roll(self.wet_mask, -1, axis=-1)
+ np.roll(self.wet_mask, 1, axis=-1)
+ np.roll(self.wet_mask, -1, axis=-2)
+ np.roll(self.wet_mask, 1, axis=-2)
)

def __call__(self, field: ArrayType):
np = get_array_module(field)

out = np.nan_to_num(field) # set all nans to zero
out = self.wet_mask * out

out = (
-fac * out
-self.wet_fac * out
+ np.roll(out, -1, axis=-1)
+ np.roll(out, 1, axis=-1)
+ np.roll(out, -1, axis=-2)
Expand Down

0 comments on commit 8b92035

Please sign in to comment.