Beispiel #1
0
def getmap(ifile, resolution = 'i'):
    from mpl_toolkits.basemap import Basemap
    from .conventions.ioapi import get_ioapi_sphere
    if getattr(ifile, 'GDTYP', 0) in (2, 7) and all([hasattr(ifile, k) for k in 'P_GAM P_ALP P_BET XORIG YORIG XCELL YCELL'.split()]):
        try:
            NROWS = len(ifile.dimensions['ROW'])
            NCOLS = len(ifile.dimensions['COL'])
        except KeyError:
            NROWS = ifile.NROWS
            NCOLS = ifile.NCOLS
            
        llcrnrx = ifile.XORIG
        urcrnrx = ifile.XORIG + NCOLS * ifile.XCELL

        llcrnry = ifile.YORIG
        urcrnry = ifile.YORIG + NROWS * ifile.YCELL
        semi_major_axis, semi_minor_axis = get_ioapi_sphere()
        if ifile.GDTYP == 2:
            from mpl_toolkits.basemap.pyproj import Proj
            p = Proj(proj='lcc',rsphere = (semi_major_axis, semi_major_axis), lon_0 = ifile.P_GAM, lat_1 = ifile.P_ALP, lat_2 = ifile.P_BET, lat_0 = ifile.YCENT)
            llcrnrlon, llcrnrlat = p(llcrnrx, llcrnry, inverse = True)
            urcrnrlon, urcrnrlat = p(urcrnrx, urcrnry, inverse = True)
            m = Basemap(projection = 'lcc', rsphere = (semi_major_axis, semi_major_axis), lon_0=ifile.P_GAM, lat_1 = ifile.P_ALP, lat_2 = ifile.P_BET, lat_0 = ifile.YCENT, llcrnrlon = llcrnrlon, llcrnrlat = llcrnrlat, urcrnrlat = urcrnrlat, urcrnrlon = urcrnrlon, resolution = resolution, suppress_ticks = False)
        elif ifile.GDTYP == 7:
            from mpl_toolkits.basemap.pyproj import Proj
            mapstr = '+proj=merc +a=%s +b=%s +lat_ts=0 +lon_0=%s' % (semi_major_axis, semi_major_axis, ifile.XCENT)
            p = Proj(mapstr)
            #p = Proj(proj='merc',rsphere = (semi_major_axis, semi_major_axis), lat_ts = ifile.P_ALP, lat_0 = ifile.YCENT, lon_0 = ifile.XCENT)
            llcrnrlon, llcrnrlat = p(llcrnrx, llcrnry, inverse = True)
            urcrnrlon, urcrnrlat = p(urcrnrx, urcrnry, inverse = True)
            m = Basemap(projection = 'merc', rsphere = (semi_major_axis, semi_major_axis), lon_0=ifile.XCENT, lat_ts = 0, llcrnrlon = llcrnrlon, llcrnrlat = llcrnrlat, urcrnrlat = urcrnrlat, urcrnrlon = urcrnrlon, resolution = resolution, suppress_ticks = False)
        print('Found IO/API Mapping parameters')
    else:
        kwds = dict(suppress_ticks = False)
        try:
            lat, latunit = getlatbnds(ifile)
            lon, lonunit = getlonbnds(ifile)
            kwds['resolution'] = 'i'
            kwds['llcrnrlat'] = lat[:].min()
            kwds['urcrnrlat'] = lat[:].max()
            kwds['llcrnrlon'] = lon[:].min()
            kwds['urcrnrlon'] = lon[:].max()
            kwds['resolution'] = resolution
        except:
            pass
        m = Basemap(**kwds)
    return m
Beispiel #2
0
 def _define_proj(self, utm_zone):
     '''
     Define the UTM projection from specified UTM zone. Store it for later use.
     '''
     self.projs[utm_zone] = Proj(proj='utm',
                                 zone=utm_zone,
                                 ellps='WGS84',
                                 datum='WGS84',
                                 units='m')
def make_proj_grids(proj_dict, grid_dict):
    map_proj = Proj(proj_dict)
    sw_x, sw_y = map_proj(grid_dict['sw_lon'], grid_dict['sw_lat'])
    ne_x, ne_y = map_proj(grid_dict['ne_lon'], grid_dict['ne_lat'])
    dx = grid_dict['dx']
    dy = grid_dict['dy']
    x = np.arange(np.round(sw_x), np.round(ne_x) + dx, dx)
    y = np.arange(np.round(sw_y), np.round(ne_y) + dy, dy)
    x_grid, y_grid = np.meshgrid(x, y)
    lon_grid, lat_grid = map_proj(x_grid, y_grid, inverse=True)
    mapping_data = {'lon': lon_grid, 'lat': lat_grid, 'x': x_grid, 'y': y_grid}
    return mapping_data
Beispiel #4
0
 def _set_proj(self):
     '''
     Define the projection
     '''
     if self.proj_name in self.proj_dict:
         for k, v in self.proj_dict[self.proj_name].iteritems():
             setattr(self, k, v)
     if self.gdtyp == 6:
         self.proj = Proj(proj='stere',
                          lat_ts=self.p_bet,
                          lat_0=self.ycent,
                          lon_0=self.p_gam)
     elif self.gdtyp == 2:
         self.proj = Proj(proj='lcc',
                          lat_1=self.p_alp,
                          lat_2=self.p_bet,
                          lon_0=self.p_gam,
                          lat_0=self.ycent,
                          a=6370000,
                          b=6370000,
                          no_defs=True)
def get_proj_obj(proj_dict):
    return Proj(proj_dict)
Beispiel #6
0
#import matplotlib.pyplot as pylab
#
from numpy import sqrt, arange, pi, array, cos, sin, dot, matrix, mat, rint, linspace, average, median, std
#from statlib import stats
#import scipy.stats as ss
#from scipy import interpolate
#
#from pylab import *
from mpl_toolkits.basemap.pyproj import Proj
from mpl_toolkits.basemap.pyproj import Geod
#from mpl_toolkits.basemap import Basemap as Basemap
#from matplotlib.mlab import griddata
#from waveloc_funcs import *
#from flexwin_funcs import *

proj_default = Proj(proj='utm', zone='10', ellps='WGS84')
geod_default = Geod(ellps='WGS84')


class GeoPoint(object):
    """
  A point in 3D space, as general as can be.
  Abstract class - do not instantiate.

  Contains methods common to daughter classes GeoPointXY and GeoPointLL.
  """
    def __init__(self):
        raise NotImplemented

    def dist_km_from(self, alat, alon):
        """
import os
from mpl_toolkits.basemap.pyproj import Proj
import matplotlib.pyplot as plt
import numpy as np
import json

# Project data to New York Long Island SRS (Spatial Reference System)
# http://www.spatialreference.org/ref/epsg/2263/
p = Proj(init="epsg:2263")

# Load GPS data from url or file
#f = urllib2.urlopen("https://feeds.citibikenyc.com/stations/stations.json")
#jsonData = json.load(f)
with open('../data/citibike.json', 'r') as f:
    jsonData = json.load(f)

X = []
for i in range(len(jsonData['stationBeanList'])):
    lon = jsonData['stationBeanList'][i]['longitude']
    lat = jsonData['stationBeanList'][i]['latitude']
    X.append((lat, lon))
X = np.array(X)
x, y = p(X[:, 1], X[:, 0])  # Projection of coordinates

# Get underlying nyc mapping data
nyc_neighborhoods = "../nyc_data/nyc_neighborhoods.json"
polygons = []
with open(nyc_neighborhoods, 'r') as f:
    jsonData = json.load(f)
    for feature in jsonData['features']:
        for polygon in feature['geometry']['coordinates']:
Beispiel #8
0
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap.pyproj import Proj
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from osgeo import ogr
import json

# Project data to New York Long Island SRS (Spatial Reference System)
# http://www.spatialreference.org/ref/epsg/2263/
p = Proj(init="epsg:2263")

# Load neighborhood histogram
histogram = np.load('neighborhood_histogram.npy').item()

# Load neighborhood polygons into dictionary
neighborhoods = {}
with open("../nyc_data/nyc_neighborhoods.json", 'r') as f:
    jsonData = json.load(f)
    for feature in jsonData['features']:
        polygon = np.array(feature['geometry']['coordinates']).squeeze()
        x, y = p(polygon[:, 0], polygon[:, 1])  # Projection of coordinates
        neighborhoods[feature['properties']['neighborhood']] = np.array(
            zip(x, y))

# Create polygon patches
patches = []
colors = []
for key in neighborhoods:
    polygon = Polygon(neighborhoods[key], True)
    patches.append(polygon)
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap.pyproj import Proj
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from osgeo import ogr
import json



# Project data to New York Long Island SRS (Spatial Reference System)
# http://www.spatialreference.org/ref/epsg/2263/
p = Proj(init="epsg:2263")

# Load neighborhood histogram
histogram = np.load('neighborhood_histogram.npy').item()

# Load neighborhood polygons into dictionary
neighborhoods = {}
with open("../nyc_data/nyc_neighborhoods.json", 'r') as f:
	jsonData = json.load(f)
	for feature in jsonData['features']:
		polygon = np.array(feature['geometry']['coordinates']).squeeze()
		x, y = p(polygon[:, 0], polygon[:, 1]) # Projection of coordinates
		neighborhoods[feature['properties']['neighborhood']] = np.array(zip(x, y))
	
	

# Create polygon patches
patches = []
colors = []