예제 #1
0
def handle(infiles, tables, user_input_path, **kwargs):
    """
    Transform MPASO timeMonthly_avg_dThreshMLD into CMIP.mlotst

    Parameters
    ----------
    infiles : dict
        a dictionary with namelist, mesh and time series file names

    tables : str
        path to CMOR tables

    user_input_path : str
        path to user input json file

    Returns
    -------
    varname : str
        the name of the processed variable after processing is complete
    """
    msg = 'Starting {name}'.format(name=__name__)
    logging.info(msg)

    meshFileName = infiles['MPAS_mesh']
    mappingFileName = infiles['MPAS_map']
    timeSeriesFiles = infiles['MPASO']

    dsMesh = xarray.open_dataset(meshFileName, mask_and_scale=False)
    cellMask2D, _ = mpas.get_cell_masks(dsMesh)

    variableList = [
        'timeMonthly_avg_dThreshMLD', 'xtime_startMonthly', 'xtime_endMonthly'
    ]

    ds = xarray.Dataset()
    with mpas.open_mfdataset(timeSeriesFiles, variableList) as dsIn:
        ds[VAR_NAME] = dsIn.timeMonthly_avg_dThreshMLD.where(cellMask2D)

        ds = mpas.add_time(ds, dsIn)
        ds.compute()

    ds = mpas.add_mask(ds, cellMask2D)
    ds = mpas.remap(ds, mappingFileName)

    mpas.setup_cmor(VAR_NAME, tables, user_input_path, component='ocean')

    # create axes
    axes = [{
        'table_entry': 'time',
        'units': ds.time.units
    }, {
        'table_entry': 'latitude',
        'units': 'degrees_north',
        'coord_vals': ds.lat.values,
        'cell_bounds': ds.lat_bnds.values
    }, {
        'table_entry': 'longitude',
        'units': 'degrees_east',
        'coord_vals': ds.lon.values,
        'cell_bounds': ds.lon_bnds.values
    }]
    try:
        mpas.write_cmor(axes, ds, VAR_NAME, VAR_UNITS)
    except Exception:
        return ""
    return VAR_NAME
예제 #2
0
def handle(infiles, tables, user_input_path, **kwargs):
    """
    Transform MPASO timeMonthly_avg_layerThickness into CMIP.zhalfo

    Parameters
    ----------
    infiles : dict
        a dictionary with namelist, mesh and time series file names

    tables : str
        path to CMOR tables

    user_input_path : str
        path to user input json file

    Returns
    -------
    varname : str
        the name of the processed variable after processing is complete
    """
    msg = 'Starting {name}'.format(name=__name__)
    logging.info(msg)

    meshFileName = infiles['MPAS_mesh']
    mappingFileName = infiles['MPAS_map']
    timeSeriesFiles = infiles['MPASO']

    dsMesh = xarray.open_dataset(meshFileName, mask_and_scale=False)
    _, cellMask3D = mpas.get_cell_masks(dsMesh)

    variableList = [
        'timeMonthly_avg_layerThickness', 'xtime_startMonthly',
        'xtime_endMonthly'
    ]

    nVertLevels = dsMesh.sizes['nVertLevels']

    ds = xarray.Dataset()
    with mpas.open_mfdataset(timeSeriesFiles, variableList) as dsIn:
        layerThickness = dsIn.timeMonthly_avg_layerThickness
        layerThickness = layerThickness.where(cellMask3D)
        thicknessSum = layerThickness.sum(dim='nVertLevels')
        mask = cellMask3D.isel(nVertLevels=0)
        zSurface = (-dsMesh.bottomDepth + thicknessSum).where(mask)
        zSurface.compute()
        # print('done zSurface')
        slices = [zSurface]
        maskSlices = [mask]
        zLayerBot = zSurface
        for zIndex in range(nVertLevels):
            mask = cellMask3D.isel(nVertLevels=zIndex)
            zLayerBot = (zLayerBot -
                         layerThickness.isel(nVertLevels=zIndex)).where(mask)
            zLayerBot.compute()
            # print('done zLayerBot {}/{}'.format(zIndex+1, nVertLevels))
            slices.append(zLayerBot)
            maskSlices.append(mask)
        ds[VAR_NAME] = xarray.concat(slices, dim='olevhalf')
        mask = xarray.concat(maskSlices, dim='olevhalf')
        ds = mpas.add_mask(ds, mask)
        ds = ds.transpose('Time', 'olevhalf', 'nCells')
        ds = mpas.add_time(ds, dsIn)
        ds.compute()

    ds = mpas.remap(ds, mappingFileName)
    depth_coord_half = numpy.zeros(nVertLevels + 1)
    depth_coord_half[1:] = dsMesh.refBottomDepth.values

    mpas.setup_cmor(VAR_NAME, tables, user_input_path, component='ocean')

    # create axes
    axes = [{
        'table_entry': 'time',
        'units': ds.time.units
    }, {
        'table_entry': 'depth_coord_half',
        'units': 'm',
        'coord_vals': depth_coord_half
    }, {
        'table_entry': 'latitude',
        'units': 'degrees_north',
        'coord_vals': ds.lat.values,
        'cell_bounds': ds.lat_bnds.values
    }, {
        'table_entry': 'longitude',
        'units': 'degrees_east',
        'coord_vals': ds.lon.values,
        'cell_bounds': ds.lon_bnds.values
    }]
    try:
        mpas.write_cmor(axes, ds, VAR_NAME, VAR_UNITS)
    except Exception:
        return ""
    return VAR_NAME
예제 #3
0
def handle(infiles, tables, user_input_path, **kwargs):
    """
    Transform MPASO timeMonthly_avg_frazilLayerThicknessTendency into
    CMIP.hfsifrazil

    Parameters
    ----------
    infiles : dict
        a dictionary with namelist, mesh and time series file names

    tables : str
        path to CMOR tables

    user_input_path : str
        path to user input json file

    Returns
    -------
    varname : str
        the name of the processed variable after processing is complete
    """
    msg = 'Starting {name}'.format(name=__name__)
    logging.info(msg)

    timeSeriesFiles = infiles['MPASO']
    mappingFileName = infiles['MPAS_map']
    meshFileName = infiles['MPAS_mesh']
    namelistFileName = infiles['MPASO_namelist']

    namelist = mpas.convert_namelist_to_dict(namelistFileName)
    config_density0 = float(namelist['config_density0'])
    config_frazil_heat_of_fusion = \
        float(namelist['config_frazil_heat_of_fusion'])

    dsMesh = xarray.open_dataset(meshFileName, mask_and_scale=False)
    _, cellMask3D = mpas.get_cell_masks(dsMesh)

    variableList = [
        'timeMonthly_avg_frazilLayerThicknessTendency', 'xtime_startMonthly',
        'xtime_endMonthly'
    ]

    ds = xarray.Dataset()
    with mpas.open_mfdataset(timeSeriesFiles, variableList) as dsIn:
        ds[VAR_NAME] = -config_density0 * config_frazil_heat_of_fusion * \
            dsIn.timeMonthly_avg_frazilLayerThicknessTendency

        ds = mpas.add_time(ds, dsIn)
        ds.compute()

    ds = mpas.add_mask(ds, cellMask3D)
    ds = mpas.add_depth(ds, dsMesh)
    ds.compute()

    ds = mpas.remap(ds, mappingFileName)

    mpas.setup_cmor(VAR_NAME, tables, user_input_path, component='ocean')

    # create axes
    axes = [{
        'table_entry': 'time',
        'units': ds.time.units
    }, {
        'table_entry': 'depth_coord',
        'units': 'm',
        'coord_vals': ds.depth.values,
        'cell_bounds': ds.depth_bnds.values
    }, {
        'table_entry': 'latitude',
        'units': 'degrees_north',
        'coord_vals': ds.lat.values,
        'cell_bounds': ds.lat_bnds.values
    }, {
        'table_entry': 'longitude',
        'units': 'degrees_east',
        'coord_vals': ds.lon.values,
        'cell_bounds': ds.lon_bnds.values
    }]
    try:
        mpas.write_cmor(axes, ds, VAR_NAME, VAR_UNITS, positive='down')
    except Exception:
        return ""
    return VAR_NAME
예제 #4
0
파일: sob.py 프로젝트: JGCRI/e3sm_to_cmip
def handle(infiles, tables, user_input_path, **kwargs):
    """
    Transform MPASO timeMonthly_avg_activeTracers_salinity into CMIP.sob

    Parameters
    ----------
    infiles : dict
        a dictionary with namelist, mesh and time series file names

    tables : str
        path to CMOR tables

    user_input_path : str
        path to user input json file

    Returns
    -------
    varname : str
        the name of the processed variable after processing is complete
    """
    if kwargs.get('simple'):
        msg = f"{VAR_NAME} is not supported for simple conversion"
        print_message(msg)
        return

    msg = 'Starting {name}'.format(name=__name__)
    logging.info(msg)

    meshFileName = infiles['MPAS_mesh']
    mappingFileName = infiles['MPAS_map']
    timeSeriesFiles = infiles['MPASO']

    dsMesh = xarray.open_dataset(meshFileName, mask_and_scale=False)
    cellMask2D, _ = mpas.get_cell_masks(dsMesh)

    variableList = [
        'timeMonthly_avg_activeTracers_salinity', 'xtime_startMonthly',
        'xtime_endMonthly'
    ]

    ds = xarray.Dataset()
    with mpas.open_mfdataset(timeSeriesFiles, variableList) as dsIn:
        ds[VAR_NAME] = dsIn.timeMonthly_avg_activeTracers_salinity
        ds = mpas.get_sea_floor_values(ds, dsMesh)
        ds = mpas.add_time(ds, dsIn)
        ds.compute()
    ds = mpas.add_mask(ds, cellMask2D)
    ds.compute()

    ds = mpas.remap(ds, mappingFileName)

    mpas.setup_cmor(VAR_NAME, tables, user_input_path, component='ocean')

    # create axes
    axes = [{
        'table_entry': 'time',
        'units': ds.time.units
    }, {
        'table_entry': 'latitude',
        'units': 'degrees_north',
        'coord_vals': ds.lat.values,
        'cell_bounds': ds.lat_bnds.values
    }, {
        'table_entry': 'longitude',
        'units': 'degrees_east',
        'coord_vals': ds.lon.values,
        'cell_bounds': ds.lon_bnds.values
    }]
    try:
        mpas.write_cmor(axes,
                        ds,
                        VAR_NAME,
                        VAR_UNITS,
                        comment='Model prognostic salinity at bottom-most '
                        'model grid cell on the Practical Salinity '
                        'Scale of 1978.')
    except Exception:
        return ""
    return VAR_NAME