コード例 #1
0
def main(argv=None):
    """
    Translate meta-data relating to the grid_id attribute from StaGE version
    1.1.0 to StaGE version 1.2.0.
    """

    cli_definition = {
        'central_arguments': ['input_file', 'output_file'],
        'specific_arguments': [],
        'description': ('Translates meta-data relating to the '
                        'grid_id attribute from StaGE version '
                        '1.1.0 to StaGE version 1.2.0. '
                        'Files that have no "grid_id" attribute '
                        'are not recognised as v1.1.0 and are '
                        'not changed. Has no effect if '
                        'input_file and output_file are the '
                        'same and contain a cube with non '
                        'v1.1.0 meta-data')
    }

    args = ArgParser(**cli_definition).parse_args(args=argv)

    cube = load_cube(args.input_filepath)
    cube_changed = update_stage_v110_metadata(cube)

    # Create normalised file paths to make them comparable
    in_file_norm = os.path.normpath(args.input_filepath)
    out_file_norm = os.path.normpath(args.output_filepath)
    if cube_changed or in_file_norm != out_file_norm:
        # Ensure data are not lazy in case we are writing back to the same
        # file.
        cube.data
        save_netcdf(cube, args.output_filepath)
コード例 #2
0
 def test_basic(self):
     """Test that cube is unchanged and function returns False"""
     result = self.cube.copy()
     output = update_stage_v110_metadata(result)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertArrayEqual(result.data, self.cube.data)
     self.assertEqual(result.attributes, self.cube.attributes)
     self.assertFalse(output)
コード例 #3
0
 def test_update_ukv(self):
     """Test that cube attributes from ukv 1.1.0 are updated"""
     self.cube.attributes['grid_id'] = 'ukvx_standard_v1'
     output = update_stage_v110_metadata(self.cube)
     self.assertTrue('mosg__grid_type' in self.cube.attributes.keys())
     self.assertTrue('mosg__model_configuration' in
                     self.cube.attributes.keys())
     self.assertTrue('mosg__grid_domain' in self.cube.attributes.keys())
     self.assertTrue('mosg__grid_version' in self.cube.attributes.keys())
     self.assertFalse('grid_id' in self.cube.attributes.keys())
     self.assertEqual('standard', self.cube.attributes['mosg__grid_type'])
     self.assertEqual('uk_det',
                      self.cube.attributes['mosg__model_configuration'])
     self.assertEqual('uk_extended',
                      self.cube.attributes['mosg__grid_domain'])
     self.assertEqual('1.1.0', self.cube.attributes['mosg__grid_version'])
     self.assertTrue(output)
コード例 #4
0
def process(cube):
    """Update grid_id meta-data for StaGE.

    Translates meta-data relating to the grid_id attribute from StaGE
    version 1.1.0 to StaGE version 1.2.0.
    Files that have no "grid_id" attribute are not recognised as v1.1.0 and
    are not changed. Has no effect if input_file and output_file are the
    same and contain a cube with non v1.1.0 meta-data.

    Args:
        cube (iris.cube.Cube):
            Cube to be changed.

    Returns:
        result (iris.cube.Cube):
            Processed Cube.

    """
    result = update_stage_v110_metadata(cube)
    return result