コード例 #1
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)
コード例 #2
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()
コード例 #3
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)
コード例 #4
0
ファイル: plot_other.py プロジェクト: wydh/mitgcm_python
 def read_data (var_name):
     # First choose the right file
     if second_file_path is not None:
         file_path_use = find_variable(file_path, second_file_path)
     else:
         file_path_use = file_path
     data = read_netcdf(file_path_use, var_name, time_index=time_index, t_start=t_start, t_end=t_end, time_average=time_average)
     return data
コード例 #5
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)
コード例 #6
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()