Skip to content

Conversation

@malmans2
Copy link
Member

@codecov
Copy link

codecov bot commented Jun 14, 2021

Codecov Report

Merging #31 (0bc4f0b) into main (db12bd9) will increase coverage by 0.92%.
The diff coverage is 94.40%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #31      +/-   ##
==========================================
+ Coverage   93.12%   94.05%   +0.92%     
==========================================
  Files           4        4              
  Lines         160      185      +25     
==========================================
+ Hits          149      174      +25     
  Misses         11       11              
Flag Coverage Δ
unittests 94.05% <94.40%> (+0.92%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pydomcfg/domzgr/zco.py 92.38% <92.22%> (+1.47%) ⬆️
pydomcfg/domzgr/zgr.py 100.00% <100.00%> (ø)
pydomcfg/utils.py 97.36% <100.00%> (+0.30%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db12bd9...0bc4f0b. Read the comment docs.

Copy link
Member Author

@malmans2 malmans2 left a comment

Choose a reason for hiding this comment

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

  1. No more loops over z
  2. Documentation in good shape
  3. A couple of additional tests
  4. We're now fully checking types (before xarray objects were replaced by Any). All functions arguments and returns have a type annotation. From now on mypy should be more helpful than annoying. If you add type annotation as soon as you define new functions, it should be easy to know if we have to make changes upstream

Comment on lines +60 to +64
ldbletanh: bool, optional
Logical flag to switch ON/OFF the double tanh stretching function.
This flag is only needed for compatibility with NEMO DOMAINcfg tools.
Just set ``ppa2``, ``ppkth2``, and ``ppacr2`` to switch ON
the double tanh stretching function.
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this flag is redundant. I suggest we keep it just for backward compatibility with NEMO tools.

Comment on lines -151 to +169
ppa1 = aa / (bb - cc * (dd - ee)) if is_nemo_none(ppa1) else ppa1
ppa0 = self._ppdzmin - ppa1 * bb if is_nemo_none(ppa0) else ppa0
ppsur = -(ppa0 + ppa1 * self._ppacr * ee) if is_nemo_none(ppsur) else ppsur
# Substitute only if is None or 999999
ppa1_out = (aa / (bb - cc * (dd - ee))) if _is_nemo_none(ppa1) else ppa1
ppa0_out = (self._ppdzmin - ppa1_out * bb) if _is_nemo_none(ppa0) else ppa0
ppsur_out = (
-(ppa0_out + ppa1_out * self._ppacr * ee) if _is_nemo_none(ppsur) else ppsur
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Just helping out mypy...

Comment on lines 298 to 306
# Errors
if ldbletanh is True and any(pp_are_none):
raise ValueError(f"{prefix_msg} MUST be all float when ldbletanh is True")
if ldbletanh is None and (any(pp_are_none) and not all(pp_are_none)):
raise ValueError(f"{prefix_msg} MUST be all None or float")

# Warning
if ldbletanh is False and not all(pp_are_none):
warnings.warn(f"{prefix_msg} are ignored when ldbletanh is False")
Copy link
Member Author

Choose a reason for hiding this comment

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

Does this look right? Before we were doing a more strict check (pp>0 rather than not null), but I think it makes more sense to default None and the user can fully play with the underlying equation. If you think we should restore pp>0 when ldbletanh is True, then maybe we should introduce more checks on all parameters (e.g., ppdzmin >= 0, ...)

Comment on lines -31 to +33
# -------------------------------------------------------------------------
def _init_ds(self):
"""
Initialise the xarray dataset with empty
``z3{T,W}`` and ``e3{T,W}``
Returns
-------
ds: Dataset
A copy of the dataset used to initialise the class with new
coordinates ``z3{T,W}`` and ``e3{T,W}`` empty dataarrays
"""
ds = self._bathy.copy()

var = ["z3", "e3"]
grd = ["T", "W"]

# Initialise a dataset with empty z3 and e3 dataarrays
da = xr.full_like(ds["Bathymetry"], None).expand_dims(z=range(self._jpk))
for v, g in product(var, grd):
ds[v + g] = da.copy()
ds = ds.set_coords(v + g)
return ds
# Z dimension
self._z = DataArray(range(jpk), dims="z")
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need to initialize the dataset anymore. If you want to start Sco with a similar approach (i.e., start with loops, then remove them) you'd have to re-introduce this.

@malmans2 malmans2 mentioned this pull request Jun 14, 2021
6 tasks
@malmans2 malmans2 requested a review from a team June 14, 2021 10:08
@malmans2 malmans2 added documentation Improvements or additions to documentation enhancement New feature or request tests Improvements or additions to tests labels Jun 14, 2021
@malmans2 malmans2 changed the title same as previous PR, but keep track of previous changes Zco: More xarray, tests, and improve/expose docstring Jun 15, 2021
@jdha
Copy link
Contributor

jdha commented Jun 16, 2021

@malmans2 - are you happy with this updated PR ... I noticed the flurry of activity so waited to review - any more additions? I'll go over the updates after the NEMO meeting this morning.

@malmans2
Copy link
Member Author

Yes, it's ready for review.
We should probably finalize it ASAP before we introduce too many conflicts with #33

@malmans2 malmans2 mentioned this pull request Jun 16, 2021
6 tasks
@malmans2 malmans2 merged commit 6cf13c5 into main Jun 16, 2021
@malmans2
Copy link
Member Author

Thanks @jdha. Merging so we don't slow down #33

@malmans2 malmans2 deleted the more_xr2 branch June 16, 2021 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request tests Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Zco and Zgr classes to public API Make more use of xarray auto-broadcasting

3 participants