esmvaltool/diag_scripts/validation.py
def coordinate_collapse(data_set, cfg):
    """Perform coordinate-specific collapse and (if) area slicing and mask"""
    # see what analysis needs performing
    analysis_type = cfg['analysis_type']

    # if subset on LAT-LON
    if 'lat_lon_slice' in cfg:
        start_longitude = cfg['lat_lon_slice']['start_longitude']
        end_longitude = cfg['lat_lon_slice']['end_longitude']
        start_latitude = cfg['lat_lon_slice']['start_latitude']
        end_latitude = cfg['lat_lon_slice']['end_latitude']
        data_set = extract_region(data_set, start_longitude, end_longitude,
                                  start_latitude, end_latitude)

    # if apply mask
    if '2d_mask' in cfg:
        mask_file = os.path.join(cfg['2d_mask'])
        mask_cube = iris.load_cube(mask_file)
        if 'mask_threshold' in cfg:
            thr = cfg['mask_threshold']
            data_set.data = np.ma.masked_array(
                data_set.data, mask=(mask_cube.data > thr))
        else:
            logger.warning('Could not find masking threshold')
            logger.warning('Please specify it if needed')
            logger.warning('Masking on 0-values = True (masked value)')
            data_set.data = np.ma.masked_array(
                data_set.data, mask=(mask_cube.data == 0))

    # if zonal mean on LON
    if analysis_type == 'zonal_mean':
        data_set = data_set.collapsed('longitude', iris.analysis.MEAN)

    # if zonal mean on LAT
    if analysis_type == 'meridional_mean':
        data_set = data_set.collapsed('latitude', iris.analysis.MEAN)

    # if vertical mean
    elif analysis_type == 'vertical_mean':
        data_set = data_set.collapsed('pressure', iris.analysis.MEAN)

    return data_set
Perform coordinate-specific collapse and (if) area slicing and mask
Perform coordinate-specific collapse and (if) area slicing and mask
Perform coordinate - specific collapse and ( if ) area slicing and mask
def coordinate_collapse(data_set, cfg):
    analysis_type = cfg['analysis_type']
    if 'lat_lon_slice' in cfg:
        start_longitude = cfg['lat_lon_slice']['start_longitude']
        end_longitude = cfg['lat_lon_slice']['end_longitude']
        start_latitude = cfg['lat_lon_slice']['start_latitude']
        end_latitude = cfg['lat_lon_slice']['end_latitude']
        data_set = extract_region(data_set, start_longitude, end_longitude,
                                  start_latitude, end_latitude)
    if '2d_mask' in cfg:
        mask_file = os.path.join(cfg['2d_mask'])
        mask_cube = iris.load_cube(mask_file)
        if 'mask_threshold' in cfg:
            thr = cfg['mask_threshold']
            data_set.data = np.ma.masked_array(
                data_set.data, mask=(mask_cube.data > thr))
        else:
            logger.warning('Could not find masking threshold')
            logger.warning('Please specify it if needed')
            logger.warning('Masking on 0-values = True (masked value)')
            data_set.data = np.ma.masked_array(
                data_set.data, mask=(mask_cube.data == 0))
    if analysis_type == 'zonal_mean':
        data_set = data_set.collapsed('longitude', iris.analysis.MEAN)
    if analysis_type == 'meridional_mean':
        data_set = data_set.collapsed('latitude', iris.analysis.MEAN)
    elif analysis_type == 'vertical_mean':
        data_set = data_set.collapsed('pressure', iris.analysis.MEAN)
    return data_set
def coordinate_collapse ( data_set , cfg ) : analysis_type = cfg [ 'analysis_type' ] if 'lat_lon_slice' in cfg : start_longitude = cfg [ 'lat_lon_slice' ] [ 'start_longitude' ] end_longitude = cfg [ 'lat_lon_slice' ] [ 'end_longitude' ] start_latitude = cfg [ 'lat_lon_slice' ] [ 'start_latitude' ] end_latitude = cfg [ 'lat_lon_slice' ] [ 'end_latitude' ] data_set = extract_region ( data_set , start_longitude , end_longitude , start_latitude , end_latitude ) if '2d_mask' in cfg : mask_file = os . path . join ( cfg [ '2d_mask' ] ) mask_cube = iris . load_cube ( mask_file ) if 'mask_threshold' in cfg : thr = cfg [ 'mask_threshold' ] data_set . data = np . ma . masked_array ( data_set . data , mask = ( mask_cube . data > thr ) ) else : logger . warning ( 'Could not find masking threshold' ) logger . warning ( 'Please specify it if needed' ) logger . warning ( 'Masking on 0-values = True (masked value)' ) data_set . data = np . ma . masked_array ( data_set . data , mask = ( mask_cube . data == 0 ) ) if analysis_type == 'zonal_mean' : data_set = data_set . collapsed ( 'longitude' , iris . analysis . MEAN ) if analysis_type == 'meridional_mean' : data_set = data_set . collapsed ( 'latitude' , iris . analysis . MEAN ) elif analysis_type == 'vertical_mean' : data_set = data_set . collapsed ( 'pressure' , iris . analysis . MEAN ) return data_set
Perform coordinate-specific collapse and (if) area slicing and mask
Perform coordinate - specific collapse and ( if ) area slicing and mask
"""Perform coordinate-specific collapse and (if) area slicing and mask""" # see what analysis needs performing # if subset on LAT-LON # if apply mask # if zonal mean on LON # if zonal mean on LAT # if vertical mean
data_set
cfg