src/coecms/um/um2oasis.py
def merge_scrip_for_oasis(scrip_grids):
    """
    Merge a set of SCRIP grids into OASIS grid description files

    Args:
        scrip_grids: A dict mapping OASIS grid names to SCRIP descriptions

    Returns:
        dict mappining keys 'masks', 'grids' and 'areas' to xarray.DataArrays
        with the relevant fields copied from the SCRIP descriptions
    """
    masks = xarray.Dataset()
    grids = xarray.Dataset()
    areas = xarray.Dataset()
    
    for name, scrip in scrip_grids.items():
        if 'nx' in scrip:
            del scrip['nx']
        if 'ny' in scrip:
            del scrip['ny']
        if 'grid_corners' in scrip:
            del scrip['grid_corners']

        scrip['grid_size'] = pandas.MultiIndex.from_product(
                [range(scrip.grid_dims.values[1]), range(scrip.grid_dims.values[0])],
                names=['ny','nx'])
        scrip = scrip.unstack('grid_size').transpose('grid_rank','grid_corners','ny','nx')

        scrip = scrip.rename({v: f'{name}.{v}' for v in scrip.variables})

        del scrip[f'{name}.nx']
        del scrip[f'{name}.ny']

        masks[f'{name}.msk'] = (1 - scrip[f'{name}.grid_imask']).astype('i4')

        grids[f'{name}.lon'] = scrip[f'{name}.grid_center_lon'].astype('f8')
        grids[f'{name}.lat'] = scrip[f'{name}.grid_center_lat'].astype('f8')
        grids[f'{name}.clo'] = scrip[f'{name}.grid_corner_lon'].astype('f8')
        grids[f'{name}.cla'] = scrip[f'{name}.grid_corner_lat'].astype('f8')

        areas[f'{name}.srf'] = scrip[f'{name}.grid_area'].astype('f8')

    return {'masks': masks, 'grids': grids, 'areas': areas}

    Merge a set of SCRIP grids into OASIS grid description files

    Args:
        scrip_grids: A dict mapping OASIS grid names to SCRIP descriptions

    Returns:
        dict mappining keys 'masks', 'grids' and 'areas' to xarray.DataArrays
        with the relevant fields copied from the SCRIP descriptions
    
Merge a set of SCRIP grids into OASIS grid description files
Merge a set of SCRIP grids into OASIS grid description files
def merge_scrip_for_oasis(scrip_grids):
    masks = xarray.Dataset()
    grids = xarray.Dataset()
    areas = xarray.Dataset()
    for name, scrip in scrip_grids.items():
        if 'nx' in scrip:
            del scrip['nx']
        if 'ny' in scrip:
            del scrip['ny']
        if 'grid_corners' in scrip:
            del scrip['grid_corners']
        scrip['grid_size'] = pandas.MultiIndex.from_product(
                [range(scrip.grid_dims.values[1]), range(scrip.grid_dims.values[0])],
                names=['ny','nx'])
        scrip = scrip.unstack('grid_size').transpose('grid_rank','grid_corners','ny','nx')
        scrip = scrip.rename({v: f'{name}.{v}' for v in scrip.variables})
        del scrip[f'{name}.nx']
        del scrip[f'{name}.ny']
        masks[f'{name}.msk'] = (1 - scrip[f'{name}.grid_imask']).astype('i4')
        grids[f'{name}.lon'] = scrip[f'{name}.grid_center_lon'].astype('f8')
        grids[f'{name}.lat'] = scrip[f'{name}.grid_center_lat'].astype('f8')
        grids[f'{name}.clo'] = scrip[f'{name}.grid_corner_lon'].astype('f8')
        grids[f'{name}.cla'] = scrip[f'{name}.grid_corner_lat'].astype('f8')
        areas[f'{name}.srf'] = scrip[f'{name}.grid_area'].astype('f8')
    return {'masks': masks, 'grids': grids, 'areas': areas}
def merge_scrip_for_oasis ( scrip_grids ) : masks = xarray . Dataset ( ) grids = xarray . Dataset ( ) areas = xarray . Dataset ( ) for name , scrip in scrip_grids . items ( ) : if 'nx' in scrip : del scrip [ 'nx' ] if 'ny' in scrip : del scrip [ 'ny' ] if 'grid_corners' in scrip : del scrip [ 'grid_corners' ] scrip [ 'grid_size' ] = pandas . MultiIndex . from_product ( [ range ( scrip . grid_dims . values [ 1 ] ) , range ( scrip . grid_dims . values [ 0 ] ) ] , names = [ 'ny' , 'nx' ] ) scrip = scrip . unstack ( 'grid_size' ) . transpose ( 'grid_rank' , 'grid_corners' , 'ny' , 'nx' ) scrip = scrip . rename ( { v : f'{name}.{v}' for v in scrip . variables } ) del scrip [ f'{name}.nx' ] del scrip [ f'{name}.ny' ] masks [ f'{name}.msk' ] = ( 1 - scrip [ f'{name}.grid_imask' ] ) . astype ( 'i4' ) grids [ f'{name}.lon' ] = scrip [ f'{name}.grid_center_lon' ] . astype ( 'f8' ) grids [ f'{name}.lat' ] = scrip [ f'{name}.grid_center_lat' ] . astype ( 'f8' ) grids [ f'{name}.clo' ] = scrip [ f'{name}.grid_corner_lon' ] . astype ( 'f8' ) grids [ f'{name}.cla' ] = scrip [ f'{name}.grid_corner_lat' ] . astype ( 'f8' ) areas [ f'{name}.srf' ] = scrip [ f'{name}.grid_area' ] . astype ( 'f8' ) return { 'masks' : masks , 'grids' : grids , 'areas' : areas }
Merge a set of SCRIP grids into OASIS grid description files
Merge a set of SCRIP grids into OASIS grid description files
"""
    Merge a set of SCRIP grids into OASIS grid description files

    Args:
        scrip_grids: A dict mapping OASIS grid names to SCRIP descriptions

    Returns:
        dict mappining keys 'masks', 'grids' and 'areas' to xarray.DataArrays
        with the relevant fields copied from the SCRIP descriptions
    """
dict mappining keys 'masks', 'grids' and 'areas' to xarray.DataArrays
with the relevant fields copied from the SCRIP descriptions
dict mappining keys ' masks ' ' grids ' and ' areas ' to xarray . DataArrays with the relevant fields copied from the SCRIP descriptions
scrip_grids
A dict mapping OASIS grid names to SCRIP descriptions
A dict mapping OASIS grid names to SCRIP descriptions