Closed aburrell closed 7 years ago
I don't have tests for this yet. Won't be able to get to that until next week. This addresses Issue #313.
Alright, tests are ready.
Import the necessary modules:
import datetime as dt
import matplotlib as mpl
import matplotlib.pyplot as plt
import davitpy
Set up the figure
plt.ion()
stime = dt.datetime(2001,9,15)
f = plt.figure(figsize=(17,5))
ax = f.add_subplot(131)
Initialize the map and mapex/grdex data:
m = davitpy.utils.plotUtils.mapObj(ax=ax, datetime=stime, coords='geo', resolution='l', lat_0=90.0, coastLineWidth=0.5, coastLineColor="0.6", fillContinents="0.6", boundinglat=30.0, fill_alpha=0.3)
sdmap = davitpy.pydarn.plotting.plotMapGrd.MapConv(stime, m, ax, grid_type='grdex', map_type='mapex')
Print the map contour object to make sure the files have loaded
print sdmap
SuperDARN Map Convection for the Northern Hemisphere
Grid File: ~/20010915.000000.20010915.000200.north.grdex Grid Time: 2001-09-15 00:02:00 to 2001-09-15 00:04:00 Map File: ~/20010915.000000.20010915.000200.north.mapex Map Time: 2001-09-15 00:02:00 to 2001-09-15 00:04:00
Map is set Subplot axis is set
Where ~/ will be the directory where this file is located. Now add the grid velocities:
sdmap.overlayGridVel()
Create a second axis where we'll plot the HMB and Fitted velocities, using non-standard formatting:
ax = f.add_subplot(132)
m.ax = ax
sdmap.axisHandle = ax
m.draw(lon_label_style="+/-")
sdmap.overlayMapFitVel(colMap=mpl.cm.viridis, label_style="agu")
sdmap.overlayHMB(hmbCol="k")
Create a third axis where we plot the model velocities and the potential contour:
ax = f.add_subplot(133)
m.ax = ax
sdmap.axisHandle = ax
m.draw()
sdmap.overlayMapModelVel(pltColBar=True, colMap=mpl.cm.Spectral_r)
sdmap.overlayCnvCntrs(zorder=10, line_color='k')
Add a title to get the example plot:
f.suptitle("Grid Vectors, Fitted Velocities with HMB, Model Velocities with Potential Contour")
Now try loading only a map file, using a 10 minute window instead of a 2 minute window:
end_time = stime + dt.timedelta(minutes=10)
sdmap = davitpy.pydarn.plotting.plotMapGrd.MapConv(stime, end_time=end_time, grid_type=None, map_type='mapex')
print sdmap
SuperDARN Map Convection for the Northern Hemisphere
Grid File: None Map File: /Users/ab763/Programs/Data/SuperDARN/Downloads/20010915.044244.20010915.045244.north.mapex Map Time: 2001-09-15 04:44:00 to 2001-09-15 04:46:00
Map is not set Subplot axis is not set
Note that the output is only for 2 minutes. This is because that is the size of the mapped data in the mapex file, the loading and reading routines can't change that. Also note that only the map data is set. All other parameters can be initialized after the fact.
sdmap.overlayCnvCntrs()
ERROR:root:no map available
AssertionError Traceback (most recent call last)
in () ----> 1 sdmap.overlayCnvCntrs() /Users/ab763/Programs/Git/davitpy/davitpy/pydarn/plotting/plotMapGrd.py in overlayCnvCntrs(self, zorder, line_color, line_width, font_size, plot_label) 730 # Test to make sure the necessary attributes have been set 731 assert self.mapData is not None, logging.error("no map data available") --> 732 assert self.mObj is not None, logging.error("no map available") 733 734 # get the lats, lons and potentials from calcCnvPots() function AssertionError: None
I have tested this code and it works perfectly for me!
Changing remotes 👎 . I'll knock the rust off of my git skills though to try to pull this branch to my local computer. Just makes it harder to test for git n00bs.
Though maybe this is just my own problem. Wasn't too hard with some research.
I was able to test this, but I think I ran into some issues. Is the test code best to run in a jupyter notebook or through command line code? I did the command line code, but things run by too quickly and I can't see any results. Using a notebook, I'm getting an error on:
m = davitpy.utils.plotUtils.mapObj(ax=ax, datetime=stime, coords='geo', resolution='1', lat_0=90.0, coastLineWidth=0.5, coastLineColor="0.6", fillContinents="0.6", boundinglat=30.0, fill_alpha=0.3)
with an error of:
/usr/local/lib/python2.7/dist-packages/davitpy-0.7-py2.7-linux-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, lon_label_style, **kwargs)
204 resolution=resolution,lat_0=self.lat_0,
205 lon_0=self.lon_0,width=width,
--> 206 height=height,ax=ax,**kwargs)
207
208 if self.ax is None:
/usr/local/lib/python2.7/dist-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)
1029 area_thresh = 1.
1030 else:
-> 1031 raise ValueError("boundary resolution must be one of 'c','l','i','h' or 'f'")
1032 self.area_thresh = area_thresh
1033 # define map boundary polygon (in lat/lon coordinates)
ValueError: boundary resolution must be one of 'c','l','i','h' or 'f' ```
I thought it might be an issue with basemap or something not being up to date, but I just reran the dependencies script and got everything up to date and no change.
Option 3! Both Katie and I ran the tests in ipython. Still not had time to learn how to use the jupyter notebooks.
On 14 Sep 2017, at 12:22, Kevin Sterne notifications@github.com wrote:
I was able to test this, but I think I ran into some issues. Is the test code best to run in a jupyter notebook or through command line code? I did the command line code, but things run by too quickly and I can't see any results. Using a notebook, I'm getting an error on:
m = davitpy.utils.plotUtils.mapObj(ax=ax, datetime=stime, coords='geo', resolution='1', lat_0=90.0, coastLineWidth=0.5, coastLineColor="0.6", fillContinents="0.6", boundinglat=30.0, fill_alpha=0.3)
with an error of:
/usr/local/lib/python2.7/dist-packages/davitpy-0.7-py2.7-linux-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, lon_label_style, kwargs) 204 resolution=resolution,lat_0=self.lat_0, 205 lon_0=self.lon_0,width=width, --> 206 height=height,ax=ax,kwargs) 207 208 if self.ax is None:
/usr/local/lib/python2.7/dist-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) 1029 area_thresh = 1. 1030 else: -> 1031 raise ValueError("boundary resolution must be one of 'c','l','i','h' or 'f'") 1032 self.area_thresh = area_thresh 1033 # define map boundary polygon (in lat/lon coordinates)
ValueError: boundary resolution must be one of 'c','l','i','h' or 'f' ```
I thought it might be an issue with basemap or something not being up to date, but I just reran the dependencies script and got everything up to date and no change. — You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/vtsuperdarn/davitpy/pull/317#issuecomment-329551309, or mute the thread https://github.com/notifications/unsubscribe-auth/AGuC_tiondxO4FaADc3lw2uVL8fIiNl8ks5siWDugaJpZM4OxSiI.
But this is strange... because you did set the resolution...
Let's try a sidestep for a moment. What happens if you set a map object just using basemap and add a datetime attribute to it? Do the rest of the tests work?
Tried this out in ipython and initially got the same error. Thinking that you're a good programmer and I'm a dumb tester, I realized the resolution value in the davitpy.utils.plotUtils.mapObj()
I initially read as the number one and not the letter l. Dag nab it!
Change this up and got it to work in ipython. Also tested this in jupyter notebook and on the mapObj()
call I get lots of deprecation warnings related to basemap... as well get some errors with image sizes being too large. I'll try to test it out another way (script/code), I think I may just need to save the figure at the end to view it to make sure it looks the same. I'll try to get to that early next week.
AH!!! I'll try to remember that for the future. I like low resolution the best, but it does look like a number. If you save the figure at the end of the script, that will do for a test. The second bit is basically using the wrong input and getting an error.
I was making some tests for the AACGM pull request today and also noted a few deprecation warnings in basemap. Fingers crossed that they get on that before too much longer...
Got this tested out on a separate computer. So looks good to go! I'm guessing this is good to merge in since @kherli tested this out as well?
Yup! Would you do the honours?
On 15 Sep 2017, at 21:27, Kevin Sterne notifications@github.com wrote:
Got this tested out on a separate computer. So looks good to go! I'm guessing this is good to merge in since @kherli https://github.com/kherli tested this out as well?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/vtsuperdarn/davitpy/pull/317#issuecomment-329939195, or mute the thread https://github.com/notifications/unsubscribe-auth/AGuC_qvJXPdw54sR2CW8hEYxgH3Iwxxvks5sizImgaJpZM4OxSiI.
Fixed and added functionality to plotMapGrd:
1) fixed error where import * was used 2) Improved docstrings 3) Improved PEP8 compliance 4) Fixed hardcoding that prevents “map” and “grd” files from being read 5) Added options for minimum velocity and minimum latitude