def _add_available_aux_coords(self, cube, filenames): from iris.aux_factory import HybridPressureFactory from iris.coords import AuxCoord from iris.exceptions import CoordinateNotFoundError import iris if cube.coords('hybrid A coefficient at layer midpoints'): # First convert the hybrid coefficients to hPa, so that air pressure will be in hPa cube.coord('hybrid A coefficient at layer midpoints').convert_units('hPa') try: surface_pressure = cube.coord('surface pressure') except iris.exceptions.CoordinateNotFoundError as e: # If there isn't a surface pressure coordinate we can try and pull out the lowest pressure level with demote_warnings(): surface_pressure_cubes = iris.load(filenames, 'atmospheric pressure at interfaces', callback=self.load_multiple_files_callback) surface_pressure_cube = surface_pressure_cubes.concatenate_cube()[:, -1, :, :] surface_pressure = AuxCoord(points=surface_pressure_cube.data, long_name='surface pressure', units='Pa') cube.add_aux_coord(surface_pressure, (0, 2, 3)) surface_pressure.convert_units('hPa') if len(cube.coords(long_name='hybrid level at layer midpoints')) > 0: cube.add_aux_factory(HybridPressureFactory(delta=cube.coord('hybrid A coefficient at layer midpoints'), sigma=cube.coord('hybrid B coefficient at layer midpoints'), surface_air_pressure=surface_pressure))
def _add_available_aux_coords(self, cube, filenames): from iris.coords import AuxCoord import iris with demote_warnings(): height_cube = iris.load_cube(filenames, 'geometric height at full level center', callback=self.load_multiple_files_callback) height = AuxCoord(points=height_cube.data, long_name='geometric height at full level center', units='m') cube.add_aux_coord(height, (1, 2, 3))
def _add_available_aux_coords(self, cube, filenames): from iris.coords import AuxCoord import iris with demote_warnings(): height_cube = iris.load_cube( filenames, 'geometric height at full level center', callback=self.load_multiple_files_callback) height = AuxCoord(points=height_cube.data, long_name='geometric height at full level center', units='m') cube.add_aux_coord(height, (1, 2, 3))
def _get_cubes(filenames, constraints=None, callback=None): import iris # Removes warnings and prepares for future Iris change iris.FUTURE.netcdf_promote = True filenames_key = tuple(filenames) if filenames_key in gd.CACHED_CUBES: all_cubes = gd.CACHED_CUBES[filenames_key] # print("Reading cached files: {}".format(filenames_key)) else: with demote_warnings(): all_cubes = iris.load_raw(filenames, callback=callback) gd.CACHED_CUBES[filenames_key] = all_cubes # print("Caching files: {}".format(filenames_key)) if constraints is not None: cubes = all_cubes.extract(constraints=constraints) else: cubes = all_cubes return cubes
def _add_available_aux_coords(self, cube, filenames): from iris.aux_factory import HybridPressureFactory from iris.coords import AuxCoord from iris.exceptions import CoordinateNotFoundError import iris try: surface_pressure = cube.coord('surface pressure') except iris.exceptions.CoordinateNotFoundError as e: # If there isn't a surface pressure coordinate we can try and pull out the lowest pressure level with demote_warnings(): surface_pressure_cubes = iris.load(filenames, 'atmospheric pressure at interfaces', callback=self.load_multiple_files_callback) surface_pressure_cube = surface_pressure_cubes.concatenate_cube()[:, -1, :, :] surface_pressure = AuxCoord(points=surface_pressure_cube.data, long_name='surface pressure', units='Pa') cube.add_aux_coord(surface_pressure, (0, 2, 3)) if len(cube.coords(long_name='hybrid level at layer midpoints')) > 0: cube.add_aux_factory(HybridPressureFactory(delta=cube.coord('hybrid A coefficient at layer midpoints'), sigma=cube.coord('hybrid B coefficient at layer midpoints'), surface_air_pressure=surface_pressure))