Example #1
0
  def __call__(self, x, y, inverse=False, coords=None):
    from models import aacgm
    from copy import deepcopy
    import numpy as np
    import inspect

    if coords is not None and coords not in self._coordsDict:
      print 'Invalid coordinate system given in coords ({}): setting "{}"'.format(coords, self.coords)
      coords = None

    if coords and coords != self.coords:
      trans = coords+'-'+self.coords
      if trans in ['geo-mag','mag-geo']:
        flag = 0 if trans == 'geo-mag' else 1
        try:
          nx, ny = len(x), len(y)
          xt = np.array(x)
          yt = np.array(y)
          shape = xt.shape    
          y, x, _ = aacgm.aacgmConvArr(list(yt.flatten()), list(xt.flatten()), [0.]*nx, flag)
          x = np.array(x).reshape(shape)
          y = np.array(y).reshape(shape)
        except TypeError as e:
          y, x, _ = aacgm.aacgmConv(y, x, 0., flag)


    if self.coords is 'geo':
      return basemap.Basemap.__call__(self, x, y, inverse=inverse)

    elif self.coords is 'mag':
      try:
        callerFile, _, callerName = inspect.getouterframes(inspect.currentframe())[1][1:4]
      except: 
        return basemap.Basemap.__call__(self, x, y, inverse=inverse)
      if isinstance(y, float) and abs(y) == 90.:
        return basemap.Basemap.__call__(self, x, y, inverse=inverse)
      if 'mpl_toolkits' in callerFile and callerName is '_readboundarydata':
        if not inverse:
          try:
            nx, ny = len(x), len(y)
            x = np.array(x)
            y = np.array(y)
            shape = x.shape
            yout, xout, _ = aacgm.aacgmConvArr(list(y.flatten()), list(x.flatten()), [0.]*nx, 0)
            xout = np.array(xout).reshape(shape)
            yout = np.array(yout).reshape(shape)
          except TypeError:
            yout, xout, _ = aacgm.aacgmConv(y, x, 0., 0)
          return basemap.Basemap.__call__(self, xout, yout, inverse=inverse)
        else:
          return basemap.Basemap.__call__(self, x, y, inverse=inverse)
      else:
        return basemap.Basemap.__call__(self, x, y, inverse=inverse)

    elif self.coords is 'mlt':
      print 'Not implemented'
      callerFile, _, callerName = inspect.getouterframes(inspect.currentframe())[1][1:4]
Example #2
0
    def _readboundarydata(self, name, as_polygons=False):
        from models import aacgm
        from copy import deepcopy
        import _geoslib
        import numpy as np

        if self.coords is 'mag':
            nPts = len(self._boundarypolyll.boundary[:, 0])
            lats, lons, _ = aacgm.aacgmConvArr(
                list(self._boundarypolyll.boundary[:, 1]),
                list(self._boundarypolyll.boundary[:, 0]), [0.] * nPts,
                self.datetime.year, 1)
            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
        else:
            return basemap.Basemap._readboundarydata(self,
                                                     name,
                                                     as_polygons=as_polygons)
Example #3
0
  def _readboundarydata(self, name, as_polygons=False):
    from models import aacgm
    from copy import deepcopy
    import _geoslib
    import numpy as np

    if self.coords is 'mag':
      nPts = len(self._boundarypolyll.boundary[:, 0])
      lats, lons, _ = aacgm.aacgmConvArr(list(self._boundarypolyll.boundary[:, 1]), 
              list(self._boundarypolyll.boundary[:, 0]), 
              [0.]*nPts, 1)
      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
    else: 
      return basemap.Basemap._readboundarydata(self, name, as_polygons=as_polygons)
Example #4
0
    def __call__(self, x, y, inverse=False, coords=None):
        from models import aacgm
        from copy import deepcopy
        import numpy as np
        import inspect

        if coords is not None and coords not in self._coordsDict:
            print 'Invalid coordinate system given in coords ({}): setting "{}"'.format(
                coords, self.coords)
            coords = None

        if coords and coords != self.coords:
            trans = coords + '-' + self.coords
            if trans in ['geo-mag', 'mag-geo']:
                flag = 0 if trans == 'geo-mag' else 1
                try:
                    nx, ny = len(x), len(y)
                    xt = np.array(x)
                    yt = np.array(y)
                    shape = xt.shape
                    y, x, _ = aacgm.aacgmConvArr(list(yt.flatten()),
                                                 list(xt.flatten()), [0.] * nx,
                                                 self.datetime.year, flag)
                    x = np.array(x).reshape(shape)
                    y = np.array(y).reshape(shape)
                except TypeError as e:
                    y, x, _ = aacgm.aacgmConv(y, x, 0., self.datetime.year,
                                              flag)

        if self.coords is 'geo':
            return basemap.Basemap.__call__(self, x, y, inverse=inverse)

        elif self.coords is 'mag':
            try:
                callerFile, _, callerName = inspect.getouterframes(
                    inspect.currentframe())[1][1:4]
            except:
                return basemap.Basemap.__call__(self, x, y, inverse=inverse)
            if isinstance(y, float) and abs(y) == 90.:
                return basemap.Basemap.__call__(self, x, y, inverse=inverse)
            if 'mpl_toolkits' in callerFile and callerName is '_readboundarydata':
                if not inverse:
                    try:
                        nx, ny = len(x), len(y)
                        x = np.array(x)
                        y = np.array(y)
                        shape = x.shape
                        yout, xout, _ = aacgm.aacgmConvArr(
                            list(y.flatten()), list(x.flatten()), [0.] * nx,
                            self.datetime.year, 0)
                        xout = np.array(xout).reshape(shape)
                        yout = np.array(yout).reshape(shape)
                    except TypeError:
                        yout, xout, _ = aacgm.aacgmConv(
                            y, x, 0., self.datetime.year, 0)
                    return basemap.Basemap.__call__(self,
                                                    xout,
                                                    yout,
                                                    inverse=inverse)
                else:
                    return basemap.Basemap.__call__(self,
                                                    x,
                                                    y,
                                                    inverse=inverse)
            else:
                return basemap.Basemap.__call__(self, x, y, inverse=inverse)

        elif self.coords is 'mlt':
            print 'Not implemented'
            callerFile, _, callerName = inspect.getouterframes(
                inspect.currentframe())[1][1:4]