def _non_std_cross_section_rules(cube, pp): """ Rules for applying non-standard cross-sections to the PP field. Args: cube: the cube being saved as a series of PP fields. pp: the current PP field having save rules applied. Returns: The PP field with updated metadata. """ # Define commonly-used coords. air_pres_coord = vector_coord(cube, 'air_pressure') depth_coord = vector_coord(cube, 'depth') eta_coord = vector_coord(cube, 'eta') lat_coord = vector_coord(cube, 'latitude') time_coord = vector_coord(cube, 'time') # Non-standard cross-section with bounds - x=latitude, y=air_pressure. if (air_pres_coord is not None and not air_pres_coord.circular and air_pres_coord.has_bounds() and lat_coord is not None and not lat_coord.circular and lat_coord.has_bounds()): pp.lbcode = 10000 + int(100 * 10) + 1 pp.bgor = 0 pp.y = air_pres_coord.points pp.y_lower_bound = air_pres_coord.bounds[:, 0] pp.y_upper_bound = air_pres_coord.bounds[:, 1] pp.x = lat_coord.points pp.x_lower_bound = lat_coord.bounds[:, 0] pp.x_upper_bound = lat_coord.bounds[:, 1] pp.lbrow = air_pres_coord.shape[0] pp.lbnpt = lat_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - x=latitude, y=depth. if (depth_coord is not None and not depth_coord.circular and depth_coord.has_bounds() and lat_coord is not None and not lat_coord.circular and lat_coord.has_bounds()): pp.lbcode = 10000 + int(100 * 10) + 4 pp.bgor = 0 pp.y = depth_coord.points pp.y_lower_bound = depth_coord.bounds[:, 0] pp.y_upper_bound = depth_coord.bounds[:, 1] pp.x = lat_coord.points pp.x_lower_bound = lat_coord.bounds[:, 0] pp.x_upper_bound = lat_coord.bounds[:, 1] pp.lbrow = depth_coord.shape[0] pp.lbnpt = lat_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - x=latitude, y=eta. if (eta_coord is not None and not eta_coord.circular and eta_coord.has_bounds() and lat_coord is not None and not lat_coord.circular and lat_coord.has_bounds()): pp.lbcode = 10000 + int(100 * 10) + 3 pp.bgor = 0 pp.y = eta_coord.points pp.y_lower_bound = eta_coord.bounds[:, 0] pp.y_upper_bound = eta_coord.bounds[:, 1] pp.x = lat_coord.points pp.x_lower_bound = lat_coord.bounds[:, 0] pp.x_upper_bound = lat_coord.bounds[:, 1] pp.lbrow = eta_coord.shape[0] pp.lbnpt = lat_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - x=days (360 calendar), y=depth. if (depth_coord is not None and not depth_coord.circular and depth_coord.has_bounds() and time_coord is not None and not time_coord.circular and time_coord.has_bounds()): pp.lbcode = 10000 + int(100 * 23) + 4 pp.bgor = 0 pp.y = depth_coord.points pp.y_lower_bound = depth_coord.bounds[:, 0] pp.y_upper_bound = depth_coord.bounds[:, 1] pp.x = time_coord.points pp.x_lower_bound = time_coord.bounds[:, 0] pp.x_upper_bound = time_coord.bounds[:, 1] pp.lbrow = depth_coord.shape[0] pp.lbnpt = time_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - # x=days (360 calendar), y=air_pressure. if (air_pres_coord is not None and not air_pres_coord.circular and air_pres_coord.has_bounds() and time_coord is not None and not time_coord.circular and time_coord.has_bounds()): pp.lbcode = 10000 + int(100 * 23) + 1 pp.bgor = 0 pp.y = air_pres_coord.points pp.y_lower_bound = air_pres_coord.bounds[:, 0] pp.y_upper_bound = air_pres_coord.bounds[:, 1] pp.x = time_coord.points pp.x_lower_bound = time_coord.bounds[:, 0] pp.x_upper_bound = time_coord.bounds[:, 1] pp.lbrow = air_pres_coord.shape[0] pp.lbnpt = time_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 return pp
def _non_std_cross_section_rules(cube, pp): """ Rules for applying non-standard cross-sections to the PP field. Args: cube: the cube being saved as a series of PP fields. pp: the current PP field having save rules applied. Returns: The PP field with updated metadata. """ # Define commonly-used coords. air_pres_coord = vector_coord(cube, 'air_pressure') depth_coord = vector_coord(cube, 'depth') eta_coord = vector_coord(cube, 'eta') lat_coord = vector_coord(cube, 'latitude') time_coord = vector_coord(cube, 'time') # Non-standard cross-section with bounds - x=latitude, y=air_pressure. if (air_pres_coord is not None and not air_pres_coord.circular and air_pres_coord.has_bounds() and lat_coord is not None and not lat_coord.circular and lat_coord.has_bounds()): pp.lbcode = 10000 + int(100*10) + 1 pp.bgor = 0 pp.y = air_pres_coord.points pp.y_lower_bound = air_pres_coord.bounds[:, 0] pp.y_upper_bound = air_pres_coord.bounds[:, 1] pp.x = lat_coord.points pp.x_lower_bound = lat_coord.bounds[:, 0] pp.x_upper_bound = lat_coord.bounds[:, 1] pp.lbrow = air_pres_coord.shape[0] pp.lbnpt = lat_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - x=latitude, y=depth. if (depth_coord is not None and not depth_coord.circular and depth_coord.has_bounds() and lat_coord is not None and not lat_coord.circular and lat_coord.has_bounds()): pp.lbcode = 10000 + int(100*10) + 4 pp.bgor = 0 pp.y = depth_coord.points pp.y_lower_bound = depth_coord.bounds[:, 0] pp.y_upper_bound = depth_coord.bounds[:, 1] pp.x = lat_coord.points pp.x_lower_bound = lat_coord.bounds[:, 0] pp.x_upper_bound = lat_coord.bounds[:, 1] pp.lbrow = depth_coord.shape[0] pp.lbnpt = lat_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - x=latitude, y=eta. if (eta_coord is not None and not eta_coord.circular and eta_coord.has_bounds() and lat_coord is not None and not lat_coord.circular and lat_coord.has_bounds()): pp.lbcode = 10000 + int(100*10) + 3 pp.bgor = 0 pp.y = eta_coord.points pp.y_lower_bound = eta_coord.bounds[:, 0] pp.y_upper_bound = eta_coord.bounds[:, 1] pp.x = lat_coord.points pp.x_lower_bound = lat_coord.bounds[:, 0] pp.x_upper_bound = lat_coord.bounds[:, 1] pp.lbrow = eta_coord.shape[0] pp.lbnpt = lat_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - x=days (360 calendar), y=depth. if (depth_coord is not None and not depth_coord.circular and depth_coord.has_bounds() and time_coord is not None and not time_coord.circular and time_coord.has_bounds()): pp.lbcode = 10000 + int(100*23) + 4 pp.bgor = 0 pp.y = depth_coord.points pp.y_lower_bound = depth_coord.bounds[:, 0] pp.y_upper_bound = depth_coord.bounds[:, 1] pp.x = time_coord.points pp.x_lower_bound = time_coord.bounds[:, 0] pp.x_upper_bound = time_coord.bounds[:, 1] pp.lbrow = depth_coord.shape[0] pp.lbnpt = time_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 # Non-standard cross-section with bounds - # x=days (360 calendar), y=air_pressure. if (air_pres_coord is not None and not air_pres_coord.circular and air_pres_coord.has_bounds() and time_coord is not None and not time_coord.circular and time_coord.has_bounds()): pp.lbcode = 10000 + int(100*23) + 1 pp.bgor = 0 pp.y = air_pres_coord.points pp.y_lower_bound = air_pres_coord.bounds[:, 0] pp.y_upper_bound = air_pres_coord.bounds[:, 1] pp.x = time_coord.points pp.x_lower_bound = time_coord.bounds[:, 0] pp.x_upper_bound = time_coord.bounds[:, 1] pp.lbrow = air_pres_coord.shape[0] pp.lbnpt = time_coord.shape[0] pp.bzx = pp.bzy = pp.bdx = pp.bdy = 0 return pp
def _grid_and_pole_rules(cube, pp): """ Rules for setting the horizontal grid and pole location of the PP field. Args: cube: the cube being saved as a series of PP fields. pp: the current PP field having save rules applied. Returns: The PP field with updated metadata. """ lon_coord = vector_coord(cube, 'longitude') grid_lon_coord = vector_coord(cube, 'grid_longitude') lat_coord = vector_coord(cube, 'latitude') grid_lat_coord = vector_coord(cube, 'grid_latitude') if lon_coord and not is_regular(lon_coord): pp.bzx = 0 pp.bdx = 0 pp.lbnpt = lon_coord.shape[0] pp.x = lon_coord.points elif grid_lon_coord and not is_regular(grid_lon_coord): pp.bzx = 0 pp.bdx = 0 pp.lbnpt = grid_lon_coord.shape[0] pp.x = grid_lon_coord.points elif lon_coord and is_regular(lon_coord): pp.bzx = lon_coord.points[0] - regular_step(lon_coord) pp.bdx = regular_step(lon_coord) pp.lbnpt = len(lon_coord.points) elif grid_lon_coord and is_regular(grid_lon_coord): pp.bzx = grid_lon_coord.points[0] - regular_step(grid_lon_coord) pp.bdx = regular_step(grid_lon_coord) pp.lbnpt = len(grid_lon_coord.points) if lat_coord and not is_regular(lat_coord): pp.bzy = 0 pp.bdy = 0 pp.lbrow = lat_coord.shape[0] pp.y = lat_coord.points elif grid_lat_coord and not is_regular(grid_lat_coord): pp.bzy = 0 pp.bdy = 0 pp.lbrow = grid_lat_coord.shape[0] pp.y = grid_lat_coord.points elif lat_coord and is_regular(lat_coord): pp.bzy = lat_coord.points[0] - regular_step(lat_coord) pp.bdy = regular_step(lat_coord) pp.lbrow = len(lat_coord.points) elif grid_lat_coord and is_regular(grid_lat_coord): pp.bzy = grid_lat_coord.points[0] - regular_step(grid_lat_coord) pp.bdy = regular_step(grid_lat_coord) pp.lbrow = len(grid_lat_coord.points) # Check if we have a rotated coord system. if cube.coord_system("RotatedGeogCS") is not None: pp.lbcode = int(pp.lbcode) + 100 # Check if we have a circular x-coord. for lon_coord in (lon_coord, grid_lon_coord): if lon_coord is not None: if lon_coord.circular: pp.lbhem = 0 else: pp.lbhem = 3 return pp