当前位置: 首页>>代码示例>>Python>>正文


Python AuxCoord.convert_units方法代码示例

本文整理汇总了Python中iris.coords.AuxCoord.convert_units方法的典型用法代码示例。如果您正苦于以下问题:Python AuxCoord.convert_units方法的具体用法?Python AuxCoord.convert_units怎么用?Python AuxCoord.convert_units使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iris.coords.AuxCoord的用法示例。


在下文中一共展示了AuxCoord.convert_units方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _add_available_aux_coords

# 需要导入模块: from iris.coords import AuxCoord [as 别名]
# 或者: from iris.coords.AuxCoord import convert_units [as 别名]
    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))
开发者ID:duncanwp,项目名称:cis_plugins,代码行数:30,代码来源:echam_ham.py

示例2: _add_available_aux_coords

# 需要导入模块: from iris.coords import AuxCoord [as 别名]
# 或者: from iris.coords.AuxCoord import convert_units [as 别名]
    def _add_available_aux_coords(self, cube, filenames):
        import iris
        from iris.aux_factory import HybridPressureFactory
        from iris.coords import AuxCoord
        from iris.exceptions import CoordinateNotFoundError

        # Only do this for fields with a vertical component - this check is a bit hacky though (doesn't consider 3D with no time...)
        if cube.ndim == 4:
            # Only read the first file for these coefficients as they are time-independant and iris won't merge them
            hybrid_a = _get_cubes(filenames, 'hybrid A coefficient at layer midpoints')
            hybrid_b = _get_cubes(filenames, 'hybrid B coefficient at layer midpoints')

            hybrid_a_coord = AuxCoord(points=hybrid_a[0].data, long_name='hybrid A coefficient at layer midpoints', units='Pa')
            hybrid_b_coord = AuxCoord(points=hybrid_b[0].data, long_name='hybrid B coefficient at layer midpoints', units='1')

            if cube.coords('surface pressure'):
                surface_pressure = cube.coord('surface pressure')
            else:
                try:
                    # If there isn't a surface pressure coordinate we can try and pull out the lowest pressure level
                    surface_pressure_cubes = _get_cubes(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))
                except ValueError:
                    # Try and get it from the vphysc stream
                    v_files = ['_'.join(f.split('_')[:-1]) + '_vphysc.nc' for f in filenames]
                    try:
                        surface_pressure_cubes = _get_cubes(v_files, 'atmospheric pressure at interfaces',
                                                            callback=self.load_multiple_files_callback)
                    except:
                        # If we can't do that then just exit - there must be a cleaner way to do this...
                        return
                    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))

            # First convert the hybrid coefficients to hPa, so that air pressure will be in hPa
            hybrid_a_coord.convert_units('hPa')
            surface_pressure.convert_units('hPa')

            cube.add_aux_coord(hybrid_a_coord, (1,))
            cube.add_aux_coord(hybrid_b_coord, (1,))

            if len(cube.coords(long_name='hybrid level at layer midpoints')) > 0:
                cube.add_aux_factory(HybridPressureFactory(delta=hybrid_a_coord, sigma=hybrid_b_coord,
                                                           surface_air_pressure=surface_pressure))
开发者ID:duncanwp,项目名称:cis_plugins,代码行数:50,代码来源:echam_ham_63.py


注:本文中的iris.coords.AuxCoord.convert_units方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。