예제 #1
0
def timeseries_area_threshold(file_path,
                              var_name,
                              threshold,
                              grid,
                              gtype='t',
                              time_index=None,
                              t_start=None,
                              t_end=None,
                              time_average=False):

    # Read the data
    data = read_netcdf(file_path,
                       var_name,
                       time_index=time_index,
                       t_start=t_start,
                       t_end=t_end,
                       time_average=time_average)
    if len(data.shape) == 2:
        # Just one timestep; add a dummy time dimension
        data = np.expand_dims(data, 0)
    # Convert to array of 1s and 0s based on threshold
    data = (data >= threshold).astype(float)
    # Now build the timeseries
    timeseries = []
    for t in range(data.shape[0]):
        timeseries.append(area_integral(data[t, :], grid, gtype=gtype))
    return np.array(timeseries)
예제 #2
0
def polynya_mask(grid_path, polynya, mask_file, prec=64):

    from plot_latlon import latlon_plot

    # Define the centre and radii of the ellipse bounding the polynya
    if polynya == 'maud_rise':  # Area 2.6 x 10^5 km^2
        lon0 = 0.
        lat0 = -65.
        rlon = 8.
        rlat = 2.
    elif polynya == 'near_shelf':  # Area 2.6 x 10^5 km^2
        lon0 = -30.
        lat0 = -70.
        rlon = 9.
        rlat = 2.2
    elif polynya == 'maud_rise_big':  # Area 6.2 x 10^5 km^2
        lon0 = 0.
        lat0 = -65.
        rlon = 15.
        rlat = 2.5
    elif polynya == 'maud_rise_small':  # Area 0.34 x 10^5 km^2
        lon0 = 0
        lat0 = -65.
        rlon = 2.8
        rlat = 0.75
    else:
        print 'Error (polynya_mask): invalid polynya option ' + polynya
        sys.exit()

    # Build the grid
    grid = Grid(grid_path)
    # Set up the mask
    mask = np.zeros([grid.ny, grid.nx])
    # Select the polynya region
    index = (grid.lon_2d - lon0)**2 / rlon**2 + (grid.lat_2d -
                                                 lat0)**2 / rlat**2 <= 1
    mask[index] = 1

    # Print the area of the polynya
    print 'Polynya area is ' + str(area_integral(mask, grid) * 1e-6) + ' km^2'
    # Plot the mask
    latlon_plot(mask_land_ice(mask, grid),
                grid,
                include_shelf=False,
                title='Polynya mask',
                figsize=(10, 6))

    # Write to file
    write_binary(mask, mask_file, prec=prec)
예제 #3
0
def find_aice_min_max(aice, grid):

    total_aice = area_integral(aice, grid, time_dependent=True)
    return np.argmin(total_aice), np.argmax(total_aice)