In [1]:
############################################
# This code adds davitpy to your python path
# Eventually, this won't be necessary
import sys
sys.path.append('/davitpy')
############################################
In [3]:
import pydarn.sdio
import datetime as dt
In [4]:
#the first routine we will call is radDataOpen, which
#establishes a data piepeline. we will now set up the args.
#sTime is the time we want to start reading (reqd input)
sTime = dt.datetime(2011,1,1,1,0)
print sTime
#rad is the 3-letter radar code for the radar we want (reqd input)
rad='bks'
#NOTE:the rest of the inputs are optional
#eTime is the end time we want to read until
eTime = dt.datetime(2011,1,1,2,0)
print eTime
#channel is the radar channel we want data from, eg 'a'
#by default this is None, which will read data from all channels
channel='a'
#bmnum is the beam number we want data from. by default this is
#None, which will read data from all beams
bmnum=7
#cp is the control program id number which we want data from
#by default, this is set to None which reads data from all cpids
cp=None
#fileType specifies the type of data we want. valid inputs are
#'fitex','fitacf','lmfit','rawacf'. by default this is 'fitex'
#if a fit type is requested but not found, the code will automatically
#look for other fit types
fileType='fitacf'
#filter is a boolean indicating whether to boxcar filter the data.
#this is onyl valid for fit types, and wont work on mongo data
filtered=False
#src is a string indicating the desired data source. valid
#inputs are 'mongo','local','sftp'. by default this is set to
#None which will sequentially try all sources
src=None
In [5]:
# Okay, now lets get the data connection
myPtr = pydarn.sdio.radDataOpen(sTime,rad,eTime=eTime,channel=channel,bmnum=bmnum,cp=cp,fileType=fileType,filtered=filtered, src=src)
In [6]:
# Note that the output or radDataOpen is of type radDataPtr
# Let's explore its contents
for key,val in myPtr.__dict__.iteritems():
print 'myPtr.'+key+' = '+str(val)
In [7]:
# Okay, now that we have our radDataPtr, we can use it to read data
# this is done with the command radDataReadRec
# this same command can be used for any type of data
myBeam = pydarn.sdio.radDataReadRec(myPtr)
In [8]:
print myBeam
In [9]:
# The output is of type beamData
# a beamData object can store fit data as well as rawacf and iqdat data
# let's look at the contents of myBeam
for key,val in myBeam.__dict__.iteritems():
print 'myBeam.'+key+' = '+str(val)
In [10]:
# See that the rawacf, fit, and prm attributes are objects
# the rawacf object is empty, since we read fitacf data
# lets look at the prm object
for key,val in myBeam.prm.__dict__.iteritems():
print 'myBeam.prm.'+key+' = '+str(val)
In [11]:
# And lets look at whats in the fit object
for key in myBeam.fit.__dict__.keys():
print 'myBeam.fit.'+key
In [12]:
# we can read to the end of the specified time period, like so:
vel, t = [], []
while(myBeam != None):
vel.append( myBeam.fit.v )
t.append( myBeam.time )
myBeam = pydarn.sdio.radDataReadRec(myPtr)
In [13]:
# For instance, we could look at the velocity distribution during that period
ax = gca()
for i in range(len(t)):
if not vel[i]: continue
scatter([date2num(t[i])]*len(vel[i]), vel[i], s=1)
ylim([-400, 400])
xlim([date2num(sTime), date2num(eTime)])
tloc = MinuteLocator(interval=10)
tfmt = DateFormatter('%H:%M')
ax.xaxis.set_major_locator(tloc)
ax.xaxis.set_major_formatter(tfmt)
ylabel('Velocity [m/s]')
grid()
In [14]:
# Now, let's try and example where we read rawacf data (this is slow)
myPtr = pydarn.sdio.radDataOpen(sTime,rad,eTime=eTime,channel=channel,bmnum=bmnum,cp=cp,fileType='rawacf',filtered=filtered, src=src)
myBeam = pydarn.sdio.radDataReadRec(myPtr)
print '\n'
for key in myBeam.rawacf.__dict__.keys():
print 'myBeam.rawacf.'+key
In [15]:
# this is a little dense, so lets look at the ACF just for range gate 0, and the lag table
print myBeam.rawacf.acfd[0]
print myBeam.prm.ltab
In [16]:
# we can plot this, like so:
import matplotlib.pyplot as plt
lags,re,im = [],[],[]
for i in range(len(myBeam.prm.ltab)-1):
lags.append(myBeam.prm.ltab[i][1]-myBeam.prm.ltab[i][0])
re.append(myBeam.rawacf.acfd[0][i][0])
im.append(myBeam.rawacf.acfd[0][i][1])
fig = plt.figure()
plt.plot(lags,re,'ro-')
plt.plot(lags,im,'bo-')
plt.show()
In [17]:
# And finally, lets try an iqdat file
# THIS IS VERY SLOOOOOW
myPtr = pydarn.sdio.radDataOpen(dt.datetime(2012,1,1,1,0),'fhe',eTime=dt.datetime(2012,1,1,1,30),channel=channel,bmnum=bmnum,cp=cp,fileType='iqdat',filtered=filtered, src=src)
myBeam = pydarn.sdio.radDataReadRec(myPtr)
for key in myBeam.iqdat.__dict__.keys():
print 'myBeam.iqdat.'+key
In [18]:
# again this is dense, lets plot a single pulse sequence iqdat
# we can plot this, like so:
samp = []
iq = [[],[]]
for i in range(myBeam.iqdat.smpnum):
samp.append(i)
iq[0].append(myBeam.iqdat.mainData[0][i][0])
iq[1].append(myBeam.iqdat.mainData[0][i][1])
fig = plt.figure()
plt.plot(samp,iq[0],'r-')
plt.plot(samp,iq[1],'b-')
plt.show()
In [15]:
# this concludes our tutorial on how to read radar data.
# ENJOY!