-
Notifications
You must be signed in to change notification settings - Fork 316
Provide info on pp-field indices in the file for structured um loads. #2977
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| * The :class:`iris.fileformats.um.FieldCollation` objects, which are passed | ||
| into load callbacks when using | ||
| :func:`iris.fileformats.um.structured_um_loading`, now | ||
| have the additional properties : | ||
| :data:`iris.fileformats.um.FieldCollation.data_filepath` and | ||
| :data:`iris.fileformats.um.FieldCollation.data_field_indices`. | ||
| These provide the file locations of the original data fields, which are | ||
| otherwise lost in the structured loading process. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| Code for fast loading of structured UM data. | ||
|
|
||
| This module defines which pp-field elements take part in structured loading, | ||
| and provides creation of :class:`FieldCollation` objects from lists of | ||
| and provides creation of :class:`BasicFieldCollation` objects from lists of | ||
| :class:`iris.fileformats.pp.PPField`. | ||
|
|
||
| """ | ||
|
|
@@ -36,18 +36,18 @@ | |
| optimal_array_structure | ||
|
|
||
|
|
||
| class FieldCollation(object): | ||
| class BasicFieldCollation(object): | ||
| """ | ||
| An object representing a group of UM fields with array structure that can | ||
| be vectorized into a single cube. | ||
|
|
||
| For example: | ||
|
|
||
| Suppose we have a set of 28 fields repeating over 7 vertical levels for | ||
| each of 4 different data times. If a FieldCollation is created to contain | ||
| these, it can identify that this is a 4*7 regular array structure. | ||
| each of 4 different data times. If a BasicFieldCollation is created to | ||
| contain these, it can identify that this is a 4*7 regular array structure. | ||
|
|
||
| This FieldCollation will then have the following properties: | ||
| This BasicFieldCollation will then have the following properties: | ||
|
|
||
| * within 'element_arrays_and_dims' : | ||
| Element 'blev' have the array shape (7,) and dims of (1,). | ||
|
|
@@ -259,7 +259,9 @@ def _um_collation_key_function(field): | |
| # vector pseudo-level coordinate directly in the structured load analysis. | ||
|
|
||
|
|
||
| def group_structured_fields(field_iterator): | ||
| def group_structured_fields(field_iterator, | ||
| collation_class=BasicFieldCollation, | ||
| **collation_kwargs): | ||
| """ | ||
| Collect structured fields into identified groups whose fields can be | ||
| combined to form a single cube. | ||
|
|
@@ -269,6 +271,13 @@ def group_structured_fields(field_iterator): | |
| * field_iterator (iterator of :class:`iris.fileformats.pp.PPField`): | ||
| A source of PP or FF fields. N.B. order is significant. | ||
|
|
||
| Kwargs: | ||
|
|
||
| * collation_class (class): | ||
| Type of collation wrapper to create from each group of fields. | ||
| * collation_kwargs (dict): | ||
| Additional constructor keywords for collation creation. | ||
|
|
||
| The function sorts and collates on phenomenon-relevant metadata only, | ||
| defined as the field components: 'lbuser[3]' (stash), 'lbproc' (statistic), | ||
| 'lbuser[6]' (model). | ||
|
|
@@ -285,8 +294,8 @@ def group_structured_fields(field_iterator): | |
| :func:`iris.fileformats.pp_load_rules._convert_time_coords`). | ||
|
|
||
| Returns: | ||
| A generator of FieldCollation objects, each of which contains a single | ||
| collated group from the input fields. | ||
| A generator of BasicFieldCollation objects, each of which contains a | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a small point perhaps, but it's not guaranteed that the generator will produce
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
| single collated group from the input fields. | ||
|
|
||
| .. note:: | ||
|
|
||
|
|
@@ -297,4 +306,4 @@ def group_structured_fields(field_iterator): | |
| """ | ||
| _fields = sorted(field_iterator, key=_um_collation_key_function) | ||
| for _, fields in itertools.groupby(_fields, _um_collation_key_function): | ||
| yield FieldCollation(tuple(fields)) | ||
| yield collation_class(tuple(fields), **collation_kwargs) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # (C) British Crown Copyright 2018, 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/>. | ||
| """ | ||
| Unit tests for the class | ||
| :class:`iris.fileformats.um._fast_load.FieldCollation`. | ||
|
|
||
| This only tests the additional functionality for recording file locations of | ||
| PPFields that make loaded cubes. | ||
| The original class is the baseclass of this, now renamed 'BasicFieldCollation'. | ||
|
|
||
| """ | ||
|
|
||
| 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 | ||
|
|
||
| from iris.tests.integration.fast_load.test_fast_load import Mixin_FieldTest | ||
|
|
||
|
|
||
| class TestFastCallbackLocationInfo(Mixin_FieldTest, tests.IrisTest): | ||
| do_fast_loads = True | ||
|
|
||
| def setUp(self): | ||
| # Call parent setup. | ||
| super(TestFastCallbackLocationInfo, self).setUp() | ||
|
|
||
| # Create a basic load test case. | ||
| self.callback_collations = [] | ||
| self.callback_filepaths = [] | ||
|
|
||
| def fast_load_callback(cube, collation, filename): | ||
| self.callback_collations.append(collation) | ||
| self.callback_filepaths.append(filename) | ||
|
|
||
| flds = self.fields(c_t='11112222', c_h='11221122', phn='01010101') | ||
| self.test_filepath = self.save_fieldcubes(flds) | ||
| iris.load(self.test_filepath, callback=fast_load_callback) | ||
|
|
||
| def test_callback_collations_filepaths(self): | ||
| self.assertEqual(len(self.callback_collations), 2) | ||
| self.assertEqual(self.callback_collations[0].data_filepath, | ||
| self.test_filepath) | ||
| self.assertEqual(self.callback_collations[1].data_filepath, | ||
| self.test_filepath) | ||
|
|
||
| def test_callback_collations_field_indices(self): | ||
| self.assertEqual( | ||
| self.callback_collations[0].data_field_indices.dtype, np.int64) | ||
| self.assertArrayEqual( | ||
| self.callback_collations[0].data_field_indices, | ||
| [[1, 3], [5, 7]]) | ||
|
DPeterK marked this conversation as resolved.
|
||
|
|
||
| self.assertEqual( | ||
| self.callback_collations[1].data_field_indices.dtype, np.int64) | ||
| self.assertArrayEqual( | ||
| self.callback_collations[1].data_field_indices, | ||
| [[0, 2], [4, 6]]) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| tests.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,8 @@ | |
| from cftime import datetime | ||
| import numpy as np | ||
|
|
||
| from iris.fileformats.um._fast_load_structured_fields import FieldCollation | ||
| from iris.fileformats.um._fast_load_structured_fields \ | ||
| import BasicFieldCollation as FieldCollation | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pp-mo don't forget to also change the module docstring to also point to this new class.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, good spot !
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have also changed the |
||
| import iris.fileformats.pp | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.