forked from SciTools/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Making coords into cubes and vice-versa #61
Open
pp-mo
wants to merge
5
commits into
coord_as_cube_BRANCHOFF
Choose a base branch
from
coord_as_cube
base: coord_as_cube_BRANCHOFF
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0db5f58
Very crude placeholder for cubelike_array_as_cube ideas.
pp-mo 282d5bd
Pep8 fix.
pp-mo 1ad2852
Added attach_cube_as_aux_coord, currently notional = untested.
pp-mo 8ac8de9
More pep8.
pp-mo 0dc932d
Obvious bugfixes in 'attach_cube_as_aux_coord', still untested.
pp-mo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
lib/iris/tests/unit/util/test_cubelike_array_as_cube.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# (C) British Crown Copyright 2013 - 2015, Met Office | ||
# | ||
# This file is part of Iris. | ||
# | ||
# Iris is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Iris is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Iris. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
Test function :func:`iris.util.cubelike_array_as_cube`. | ||
|
||
FOR NOW: not proper tests, just exercising + not getting errors. | ||
ALSO for now we are cheating and *also* testing cube.coord_as_cube here. | ||
|
||
""" | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
from six.moves import (filter, input, map, range, zip) # noqa | ||
|
||
# Import iris.tests first so that some things can be initialised before | ||
# importing anything else. | ||
import iris.tests as tests | ||
|
||
import numpy as np | ||
|
||
import iris | ||
import iris.tests | ||
import iris.tests.stock as istk | ||
|
||
from iris.util import cubelike_array_as_cube | ||
|
||
|
||
class Test_coord_as_cube(iris.tests.IrisTest): | ||
def setUp(self): | ||
self.cube_multidim = istk.simple_2d_w_multidim_coords() | ||
self.cube_3d = istk.realistic_3d() | ||
self.cubes = [self.cube_3d, self.cube_multidim] | ||
|
||
def test_allcoords(self): | ||
for i_test, cube in enumerate(self.cubes): | ||
print() | ||
print('Test #{}. cube =...'.format(i_test)) | ||
print(cube) | ||
for coord in cube.coords(): | ||
if cube.coord_dims(coord): | ||
# Extract and print non-scalar coords. | ||
coord_name = coord.name() | ||
print('Extract {}:'.format(coord_name)) | ||
coord_cube = cube.coord_as_cube(coord_name) | ||
print(coord_cube) | ||
|
||
|
||
class Test_cubelike_array_as_cube(iris.tests.IrisTest): | ||
def setUp(self): | ||
self.cube_multidim = istk.simple_2d_w_multidim_coords() | ||
self.cube_3d = istk.realistic_3d() | ||
|
||
def test1(self): | ||
print() | ||
print('New data over 1d, dim-0:') | ||
print(cubelike_array_as_cube(np.arange(3), self.cube_multidim, (0,), | ||
name='odd_data_dim0', units='m s-1')) | ||
print() | ||
print('New data over 1d, dim-1:') | ||
print(cubelike_array_as_cube(np.arange(4), self.cube_multidim, (1,), | ||
name='odd_data_dim1', units='K')) | ||
|
||
print() | ||
print('New data over 2d:') | ||
print(cubelike_array_as_cube(np.zeros((3, 4)), | ||
self.cube_multidim, (0, 1,), | ||
long_name='longname_2d', units='rad s-1')) | ||
|
||
print() | ||
print('Transposed new data over 2d:') | ||
print(cubelike_array_as_cube( | ||
np.zeros((4, 3)), self.cube_multidim, (1, 0,), | ||
standard_name='model_level_number', units='1')) | ||
|
||
print() | ||
print('Data over longitude+time:') | ||
print(cubelike_array_as_cube(np.zeros((11, 7)), self.cube_3d, (2, 0), | ||
name='twod_lon_time', units='m')) | ||
|
||
print() | ||
print('Data over time+longitude, specified by name:') | ||
print(cubelike_array_as_cube(np.zeros((7, 11)), | ||
self.cube_3d, ('time', 'grid_longitude'), | ||
name='twod_time_lons', units='m')) | ||
|
||
|
||
if __name__ == '__main__': | ||
tests.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 code probably now wants to be replaced with use of ".metadata" and the common-metadata approach generally.
I think all that stuff is new since this was written !