Exemplo n.º 1
0
    def __init__(self, grid=None, llcrnrlon=-180, llcrnrlat=-40, urcrnrlon=180,
                 urcrnrlat=40, proj='lcc', resolution='c', figsize=(8., 6.),
                 dlat=1, dlon=2):
        """
        map class for abstracting the basemap methods for quick and easy creation
        of geographically referenced data figures


        Parameters
        ----------
        grid: seapy.model.grid or string, optional:
            grid to use to define boundaries
        llcrnrlon: float, optional
            longitude of lower, left corner
        llcrnrlat: float, optional
            latitude of lower, left corner
        urcrnrlon: float, optional
            longitude of upper, right corner
        urcrnrlat: float, optional
            latitude of upper, right corner
        proj: string, optional
            projection to use for map
        resolution: character
            resolution to use for coastline, etc. From Basemap:
            'c' (crude), 'l' (low), 'i' (intermediate),
            'h' (high), 'f' (full), or None
        figsize: list, optional
            dimensions to use for creation of figure
        dlat: float, optional
            how often to mark latitude lines
        dlon: float, optional
            how often to mark longitude lines


        Returns
        -------
        None

        """
        if grid is not None:
            grid = asgrid(grid)
            llcrnrlat = np.min(grid.lat_rho)
            urcrnrlat = np.max(grid.lat_rho)
            llcrnrlon = np.min(grid.lon_rho)
            urcrnrlon = np.max(grid.lon_rho)

        self.basemap = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat,
                               urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat,
                               projection=proj,
                               lat_0=urcrnrlat - (urcrnrlat - llcrnrlat) / 2.,
                               lon_0=urcrnrlon - (urcrnrlon - llcrnrlon) / 2.,
                               resolution=resolution, area_thresh=0.0)

        self.figsize = figsize
        self.dlon = dlon
        self.dlat = dlat
        self.fig = None
        self.new_figure()
Exemplo n.º 2
0
    def __init__(self, grid=None, region=(-180, -40, 180, 40),
                 proj='PlateCarree', resolution='auto', figsize=(8., 6.),
                 fig=None, fill_color=cft.COLORS['water']):
        import inspect

        if grid is not None:
            grid = asgrid(grid)
            self.region = (np.min(grid.lon_rho), np.min(grid.lat_rho),
                           np.max(grid.lon_rho), np.max(grid.lat_rho))
        else:
            self.region = region

        # Set up the projection scheme
        try:
            cproj = getattr(ccrs, proj)
        except AttributeError:
            warn(
                f"WARNING: {proj} is not a valid projection. " +
                "Using 'PlateCarree' instead")
            cproj = ccrs.PlateCarree
        self.proj = cproj

        # Determine what our projection needs
        self.clon = 0.5 * (region[0] + region[2])
        self.clat = 0.5 * (region[1] + region[3])

        args = inspect.getfullargspec(cproj)[0]
        if "central_latitude" not in args:
            self.clat = None

        self.fill = fill_color
        self.figsize = figsize
        self.res = resolution
        self.fig = fig
        if fig is None:
            self.new_figure()
Exemplo n.º 3
0
    def __init__(self, grid=None, llcrnrlon=-180, llcrnrlat=-40, urcrnrlon=180,
                 urcrnrlat=40, proj='lcc', resolution='c', figsize=(8., 6.),
                 dlat=1, dlon=2, fig=None, ax=None, fill_color="aqua"):
        """
        map class for abstracting the basemap methods for quick and easy creation
        of geographically referenced data figures


        Parameters
        ----------
        grid: seapy.model.grid or string, optional:
            grid to use to define boundaries
        llcrnrlon: float, optional
            longitude of lower, left corner
        llcrnrlat: float, optional
            latitude of lower, left corner
        urcrnrlon: float, optional
            longitude of upper, right corner
        urcrnrlat: float, optional
            latitude of upper, right corner
        proj: string, optional
            projection to use for map
        resolution: character
            resolution to use for coastline, etc. From Basemap:
            'c' (crude), 'l' (low), 'i' (intermediate),
            'h' (high), 'f' (full), or None
        figsize: list, optional
            dimensions to use for creation of figure
        dlat: float, optional
            interval to mark latitude lines (e.g., if dlat=0.5 every 0.5deg mark)
        dlon: float, optional
            interval to mark longitude lines (e.g., if dlon=0.5 every 0.5deg mark)
        fig: matplotlib.pyplot.figure object, optional
            If you want to plot on a pre-configured figure, pass the figure object
            along with the axis object.
        ax: matplotlib.pyplot.axis object, optional
            If you want to plot on a pre-configured figure, pass the axis object
            along with the figure object.
        fill_color: string, optional
            The color to use for the axis background

        Returns
        -------
        None

        """
        if grid is not None:
            grid = asgrid(grid)
            llcrnrlat = np.min(grid.lat_rho)
            urcrnrlat = np.max(grid.lat_rho)
            llcrnrlon = np.min(grid.lon_rho)
            urcrnrlon = np.max(grid.lon_rho)

        self.basemap = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat,
                               urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat,
                               projection=proj,
                               lat_0=urcrnrlat - (urcrnrlat - llcrnrlat) / 2.,
                               lon_0=urcrnrlon - (urcrnrlon - llcrnrlon) / 2.,
                               resolution=resolution, area_thresh=0.0, ax=ax)

        self.figsize = figsize
        self.dlon = dlon
        self.dlat = dlat
        self.fig = fig
        self.ax = ax
        self.fill_color = fill_color
        reset = True if fig is None else False
        self.new_figure(reset=reset)
Exemplo n.º 4
0
    def __init__(self,
                 grid=None,
                 llcrnrlon=-180,
                 llcrnrlat=-40,
                 urcrnrlon=180,
                 urcrnrlat=40,
                 proj='lcc',
                 resolution='c',
                 figsize=(8., 6.),
                 dlat=1,
                 dlon=2,
                 fig=None,
                 ax=None,
                 fill_color="aqua"):
        """
        map class for abstracting the basemap methods for quick and easy creation
        of geographically referenced data figures


        Parameters
        ----------
        grid: seapy.model.grid or string, optional:
            grid to use to define boundaries
        llcrnrlon: float, optional
            longitude of lower, left corner
        llcrnrlat: float, optional
            latitude of lower, left corner
        urcrnrlon: float, optional
            longitude of upper, right corner
        urcrnrlat: float, optional
            latitude of upper, right corner
        proj: string, optional
            projection to use for map
        resolution: character
            resolution to use for coastline, etc. From Basemap:
            'c' (crude), 'l' (low), 'i' (intermediate),
            'h' (high), 'f' (full), or None
        figsize: list, optional
            dimensions to use for creation of figure
        dlat: float, optional
            interval to mark latitude lines (e.g., if dlat=0.5 every 0.5deg mark)
        dlon: float, optional
            interval to mark longitude lines (e.g., if dlon=0.5 every 0.5deg mark)
        fig: matplotlib.pyplot.figure object, optional
            If you want to plot on a pre-configured figure, pass the figure object
            along with the axis object.
        ax: matplotlib.pyplot.axis object, optional
            If you want to plot on a pre-configured figure, pass the axis object
            along with the figure object.
        fill_color: string, optional
            The color to use for the axis background

        Returns
        -------
        None

        """
        if grid is not None:
            grid = asgrid(grid)
            llcrnrlat = np.min(grid.lat_rho)
            urcrnrlat = np.max(grid.lat_rho)
            llcrnrlon = np.min(grid.lon_rho)
            urcrnrlon = np.max(grid.lon_rho)

        self.basemap = Basemap(llcrnrlon=llcrnrlon,
                               llcrnrlat=llcrnrlat,
                               urcrnrlon=urcrnrlon,
                               urcrnrlat=urcrnrlat,
                               projection=proj,
                               lat_0=urcrnrlat - (urcrnrlat - llcrnrlat) / 2.,
                               lon_0=urcrnrlon - (urcrnrlon - llcrnrlon) / 2.,
                               resolution=resolution,
                               area_thresh=0.0,
                               ax=ax)

        self.figsize = figsize
        self.dlon = dlon
        self.dlat = dlat
        self.fig = fig
        self.ax = ax
        self.fill_color = fill_color
        reset = True if fig is None else False
        self.new_figure(reset=reset)
Exemplo n.º 5
0
    parser.add_argument('--step', help = 'number of days')
    parser.add_argument('--obs', default = None, nargs = '+', type = str, help = 'list of obs files')
    args = parser.parse_args()
    

    start, end = args.drange
    step = int(args.step)
    units = 'days since 2000-01-01'
    
    sdate = int(date2num(datetime.strptime(start,'%Y%m%d'), units=units))
    edate =int(date2num(datetime.strptime(end,'%Y%m%d'), units=units))
    drange = [(i, i+step) for i in range(sdate,edate,step)]
    
    # remove obs on the edge of the model grid within 5 cells
    grid_file = os.path.join(path, 'grid.nc')
    grid = asgrid(grid_file)
    pad = 5    
    limits = {'north':grid.eta_rho-pad, 'south':pad, 'east':grid.xi_rho-pad, 'west':pad}

    obs_list = args.obs    
    if args.obs is None:
        obs_list = name_dict.keys()
        
    obs_files = []
    for name in obs_list:
        data_dir = os.path.join(path, 'GRIDDED', name)
        fname = name_dict[name] + '.nc'
        flist = glob.glob(os.path.join(data_dir, fname))
        if flist == []:
            continue
        for f in flist: