Exemplo n.º 1
0
 def read_and_mask (var_name, file_path, check_diff_time=False, gtype='t'):
     if var_name in ['tminustf', 'rho']:
         # Need to read 2 variables
         temp = read_and_mask('THETA', file_path, check_diff_time=check_diff_time)
         salt = read_and_mask('SALT', file_path, check_diff_time=check_diff_time)
         if var_name == 'rho':
             return mask_3d(density(eosType, salt, temp, ref_depth, rhoConst=rhoConst, Tref=Tref, Sref=Sref, tAlpha=tAlpha, sBeta=sBeta), grid)
         elif var_name == 'tminustf':
             return t_minus_tf(temp, salt, grid)
     elif var_name in ['vnorm', 'valong']:
         u = read_and_mask('UVEL', file_path, check_diff_time=check_diff_time, gtype='u')
         v = read_and_mask('VVEL', file_path, check_diff_time=check_diff_time, gtype='v')
         if var_name == 'vnorm':
             return normal_vector(u, v, grid, point0, point1)
         elif var_name == 'valong':
             return parallel_vector(u, v, grid, point0, point1)
     elif var_name == 'tadv_along':
         tadv_x = read_and_mask('ADVx_TH', file_path, check_diff_time=check_diff_time)
         tadv_y = read_and_mask('ADVy_TH', file_path, check_diff_time=check_diff_time)
         return parallel_vector(tadv_x, tadv_y, grid, point0, point1)
     elif var_name == 'tdif_along':
         tdif_x = read_and_mask('DFxE_TH', file_path, check_diff_time=check_diff_time)
         tdif_y = read_and_mask('DFyE_TH', file_path, check_diff_time=check_diff_time)
         return parallel_vector(tdif_x, tdif_y, grid, point0, point1)
     else:
         if check_diff_time and diff_time:
             return mask_3d(read_netcdf(file_path, var_name, time_index=time_index_2, t_start=t_start_2, t_end=t_end_2, time_average=time_average), grid, gtype=gtype)
         else:
             return mask_3d(read_netcdf(file_path, var_name, time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid, gtype=gtype)
Exemplo n.º 2
0
def read_plot_ts_slice (file_path, grid, lon0=None, lat0=None, time_index=None, t_start=None, t_end=None, time_average=False, hmin=None, hmax=None, zmin=None, zmax=None, tmin=None, tmax=None, smin=None, smax=None, date_string=None, fig_name=None, second_file_path=None):

    # Make sure we'll end up with a single record in time
    if time_index is None and not time_average:
        print 'Error (read_plot_ts_slice): either specify time_index or set time_average=True.'
        sys.exit()

    if date_string is None and time_index is not None:
        # Determine what to write about the date
        date_string = parse_date(file_path=file_path, time_index=time_index)

    if not isinstance(grid, Grid):
        # This is the path to the NetCDF grid file, not a Grid object
        # Make a grid object from it
        grid = Grid(grid)

    # Read temperature
    if second_file_path is not None:
        file_path_use = find_variable(file_path, second_file_path, 'THETA')
    else:
        file_path_use = file_path        
    temp = mask_3d(read_netcdf(file_path_use, 'THETA', time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid)
    # Read salinity
    if second_file_path is not None:
        file_path_use = find_variable(file_path, second_file_path, 'SALT')
    else:
        file_path_use = file_path        
    salt = mask_3d(read_netcdf(file_path_use, 'SALT', time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid)

    # Plot
    ts_slice_plot(temp, salt, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, tmin=tmin, tmax=tmax, smin=smin, smax=smax, date_string=date_string, fig_name=fig_name)
Exemplo n.º 3
0
 def read_and_mask (var_name, file_path, second_file_path=None, check_diff_time=False):
     # Do we need to choose the right file?
     if second_file_path is not None:
         file_path_use = find_variable(file_path, second_file_path, var_name)
     else:
         file_path_use = file_path
     # Read and mask the data
     if check_diff_time and diff_time:
         return mask_3d(read_netcdf(file_path_use, var_name, time_index=time_index_2, t_start=t_start_2, t_end=t_end_2, time_average=time_average), grid)
     else:
         return mask_3d(read_netcdf(file_path_use, var_name, time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid)
Exemplo n.º 4
0
def timeseries_transport_transect(file_path,
                                  grid,
                                  point0,
                                  point1,
                                  direction='N',
                                  time_index=None,
                                  t_start=None,
                                  t_end=None,
                                  time_average=False):

    # Read u and v
    u = mask_3d(read_netcdf(file_path,
                            'UVEL',
                            time_index=time_index,
                            t_start=t_start,
                            t_end=t_end,
                            time_average=time_average),
                grid,
                gtype='u',
                time_dependent=True)
    v = mask_3d(read_netcdf(file_path,
                            'VVEL',
                            time_index=time_index,
                            t_start=t_start,
                            t_end=t_end,
                            time_average=time_average),
                grid,
                gtype='v',
                time_dependent=True)
    if len(u.shape) == 3:
        # Just one timestep; add a dummy time dimension
        u = np.expand_dims(u, 0)
        v = np.expand_dims(v, 0)
    # Build the timeseries
    timeseries = []
    for t in range(u.shape[0]):
        # Get the "southward" and "northward" components
        trans_S, trans_N = transport_transect(u[t, :], v[t, :], grid, point0,
                                              point1)
        # Combine them
        if direction == 'N':
            trans = trans_N - trans_S
        elif direction == 'S':
            trans = trans_S - trans_N
        else:
            print 'Error (timeseries_transport_transect): invalid direction ' + direction
            sys.exit()
        timeseries.append(trans)
    return np.array(timeseries)
Exemplo n.º 5
0
def read_plot_slice (var, file_path, grid, lon0=None, lat0=None, time_index=None, t_start=None, t_end=None, time_average=False, hmin=None, hmax=None, zmin=None, zmax=None, vmin=None, vmax=None, date_string=None, fig_name=None, second_file_path=None):

    # Make sure we'll end up with a single record in time
    if time_index is None and not time_average:
        print 'Error (read_plot_slice): either specify time_index or set time_average=True.'
        sys.exit()

    if date_string is None and time_index is not None:
        # Determine what to write about the date
        date_string = parse_date(file_path=file_path, time_index=time_index)

    if not isinstance(grid, Grid):
        # This is the path to the NetCDF grid file, not a Grid object
        # Make a grid object from it
        grid = Grid(grid)

    # Read necessary variables from NetCDF file and mask appropriately
    if var in ['temp', 'tminustf']:
        # Read temperature. Some of these variables need more than temperature and so second_file_path might be set.
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, 'THETA')
        else:
            file_path_use = file_path        
        temp = mask_3d(read_netcdf(file_path_use, 'THETA', time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid)
    if var in ['salt', 'tminustf']:
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, 'SALT')
        else:
            file_path_use = file_path
        salt = mask_3d(read_netcdf(file_path_use, 'SALT', time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid)
    if var == 'u':
        u = mask_3d(read_netcdf(file_path, 'UVEL', time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid, gtype='u')
    if var == 'v':
        v = mask_3d(read_netcdf(file_path, 'VVEL', time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid, gtype='v')

    # Plot
    if var == 'temp':
        slice_plot(temp, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, title=r'Temperature ($^{\circ}$C)', date_string=date_string, fig_name=fig_name)
    elif var == 'salt':
        slice_plot(salt, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, title='Salinity (psu)', date_string=date_string, fig_name=fig_name)
    elif var == 'tminustf':
        slice_plot(t_minus_tf(temp, salt, grid), grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', title=r'Difference from in-situ freezing point ($^{\circ}$C)', date_string=date_string, fig_name=fig_name)
    elif var == 'u':
        slice_plot(u, grid, gtype='u', lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', title='Zonal velocity (m/s)', date_string=date_string, fig_name=fig_name)
    elif var == 'v':
        slice_plot(v, grid, gtype='v', lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', title='Zonal velocity (m/s)', date_string=date_string, fig_name=fig_name)
    else:
        print 'Error (read_plot_slice): variable key ' + str(var) + ' does not exist'
        sys.exit()
Exemplo n.º 6
0
 def read_process_data (file_path, var_name, grid, mask_option='3d', gtype='t', lev_option=None, ismr=False, psi=False):
     data = read_netcdf(file_path, var_name)
     if mask_option == '3d':
         data = mask_3d(data, grid, gtype=gtype, time_dependent=True)
     elif mask_option == 'except_ice':
         data = mask_except_ice(data, grid, gtype=gtype, time_dependent=True)
     elif mask_option == 'land':
         data = mask_land(data, grid, gtype=gtype, time_dependent=True)
     elif mask_option == 'land_ice':
         data = mask_land_ice(data, grid, gtype=gtype, time_dependent=True)
     else:
         print 'Error (read_process_data): invalid mask_option ' + mask_option
         sys.exit()
     if lev_option is not None:
         if lev_option == 'top':
             data = select_top(data)
         elif lev_option == 'bottom':
             data = select_bottom(data)
         else:
             print 'Error (read_process_data): invalid lev_option ' + lev_option
             sys.exit()
     if ismr:
         data = convert_ismr(data)
     if psi:
         data = np.sum(data, axis=-3)*1e-6
     return data
Exemplo n.º 7
0
def timeseries_avg_3d(file_path,
                      var_name,
                      grid,
                      gtype='t',
                      time_index=None,
                      t_start=None,
                      t_end=None,
                      time_average=False,
                      mask=None):

    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) == 3:
        # Just one timestep; add a dummy time dimension
        data = np.expand_dims(data, 0)
    # Process one time index at a time to save memory
    timeseries = []
    for t in range(data.shape[0]):
        if mask is None:
            data_tmp = mask_3d(data[t, :], grid, gtype=gtype)
        else:
            data_tmp = apply_mask(data[t, :],
                                  np.invert(mask),
                                  depth_dependent=True)
        # Volume average
        timeseries.append(volume_average(data_tmp, grid, gtype=gtype))
    return np.array(timeseries)
Exemplo n.º 8
0
 def read_and_mask (var_name, check_second=False, gtype='t'):
     # Do we need to choose the right file?
     if check_second and second_file_path is not None:
         file_path_use = find_variable(file_path, second_file_path, var_name)
     else:
         file_path_use = file_path
     # Read and mask the data
     return mask_3d(read_netcdf(file_path_use, var_name, time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid, gtype=gtype)
Exemplo n.º 9
0
def vertical_resolution (grid, lon0=None, lat0=None, hmin=None, hmax=None, zmin=None, zmax=None, vmin=None, vmax=None, fig_name=None):

    if not isinstance(grid, Grid):
        # Create a Grid object from the given path
        grid = Grid(grid)

    # Tile dz so it's 3D, and apply mask and hFac
    dz = mask_3d(z_to_xyz(grid.dz, grid), grid)*grid.hfac

    # Plot
    slice_plot(dz, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, title='Vertical resolution (m)', fig_name=fig_name)
Exemplo n.º 10
0
def precompute_hovmoller (mit_file, hovmoller_file, loc=['PIB', 'Dot'], var=['temp', 'salt'], monthly=True):

    # Build the grid
    grid = Grid(mit_file)

    # Set up or update the file and time axis
    id = set_update_file(hovmoller_file, grid, 'zt')
    num_time = set_update_time(id, mit_file, monthly=monthly)

    for v in var:
        print 'Processing ' + v
        if v == 'temp':
            var_name = 'THETA'
            title = 'Temperature'
            units = 'degC'
        elif v == 'salt':
            var_name = 'SALT'
            title = 'Salinity'
            units = 'psu'
        # Read data and mask land/ice shelves
        data_full = mask_3d(read_netcdf(mit_file, var_name), grid, time_dependent=True)
        for l in loc:
            print '...at ' + l            
            if l == 'PIB':
                loc_name = 'Pine Island Bay'
                [xmin, xmax, ymin, ymax] = bounds_PIB
            elif l == 'Dot':
                loc_name = 'Dotson front'
                [xmin, xmax, ymin, ymax] = bounds_Dot
            # Average over the correct region
            data = mask_outside_box(data_full, grid, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, time_dependent=True)
            data = area_average(data, grid, time_dependent=True)
            set_update_var(id, num_time, data, 'zt', l+'_'+v, loc_name+' '+title, units)

    # Finished
    if isinstance(id, nc.Dataset):
        id.close()
    elif isinstance(id, NCfile):
        id.close()
Exemplo n.º 11
0
def interp_grid(data,
                grid,
                gtype_in,
                gtype_out,
                time_dependent=False,
                mask=True,
                mask_shelf=False,
                mask_with_zeros=False,
                periodic=False):

    depth_dependent = is_depth_dependent(data, time_dependent=time_dependent)
    # Make sure we're not trying to mask the ice shelf from a depth-dependent field
    if mask_shelf and depth_dependent:
        print "Error (interp_grid): can't set mask_shelf=True for a depth-dependent field."
        sys.exit()

    if mask and gtype_in in ['u', 'v', 'psi', 'w']:
        # Fill the mask with zeros (okay because no-slip boundary condition)
        data_tmp = np.copy(data)
        data_tmp[data.mask] = 0.0
    else:
        # Tracer land mask is the least restrictive, so it doesn't matter what the masked values are - they will definitely get re-masked at the end.
        data_tmp = data

    # Interpolate
    data_interp = np.empty(data_tmp.shape)
    if gtype_in == 'u' and gtype_out == 't':
        # Midpoints in the x direction
        data_interp[..., :-1] = 0.5 * (data_tmp[..., :-1] + data_tmp[..., 1:])
        # Extend/wrap the easternmost column
        if periodic:
            data_interp[..., -1] = data_interp[..., 0]
        else:
            data_interp[..., -1] = data_tmp[..., -1]
    elif gtype_in == 'v' and gtype_out == 't':
        # Midpoints in the y direction
        data_interp[..., :-1, :] = 0.5 * (data_tmp[..., :-1, :] +
                                          data_tmp[..., 1:, :])
        # Extend the northernmost row
        data_interp[..., -1, :] = data_tmp[..., -1, :]
    elif gtype_in == 't' and gtype_out == 'u':
        # Midpoints in the x direction
        data_interp[..., 1:] = 0.5 * (data_tmp[..., :-1] + data_tmp[..., 1:])
        # Extend/wrap the westernmost column
        if periodic:
            data_interp[..., 0] = data_interp[..., -1]
        else:
            data_interp[..., 0] = data_tmp[..., 0]
    elif gtype_in == 't' and gtype_out == 'v':
        # Midpoints in the y direction
        data_interp[..., 1:, :] = 0.5 * (data_tmp[..., :-1, :] +
                                         data_tmp[..., :-1, :])
        # Extend the southernmost row
        data_interp[..., 0, :] = data_tmp[..., 0, :]
    else:
        print 'Error (interp_grid): interpolation from the ' + gtype_in + '-grid to the ' + gtype_out + '-grid is not yet supported'
        sys.exit()

    if mask:
        # Now apply the mask
        if depth_dependent:
            data_interp = mask_3d(data_interp,
                                  grid,
                                  gtype=gtype_out,
                                  time_dependent=time_dependent)
        else:
            if mask_shelf:
                data_interp = mask_land_ice(data_interp,
                                            grid,
                                            gtype=gtype_out,
                                            time_dependent=time_dependent)
            else:
                data_interp = mask_land(data_interp,
                                        grid,
                                        gtype=gtype_out,
                                        time_dependent=time_dependent)

        if mask_with_zeros:
            # Remove mask and fill with zeros
            data_interp[data_interp.mask] = 0
            data_interp = data_interp.data

    return data_interp
Exemplo n.º 12
0
def read_plot_slice (var, file_path, grid=None, lon0=None, lat0=None, point0=None, point1=None, time_index=None, t_start=None, t_end=None, time_average=False, hmin=None, hmax=None, zmin=None, zmax=None, vmin=None, vmax=None, contours=None, date_string=None, fig_name=None, second_file_path=None, eosType='MDJWF', rhoConst=None, Tref=None, Sref=None, tAlpha=None, sBeta=None, ref_depth=0):

    # Build the grid if needed
    grid = choose_grid(grid, file_path)
    # Make sure we'll end up with a single record in time
    check_single_time(time_index, time_average)
    # Determine what to write about the date
    date_string = check_date_string(date_string, file_path, time_index)

    # Inner function to read a variable from the correct NetCDF file and mask appropriately
    def read_and_mask (var_name, check_second=False, gtype='t'):
        # Do we need to choose the right file?
        if check_second and second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, var_name)
        else:
            file_path_use = file_path
        # Read and mask the data
        return mask_3d(read_netcdf(file_path_use, var_name, time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average), grid, gtype=gtype)

    # Read necessary variables from NetCDF file and mask appropriately
    if var in ['temp', 'tminustf', 'rho']:
        temp = read_and_mask('THETA', check_second=True)
    if var in ['salt', 'tminustf', 'rho']:
        salt = read_and_mask('SALT', check_second=True)
    if var in ['u', 'vnorm', 'valong']:
        u = read_and_mask('UVEL', gtype='u')
    if var in ['v', 'vnorm', 'valong']:
        v = read_and_mask('VVEL', gtype='v')
    if var == 'tadv_along':
        tadv_x = read_and_mask('ADVx_TH')
        tadv_y = read_and_mask('ADVy_TH')
    if var == 'tdif_along':
        tdif_x = read_and_mask('DFxE_TH')
        tdif_y = read_and_mask('DFyE_TH')

    if var in ['vnorm', 'valong', 'tadv_along', 'tdif_along'] and None in [point0, point1]:
        print 'Error (read_plot_slice): normal or along-transect variables require point0 and point1 to be specified.'
        sys.exit()
            
    # Plot
    if var == 'temp':
        slice_plot(temp, grid, lon0=lon0, lat0=lat0, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, contours=contours, title='Temperature ('+deg_string+'C)', date_string=date_string, fig_name=fig_name)
    elif var == 'salt':
        slice_plot(salt, grid, lon0=lon0, lat0=lat0, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, contours=contours, title='Salinity (psu)', date_string=date_string, fig_name=fig_name)
    elif var == 'tminustf':
        slice_plot(t_minus_tf(temp, salt, grid), grid, lon0=lon0, lat0=lat0, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, contours=contours, ctype='plusminus', title='Difference from in-situ freezing point ('+deg_string+'C)', date_string=date_string, fig_name=fig_name)
    elif var == 'rho':
        # Calculate density
        rho = mask_3d(density(eosType, salt, temp, ref_depth, rhoConst=rhoConst, Tref=Tref, Sref=Sref, tAlpha=tAlpha, sBeta=sBeta), grid)
        slice_plot(rho, grid, lon0=lon0, lat0=lat0, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, contours=contours, title=r'Density (kg/m$^3$)', date_string=date_string, fig_name=fig_name)
    elif var == 'u':
        slice_plot(u, grid, gtype='u', lon0=lon0, lat0=lat0, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', contours=contours, title='Zonal velocity (m/s)', date_string=date_string, fig_name=fig_name)
    elif var == 'v':
        slice_plot(v, grid, gtype='v', lon0=lon0, lat0=lat0, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', contours=contours, title='Meridional velocity (m/s)', date_string=date_string, fig_name=fig_name)
    elif var == 'vnorm':
        vnorm = normal_vector(u, v, grid, point0, point1)
        slice_plot(vnorm, grid, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', contours=contours, title='Normal velocity (m/s)', date_string=date_string, fig_name=fig_name)
    elif var == 'valong':
        valong = parallel_vector(u, v, grid, point0, point1)
        slice_plot(valong, grid, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', contours=contours, title='Along-transect velocity (m/s)', date_string=date_string, fig_name=fig_name)
    elif var == 'tadv_along':
        tadv_along = parallel_vector(tadv_x, tadv_y, grid, point0, point1)
        slice_plot(tadv_along, grid, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', contours=contours, title=r'Along-transect advective heat transport (Km$^3$/s)', date_string=date_string, fig_name=fig_name)
    elif var == 'tdif_along':
        tdif_along = parallel_vector(tdif_x, tdif_y, grid, point0, point1)
        slice_plot(tdif_along, grid, point0=point0, point1=point1, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, vmin=vmin, vmax=vmax, ctype='plusminus', contours=contours, title=r'Along-transect diffusive heat transport (Km$^3$/s)', date_string=date_string, fig_name=fig_name)
    else:
        print 'Error (read_plot_slice): variable key ' + str(var) + ' does not exist'
        sys.exit()
Exemplo n.º 13
0
def read_plot_latlon(var,
                     file_path,
                     grid,
                     time_index=None,
                     t_start=None,
                     t_end=None,
                     time_average=False,
                     vmin=None,
                     vmax=None,
                     zoom_fris=False,
                     xmin=None,
                     xmax=None,
                     ymin=None,
                     ymax=None,
                     date_string=None,
                     fig_name=None,
                     second_file_path=None,
                     change_points=None,
                     tf_option='min',
                     vel_option='avg'):

    # Make sure we'll end up with a single record in time
    if time_index is None and not time_average:
        print 'Error (read_plot_latlon): either specify time_index or set time_average=True.'
        sys.exit()

    if date_string is None and time_index is not None:
        # Determine what to write about the date
        date_string = parse_date(file_path=file_path, time_index=time_index)

    if not isinstance(grid, Grid):
        # This is the path to the NetCDF grid file, not a Grid object
        # Make a grid object from it
        grid = Grid(grid)

    # Read necessary variables from NetCDF file(s), and mask appropriately
    if var == 'ismr':
        shifwflx = mask_except_zice(
            read_netcdf(file_path,
                        'SHIfwFlx',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var in ['bwtemp', 'sst', 'tminustf']:
        # Read temperature. Some of these variables need more than temperature and so second_file_path might be set.
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, 'THETA')
        else:
            file_path_use = file_path
        temp = mask_3d(
            read_netcdf(file_path_use,
                        'THETA',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var in ['bwsalt', 'sss', 'tminustf']:
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, 'SALT')
        else:
            file_path_use = file_path
        salt = mask_3d(
            read_netcdf(file_path_use,
                        'SALT',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var == 'aice':
        aice = mask_land_zice(
            read_netcdf(file_path,
                        'SIarea',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var == 'hice':
        hice = mask_land_zice(
            read_netcdf(file_path,
                        'SIheff',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var == 'mld':
        mld = mask_land_zice(
            read_netcdf(file_path,
                        'MXLDEPTH',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var == 'eta':
        eta = mask_land_zice(
            read_netcdf(file_path,
                        'ETAN',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var == 'saltflx':
        saltflx = mask_land_zice(
            read_netcdf(file_path,
                        'SIempmr',
                        time_index=time_index,
                        t_start=t_start,
                        t_end=t_end,
                        time_average=time_average), grid)
    if var == 'vel':
        # First read u
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, 'UVEL')
        else:
            file_path_use = file_path
        u = mask_3d(read_netcdf(file_path_use,
                                'UVEL',
                                time_index=time_index,
                                t_start=t_start,
                                t_end=t_end,
                                time_average=time_average),
                    grid,
                    gtype='u')
        # Now read v
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path, 'VVEL')
        else:
            file_path_use = file_path
        v = mask_3d(read_netcdf(file_path_use,
                                'VVEL',
                                time_index=time_index,
                                t_start=t_start,
                                t_end=t_end,
                                time_average=time_average),
                    grid,
                    gtype='v')
    if var == 'velice':
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path,
                                          'SIuice')
        else:
            file_path_use = file_path
        uice = mask_land_zice(read_netcdf(file_path_use,
                                          'SIuice',
                                          time_index=time_index,
                                          t_start=t_start,
                                          t_end=t_end,
                                          time_average=time_average),
                              grid,
                              gtype='u')
        if second_file_path is not None:
            file_path_use = find_variable(file_path, second_file_path,
                                          'SIvice')
        else:
            file_path_use = file_path
        vice = mask_land_zice(read_netcdf(file_path_use,
                                          'SIvice',
                                          time_index=time_index,
                                          t_start=t_start,
                                          t_end=t_end,
                                          time_average=time_average),
                              grid,
                              gtype='v')

    # Plot
    if var == 'ismr':
        plot_ismr(shifwflx,
                  grid,
                  vmin=vmin,
                  vmax=vmax,
                  zoom_fris=zoom_fris,
                  xmin=xmin,
                  xmax=xmax,
                  ymin=ymin,
                  ymax=ymax,
                  change_points=change_points,
                  date_string=date_string,
                  fig_name=fig_name)
    elif var == 'bwtemp':
        plot_bw('temp',
                temp,
                grid,
                vmin=vmin,
                vmax=vmax,
                zoom_fris=zoom_fris,
                xmin=xmin,
                xmax=xmax,
                ymin=ymin,
                ymax=ymax,
                date_string=date_string,
                fig_name=fig_name)
    elif var == 'bwsalt':
        plot_bw('salt',
                salt,
                grid,
                vmin=vmin,
                vmax=vmax,
                zoom_fris=zoom_fris,
                xmin=xmin,
                xmax=xmax,
                ymin=ymin,
                ymax=ymax,
                date_string=date_string,
                fig_name=fig_name)
    elif var == 'sst':
        plot_ss('temp',
                temp,
                grid,
                vmin=vmin,
                vmax=vmax,
                zoom_fris=zoom_fris,
                xmin=xmin,
                xmax=xmax,
                ymin=ymin,
                ymax=ymax,
                date_string=date_string,
                fig_name=fig_name)
    elif var == 'sss':
        plot_ss('salt',
                salt,
                grid,
                vmin=vmin,
                vmax=vmax,
                zoom_fris=zoom_fris,
                xmin=xmin,
                xmax=xmax,
                ymin=ymin,
                ymax=ymax,
                date_string=date_string,
                fig_name=fig_name)
    elif var == 'aice':
        plot_2d_noshelf('aice',
                        aice,
                        grid,
                        vmin=vmin,
                        vmax=vmax,
                        zoom_fris=zoom_fris,
                        xmin=xmin,
                        xmax=xmax,
                        ymin=ymin,
                        ymax=ymax,
                        date_string=date_string,
                        fig_name=fig_name)
    elif var == 'hice':
        plot_2d_noshelf('hice',
                        hice,
                        grid,
                        vmin=vmin,
                        vmax=vmax,
                        zoom_fris=zoom_fris,
                        xmin=xmin,
                        xmax=xmax,
                        ymin=ymin,
                        ymax=ymax,
                        date_string=date_string,
                        fig_name=fig_name)
    elif var == 'mld':
        plot_2d_noshelf('mld',
                        mld,
                        grid,
                        vmin=vmin,
                        vmax=vmax,
                        zoom_fris=zoom_fris,
                        xmin=xmin,
                        xmax=xmax,
                        ymin=ymin,
                        ymax=ymax,
                        date_string=date_string,
                        fig_name=fig_name)
    elif var == 'eta':
        plot_2d_noshelf('eta',
                        eta,
                        grid,
                        ctype='plusminus',
                        vmin=vmin,
                        vmax=vmax,
                        zoom_fris=zoom_fris,
                        xmin=xmin,
                        xmax=xmax,
                        ymin=ymin,
                        ymax=ymax,
                        date_string=date_string,
                        fig_name=fig_name)
    elif var == 'saltflx':
        plot_2d_noshelf('saltflx',
                        saltflx,
                        grid,
                        ctype='plusminus',
                        vmin=vmin,
                        vmax=vmax,
                        zoom_fris=zoom_fris,
                        xmin=xmin,
                        xmax=xmax,
                        ymin=ymin,
                        ymax=ymax,
                        date_string=date_string,
                        fig_name=fig_name)
    elif var == 'tminustf':
        plot_tminustf(temp,
                      salt,
                      grid,
                      vmin=vmin,
                      vmax=vmax,
                      zoom_fris=zoom_fris,
                      xmin=xmin,
                      xmax=xmax,
                      ymin=ymin,
                      ymax=ymax,
                      tf_option=tf_option,
                      date_string=date_string,
                      fig_name=fig_name)
    elif var == 'vel':
        plot_vel(u,
                 v,
                 grid,
                 vel_option=vel_option,
                 vmin=vmin,
                 vmax=vmax,
                 zoom_fris=zoom_fris,
                 xmin=xmin,
                 xmax=xmax,
                 ymin=ymin,
                 ymax=ymax,
                 date_string=date_string,
                 fig_name=fig_name)
    elif var == 'velice':
        plot_vel(uice,
                 vice,
                 grid,
                 vel_option='ice',
                 vmin=vmin,
                 vmax=vmax,
                 zoom_fris=zoom_fris,
                 xmin=xmin,
                 xmax=xmax,
                 ymin=ymin,
                 ymax=ymax,
                 date_string=date_string,
                 fig_name=fig_name)
    else:
        print 'Error (read_plot_latlon): variable key ' + str(
            var) + ' does not exist'
        sys.exit()