Ejemplo n.º 1
0
def iceberg_meltwater(grid_path, input_dir, output_file, nc_out=None, prec=32):

    from plot_latlon import latlon_plot

    input_dir = real_dir(input_dir)
    file_head = 'icebergs_'
    file_tail = '.nc'

    print 'Building grids'
    # Read the NEMO grid from the first file
    # It has longitude in the range -180 to 180
    file_path = input_dir + file_head + '01' + file_tail
    nemo_lon = read_netcdf(file_path, 'nav_lon')
    nemo_lat = read_netcdf(file_path, 'nav_lat')
    # Build the model grid
    model_grid = Grid(grid_path, max_lon=180)

    print 'Interpolating'
    icebergs_interp = np.zeros([12, model_grid.ny, model_grid.nx])
    for month in range(12):
        print '...month ' + str(month + 1)
        # Read the data
        file_path = input_dir + file_head + '{0:02d}'.format(month +
                                                             1) + file_tail
        icebergs = read_netcdf(file_path, 'berg_total_melt', time_index=0)
        # Interpolate
        icebergs_interp_tmp = interp_nonreg_xy(nemo_lon,
                                               nemo_lat,
                                               icebergs,
                                               model_grid.lon_1d,
                                               model_grid.lat_1d,
                                               fill_value=0)
        # Make sure the land and ice shelf cavities don't get any iceberg melt
        icebergs_interp_tmp[model_grid.land_mask + model_grid.ice_mask] = 0
        # Save to the master array
        icebergs_interp[month, :] = icebergs_interp_tmp

    write_binary(icebergs_interp, output_file, prec=prec)

    print 'Plotting'
    # Make a nice plot of the annual mean
    latlon_plot(mask_land_ice(np.mean(icebergs_interp, axis=0), model_grid),
                model_grid,
                include_shelf=False,
                vmin=0,
                title=r'Annual mean iceberg melt (kg/m$^2$/s)')
    if nc_out is not None:
        # Also write to NetCDF file
        print 'Writing ' + nc_out
        ncfile = NCfile(nc_out, model_grid, 'xyt')
        ncfile.add_time(np.arange(12) + 1, units='months')
        ncfile.add_variable('iceberg_melt',
                            icebergs_interp,
                            'xyt',
                            units='kg/m^2/s')
        ncfile.close()
Ejemplo n.º 2
0
 def read_data(file_path):
     f = loadmat(file_path)
     x, y, connectivity = read_ua_mesh(f)
     # Set up regular grid. This will be the same for both steps because the boundary is fixed.
     x_reg = np.linspace(np.amin(x), np.amax(x), num=nx)
     y_reg = np.linspace(np.amin(y), np.amax(y), num=ny)
     if var == 'velb':
         data = np.sqrt(f['ub'][:, 0]**2 + f['vb'][:, 0]**2)
     else:
         data = f[var][:, 0]
     data_reg = interp_nonreg_xy(x, y, data, x_reg, y_reg)
     if mask is not None:
         # Read ice base elevation and bedrock depth
         ice_base = f['b'][:, 0]
         bedrock = f['B'][:, 0]
         flt_mask = interp_nonreg_xy(x, y,
                                     (ice_base > bedrock).astype(float),
                                     x_reg, y_reg)
         flt_mask[flt_mask < 0.5] = 0
         flt_mask[flt_mask >= 0.5] = 1
     else:
         flt_mask = None
     return x_reg, y_reg, data_reg, flt_mask