Skip to content
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

add zgr and zco classes #15

Merged
merged 32 commits into from Jun 11, 2021
Merged

add zgr and zco classes #15

merged 32 commits into from Jun 11, 2021

Conversation

oceandie
Copy link
Contributor

@oceandie oceandie commented Jun 7, 2021

No description provided.

@codecov
Copy link

codecov bot commented Jun 7, 2021

Codecov Report

Merging #15 (e94dad4) into main (687d67c) will increase coverage by 0.81%.
The diff coverage is 93.38%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   92.30%   93.12%   +0.81%     
==========================================
  Files           2        4       +2     
  Lines          39      160     +121     
==========================================
+ Hits           36      149     +113     
- Misses          3       11       +8     
Flag Coverage Δ
unittests 93.12% <93.38%> (+0.81%) ⬆️

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

Impacted Files Coverage Δ
pydomcfg/domzgr/zco.py 90.90% <90.90%> (ø)
pydomcfg/domzgr/zgr.py 100.00% <100.00%> (ø)
pydomcfg/utils.py 97.05% <100.00%> (+0.18%) ⬆️

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 687d67c...e94dad4. Read the comment docs.

Copy link
Member

@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.

I added comments that should make darglint happy.

pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
@oceandie
Copy link
Contributor Author

oceandie commented Jun 7, 2021

Next step I am going to write the test. Thanks @malmans2 for the help with the bloody darglint ;) :)

@oceandie
Copy link
Contributor Author

oceandie commented Jun 7, 2021

Any idea why the failing of CI / upstream-dev (pull_request)?

Copy link
Member

@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.

I've only glanced through it, but here are a few xarray tips.

pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
@malmans2
Copy link
Member

malmans2 commented Jun 7, 2021

Any idea why the failing of CI / upstream-dev (pull_request)?

Must have been a connection hiccup. I re-triggered it and looks OK.

oceandie and others added 3 commits June 7, 2021 11:32
Co-authored-by: Mattia Almansi <mattia.almansi@noc.ac.uk>
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
Co-authored-by: Mattia Almansi <mattia.almansi@noc.ac.uk>
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
oceandie and others added 2 commits June 7, 2021 14:32
Co-authored-by: Mattia Almansi <mattia.almansi@noc.ac.uk>
@oceandie oceandie changed the title add zgr and zco classes - darglint failing add zgr and zco classes Jun 7, 2021
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
@jdha jdha mentioned this pull request Jun 8, 2021
@oceandie
Copy link
Contributor Author

oceandie commented Jun 8, 2021

Ok so let me just write down my next steps:

  1. Implement analytical e3T/W (to keep compatibility with 3.6 and for testing)
  2. Implement @malmans2 add zgr and zco classes #15 (comment) suggestion
  3. Implement some of @malmans2 73008a4 suggestions for sigma, compute_z3, compute_e3
  4. Write the testing

Any other things we want to add?

@malmans2
Copy link
Member

malmans2 commented Jun 8, 2021

Ok so let me just write down my next steps:

  1. Implement analytical e3T/W (to keep compatibility with 3.6 and for testing)
  2. Implement @malmans2 #15 (comment) suggestion
  3. Implement some of @malmans2 73008a4 suggestions for sigma, compute_z3, compute_e3
  4. Write the testing

Any other things we want to add?

Looks good. As you are not going to add that much at this point, I think 3 can wait after 4 so we can safely refactor if we need to. Just one comment about testing, I think the best way is to only test public methods (aka, easier to maintain and if we don't hit all private methods testing public methods, something is not right... codecov will tell us). Zco is already in good shape, I think you can make pretty much all methods in Zgr private as well...

Copy link
Member

@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.

There a few times where I think for loops of the kind for var in (varT, varK) clarify when the same thing is done and will prevent typos and bugs...
I've used GH inline comments without running the code so please double check if you are going to implement it.

Also, does it make sense to isolate the entire for loop in __call__ that generates ds["z3{T,W}"] in a separate method? That way __call__ is very clean and just glancing through it shows all the steps that are done.

pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
@malmans2
Copy link
Member

malmans2 commented Jun 9, 2021

There a few times where I think for loops of the kind for var in (varT, varK) clarify when the same thing is done and will prevent typos and bugs...
I've used GH inline comments without running the code so please double check if you are going to implement it.

I also just realized that all the inline for loops in __call__ can probably be condensed in one outer for loop:

for varname, kx, sig, sig_p1 in zip(["z3T", "z3W"], [kindx, kindx + 1.], sigmas, sigmas_p1):

so pretty much the same as this: #15 (comment)

@malmans2
Copy link
Member

malmans2 commented Jun 9, 2021

When we have the tests, I think this will be the way to go:
Instead of having T and W variables stored directly in the class, we can define two separate datasets since the very beginning with identical variable names: e.g., self._ds_t, self._ds_w).
A the very end, we append to the variable names "t" or "w" and we merge the two datasets (removing variables that we don't want to output, such as sig).

Copy link
Member

@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.

Final minor comments...

pydomcfg/domzgr/zco.py Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zgr.py Outdated Show resolved Hide resolved
pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
jpk = 31

# Bathymetry dataset
ds_bathy = Bathymetry(1000.0, 1200.0, 100, 200).flat(5000.0)
Copy link
Member

@malmans2 malmans2 Jun 10, 2021

Choose a reason for hiding this comment

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

What if we test:

ds_bathy = Bathymetry(1000.0, 1200.0, 1, 1).flat(5000.0)

and possibly we have a separate test to make sure that all z/e3 are identical for 2D flat domains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry but I don't understand what you mean ...

Copy link
Member

Choose a reason for hiding this comment

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

pydomcfg/domzgr/zco.py Outdated Show resolved Hide resolved
@oceandie
Copy link
Contributor Author

This is the code that fail mypy

pydomcfg/domzgr/zco.py Show resolved Hide resolved
Comment on lines +124 to +125
if not self._is_uniform:
self._ppsur, self._ppa0, self._ppa1 = self._compute_pp(ppsur, ppa0, ppa1)
Copy link
Member

Choose a reason for hiding this comment

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

I think we are missing an error here, i.e. the case where is uniform and the user provides any of [ppsur, ppa0, ppa1]

Copy link
Contributor Author

@oceandie oceandie Jun 11, 2021

Choose a reason for hiding this comment

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

If the user wants a uniform grid (acr or kth == 0) then we don't need ppsur, ppa0 and ppa1 at all - they are not used. So even if the user provide ppsur, ppa0 and ppa1, the condition of uniform grid prevent to set them. I think we are safe like this.

Copy link
Member

Choose a reason for hiding this comment

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

OK! Still the user is probably misunderstanding something... Let's add a warning?

Copy link
Member

Choose a reason for hiding this comment

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

OK! Still the user is probably misunderstanding something... Let's add a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fine by me

Co-authored-by: Mattia Almansi <mattia.almansi@noc.ac.uk>
@oceandie oceandie linked an issue Jun 11, 2021 that may be closed by this pull request
@oceandie oceandie merged commit 34ca3ca into main Jun 11, 2021
@oceandie oceandie deleted the zco_dev branch June 12, 2021 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Develop zgr and zco classes
2 participants