예제 #1
0
            # add the latitude and longitude coordinates to the cube, with mappings to data dimensions
            cube.add_dim_coord(lat_coord, 0)
            cube.add_dim_coord(lon_coord, 1)

            # implement standard iris callback capability. Although callbacks are not used in this example, the standard
            # mechanism for a custom loader to implement a callback is shown:
            cube = iris.io.run_callback(callback, cube, [header, field_headings, data_array], filename)

            # yield the cube created (the loop will continue when the next() element is requested)
            yield cube


# Create a format_picker specification of the NAME file format giving it a
# priority greater than the built in NAME loader.
_NAME_III_spec = format_picker.FormatSpecification('Name III', format_picker.LeadingLine(),
                                      lambda line: line.startswith("NAME III"), NAME_to_cube,
                                      priority=6)

# Register the NAME loader with iris
iris.fileformats.FORMAT_AGENT.add_spec(_NAME_III_spec)



# ---------------------------------------------
# |          Using the new loader             |
# ---------------------------------------------

def main():
    fname = iris.sample_data_path('NAME_output.txt')

    boundary_volc_ash_constraint = iris.Constraint('VOLCANIC_ASH_AIR_CONCENTRATION', flight_level='From FL000 - FL200')
            # implement standard iris callback capability. Although callbacks are not used in this example, the standard
            # mechanism for a custom loader to implement a callback is shown:
            cube = iris.io.run_callback(callback, cube,
                                        [header, field_headings, data_array],
                                        filename)

            # yield the cube created (the loop will continue when the next() element is requested)
            yield cube


# Create a format_picker specification of the NAME file format giving it a priority below NetCDF, GRIB & PP etc.
_NAME_III_spec = format_picker.FormatSpecification(
    'Name III',
    format_picker.LEADING_LINE,
    lambda line: line.startswith("NAME III"),
    NAME_to_cube,
    priority=3,
)

# Register the NAME loader with iris
iris.fileformats.FORMAT_AGENT.add_spec(_NAME_III_spec)

# ---------------------------------------------
# |          Using the new loader             |
# ---------------------------------------------


def main():
    fname = iris.sample_data_path('NAME_output.txt')
예제 #3
0
        self._endian = endian
        super(LeadingLineUff, self).__init__(requires_fh=True)

    def get_element(self, basename, file_handle):
        with uff.FortranFile(file_handle.name, endian=self._endian) as uffile:
            try:
                leading_line = uffile.readline()
            except IOError:
                leading_line = ''
        return leading_line


bpch_spec = fp.FormatSpecification(
    'Binary Punch File (BPCH) v2 (big-endian)',
    LeadingLineUff('>'),
    lambda line: line.lstrip().startswith(bpch.FILETYPE02),
    cubes_from_bpch,
    priority=7
)
iris.fileformats.FORMAT_AGENT.add_spec(bpch_spec)
bpch_spec_le = fp.FormatSpecification(
    'Binary Punch File (BPCH) v2 (little-endian)',
    LeadingLineUff('<'),
    lambda line: line.lstrip().startswith(bpch.FILETYPE02),
    lambda filenames, callback=None: cubes_from_bpch(filenames, callback,
                                                     endian='<'),
    priority=6
)
iris.fileformats.FORMAT_AGENT.add_spec(bpch_spec_le)
# TODO: CTM bin 4D  format (?)