vtsuperdarn / davitpy

DEPRECATED The DaViT Python project
http://vtsuperdarn.github.com/davitpy/
GNU General Public License v3.0
37 stars 59 forks source link

Can't get example calls to mapObj to work #362

Closed johncoxon closed 6 years ago

johncoxon commented 6 years ago

I'm trying to get either of the two example calls to plotUtils.mapObj to work from the plotUtils.py file and I'm hoping someone can tell me why they're not working…!

When I try the first example call, I get this:

myMap = plotUtils.mapObj(lat_0=50, lon_0=-95, width=111e3*60, height=111e3*60)
WARNING:root:datetime/dateTime not specified, using current time.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-29-16423849a8c8> in <module>()
----> 1 myMap = plotUtils.mapObj(lat_0=50, lon_0=-95, width=111e3*60, height=111e3*60)

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/utils/plotUtils.pyc in __init__(self, ax, datetime, coords, projection, resolution, dateTime, lat_0, lon_0, boundinglat, width, height, draw, fillContinents, fillOceans, fillLakes, fill_alpha, coastLineWidth, coastLineColor, grid, gridLabels, gridLatRes, showCoords, altitude, lon_label_style, **kwargs)
    216 
    217         if draw:
--> 218           self.draw(lon_label_style=lon_label_style)
    219 
    220     def draw(self, lon_label_style=None):

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/utils/plotUtils.pyc in draw(self, lon_label_style)
    235         _ = self.fillcontinents(color=self._fillContinents,
    236                                 lake_color=self._fillLakes,
--> 237                                 alpha=self._fill_alpha)
    238 
    239         # Add coordinate spec

/anaconda2/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in fillcontinents(self, color, lake_color, ax, zorder, alpha)
   1796         self.set_axes_limits(ax=ax)
   1797         # clip continent polygons to map limbs
-> 1798         polys,c = self._cliplimb(ax,polys)
   1799         return polys
   1800 

/anaconda2/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in _cliplimb(self, ax, coll)
   1804         c = self._mapboundarydrawn
   1805         if c not in ax.patches:
-> 1806             p = ax.add_patch(c)
   1807             #p.set_clip_on(False)
   1808         try:

/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in add_patch(self, p)
   1832         if p.get_clip_path() is None:
   1833             p.set_clip_path(self.patch)
-> 1834         self._update_patch_limits(p)
   1835         self.patches.append(p)
   1836         p._remove_method = lambda h: self.patches.remove(h)

/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _update_patch_limits(self, patch)
   1855             if patch.get_data_transform() != self.transData:
   1856                 patch_to_data = (patch.get_data_transform() -
-> 1857                                  self.transData)
   1858                 xys = patch_to_data.transform(xys)
   1859 

/anaconda2/lib/python2.7/site-packages/matplotlib/transforms.pyc in __sub__(self, other)
   1386             if sub_tree == self:
   1387                 if not remainder.has_inverse:
-> 1388                     raise ValueError("The shortcut cannot be computed since "
   1389                      "other's transform includes a non-invertable component.")
   1390                 return remainder.inverted()

ValueError: The shortcut cannot be computed since other's transform includes a non-invertable component.

When I try the second call, I get this:

myMap = plotUtils.mapObj(boundinglat=30, coords='mag')
WARNING:root:datetime/dateTime not specified, using current time.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-27-869a25717fd1> in <module>()
----> 1 myMap = plotUtils.mapObj(boundinglat=30, coords='mag')

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/utils/plotUtils.pyc in __init__(self, ax, datetime, coords, projection, resolution, dateTime, lat_0, lon_0, boundinglat, width, height, draw, fillContinents, fillOceans, fillLakes, fill_alpha, coastLineWidth, coastLineColor, grid, gridLabels, gridLatRes, showCoords, altitude, lon_label_style, **kwargs)
    210                                      resolution=resolution,lat_0=self.lat_0,
    211                                      lon_0=self.lon_0,width=width,
--> 212                                      height=height,ax=ax,**kwargs)
    213 
    214         if self.ax is None:

/anaconda2/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in __init__(self, llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat, llcrnrx, llcrnry, urcrnrx, urcrnry, width, height, projection, resolution, area_thresh, rsphere, ellps, lat_ts, lat_1, lat_2, lat_0, lon_0, lon_1, lon_2, o_lon_p, o_lat_p, k_0, no_rot, suppress_ticks, satellite_height, boundinglat, fix_aspect, anchor, celestial, round, epsg, ax)
   1107         if self.resolution is not None:
   1108             self.coastsegs, self.coastpolygontypes =\
-> 1109             self._readboundarydata('gshhs',as_polygons=True)
   1110             # reformat for use in matplotlib.patches.Polygon.
   1111             self.coastpolygons = []

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/utils/plotUtils.pyc in _readboundarydata(self, name, as_polygons)
    342         self._boundarypolyll = newgeom
    343         out = basemap.Basemap._readboundarydata(self, name,
--> 344                                                 as_polygons=as_polygons)
    345         self._boundarypolyll = oldgeom
    346         return out

/anaconda2/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in _readboundarydata(self, name, as_polygons)
   1412                         b[:,0], b[:,1] = maptran(b[:,0], b[:,1])
   1413                     else:
-> 1414                         b[:,0], b[:,1] = self(b[:,0], b[:,1])
   1415                     goodmask = np.logical_and(b[:,0]<1.e20,b[:,1]<1.e20)
   1416                     # if less than two points are valid in

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/utils/plotUtils.pyc in __call__(self, x, y, inverse, coords)
    303         if 'mpl_toolkits' in callerFile and callerName is '_readboundarydata':
    304           x, y = coord_conv(x, y, "geo", self.coords, altitude=self.altitude,
--> 305                             date_time=self.datetime)
    306           return basemap.Basemap.__call__(self, x, y, inverse=False)
    307 

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/utils/coordUtils.pyc in coord_conv(lon, lat, start, end, altitude, date_time, end_altitude)
    298             if start == "geo":
    299                 lat, lon, _ = aacgm.convert_latlon_arr(lat, lon, alt, date_time,
--> 300                                                        'G2A', igrf_file, root)
    301                 start = "mag"
    302 

/anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy/models/aacgm/wrapper.pyc in convert_latlon_arr(in_lat, in_lon, height, dtime, code, igrf_file, coeff_prefix)
    226     # convert
    227     lat_out, lon_out, r_out = convert_vectorised(in_lat, in_lon, height,
--> 228                                                  bit_code, igrf_file)
    229 
    230     return lat_out, lon_out, r_out

/anaconda2/lib/python2.7/site-packages/numpy/lib/function_base.pyc in __call__(self, *args, **kwargs)
   2737             vargs.extend([kwargs[_n] for _n in names])
   2738 
-> 2739         return self._vectorize_call(func=func, args=vargs)
   2740 
   2741     def _get_ufunc_and_otypes(self, func, args):

/anaconda2/lib/python2.7/site-packages/numpy/lib/function_base.pyc in _vectorize_call(self, func, args)
   2813                       for a in args]
   2814 
-> 2815             outputs = ufunc(*inputs)
   2816 
   2817             if ufunc.nout == 1:

RuntimeError: AACGM_v2_Convert returned error code -1

I am running Python 2.7.14 with Numpy 1.13.3, matplotlib 2.1.0, and basemap 1.1.0. (When I print davitpy.__version__, it gives me 0.5, but the path is /anaconda2/lib/python2.7/site-packages/davitpy-0.8-py2.7-macosx-10.6-x86_64.egg/davitpy so I'm not sure why?)

asreimer commented 6 years ago

The version number hasn't been updated in awhile... https://github.com/vtsuperdarn/davitpy/blob/master/davitpy/__init__.py#L36 so that explains why davitpy.__version__ spits out 0.5.

I'm running this from the master branch: 1) With python 2.7.15, numpy==1.12.1, matplotlib==1.5.2, and basemap==1.0.7, I'm able to run your test commands just fine.

2) With python 2.7.15, numpy==1.13.3, and matplotlib==2.0.2, and basemap==1.0.7, I'm able to run your test commands just fine. 3) With python 2.7.15, numpy==1.13.3, and matplotlib==2.1.0, and basemap==1.1.0, I'm able to run your test commands just fine.

From the develop branch: 1) With python 2.7.15, numpy==1.13.3, and matplotlib==2.1.0, and basemap==1.1.0, I'm able to run your test commands just fine.

So I can't reproduce the issue with the first command that you've posted.

The second command fails because it is trying to convert an x and y that are:

x = np.array([31.91916656,32.28450012,32.55867004,32.47836304,32.6253891,33.58622742,35.13874817,35.79374695,35.47622681,35.66789246,36.89541626,37.31874847,37.1111908,37.41205597,38.55705261,39.7120285,39.875,40.2099762,41.18997192,43.32702637,43.37619019,42.52747345,43.15661621,44.57580566,45.80583191,46.44081116,47.41249847,49.42666626,50.79760742,51.29124451,51.02205658,51.41542053,50.90205383,50.83041382,47.96543884,46.01166534,43.55916595,41.31497192,40.77455139,40.98791504,40.1862793,39.20194244,38.77288818,39.55125427,39.21710968,39.447052,39.25538635,39.70444489,40.64205933,40.33208466,40.64208221,40.39455414,40.84210968,39.85664368,36.85497284,36.3125,34.88499451,34.63122559,34.66122437,35.54621887,35.50205994,32.49867249,32.83406067,32.96438599,32.38539124,31.27455139,30.00917053,27.01164246,24.83996582,22.55583191,20.01997375,18.790802,18.39994812,17.84788513,18.3270874,18.20043945,14.94625092,14.50202942,11.79949951,11.74455261,12.53289032,13.65705872,13.86283112,12.99458313,13.39211273,12.2729187,12.67294312,12.16791534,11.7278595,9.61958313,8.70038605,9.13041687,9.35163879,9.50166321,9.98708344,9.30958557,9.66374969,9.69596863,9.34371948,9.97541809,9.54291534,9.83369446,9.72794342,9.21416473,8.83039093,8.55496979,8.23577881,8.27827454,7.33999634,7.07580566,7.00577545,6.77913666,6.86746979,6.72333527,6.70502472,5.98332977,5.36208344,5.68044281,5.36166382,5.17624664,5.54286194,5.08039093,5.36708069,5.06416321,4.43083191,3.40125275,3.82164001,1.3433609,0.,-1.98169708,-4.01699829,-6.1241684,-7.48080444,-8.71749878,-11.23075104,-12.52127838,-12.45625305,-13.29377747,-12.83708191,-13.17461395,-13.30393982,-13.72374725,-13.53705597,-14.45583344,-14.69708252,-15.07839203,-15.00463867,-15.23500061,-15.50460815,-15.03375244,-15.50958252,-14.93916321,-15.95583344,-15.85377502,-16.3520813,-16.01419067,-16.77624512,-16.22047424,-16.76377869,-16.71794128,-16.35502625,-15.57460785,-16.50666809,-16.51377869,-17.53377533,-16.57705688,-16.04374695,-16.5479126,-16.19792175,-16.91252136,-17.10722351,-16.98300171,-15.70458221,-15.91542053,-14.90377808,-14.46541595,-13.65125275,-12.91586304,-11.52500153,-10.21794128,-9.66294098,-9.84622192,-9.28710938,-6.8125,-5.93463898,-5.47086334,-4.68838501,-2.97914124,-2.83008575,-1.95749664,-0.93753052,0.,1.08413696,3.89585876,5.3441391,6.415802,7.89997101,9.74500275,10.43161011,11.03913879,10.46783447,11.16291809,10.01786041,10.21414185,12.29914093,13.38830566,15.20502472,15.7416687,17.853302,18.98997498,20.05708313,20.09999847,21.70830536,23.10746765,23.31994629,24.97982788,25.20083618,26.98246765,29.06494141,31.02830505,31.91916656])
y = np.array([31.53121948,31.23280334,29.93505096,29.94041443,28.97663879,27.84750366,24.51333618,23.90922546,23.93421936,22.9466095,22.0633316,21.06500244,21.21416473,18.875,18.06010437,15.09500122,15.50788879,14.94872284,14.62371826,12.47577667,11.98835754,11.52288818,11.61294556,10.3753891,10.8678894,10.68374634,11.17958069,11.33789062,11.9861145,11.83330536,10.42080688,10.44332886,10.31494141,9.41916656,4.47750092,2.42952728,0.71458435,-1.96125031,-1.93416595,-2.26419067,-2.73583221,-4.68086243,-6.05252838,-7.01750183,-7.85083008,-7.81336212,-8.29252625,-10.03182983,-10.6842804,-11.3133316,-12.74669647,-12.9283905,-14.83252716,-16.43880463,-17.87875366,-18.87710571,-19.85294342,-19.65083313,-20.55505371,-22.17172241,-24.10752869,-25.96005249,-26.29291534,-26.08410645,-28.54919434,-29.45419312,-31.29711151,-33.56541443,-34.20628357,-33.97874451,-34.83044434,-34.08044434,-34.30210876,-32.82002258,-32.5300293,-31.68249512,-26.31752777,-22.54261017,-17.97919464,-15.83583069,-13.41835785,-12.23503113,-11.00836182,-9.08752441,-8.38833618,-6.13999939,-6.01086426,-5.72755432,-4.45085907,-2.40836334,-0.66835785,-0.71419525,0.35791779,0.05039215,0.17250061,0.51249695,0.45249939,1.07875061,1.17583466,3.07910919,3.81083679,3.80916595,4.09750366,3.94119263,4.74666595,4.48205566,4.92874908,4.53622437,4.44372559,4.73791504,4.37291718,4.66786194,4.35958099,4.61291504,4.33872223,4.31041718,5.16330719,5.540802,5.39041901,5.56830597,5.61919403,5.71833038,5.97000122,5.76452637,6.35038757,6.39580536,6.62119293,6.16116333,5.59290314,4.75460815,5.25839233,4.99702454,4.36035919,4.80708313,6.78949738,7.3841095,7.76663971,8.42163849,8.56083679,8.53166962,9.33486176,9.50663757,9.79660797,10.20872498,11.07663727,10.91872406,11.18330383,10.99791718,11.32833099,11.64328003,11.78916931,11.98872375,11.73455811,11.99246979,12.09666443,12.34539032,12.4066391,12.60997009,12.5716095,13.45999908,13.24958038,13.51580811,13.36125183,13.87916565,14.7416687,15.69747162,17.74749756,19.37999725,20.22497559,21.16119385,20.83752441,21.79814148,23.97250366,23.80330658,24.68585968,26.19667053,26.65919495,27.95625305,28.29875183,29.30914307,30.07164001,31.39749908,32.5458374,34.02539062,35.79077911,35.91711426,35.20628357,35.44197083,35.10866547,35.07539368,35.72792053,35.84288788,36.49375153,36.92538452,36.64118958,37.08625031,36.8429184,37.34955597,36.71289062,37.08958435,36.13577271,35.21583557,34.18753052,33.79708862,32.83789062,32.89785767,32.38205719,31.39788818,30.92538452,30.27458191,30.8508606,32.18205261,32.94122314,32.63539124,32.15289307,31.97105408,31.52363586,31.44205475,30.822052,31.60038757,31.53121948])
altitude = 350.0

Notice that the latitude (y) dips past the equator. AACGM doesn't like the equator, so the coordinate conversion fails and returns a -1. This is expected behaviour AFAIK and isn't a bug as such.

asreimer commented 6 years ago

So we could maybe try to add a message saying the coordinate conversion failed because AACGM isn't specified near the equator, but this will be a tricky thing to do methinks.

johncoxon commented 6 years ago

Hi @asreimer – I just tried to rerun these to see whether I could see what the problem was and they both run fine on my machine with the latest master branch so I don't know why they originally didn't. Sorry to raise a false flag!

johncoxon commented 6 years ago

(I should note that to get it to work, I changed boundinglat to 60 so that the equator wouldn't be the problem – I tried both originally and got different errors, but it clearly now works as intended…)