#         X = X.where(X>=0, other=0)

#     # Apply model mask
#     X = X.where(X.imask)

# Calculate regridding matrix
    regridder = xe.Regridder(ds,
                             obs_grid,
                             method,
                             periodic=False,
                             reuse_weights=weights_flag)
    weights_flag = True  # Set true for following loops

    # Add NaNs to empty rows of matrix (forces any target cell with ANY source cells containing NaN to be NaN)
    if method == 'conservative':
        regridder = import_data.add_matrix_NaNs(regridder)

    # Regrid variable
    var_out = regridder(ds[cvar])

    # Expand dims
    var_out = import_data.expand_to_sipn_dims(var_out)

    # # Save regridded to netcdf file

    var_out.to_netcdf(f_out)
    var_out = None  # Memory clean up
    print('Saved ', f_out)

# In[ ]:
Beispiel #2
0
        # Calculate regridding matrix
        regridder_top = xe.Regridder(ds_top,
                                     obs_grid,
                                     method,
                                     periodic=False,
                                     reuse_weights=weights_flag)
        regridder_bottom = xe.Regridder(ds_bottom,
                                        obs_grid,
                                        method,
                                        periodic=False,
                                        reuse_weights=weights_flag)
        weights_flag = True  # Set true for following loops

        # Add NaNs to empty rows of matrix (forces any target cell with ANY source cells containing NaN to be NaN)
        if method == 'conservative':
            regridder_top = import_data.add_matrix_NaNs(regridder_top)
            regridder_bottom = import_data.add_matrix_NaNs(regridder_bottom)

        # Average over all sea ice categories
        native_top = ds_top.sum(dim='ct', skipna=False)
        native_bottom = ds_bottom.sum(dim='ct', skipna=False)

        # Loop through each variable (xemsf not dataset enabled yet)
        da_out_all_list = []
        for cvar in native_top.data_vars:
            da_out_all_list.append(
                import_data.regrid_gfdl_split_domain(ds_all, native_top[cvar],
                                                     native_bottom[cvar],
                                                     regridder_top,
                                                     regridder_bottom))
        ds_out_all = xr.merge(da_out_all_list)