-
Notifications
You must be signed in to change notification settings - Fork 1
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
Developing sco class #33
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## main #33 +/- ##
===========================================
- Coverage 94.85% 81.67% -13.19%
===========================================
Files 5 5
Lines 214 251 +37
===========================================
+ Hits 203 205 +2
- Misses 11 46 +35
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
pyDOMCFG/pydomcfg/domzgr/sco.py Line 114 in 80b4b58
Worthy to implement the same strategy for zco? ... will allow to get rid of the quite annoying ldbletanh boolean flag ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced a few changes in Zgr
with #31.
I think it makes sense to review and merge #31, so we build Sco
starting from the most recent version.
Also, mypy is fully integrated in #31, while here you are not really checking xarray objects as xarray is not an additional dependency in the config file.
The only major change that #31 introduces is that _init_ds
is gone, as we don't have to initialize e3 and z3 variables anymore. But If you want to start translating from fortran using it, I would introduce _init_ds
in the child class. I.e., we will do something like for Zco (1. translate from fortran, 2. refactor to make more use of xarray) but we don't have to change/refactor anything in the base class.
pydomcfg/domzgr/sco.py
Outdated
# set stretching parameters after checking their consistency | ||
if self._stretch: | ||
self._set_stretch_par(psurf, pbott, alpha, efold, pbot2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we append variables to self
in separate methods, they're kind of hidden. I would do something like in Zco
, so self._set_stretch_par
returns psurf, pbott, alpha, efold, pbot2
.
Actually, what you are doing so far (basically self._psurf = psurf or None
, ...) is easy enough that I think you can set these variables directly in __call__
, and rename the function to something like check_stetch_par
.
pydomcfg/domzgr/sco.py
Outdated
if self._stretch: | ||
self._set_stretch_par(psurf, pbott, alpha, efold, pbot2) | ||
|
||
ds = self._init_ds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_init_ds
is gone in #31 as we don't need to initialize e3
and z3
variables anymore.
pydomcfg/domzgr/sco.py
Outdated
ds_env = self._compute_env(ds) | ||
|
||
# compute sigma-coordinates for z3 computation | ||
kindx = ds_env["z"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we merge #31 you can do this:
kindx = self._z
pydomcfg/domzgr/sco.py
Outdated
|
||
# compute sigma-coordinates for z3 computation | ||
kindx = ds_env["z"] | ||
sigma = (self._compute_sigma(kk) for kk in kindx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be:
sigma = (self._compute_sigma(kk) for kk in kindx) | |
sigma = self._compute_sigma(kindx) |
pydomcfg/domzgr/sco.py
Outdated
msg = ( | ||
srf | ||
+ " and " | ||
+ bot | ||
+ "MUST be set when using " | ||
+ self._stretch | ||
+ " stretching." | ||
) | ||
raise ValueError(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg = ( | |
srf | |
+ " and " | |
+ bot | |
+ "MUST be set when using " | |
+ self._stretch | |
+ " stretching." | |
) | |
raise ValueError(msg) | |
raise ValueError( | |
f"{srf} and {bot} MUST be set when using {self._stretch} stretching." | |
) |
pydomcfg/domzgr/sco.py
Outdated
self._psurf = psurf if psurf else 0.0 | ||
self._pbott = pbott if pbott else 0.0 | ||
self._alpha = alpha if alpha else 0.0 | ||
self._efold = efold if efold else 0.0 | ||
self._pbot2 = pbot2 if pbot2 else 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._psurf = psurf if psurf else 0.0 | |
self._pbott = pbott if pbott else 0.0 | |
self._alpha = alpha if alpha else 0.0 | |
self._efold = efold if efold else 0.0 | |
self._pbot2 = pbot2 if pbot2 else 0.0 | |
self._psurf = psurf or 0 | |
self._pbott = pbott or 0 | |
self._alpha = alpha or 0 | |
self._efold = efold or 0 | |
self._pbot2 = pbot2 or 0 |
Also, I think you can do this directly in __call__
pydomcfg/utils.py
Outdated
@@ -26,6 +27,51 @@ def is_nemo_none(var: Optional[float] = None) -> bool: | |||
return var in [None, 999999.0] | |||
|
|||
|
|||
# ----------------------------------------------------------------------------- | |||
def calc_rmax(depth: DataArray) -> DataArray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same used by the Bathymetry
class, right?
Then we could delete it in tests/bathymetry.py
and import from here.
Right, although I think the best we can do with pyDOMCFG/pydomcfg/domzgr/zco.py Line 288 in 0bc4f0b
I.e., default is None, set to True/False if the user defines it, otherwise False if the tanh parameters are not set (and viceversa). |
if self._stretch == "sh94": | ||
srf = "rn_theta" | ||
bot = "rn_bb" | ||
elif self._stretch == "md96": | ||
srf = "rn_theta" | ||
bot = "rn_thetb" | ||
elif self._stretch == "sf12": | ||
srf = "rn_zs" | ||
bot = "rn_zb_a" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a final else
with a slightly different error (i.e., typo or the stretch is not supported)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calc_rmax
is now in utils.py
which I guess makes _calc_rmax
in tests/bathymetry.py
redundant. Unless told otherwise I'll raise an issue to tidy after this PR.
@malmans2 Yes I know, all your comments are correct but as I specified in the committ this was just to start the work, so just a quick structure of the module, surely not ready for review ;) |
My idea is to introduce an intermediate step (function) where we translate (map) from NEMO-like namelist parameters to pyDOMCFG-like parameters. |
@jdha I think it would make more sense to do it here @oceandie no need to open a new PR, we'll just rebase once we merge #31
|
I like it, it would make everything much easier! I suggest we open an issue about this and we address it in a separate PR. |
|
Perfect, thanks a lot both for the clarifications - I thought opening a PR was kind of "mandatory" everytime you open a branch ... good to know ;) I think for this one I will do as suggested by @malmans2, I'll put draft status |
@oceandie you'll need to merge main into this. The only conflict with main is basically just the Anyways, if you haven't done it before, here is what I would do from terminal
Fix conflicts: Git add, commit and push
|
Don't worry about the CI/upstream-dev action failing. We'll add |
pydomcfg/utils.py
Outdated
# Do we actually need this? mypy complains since | ||
# DataArray.reset_indexe() returns Optional["DataArray"] | ||
# | ||
# depth = depth.reset_index(list(depth.dims)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, not sure why they assigned that type annotation to reset_index
. One quick solution is DataArray(depth.reset_index(list(depth.dims)))
.
_calc_rmax
doesn't really need this, the problem is that if we don't use it a DataArray with different indexes is returned. This means that we'll get conflicts when we try to merge in the main dataset.
I was just lazy though... it's quite easy in this case to properly use the indexes. I'll open a separate PR for that as you haven't removed calc_rmax
from Bathymetry
yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will implement the quick solution DataArray(depth.reset_index(list(depth.dims)))
for now i my branch since it seems we need it also in _calc_rmax: if I remove it, I get the following error:
ValueError: cannot reindex or align along dimension 'y' because the index has duplicate values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, forza azzurri !!!!
pydomcfg/utils.py
Outdated
@@ -59,6 +56,8 @@ def _calc_rmax(depth: DataArray) -> float: | |||
depth_diff = depth.diff(dim) | |||
depth_rolling_sum = depth.rolling({dim: 2}).sum().dropna(dim) | |||
rmax = depth_diff / depth_rolling_sum | |||
# dealing with nans at land points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why mypy is failing ... any idea? |
* refactor to avoid loops * apply Diego's suggestions * remove useless return after error
Looks like there aren't conflicts right now, so I'd merge pyDOMCFG/pydomcfg/domzgr/zco.py Lines 21 to 22 in 6888e41
|
pre-commit run --all-files
whats-new.rst
api.rst