Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #306 from vtsuperdarn/0.7-release
Browse files Browse the repository at this point in the history
0.7 release into master
  • Loading branch information
ksterne authored Jun 1, 2017
2 parents 04e0baf + c15dc9e commit b80700a
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 83 deletions.
61 changes: 56 additions & 5 deletions davitpy/pydarn/plotting/acfPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))) -
Expand All @@ -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])
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions davitpy/pydarn/plotting/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
72 changes: 21 additions & 51 deletions davitpy/pydarn/plotting/plotMapGrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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
--------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.,
Expand Down
38 changes: 23 additions & 15 deletions davitpy/pydarn/radar/radInfoIo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"""
import logging


def radarRead(path=None):
"""Reads radar.dat file
Expand Down Expand Up @@ -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:'
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit b80700a

Please sign in to comment.