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
Implement from_namelist
method
#43
Conversation
Codecov Report
@@ Coverage Diff @@
## main #43 +/- ##
==========================================
- Coverage 94.85% 94.07% -0.79%
==========================================
Files 5 5
Lines 214 287 +73
==========================================
+ Hits 203 270 +67
- Misses 11 17 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
OK, it's coming together. Looks like this right now: ds_bathy = Bathymetry(1.0e3, 1.2e3, 1, 1).flat(5.0e3)
ds_bathy.domcfg.nml_ref_path = "path/to/namelist_ref"
ds_zgr = ds_bathy.domcfg.from_namelist("path/to/namelist_cfg") |
Adding error handle when importing namelist
@jdha CI log shows that
We are testing using this namelist_ref and this namelist_cfg. |
OK - thanks @malmans2 for pointing out the namelists. Looks like the domain cfg namelists have some legacy 3.6 bits in there (most of which a redundant: e.g. nambdy). I'll scape all the possible permutations of namelist variables from the Fortran and update the checking asap). |
OK! A couple of things that we might consider:
|
re: 1. I was already looking at that - seems crazy to read in the whole namelist if you only need a few namblocks. I'll double check with the fortran to see which namblocks are active so we can refine the code to read just those. I think I'll code the exceptions anyway as I'll probably end up using the code for the NEMO namelists too. re: 2. could do - but if the type or length is not correct, it ain't going run, no? I'm not convinced - but I'll take another look. |
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.
@jdha I've changed it a bit and applied checks only to variables that we actually use. I'm going to push the changes to this PR. Let me know your thoughts (we can always revert back to your version). I haven't tested it too much though. Could you please test the new function _check_namelist_entries
with your namelists that you know should pass/fail? In pydomcfg
right now we are pretty much only looking at ln
variables...
@malmans2 sorry didn't have time to finish the namelist stuff off today - I'll review it tomorrow morning. |
pydomcfg/accessor.py
Outdated
if key != "self" | ||
} | ||
|
||
_check_namelist_entries(kwargs) |
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 think we can now move _check_namelist_entries
in Zgr
, so we run the exact same checks to the namelists and the arguments of our classes. (I think we just have to make a small change to support optional arguments).
This is why I'm using isinstance(value, int)
which is a less strict check compared to type(value) == int
.
For example, isinstance(True, int)
is True
which is OK for pydomcfg
although NEMO would probably complain.
But I think it makes sense to use isinstance
as we are not creating namelists to feed into NEMO.
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.
@malmans2 I guess this is where nml_meld will diverge then as 1 != .true.
in NEMO speak. But I think that's fine.
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.
Right, if eventually pydomcfg will make use of nml_meld, I think we just need an extra argument list isinstance=True
for pydomcfg but False
by default.
Just had a quick play and it seems to read a cut-down NEMO namelist_cfg ok [after removing exotics such as |
OK! I think we should still raise a TypeError (a list is passed where we expect an int), but let's change the error message in that case. If we expect a list and a list with wrong size is passed we raise a ValueError.
Let's add those as well, should be easy! Even if we deprecate |
@pyNEMO/pydomcfg This is ready for review! |
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.
Looks good. Well all the bits I understand at least! Just trying to get my head around wraps
. But I'll have a play with some examples this afternoon.
Thanks! |
Yeah. I read as much - just need to try it out. I guess I was a little puzzled as to when you wouldn't want that functionality? Is there a case when that kind of inheritance is undesirable? Probably a silly question ... |
In our case we use the decorator just to run some extra checks before entering the function. But I guess for decorators that actually change the behavior of the decorated functions, |
ldbletanh
#38pre-commit run --all-files
api.rst
whats-new.rst