def __call__(self, x, y, inverse=False, coords=None): from copy import deepcopy import numpy as np import inspect from davitpy.utils import coord_conv # First we need to check and see if drawcoastlines() or a similar # method is calling because if we are in a coordinate system # differing from 'geo' then the coastlines will get plotted # in the wrong location... try: callerFile, _, callerName = \ inspect.getouterframes(inspect.currentframe())[1][1:4] except: return basemap.Basemap.__call__(self, x, y, inverse=inverse) # If call was from drawcoastlines, etc. then we do something different # Remember that AACGM is not designed to be used near the ground. if 'mpl_toolkits' in callerFile and callerName is '_readboundarydata': x, y = coord_conv(x, y, "geo", self.coords, altitude=self.altitude, date_time=self.datetime) return basemap.Basemap.__call__(self, x, y, inverse=False) # If the call was not from drawcoastlines, etc. do the conversion. # If we aren't changing between lat/lon coordinate systems: elif coords is None: return basemap.Basemap.__call__(self, x, y, inverse=inverse) # If inverse is true do the calculation of x,y map coords first, # then lat/lon coord system change. elif inverse: x, y = basemap.Basemap.__call__(self, x, y, inverse=True) return coord_conv(x, y, self.coords, coords, altitude=self.altitude, date_time=self.datetime) # If inverse is false do the lat/lon coord system change first, # then calculation of x,y map coords. else: x, y = coord_conv(x, y, coords, self.coords, altitude=self.altitude, date_time=self.datetime) return basemap.Basemap.__call__(self, x, y, inverse=False)
def _readboundarydata(self, name, as_polygons=False): from copy import deepcopy import _geoslib import numpy as np from davitpy.utils import coord_conv lons, lats = coord_conv(list(self._boundarypolyll.boundary[:, 0]), list(self._boundarypolyll.boundary[:, 1]), self.coords, "geo", altitude=0., date_time=self.datetime) b = np.asarray([lons,lats]).T oldgeom = deepcopy(self._boundarypolyll) newgeom = _geoslib.Polygon(b).fix() self._boundarypolyll = newgeom out = basemap.Basemap._readboundarydata(self, name, as_polygons=as_polygons) self._boundarypolyll = oldgeom return out
def __init__(self, datetime=None, coords='geo', projection='stere', resolution='c', dateTime=None, lat_0=None, lon_0=None, boundinglat=None, width=None, height=None, draw=True, fillContinents='.8', fillOceans='None', fillLakes=None, fill_alpha=.5, coastLineWidth=0., coastLineColor=None, grid=True, gridLabels=True, showCoords=True, **kwargs): """ Create empty map **Args**: * **[datetime]** (datetime.datetime or NoneType): new format for providing the time that is added to the mapObj class as the attribute "datetime". This is needed when plotting in MLT. If not provided, (and not provided in dateTime) the current time will be used (default=None) * **[coords]**: plotting coordinates. (default='geo') * **[projection]**: map projection. (default='stere') * **[resolution]**: map resolution. c=crude, i=inter. (default='c') * **[dateTime]** (datetime.datetime or NoneType): old format for providing the time that is added to the mapObj class as the attribute "dateTime". This is needed when plotting in MLT. If not provided, (and not provided in datetime) the current time will be used. (default=None) * **[lon_0]**: center meridian (default is -70E) * **[lat_0]**: center latitude (default is -90E) * **[boundinglat]**: bounding latitude (default is +/-20) * **[width]**: width in m from the (lat_0, lon_0) center * **[height]**: height in m from the (lat_0, lon_0) center * **[draw]**: set to "False" to skip initial drawing of map * **[fillContinents]**: continent color. Default=0.8 is 'grey' * **[fillOceans]**: ocean color. Default='None' provides no filling * **[fillLakes]**: lake color. Default='None' provides no filling * **[fill_alpha]**: Specifies transparency for continents and lakes. Default=.5 provides 50% transparency. * **[coastLineWidth]**: Line width for coastlines. Default=0.0 * **[coastLineColor]**: Line color for coastlines. Default=None * **[grid]**: show/hide parallels and meridians grid (default=True) * **[gridLabels]**: label parallels and meridians (default=True) * **[showCoords]**: display coordinate system name in upper right corner (default=True) * **[kwargs]**: See <http://tinyurl.com/d4rzmfo> for more keywords **Returns**: * **map**: a Basemap object (<http://tinyurl.com/d4rzmfo>) with an additional attribute that specifies the datetime **Example**: :: myMap = mapObj(lat_0=50, lon_0=-95, width=111e3*60, height=111e3*60) written by Sebastien, 2013-02 """ import math from copy import deepcopy import datetime as dt from davitpy.utils import coord_conv, get_coord_dict self.lat_0=lat_0 self.lon_0=lon_0 self._coastLineWidth=coastLineWidth self._coastLineColor=coastLineColor self._fillContinents=fillContinents self._fillOceans=fillOceans self._fillLakes=fillLakes self._showCoords=showCoords self._grid=grid self._gridLabels=gridLabels self._coordsDict, self._coords_string = get_coord_dict() if datetime is None and dateTime is None: print "Warning, datetime/dateTime not specified, using current time." datetime = dt.datetime.utcnow() dateTime = datetime elif datetime is None and dateTime is not None: print "Warning, setting datetime to dateTime" datetime = dateTime elif datetime is not None and dateTime is None: print "Warning, setting dateTime to datetime" dateTime = datetime else: assert(datetime == dateTime),\ "Cannot set datetime and dateTime to different times!" self.datetime = datetime self.dateTime = dateTime # Still a good idea to check whether coords are possible, because # there may be no call to coord_conv within this init. assert(coords in self._coordsDict),\ "coords set to " + coords + ",\n" + self.coords_string # Add an extra member to the Basemap class. self.coords = coords # Set map projection limits and center point depending on hemisphere selection if self.lat_0 is None: self.lat_0 = 90. if boundinglat: self.lat_0 = math.copysign(self.lat_0, boundinglat) if self.lon_0 is None: self.lon_0, _ = coord_conv(-100., 0., "geo", self.coords, altitude=0., date_time=self.datetime) if boundinglat: width = height = 2*111e3*( abs(self.lat_0 - boundinglat) ) # Initialize map with original Basemap super(mapObj, self).__init__(projection=projection, resolution=resolution, lat_0=self.lat_0, lon_0=self.lon_0, width=width, height=height, **kwargs) if draw: self.draw()
def __init__(self, ax=None, datetime=None, coords='geo', projection='stere', resolution='c', dateTime=None, lat_0=None, lon_0=None, boundinglat=None, width=None, height=None, draw=True, fillContinents='.8', fillOceans='None', fillLakes=None, fill_alpha=.5, coastLineWidth=0., coastLineColor=None, grid=True, gridLabels=True, gridLatRes=20., showCoords=True, altitude=0.0, lon_label_style=None, **kwargs): """This class wraps arround :class:`mpl_toolkits.basemap.Basemap` (<http://tinyurl.com/d4rzmfo>) """ import math from copy import deepcopy import datetime as dt from matplotlib import pyplot from davitpy.utils import coord_conv, get_coord_dict self.lat_0 = lat_0 self.lon_0 = lon_0 self._coastLineWidth = coastLineWidth self._coastLineColor = coastLineColor self._fillContinents = fillContinents self._fillOceans = fillOceans self._fillLakes = fillLakes self._fill_alpha = fill_alpha self._showCoords = showCoords self._grid = grid self._gridLabels = gridLabels self._gridLatRes = gridLatRes self._coordsDict, self._coords_string = get_coord_dict() self.altitude = altitude if coords.lower() != "geo" and altitude == 0.0: self.altitude = 350.0 if datetime is None and dateTime is None: logging.warning( "datetime/dateTime not specified, using current time.") datetime = dt.datetime.utcnow() dateTime = datetime elif datetime is None and dateTime is not None: logging.warning("setting datetime to dateTime") datetime = dateTime elif datetime is not None and dateTime is None: logging.warning("setting dateTime to datetime") dateTime = datetime else: assert(datetime == dateTime),\ logging.error("Cannot set datetime and dateTime to different times!") self.datetime = datetime self.dateTime = dateTime # Still a good idea to check whether coords are possible, because # there may be no call to coord_conv within this init. assert(coords in self._coordsDict),\ logging.error("coords set to " + coords + ",\n" + self.coords_string) # Add an extra member to the Basemap class. self.coords = coords # Set map projection limits and center point depending on hemisphere selection if self.lat_0 is None: self.lat_0 = 90. if boundinglat: self.lat_0 = math.copysign(self.lat_0, boundinglat) if self.lon_0 is None: self.lon_0, _ = coord_conv(-100., 0., "geo", self.coords, altitude=0., date_time=self.datetime) if boundinglat: width = height = 2 * 111e3 * (abs(self.lat_0 - boundinglat)) # Initialize map with original Basemap super(mapObj, self).__init__(projection=projection, resolution=resolution, lat_0=self.lat_0, lon_0=self.lon_0, width=width, height=height, ax=ax, **kwargs) if self.ax is None: self.ax = pyplot.gca() if draw: self.draw(lon_label_style=lon_label_style)
def __init__(self, ax=None, datetime=None, coords='geo', projection='stere', resolution='c', dateTime=None, lat_0=None, lon_0=None, boundinglat=None, width=None, height=None, draw=True, fillContinents='.8', fillOceans='None', fillLakes=None, fill_alpha=.5, coastLineWidth=0., coastLineColor=None, grid=True, gridLabels=True, showCoords=True, **kwargs): """This class wraps arround :class:`mpl_toolkits.basemap.Basemap` (<http://tinyurl.com/d4rzmfo>) """ import math from copy import deepcopy import datetime as dt from matplotlib import pyplot from davitpy.utils import coord_conv, get_coord_dict self.lat_0=lat_0 self.lon_0=lon_0 self._coastLineWidth=coastLineWidth self._coastLineColor=coastLineColor self._fillContinents=fillContinents self._fillOceans=fillOceans self._fillLakes=fillLakes self._showCoords=showCoords self._grid=grid self._gridLabels=gridLabels self._coordsDict, self._coords_string = get_coord_dict() if datetime is None and dateTime is None: logging.warning("datetime/dateTime not specified, using current time.") datetime = dt.datetime.utcnow() dateTime = datetime elif datetime is None and dateTime is not None: logging.warning("setting datetime to dateTime") datetime = dateTime elif datetime is not None and dateTime is None: logging.warning("setting dateTime to datetime") dateTime = datetime else: assert(datetime == dateTime),\ logging.error("Cannot set datetime and dateTime to different times!") self.datetime = datetime self.dateTime = dateTime # Still a good idea to check whether coords are possible, because # there may be no call to coord_conv within this init. assert(coords in self._coordsDict),\ logging.error("coords set to " + coords + ",\n" + self.coords_string) # Add an extra member to the Basemap class. self.coords = coords # Set map projection limits and center point depending on hemisphere selection if self.lat_0 is None: self.lat_0 = 90. if boundinglat: self.lat_0 = math.copysign(self.lat_0, boundinglat) if self.lon_0 is None: self.lon_0, _ = coord_conv(-100., 0., "geo", self.coords, altitude=0., date_time=self.datetime) if boundinglat: width = height = 2*111e3*( abs(self.lat_0 - boundinglat) ) # Initialize map with original Basemap super(mapObj, self).__init__(projection=projection, resolution=resolution,lat_0=self.lat_0, lon_0=self.lon_0,width=width, height=height,ax=ax,**kwargs) if self.ax is None: self.ax = pyplot.gca() if draw: self.draw()
def __init__(self, ax=None, datetime=None, coords='geo', projection='stere', resolution='c', dateTime=None, lat_0=None, lon_0=None, boundinglat=None, width=None, height=None, draw=True, fillContinents='.8', fillOceans='None', fillLakes=None, fill_alpha=.5, coastLineWidth=0., coastLineColor=None, grid=True, gridLabels=True, showCoords=True, **kwargs): """ Create empty map **Args**: * **[ax]** (matplotlib.axes._subplots.AxesSubplot or NoneType): Subplot axis to associate with this map (default=None) * **[datetime]** (datetime.datetime or NoneType): new format for providing the time that is added to the mapObj class as the attribute "datetime". This is needed when plotting in MLT. If not provided, (and not provided in dateTime) the current time will be used (default=None) * **[coords]**: plotting coordinates. (default='geo') * **[projection]**: map projection. (default='stere') * **[resolution]**: map resolution. c=crude, i=inter. (default='c') * **[dateTime]** (datetime.datetime or NoneType): old format for providing the time that is added to the mapObj class as the attribute "dateTime". This is needed when plotting in MLT. If not provided, (and not provided in datetime) the current time will be used. (default=None) * **[lon_0]**: center meridian (default is -70E) * **[lat_0]**: center latitude (default is -90E) * **[boundinglat]**: bounding latitude (default is +/-20) * **[width]**: width in m from the (lat_0, lon_0) center * **[height]**: height in m from the (lat_0, lon_0) center * **[draw]**: set to "False" to skip initial drawing of map * **[fillContinents]**: continent color. Default=0.8 is 'grey' * **[fillOceans]**: ocean color. Default='None' provides no filling * **[fillLakes]**: lake color. Default='None' provides no filling * **[fill_alpha]**: Specifies transparency for continents and lakes. Default=.5 provides 50% transparency. * **[coastLineWidth]**: Line width for coastlines. Default=0.0 * **[coastLineColor]**: Line color for coastlines. Default=None * **[grid]**: show/hide parallels and meridians grid (default=True) * **[gridLabels]**: label parallels and meridians (default=True) * **[showCoords]**: display coordinate system name in upper right corner (default=True) * **[kwargs]**: See <http://tinyurl.com/d4rzmfo> for more keywords **Returns**: * **map**: a Basemap object (<http://tinyurl.com/d4rzmfo>) with an additional attribute that specifies the datetime **Example**: :: myMap = mapObj(lat_0=50, lon_0=-95, width=111e3*60, height=111e3*60) written by Sebastien, 2013-02 """ import math from copy import deepcopy import datetime as dt from davitpy.utils import coord_conv, get_coord_dict self.lat_0 = lat_0 self.lon_0 = lon_0 self._coastLineWidth = coastLineWidth self._coastLineColor = coastLineColor self._fillContinents = fillContinents self._fillOceans = fillOceans self._fillLakes = fillLakes self._showCoords = showCoords self._grid = grid self._gridLabels = gridLabels self._coordsDict, self._coords_string = get_coord_dict() if datetime is None and dateTime is None: print "Warning, datetime/dateTime not specified, using current time." datetime = dt.datetime.utcnow() dateTime = datetime elif datetime is None and dateTime is not None: print "Warning, setting datetime to dateTime" datetime = dateTime elif datetime is not None and dateTime is None: print "Warning, setting dateTime to datetime" dateTime = datetime else: assert(datetime == dateTime),\ "Cannot set datetime and dateTime to different times!" self.datetime = datetime self.dateTime = dateTime # Still a good idea to check whether coords are possible, because # there may be no call to coord_conv within this init. assert(coords in self._coordsDict),\ "coords set to " + coords + ",\n" + self.coords_string # Add an extra member to the Basemap class. self.coords = coords # Set map projection limits and center point depending on hemisphere selection if self.lat_0 is None: self.lat_0 = 90. if boundinglat: self.lat_0 = math.copysign(self.lat_0, boundinglat) if self.lon_0 is None: self.lon_0, _ = coord_conv(-100., 0., "geo", self.coords, altitude=0., date_time=self.datetime) if boundinglat: width = height = 2 * 111e3 * (abs(self.lat_0 - boundinglat)) # Initialize map with original Basemap super(mapObj, self).__init__(projection=projection, resolution=resolution, lat_0=self.lat_0, lon_0=self.lon_0, width=width, height=height, **kwargs) if ax is not None: mapObj.ax = ax if draw: self.draw()