-
Notifications
You must be signed in to change notification settings - Fork 65
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
Read mitgrid files #114
Read mitgrid files #114
Conversation
gridfile must contain <NFACET> as wildcard (e.g. tile<NFACET>.mitgrid) | ||
nx: int | ||
size of the face in the x direction | ||
ny: int |
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.
E501 line too long (81 > 79 characters)
xmitgcm/utils.py
Outdated
# create placeholders for data | ||
gridfields= {} | ||
for field in file_metadata['fldList']: | ||
gridfields.update({field: np.zeros(shape_out)}) |
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.
F841 local variable 'shape' is assigned to but never used
nygrid = file_metadata['nx'] + 1 | ||
|
||
grid_metadata.update({'nx': nxgrid, 'ny': nygrid, | ||
'has_faces': False}) |
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.
E501 line too long (80 > 79 characters)
gridfile: str | ||
gridfile must contain <NFACET> as wildcard (e.g. tile<NFACET>.mitgrid) | ||
nx: int | ||
size of the face in the x direction |
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.
E501 line too long (81 > 79 characters)
|
||
# create placeholders for data | ||
gridfields = {} | ||
for field in file_metadata['fldList']: |
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.
F841 local variable 'shape' is assigned to but never used
nxgrid = file_metadata['ny_facets'][kfacet] + 1 | ||
nygrid = file_metadata['nx'] + 1 | ||
|
||
grid_metadata.update({'nx': nxgrid, 'ny': nygrid, |
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.
E501 line too long (80 > 79 characters)
Codecov Report
@@ Coverage Diff @@
## master #114 +/- ##
=========================================
+ Coverage 92.28% 93.59% +1.3%
=========================================
Files 4 4
Lines 830 890 +60
Branches 190 203 +13
=========================================
+ Hits 766 833 +67
+ Misses 38 32 -6
+ Partials 26 25 -1
Continue to review full report at Codecov.
|
gridfile: str | ||
gridfile must contain <NFACET> as wildcard (e.g. tile<NFACET>.mitgrid) | ||
nx: int | ||
size of the face in the x direction |
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.
W291 trailing whitespace
This looks very useful! Tests and documentation are necessary. |
xmitgcm/utils.py
Outdated
'RAS': (['face', 'j_g', 'i'], gridfields['RAS']), | ||
'DXG': (['face', 'j_g', 'i'], gridfields['DXG']), | ||
'DYG': (['face', 'j', 'i_g'], gridfields['DYG']) | ||
}) |
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.
This dataset is missing the coordinates for j
and i
. In a regular xmitgcm dataset, these variables have explicit coordinates.
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.
done
|
||
for field in file_metadata['fldList']: | ||
# symetrize | ||
tmp = rawfields[field][:, :, :-1, :-1].squeeze() |
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.
It occurs to me that we are potentially throwing away some useful information here. One thing that I dislike about MDS output is that it throws away the outer cell face point. Might be worth having an option to keep those outer elements for variables on the u and v 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.
it's all zeros so no worries.
import numpy as np
all = np.fromfile('tile003.mitgrid','>d')
XC = all[:91*91]
XC = np.reshape(XC,(91,91))
In [14]: XC[-1,:]
Out[14]:
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0.])
In [15]: XC[:,-1]
Out[15]:
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0.])
xmitgcm/utils.py
Outdated
if file_metadata['transpose_face'][face]: | ||
dataface = dataface.transpose() | ||
# assign values | ||
gridfields[field][face, :, :] = dataface |
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.
Doesn't this same logic already live elsewhere in xmitgcm? If so, it's probably better to re-call that function.
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 haven't seen anywhere in xmitgcm functions working on multi-files but I can have missed it.
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.
Does this work with dask?
xmitgcm/utils.py
Outdated
grid_metadata.update({'nx': nxgrid, 'ny': nygrid, | ||
'has_faces': False}) | ||
|
||
raw = read_all_variables(grid_metadata['vars'], grid_metadata) |
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.
Is there a dask option here?
I'm thinking about what will happen if I run this on the LLC4320 mitgrid files.
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.
done
xmitgcm/test/test_utils.py
Outdated
use_dask=False, | ||
extra_metadata=md) | ||
assert type(ds) == xarray.Dataset | ||
assert ds['XC'].values.shape == expected['shape'] |
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.
F405 'xarray' may be undefined, or defined from star imports: xmitgcm.test.test_xmitgcm_common
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.
maybe add a check here that all the expected variables are in 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.
Also need to check that use_dask
works as expected and doesn't trigger eagerreading of the data.
precision='double', endian='>', | ||
use_dask=False, | ||
extra_metadata=md) | ||
assert type(ds) == xarray.Dataset |
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.
F405 'xarray' may be undefined, or defined from star imports: xmitgcm.test.test_xmitgcm_common
archive for grid tests are on figshare. Build will work when #115 is merged |
281f0bb
to
df9b9ca
Compare
|
||
# passing llc without metadata should fail | ||
if expected['geometry'] == 'llc': | ||
with pytest.raises(ValueError): |
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.
F405 'pytest' may be undefined, or defined from star imports: xmitgcm.test.test_xmitgcm_common
@rabernat strickler-ci is really nitpicking, can we merge this anyway? I will fill in the blanks with the cube sphere grid in the cs branch. Not very orthogonal here I'm sorry! |
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.
Looking good. Just want to verify that the use_dask
option actually works as described. So that needs a test.
xmitgcm/test/test_utils.py
Outdated
use_dask=False, | ||
extra_metadata=md) | ||
assert type(ds) == xarray.Dataset | ||
assert ds['XC'].values.shape == expected['shape'] |
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.
maybe add a check here that all the expected variables are in ds
?
xmitgcm/utils.py
Outdated
gridfields.update({field: np.zeros(shape)}) | ||
|
||
if geometry == 'llc': | ||
for kfacet in np.arange(nfacets): |
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.
range(nfacets)
would be better here
xmitgcm/utils.py
Outdated
if file_metadata['transpose_face'][face]: | ||
dataface = dataface.transpose() | ||
# assign values | ||
gridfields[field][face, :, :] = dataface |
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.
Does this work with dask?
xmitgcm/test/test_utils.py
Outdated
use_dask=False, | ||
extra_metadata=md) | ||
assert type(ds) == xarray.Dataset | ||
assert ds['XC'].values.shape == expected['shape'] |
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.
Also need to check that use_dask
works as expected and doesn't trigger eagerreading of the data.
@@ -843,3 +844,39 @@ def test_get_extra_metadata(domain, nx): | |||
|
|||
with pytest.raises(ValueError): | |||
em = get_extra_metadata(domain='notinlist', nx=nx) | |||
|
|||
|
|||
@pytest.mark.parametrize("usedask", [True, False]) |
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.
F405 'pytest' may be undefined, or defined from star imports: xmitgcm.test.test_xmitgcm_common
# create placeholders for data | ||
gridfields = {} | ||
for field in file_metadata['fldList']: | ||
gridfields.update({field: None}) |
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.
F841 local variable 'shape' is assigned to but never used
gridfields = {} | ||
for field in file_metadata['fldList']: | ||
gridfields.update({field: None}) | ||
|
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.
F841 local variable 'chunks' is assigned to but never used
@rabernat dask should work with global llc grids (not regional because of the padding), the dsa.concatenate on l1260 in utils.py makes the results being a dask array wether the input is a dask or numpy array so I can't test for the type in the output. |
Ok, then maybe we can come back to this in a future PR. I would prefer to use a version of concatenate that returns numpy arrays for numpy inputs. We have something like that in xgcm: |
* start working on reading grid * read ext grid * works for llc * works with aste+docstring * Fixing style errors. * fix cosmetics * fix cosmetics * fixes * Fixing style errors. * testing * Fixing style errors. * fix strickler * add link/md5 * fix strickler * more testing * Fixing style errors. * fix strickler * fix strickler * make dask lazy * Fixing style errors. * fix from strickler
fixes #14
tested with llc90 and aste. there is room to add cube sphere support once #91 is resolved
and it would be also easy to make it work with simpler geometries, although I have not seen
yet the case of users using input grid files in those.