scripts/um/demask_ancil.py
def demask(input_path, output_path):
    """
    Remove a mask from a UM ancil file by doing a one-to-one regrid from a
    masked field to an unmasked field with extrapolation
    """
    anc = mule.AncilFile.from_file(input_path)

    field0 = anc.fields[0]
    mask = numpy.where(field0.get_data() == -1073741824, 0, 1)

    lats = xarray.DataArray(
        field0.bzy + (1 + numpy.array(range(mask.shape[0]))) * field0.bdy,
        dims='lat')
    lons = xarray.DataArray(
        field0.bzx + (1 + numpy.array(range(mask.shape[1]))) * field0.bdx,
        dims='lon')

    src_grid = LonLatGrid(lats=lats, lons=lons, mask=mask).to_scrip()
    tgt_grid = LonLatGrid(lats=lats, lons=lons).to_scrip()

    weights = esmf_generate_weights(src_grid, tgt_grid, method='neareststod',
                                    line_type='greatcircle', extrap_method='neareststod')

    op = RegridOperator(weights=weights)

    anc_out = anc.copy()

    def no_validate(*args, **kwargs):
        pass
    anc_out.validate = no_validate

    for f in anc.fields:
        anc_out.fields.append(op(f))
    anc_out.to_file(output_path)

    Remove a mask from a UM ancil file by doing a one-to-one regrid from a
    masked field to an unmasked field with extrapolation
    
Remove a mask from a UM ancil file by doing a one-to-one regrid from a
masked field to an unmasked field with extrapolation
Remove a mask from a UM ancil file by doing a one - to - one regrid from a masked field to an unmasked field with extrapolation
def demask(input_path, output_path):
    anc = mule.AncilFile.from_file(input_path)
    field0 = anc.fields[0]
    mask = numpy.where(field0.get_data() == -1073741824, 0, 1)
    lats = xarray.DataArray(
        field0.bzy + (1 + numpy.array(range(mask.shape[0]))) * field0.bdy,
        dims='lat')
    lons = xarray.DataArray(
        field0.bzx + (1 + numpy.array(range(mask.shape[1]))) * field0.bdx,
        dims='lon')
    src_grid = LonLatGrid(lats=lats, lons=lons, mask=mask).to_scrip()
    tgt_grid = LonLatGrid(lats=lats, lons=lons).to_scrip()
    weights = esmf_generate_weights(src_grid, tgt_grid, method='neareststod',
                                    line_type='greatcircle', extrap_method='neareststod')
    op = RegridOperator(weights=weights)
    anc_out = anc.copy()
    def no_validate(*args, **kwargs):
        pass
    anc_out.validate = no_validate
    for f in anc.fields:
        anc_out.fields.append(op(f))
    anc_out.to_file(output_path)
def demask ( input_path , output_path ) : anc = mule . AncilFile . from_file ( input_path ) field0 = anc . fields [ 0 ] mask = numpy . where ( field0 . get_data ( ) == - 1073741824 , 0 , 1 ) lats = xarray . DataArray ( field0 . bzy + ( 1 + numpy . array ( range ( mask . shape [ 0 ] ) ) ) * field0 . bdy , dims = 'lat' ) lons = xarray . DataArray ( field0 . bzx + ( 1 + numpy . array ( range ( mask . shape [ 1 ] ) ) ) * field0 . bdx , dims = 'lon' ) src_grid = LonLatGrid ( lats = lats , lons = lons , mask = mask ) . to_scrip ( ) tgt_grid = LonLatGrid ( lats = lats , lons = lons ) . to_scrip ( ) weights = esmf_generate_weights ( src_grid , tgt_grid , method = 'neareststod' , line_type = 'greatcircle' , extrap_method = 'neareststod' ) op = RegridOperator ( weights = weights ) anc_out = anc . copy ( ) def no_validate ( * args , ** kwargs ) : pass anc_out . validate = no_validate for f in anc . fields : anc_out . fields . append ( op ( f ) ) anc_out . to_file ( output_path )
Remove a mask from a UM ancil file by doing a one-to-one regrid from a
masked field to an unmasked field with extrapolation
Remove a mask from a UM ancil file by doing a one - to - one regrid from a masked field to an unmasked field with extrapolation
"""
    Remove a mask from a UM ancil file by doing a one-to-one regrid from a
    masked field to an unmasked field with extrapolation
    """
input_path
output_path