diff --git a/davitpy/pydarn/plotting/acfPlot.py b/davitpy/pydarn/plotting/acfPlot.py index 85b6a2f3..bc4c5143 100755 --- a/davitpy/pydarn/plotting/acfPlot.py +++ b/davitpy/pydarn/plotting/acfPlot.py @@ -93,6 +93,36 @@ def plot_acf(myBeam, gate, normalized=True, mark_blanked=True, import numpy as np from davitpy import pydarn + # Input checks + # myBeam check for rawacf file + assert(myBeam.fType == 'rawacf'), logging.error( + 'myBeam must be from a rawacf file') + # Check of gate parameter + assert(isinstance(gate, int) and gate >= 0), logging.error( + 'gate must be an integer and zero or positive') + # Check of normalized + assert(isinstance(normalized, bool)), logging.error( + 'normalized must be a boolean') + # Check of mark_blanked + assert(isinstance(mark_blanked, bool)), logging.error( + 'mark_blanked must be a boolean') + # Check of xcf + assert(isinstance(xcf, bool)), logging.error( + 'xcf must be a boolean') + # Check of panel + assert(isinstance(panel, int)), logging.error( + 'panel must be an integer') + # Space for ax check(s) + # Check of show variable type + assert(isinstance(show, bool)), logging.error( + 'show must be a boolean') + # Check of png variable type + assert(isinstance(png, bool)), logging.error( + 'png must be a boolean') + # Check of pdf variable type + assert(isinstance(pdf, bool)), logging.error( + 'pdf must be a boolen') + lags = list(set([x[1] - x[0] for x in myBeam.prm.ltab])) ltab = myBeam.prm.ltab tau = myBeam.prm.mpinc @@ -139,7 +169,7 @@ def plot_acf(myBeam, gate, normalized=True, mark_blanked=True, acfFFT = [] acfFFT.extend(temp[len(temp) / 2 + 1:]) acfFFT.extend(temp[0:len(temp) / 2 + 1]) - freq_scale_factor = ((3. * 10 ** 8) / + freq_scale_factor = ((3. * 10 ** 8) / (myBeam.prm.tfreq * 1000. * 2. * lags[-1] * myBeam.prm.mpinc * 10.0 ** -6)) vels = freq_scale_factor * (np.array(range(len(acfFFT))) - @@ -160,7 +190,7 @@ def plot_acf(myBeam, gate, normalized=True, mark_blanked=True, if show: fig = pyplot.figure() else: - if (png == False) and (pdf == False): + if (png is False) and (pdf is False): png = True fig = mpl_fig() ax1 = fig.add_axes([0.1, 0.55, 0.35, 0.35]) @@ -385,7 +415,8 @@ def calc_blanked(ltab, tp, tau, tfr, gate): return txs_in_lag -def plot_rli(myBeam, normalized=True, xcf=False, show=True, png=False, pdf=False): +def plot_rli(myBeam, normalized=True, xcf=False, + show=True, png=False, pdf=False): """This function plots a range-lag-intensity plot of ACF/XCF data for an input beamData object. @@ -431,6 +462,26 @@ def plot_rli(myBeam, normalized=True, xcf=False, show=True, png=False, pdf=False import matplotlib.cm as cmx from davitpy import pydarn + # Input checks + # myBeam check for rawacf file + assert(myBeam.fType == 'rawacf'), logging.error( + 'myBeam must be from a rawacf file') + # Check of normalized variable type + assert(isinstance(normalized, bool)), logging.error( + 'normalized must be a boolean') + # Check of xcf variable type + assert(isinstance(xcf, bool)), logging.error( + 'xcf must be a boolean') + # Check of show variable type + assert(isinstance(show, bool)), logging.error( + 'show must be a boolean') + # Check of png variable type + assert(isinstance(png, bool)), logging.error( + 'png must be a boolean') + # Check of pdf variable type + assert(isinstance(pdf, bool)), logging.error( + 'pdf must be a boolen') + # Get parameters lags = list(set([x[1] - x[0] for x in myBeam.prm.ltab])) range_gates = np.linspace(0.5, myBeam.prm.nrang + 0.5, @@ -442,7 +493,7 @@ def plot_rli(myBeam, normalized=True, xcf=False, show=True, png=False, pdf=False if show: fig = pyplot.figure() else: - if (png == False) and (pdf == False): + if (png is False) and (pdf is False): png = True fig = mpl_fig() @@ -543,7 +594,7 @@ def plot_rli(myBeam, normalized=True, xcf=False, show=True, png=False, pdf=False 'ACF ' + rad_name + ' Beam: ' + str(myBeam.bmnum) fig.suptitle(title, y=0.94) - #handle the outputs + # handle the outputs if png: if not show: canvas = FigureCanvasAgg(fig) diff --git a/davitpy/pydarn/plotting/fan.py b/davitpy/pydarn/plotting/fan.py index 35298f4b..19fea009 100644 --- a/davitpy/pydarn/plotting/fan.py +++ b/davitpy/pydarn/plotting/fan.py @@ -342,11 +342,11 @@ def plotFan(sTime, rad, interval=60, fileType='fitex', param='velocity', va='center') xctr = x[0] + .175 * (x[1] - x[0]) if(w < 4): - myFig.scatter(xctr, y[1] * (.98 - w * .025), s=.1 * pts[w], + myFig.gca().scatter(xctr, y[1] * (.98 - w * .025), s=.1 * pts[w], zorder=15, marker='o', linewidths=.5, edgecolor='face', facecolor='k') elif(w == 4): - myFig.scatter(xctr, y[1] * (.98 - w * .025), s=.1 * 35., + myFig.gca().scatter(xctr, y[1] * (.98 - w * .025), s=.1 * 35., zorder=15, marker='o', linewidths=.5, edgecolor='k', facecolor='w') elif(w == 5): diff --git a/davitpy/pydarn/plotting/plotMapGrd.py b/davitpy/pydarn/plotting/plotMapGrd.py index 5c9b8726..8aea942e 100644 --- a/davitpy/pydarn/plotting/plotMapGrd.py +++ b/davitpy/pydarn/plotting/plotMapGrd.py @@ -34,8 +34,6 @@ class MapConv(object): maxVelScale : Optional[float] maximum velocity to be used for plotting, min is zero so scale is [0,1000] - plotCoords : Optional[str] - coordinates of the plot, only use either 'mag' or 'mlt' Attributes ---------- @@ -52,7 +50,7 @@ class MapConv(object): the axis handle used mObj : utils.plotUtils.mapObj the map object you want data to be overlayed on. - + Methods -------- @@ -103,7 +101,7 @@ class MapConv(object): def __init__(self, startTime, mObj, axisHandle, hemi='north', - maxVelScale=1000., plotCoords='mag'): + maxVelScale=1000.): import datetime from davitpy.pydarn.sdio import sdDataOpen @@ -124,21 +122,18 @@ def __init__(self, startTime, mObj, axisHandle, hemi='north', # requested if hemi == "north": assert(mObj.boundarylats[0] > 0.), \ - logging.error("Map object is using one hemisphere and data the" - " other") + logging.error("Map and data objects must be from the same" + " hemisphere") else: assert(mObj.boundarylats[0] < 0.), \ - logging.error("Map object is using one hemisphere and data the" - " other") + logging.error("Map and data objects must be from the same" + " hemisphere") # check if hemi and coords keywords are correct assert(hemi == "north" or hemi == "south"), \ logging.error("hemi should either be 'north' or 'south'") - assert(plotCoords == 'mag' or coords == 'mlt'), \ - logging.error("error, coords must be one of 'mag' or 'mlt'") self.hemi = hemi - self.plotCoords = plotCoords # Read the corresponding data record from both map and grid files. # This is the way I'm setting stuff up to avoid confusion of reading @@ -215,18 +210,13 @@ def overlayGridVel(self, pltColBar=True, overlayRadNames=True, # depending on whether we have 'mag' or 'mlt' coords, # calculate endLon - if self.plotCoords == 'mag': - endLon = mlonsPlot[nn] + numpy.degrees(delLon) - elif self.plotCoords == 'mlt': - endLon = (mlonsPlot[nn] + numpy.degrees(delLon)) / 15. - else: - logging.warning('Check the coords') + endLon = mlonsPlot[nn] + numpy.degrees(delLon) # get the start and end vecs xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], - coords=self.plotCoords) + coords='mag') xVecEnd, yVecEnd = self.mObj(endLon, endLat, - coords=self.plotCoords) + coords='mag') # Plot the start point and then append the vector indicating magn. # and azimuth @@ -496,7 +486,8 @@ def calcCnvPots(self): import datetime import numpy import scipy - + from davitpy.utils import * + import davitpy.models.aacgm as aacgm if self.hemi == 'north': hemisphere = 1 @@ -611,14 +602,7 @@ def calcCnvPots(self): else: logging.warning('LatShift is not zero, need to rewrite code for that, currently continuing assuming it is zero') - # mlt conversion stuff - if self.plotCoords == 'mlt': - epoch = timeUtils.datetimeToEpoch(strtTime) - mltDef = aacgm.mltFromEpoch(epoch,0.0) * 15. - lonShftFit += mltDef - gridArr[1,:] = numpy.mod( ( gridArr[1,:] + lonShftFit ) / 15., 24. ) - else: - gridArr[1,:] = ( gridArr[1,:] + lonShftFit ) + gridArr[1,:] = ( gridArr[1,:] + lonShftFit ) latCntr = gridArr[0,:].reshape( ( 181, 60 ) ) lonCntr = gridArr[1,:].reshape( ( 181, 60 ) ) @@ -650,7 +634,7 @@ def overlayCnvCntrs(self): ( latCntr, lonCntr, potCntr ) = self.calcCnvPots() #plot the contours - xCnt, yCnt = self.mObj( lonCntr, latCntr, coords=self.plotCoords ) + xCnt, yCnt = self.mObj( lonCntr, latCntr, coords='mag') cntrPlt = self.mObj.contour( xCnt, yCnt, potCntr, zorder = 2., vmax=potCntr.max(), vmin=potCntr.min(), @@ -680,7 +664,7 @@ def overlayHMB(self, hmbCol='Gray'): """ xVecHMB, yVecHMB = self.mObj( self.mapData.model.boundarymlon, - self.mapData.model.boundarymlat, coords = self.plotCoords ) + self.mapData.model.boundarymlat, coords='mag' ) grdPltHMB = self.mObj.plot( xVecHMB, yVecHMB, linewidth = 2., linestyle = ':', color = hmbCol, zorder = 4. ) grdPltHMB2 = self.mObj.plot( xVecHMB, yVecHMB, @@ -741,16 +725,10 @@ def overlayMapModelVel(self, pltColBar=False, delLon = ( numpy.arctan2( numpy.sin(numpy.deg2rad( velAzm[nn] ) )*numpy.sin(vecLen)*numpy.cos(numpy.deg2rad( mlatsPlot[nn] ) ), numpy.cos(vecLen) - numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) )*numpy.sin(numpy.deg2rad( endLat ) ) ) ) - if self.plotCoords == 'mag': - endLon = mlonsPlot[nn] + numpy.degrees( delLon ) - elif self.plotCoords == 'mlt': - endLon = ( mlonsPlot[nn] + numpy.degrees( delLon ) )/15. - else: - logging.warning('Check the coords.') - - - xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], coords=self.plotCoords) - xVecEnd, yVecEnd = self.mObj(endLon, endLat, coords = self.plotCoords) + endLon = mlonsPlot[nn] + numpy.degrees( delLon ) + + xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], coords='mag') + xVecEnd, yVecEnd = self.mObj(endLon, endLat, coords='mag') self.mapModelPltStrt = self.mObj.scatter( xVecStrt, yVecStrt, c=velMagn[nn], s=10., vmin=0, vmax=self.maxVelPlot, alpha=0.7, @@ -834,18 +812,10 @@ def overlayMapFitVel(self, pltColBar=True, numpy.cos(vecLen) - numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) ) \ *numpy.sin(numpy.deg2rad( endLat ) ) ) ) - if self.plotCoords == 'mag': - endLon = mlonsPlot[nn] + numpy.degrees( delLon ) - elif self.plotCoords == 'mlt': - endLon = ( mlonsPlot[nn] + numpy.degrees( delLon ) )/15. - else: - logging.warning('Check the coords.') - + endLon = mlonsPlot[nn] + numpy.degrees( delLon ) - xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], - coords=self.plotCoords) - xVecEnd, yVecEnd = self.mObj(endLon, endLat, - coords = self.plotCoords) + xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], coords='mag') + xVecEnd, yVecEnd = self.mObj(endLon, endLat, coords='mag') self.mapFitPltStrt.append(self.mObj.scatter( xVecStrt, yVecStrt, c=velMagn[nn], s=10., diff --git a/davitpy/pydarn/radar/radInfoIo.py b/davitpy/pydarn/radar/radInfoIo.py index 16fa6289..2066bfb8 100644 --- a/davitpy/pydarn/radar/radInfoIo.py +++ b/davitpy/pydarn/radar/radInfoIo.py @@ -30,6 +30,7 @@ """ import logging + def radarRead(path=None): """Reads radar.dat file @@ -71,9 +72,9 @@ def radarRead(path=None): txt = 'You may be getting this error because your computer cannot ' txt = '{:s}contact an appropriate internet server to get '.format(txt) txt = '{:s}the latest radar.dat information. You can '.format(txt) - txt = '{:s}use a local file instead by setting the SD_RADAR'.format(txt) - txt = '{:s} environment variable to the location of a local'.format(txt) - txt = '{:s} copy of radar.dat.\n'.format(txt) + txt = '{:s}use a local file instead by setting the '.format(txt) + txt = '{:s}SD_RADAR environment variable to the location '.format(txt) + txt = '{:s}of a local copy of radar.dat.\n'.format(txt) print txt print 'Example, you might add a similar line to your .bashrc:' @@ -149,7 +150,6 @@ def hdwRead(fname, path=None): if path: pathOpen = os.path.join(path, fname) else: - pathOpen = os.getenv('SD_RADAR') pathOpen = os.path.join(str(os.getenv('SD_HDWPATH')), fname) try: @@ -161,10 +161,10 @@ def hdwRead(fname, path=None): txt = 'You may be getting this error because your computer cannot ' txt = '{:s}contact an appropriate internet server to get '.format(txt) - txt = '{:s}the latest hdw.dat information. You can can use'.format(txt) - txt = '{:s} a local file instead by setting the SD_HDWPATH '.format(txt) - txt = '{:s}environment variable to the location of the '.format(txt) - txt = '{:s}local hdw.dat path.'.format(txt) + txt = '{:s}the latest hdw.dat information. You can can '.format(txt) + txt = '{:s}use a local file instead by setting the '.format(txt) + txt = '{:s}SD_HDWPATH environment variable to the location'.format(txt) + txt = '{:s} of the local hdw.dat path.'.format(txt) print txt txt = 'You can get the latest hdw.dat files from ' txt = '{:s}https://github.com/vtsuperdarn/hdw.dat\n'.format(txt) @@ -219,7 +219,7 @@ class updateRadars(object): if the database cannot be reached. Currently, the remote database is housed on the VT servers. - Attributes + Attributes ------- sql_path : str path to sqlite file @@ -304,24 +304,30 @@ class : updateRadars """ from pymongo import MongoClient import sys + import os # print self.db_user,self.db_pswd,self.db_host, self.db_name uri = 'mongodb://{0}:{1}@{2}/{3}'.format(self.db_user, self.db_pswd, self.db_host, self.db_name) # print uri try: + logging.debug('Trying to connect to hdw.dat mongodb') conn = MongoClient(uri) + # Force connection attempt + conn.server_info() dba = conn[self.db_name] except: - logging.exception('Could not connect to remote DB: ', - sys.exc_info()[0]) + logging.error('Could not connect to remote DB: %s', + str(uri)) dba = False if dba: + logging.debug('Connection a success, so proceeding with remote db') try: colSel = lambda colName: dba[colName].find() - self.db_select = {'rad': colSel("radars"), 'hdw': colSel("hdw"), + self.db_select = {'rad': colSel("radars"), + 'hdw': colSel("hdw"), 'inf': colSel("metadata")} return True except: @@ -332,6 +338,8 @@ class : updateRadars hdw.dat info') return False else: + logging.warning('Reading hdw.dat info from local files in %s', + os.getenv('SD_HDWPATH')) result = self.__readFromFiles() if not result: logging.error('Could not update .radars.sqlite file with \ @@ -419,11 +427,11 @@ class : updateRadars cur.execute("CREATE TABLE hdw (%s)" % ', '.join(self.dtype_hdw)) cur.execute("CREATE TABLE inf (%s)" % ', '.join(self.dtype_inf)) - cur.executemany("INSERT INTO rad VALUES(%s)" % ', '.join(['?'] * \ + cur.executemany("INSERT INTO rad VALUES(%s)" % ', '.join(['?'] * len(self.dtype_rad)), arr_rad) - cur.executemany("INSERT INTO hdw VALUES(%s)" % ', '.join(['?'] * \ + cur.executemany("INSERT INTO hdw VALUES(%s)" % ', '.join(['?'] * len(self.dtype_hdw)), arr_hdw) - cur.executemany("INSERT INTO inf VALUES(%s)" % ', '.join(['?'] * \ + cur.executemany("INSERT INTO inf VALUES(%s)" % ', '.join(['?'] * len(self.dtype_inf)), arr_inf) return True diff --git a/davitpy/utils/geoPack.py b/davitpy/utils/geoPack.py index d9f509b4..618aa3e4 100644 --- a/davitpy/utils/geoPack.py +++ b/davitpy/utils/geoPack.py @@ -643,7 +643,7 @@ def greatCircleDist(lat1, lon1, lat2, lon2): lon2 = np.radians(lon2) dlat = (lat2 - lat1) / 2.0 - dlon = (lon2 - lon1) / 2,0 + dlon = (lon2 - lon1) / 2.0 a = np.sin(dlat)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon)**2 radDist = 2.0 * np.arctan2(np.sqrt(a), np.sqrt(1.0 - a)) diff --git a/davitpy/utils/plotUtils.py b/davitpy/utils/plotUtils.py index a7e9d3b5..eb040f19 100644 --- a/davitpy/utils/plotUtils.py +++ b/davitpy/utils/plotUtils.py @@ -78,6 +78,8 @@ class as the attribute "dateTime". This is needed when plotting show/hide parallels and meridians grid (default=True) gridLabels : Optional[bool] label parallels and meridians (default=True) + gridLatRes: Optional[float] + set the latitude resolution of gridlines (default=20.) showCoords : Optional[bool] display coordinate system name in upper right corner (default=True) @@ -133,7 +135,7 @@ def __init__(self, ax=None, datetime=None, coords='geo', projection='stere', 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): + grid=True, gridLabels=True, gridLatRes=20., showCoords=True, **kwargs): """This class wraps arround :class:`mpl_toolkits.basemap.Basemap` () @@ -155,6 +157,7 @@ def __init__(self, ax=None, datetime=None, coords='geo', projection='stere', self._showCoords=showCoords self._grid=grid self._gridLabels=gridLabels + self._gridLatRes=gridLatRes self._coordsDict, self._coords_string = get_coord_dict() if datetime is None and dateTime is None: @@ -218,7 +221,7 @@ def draw(self): # draw parallels and meridians. if self._grid: - parallels = np.arange(-80.,81.,20.) + parallels = np.arange(-80.,81.,self._gridLatRes) out = self.drawparallels(parallels, color='.6', zorder=10) # Set format of meridian labels. if self.coords == "mlt": diff --git a/install/python_install_mac_port.sh b/install/python_install_mac_port.sh index 9c13e763..5d581a5a 100755 --- a/install/python_install_mac_port.sh +++ b/install/python_install_mac_port.sh @@ -7,9 +7,15 @@ ver=27 port -n install python${ver} -port -n install mpich +gcc47 +port -n install mpich +port -n install gcc49 +port -n select gcc mp-gcc49 +hash gfotran port -n install coreutils -easy_install pip +#easy_install pip +port install py${ver}-pip +port install pip_select +port select --set pip pip${ver} pip install --upgrade numpy pip install --upgrade matplotlib port -n install py${ver}-matplotlib-basemap @@ -19,7 +25,7 @@ pip install --upgrade pyzmq tornado pygments pip install --upgrade ipython pip install --upgrade jupyter python -c 'from IPython.external import mathjax; mathjax.install_mathjax()' -pip install --upgrade PIL +pip install --upgrade pillow pip install --upgrade pymongo pip install --upgrade paramiko pip install --upgrade jinja2 @@ -27,9 +33,16 @@ pip install --upgrade jsonschema pip install --upgrade cython pip install --upgrade scikit-image pip install --upgrade pandas +pip install netCDF4 dir=$(pwd) cd /tmp git clone --branch v1.0.7rel https://github.com/matplotlib/basemap.git -cd basemap -python2.7 setup.py install + +cd basemap/geos-3.3.3 +export GEOS_DIR=/usr/local/geos +./configure --prefix=$GEOS_DIR +make +make install +cd .. +python setup.py install \ No newline at end of file diff --git a/setup.py b/setup.py index d4f58aa5..e27a27a8 100644 --- a/setup.py +++ b/setup.py @@ -114,7 +114,7 @@ def read(fname): # Now execute the setup ############################################################################# setup(name='davitpy', - version="0.6", + version="0.7", description="Space Science Toolkit", author="VT SuperDARN Lab and friends", author_email="ajribeiro86@gmail.com", @@ -132,7 +132,7 @@ def read(fname): py_modules=['davitpy'], install_requires=[], classifiers=[ - "Development Status :: 6 - Beta", + "Development Status :: 7 - Beta", "Topic :: Scientific/Engineering", "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU General Public License (GPL)",