-
Notifications
You must be signed in to change notification settings - Fork 12
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
(0.5.0) Better experiment.bathymetry
method
#147
Conversation
use kwargs
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
@ashjbarnes, what is the purpose of |
regional_mom6/regional_mom6.py
Outdated
if not positive_down: | ||
## Ensure that coordinate is positive down! | ||
topog["depth"] *= -1 |
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.
why multiplying by -1 ensures that? there is an assumption that it wasn't already positive down which implies that the user was careful enough, right?
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.
No the user can provide their bathymetry without having to pre-multiply it. Passing the positive_down
argument just specifies what the raw data is and the code adjusts by multiplying by -1 or not. gebco for example has positive values for land and neg for ocean whereas MOM6 wants depth to be positive
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.
My point was that this implies that the user knows what “positive down” is. We can alternatively have the code here test to figure out whether the provided bathymetry needs to be multiplied w -1 or not and do that and print an info message to the user?
@ashjbarnes question: Is this method here an old name? regional-mom6/regional_mom6/regional_mom6.py Line 1287 in 4ceaf39
|
yeah that was an old thing! I'm fixing it now |
…ods, more documentation
what does the * do here? I'm not familiar with this notation
|
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.
If @navidcy is happy with the changes I've made then this is good to go. I've switched to calling everything 'bathymetry', added more docstrings, removed redundant make_topog argument and switched the coordinate names dict to kwargs instead
it splits the args from kwargs; |
@ashjbarnes, I'd like to automate this multiplication and remove the Could you give me an example of a vertical coordinate that it is |
That's what I'd hoped originally, but what ended up with me accidentally inverting the bathymetry! If the user gives the bathymetry for an existing MOM6 run, then it will have depths of 0 -> 6000. If you give it GEBCO it'll have depths of -6000-> 0 and positive values correspond to land. What do you think is a robust way for the model to assume correctly the orientation of the vertical coordinate? |
The vertical coordinate could be one of:
Whatever the vertical coordinate convention is we need to convert it to MOM6 convention, right? |
@ashjbarnes what do you think of the following? import numpy as np
def convert_to_MOM6_convention(vcoord):
'''
Converts the vertical coordinate (``vcoord``) to have the convention expected by
MOM6, that is positive values that depict the distance below sea level and with
ascending order. For example ``vcoord = [0, 10, 50, 100]``.
'''
# for single vertical layer config don't do anything
if len(vcoord)==1:
return vcoord
# ensure vcoord is numpy.array
vcoord = np.array(vcoord)
# if in descending order then flip them
if vcoord[1] > vcoord[0]:
ascending = True
elif vcoord[1] < vcoord[0]:
return convert_to_MOM6_convention(np.flip(vcoord))
else:
raise ValueError("vcoord seems constant...")
# if values are negative, convert to positive
if vcoord[1] > 0 and vcoord[0] >= 0:
is_positive = True
elif vcoord[1] < 0 and vcoord[0] <= 0:
return convert_to_MOM6_convention(-1 * vcoord)
else:
raise ValueError("vcoord has both positive and negative values...")
# if vcoord follows MOM6 convention then all is well
if is_positive and ascending:
return vcoord When I try it out: # test that convert_to_MOM6 does what is supposed to do
vcoords = ([0, 1, 2, 10],
[0, -1, -2, -10],
[10, 2, 1, 0],
[-10, -2, -1, 0],
np.array([0, 1, 2, 10]),
np.array([0, -1, -2, -10]),
np.array([10, 2, 1, 0]),
np.array([-10, -2, -1, 0]),
[0.2, 1, 2, 10],
[-0.2, -1, -2, -10],
[10, 2, 1, 0.2],
[-10, -2, -1, -0.2],
)
for vcoord in vcoords:
print(convert_to_MOM6_convention(vcoord)) gives [ 0 1 2 10]
[ 0 1 2 10]
[ 0 1 2 10]
[ 0 1 2 10]
[ 0 1 2 10]
[ 0 1 2 10]
[ 0 1 2 10]
[ 0 1 2 10]
[ 0.2 1. 2. 10. ]
[ 0.2 1. 2. 10. ]
[ 0.2 1. 2. 10. ]
[ 0.2 1. 2. 10. ] demonstrating that it does return things how MOM6 expect them? |
In MOM6 what values does land have? |
I decided to merge this and potentially deal with the |
experiment.bathymetry
methodexperiment.bathymetry
method
Gebco is more like [-5000...0...5000] How do we automatically tell which bits are land and which are ocean? That's the issue. I also don't think that whether it's 0,1,2,3 or 3,2,1,0 matters since it gets interpolated onto the base grid anyway |
Let's continue the discussion about potential elimination of |
use kwargs