Esempio n. 1
0
def sdDataReadAll(myPtr):
  """A function to read a large amount (to the end of the request) of radar data into a list from a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object
  
  .. note::
    to use this, you must first create a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object with :func:`sdDataOpen`

  **Args**:
    * **myPtr** (:class:`pydarn.sdio.sdDataTypes.sdDataPtr`): contains the pipeline to the data we are after
  **Returns**:
    * **myList** (list): a list filled with :class:`pydarn.sdio.sdDataTypes.gridData` or :class:`pydarn.sdio.sdDataTypes.mapData` objects holding the data we are after.  *will return None if nothing is found*
    
  **Example**:
    ::
    
      import datetime as dt
      myPtr = sdDataOpen(dt.datetime(2011,1,1),'bks',eTime=dt.datetime(2011,1,1,2),channel='a', bmnum=7,cp=153,fileType='fitex',filtered=False, src=None):
      myList = sdDataReadAll(myPtr)
    
  Written by AJ 20130606
  """
  from pydarn.sdio.sdDataTypes import sdDataPtr, gridData, mapData, alpha
  import pydarn
  import datetime as dt
  
  #check input
  assert(isinstance(myPtr,sdDataPtr)),\
    'error, input must be of type sdDataPtr'
  if myPtr.ptr == None:
    print 'error, your pointer does not point to any data'
    return None
  if myPtr.ptr.closed:
    print 'error, your file pointer is closed'
    return None
  
  myList = []
  #do this until we reach the requested start time
  #and have a parameter match
  while(1):

    dfile = pydarn.dmapio.readDmapRec(myPtr.fd)
    print "python tell:",myPtr.ptr.tell()
    #check for valid data
    try:
      dtime = dt.datetime(dfile['start.year'],dfile['start.month'],dfile['start.day'], \
                          dfile['start.hour'],dfile['start.minute'],int(dfile['start.second']))
    except Exception,e:
      print e
      print 'problem reading time from file, returning None'
      return None

    if dfile == None or dtime > myPtr.eTime:
      #if we dont have valid data, clean up, get out
      print '\nreached end of data'
      myPtr.ptr.close()
      break
    #check that we're in the time window, and that we have a 
    #match for the desired params
    if myPtr.sTime <= dtime <= myPtr.eTime:
      #fill the beamdata object
      if myPtr.fType == 'grd' or myPtr.fType == 'grdex':
        myData = gridData(dataDict=dfile)
      elif myPtr.fType == 'map' or myPtr.fType == 'mapex':
        myData = mapData(dataDict=dfile)
      else:
        print 'error, unrecognized file type'
        return None
      myData.fType = myPtr.fType
      myList.append(myData)
Esempio n. 2
0
def sdDataReadAll(myPtr):
    """A function to read a large amount (to the end of the request) of radar data into a list from a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object
  
  .. note::
    to use this, you must first create a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object with :func:`sdDataOpen`

  **Args**:
    * **myPtr** (:class:`pydarn.sdio.sdDataTypes.sdDataPtr`): contains the pipeline to the data we are after
  **Returns**:
    * **myList** (list): a list filled with :class:`pydarn.sdio.sdDataTypes.gridData` or :class:`pydarn.sdio.sdDataTypes.mapData` objects holding the data we are after.  *will return None if nothing is found*
    
  **Example**:
    ::
    
      import datetime as dt
      myPtr = sdDataOpen(dt.datetime(2011,1,1),'bks',eTime=dt.datetime(2011,1,1,2),channel='a', bmnum=7,cp=153,fileType='fitex',filtered=False, src=None):
      myList = sdDataReadAll(myPtr)
    
  Written by AJ 20130606
  """
    from pydarn.sdio.sdDataTypes import sdDataPtr, gridData, mapData, alpha
    import pydarn
    import datetime as dt

    #check input
    assert(isinstance(myPtr,sdDataPtr)),\
      'error, input must be of type sdDataPtr'
    if myPtr.ptr == None:
        print 'error, your pointer does not point to any data'
        return None
    if myPtr.ptr.closed:
        print 'error, your file pointer is closed'
        return None

    myList = []
    #do this until we reach the requested start time
    #and have a parameter match
    while (1):

        dfile = pydarn.dmapio.readDmapRec(myPtr.ptr)

        #check for valid data
        try:
            dtime = dt.datetime(dfile['start.year'],dfile['start.month'],dfile['start.day'], \
                                dfile['start.hour'],dfile['start.minute'],int(dfile['start.second']))
        except Exception, e:
            print e
            print 'problem reading time from file, returning None'
            return None

        if dfile == None or dtime > myPtr.eTime:
            #if we dont have valid data, clean up, get out
            print '\nreached end of data'
            myPtr.ptr.close()
            break
        #check that we're in the time window, and that we have a
        #match for the desired params
        if myPtr.sTime <= dtime <= myPtr.eTime:
            #fill the beamdata object
            if myPtr.fType == 'grd' or myPtr.fType == 'grdex':
                myData = gridData(dataDict=dfile)
            elif myPtr.fType == 'map' or myPtr.fType == 'mapex':
                myData = mapData(dataDict=dfile)
            else:
                print 'error, unrecognized file type'
                return None
            myData.fType = myPtr.fType
            myList.append(myData)
Esempio n. 3
0
def sdDataReadRec(myPtr):
  """A function to read a single record of radar data from a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object
  
  .. note::
    to use this, you must first create a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object with :func:`sdDataOpen` 

  **Args**:
    * **myPtr** (:class:`pydarn.sdio.sdDataTypes.sdDataPtr`): contains the pipeline to the data we are after
  **Returns**:
    * **myData** (:class:`pydarn.sdio.sdDataTypes.gridData` or :class:`pydarn.sdio.sdDataTypes.mapData`): an object filled with the data we are after.  *will return None when finished reading the file*
    
  **Example**:
    ::
    
      import datetime as dt
      myPtr = sdDataOpen(dt.datetime(2011,1,1),'south'):
      myData = sdDataReadRec(myPtr)
    
  Written by AJ 20130610
  """

  from pydarn.sdio.sdDataTypes import sdDataPtr, gridData, mapData, alpha
  import pydarn
  import datetime as dt
  
  #check input
  assert(isinstance(myPtr,sdDataPtr)),\
    'error, input must be of type sdDataPtr'
  if myPtr.ptr == None:
    print 'error, your pointer does not point to any data'
    return None
  if myPtr.ptr.closed:
    print 'error, your file pointer is closed'
    return None
  

  if myPtr.fType == 'grd' or myPtr.fType == 'grdex':
    myData = gridData()
  elif myPtr.fType == 'map' or myPtr.fType == 'mapex':
    myData = mapData()
  else:
    print 'error, unrecognized file type'
    return None

  #do this until we reach the requested start time
  #and have a parameter match
  while(1):
    dfile = pydarn.dmapio.readDmapRec(myPtr.fd)
    #check for valid data
    try:
      dtime = dt.datetime(dfile['start.year'],dfile['start.month'],dfile['start.day'], \
                          dfile['start.hour'],dfile['start.minute'],int(dfile['start.second']))
    except Exception,e:
      print e
      print 'problem reading time from file, returning None'
      return None
    if dfile == None or dtime > myPtr.eTime:
      #if we dont have valid data, clean up, get out
      print '\nreached end of data'
      myPtr.ptr.close()
      return None
    #check that we're in the time window, and that we have a 
    #match for the desired params
    if myPtr.sTime <= dtime <= myPtr.eTime:
      #fill the data object
      if myPtr.fType == 'grd' or myPtr.fType == 'grdex':
        myData = gridData(dataDict=dfile)
      elif myPtr.fType == 'map' or myPtr.fType == 'mapex':
        myData = mapData(dataDict=dfile)
      else:
        print 'error, unrecognized file type'
        return None
      myData.fType = myPtr.fType
      return myData
Esempio n. 4
0
def sdDataReadRec(myPtr):
    """A function to read a single record of radar data from a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object
  
  .. note::
    to use this, you must first create a :class:`pydarn.sdio.sdDataTypes.sdDataPtr` object with :func:`sdDataOpen` 

  **Args**:
    * **myPtr** (:class:`pydarn.sdio.sdDataTypes.sdDataPtr`): contains the pipeline to the data we are after
  **Returns**:
    * **myData** (:class:`pydarn.sdio.sdDataTypes.gridData` or :class:`pydarn.sdio.sdDataTypes.mapData`): an object filled with the data we are after.  *will return None when finished reading the file*
    
  **Example**:
    ::
    
      import datetime as dt
      myPtr = sdDataOpen(dt.datetime(2011,1,1),'south'):
      myData = sdDataReadRec(myPtr)
    
  Written by AJ 20130610
  """

    from pydarn.sdio.sdDataTypes import sdDataPtr, gridData, mapData, alpha
    import pydarn
    import datetime as dt

    #check input
    assert(isinstance(myPtr,sdDataPtr)),\
      'error, input must be of type sdDataPtr'
    if myPtr.ptr == None:
        print 'error, your pointer does not point to any data'
        return None
    if myPtr.ptr.closed:
        print 'error, your file pointer is closed'
        return None

    if myPtr.fType == 'grd' or myPtr.fType == 'grdex':
        myData = gridData()
    elif myPtr.fType == 'map' or myPtr.fType == 'mapex':
        myData = mapData()
    else:
        print 'error, unrecognized file type'
        return None

    #do this until we reach the requested start time
    #and have a parameter match
    while (1):
        dfile = pydarn.dmapio.readDmapRec(myPtr.ptr)
        #check for valid data
        try:
            dtime = dt.datetime(dfile['start.year'],dfile['start.month'],dfile['start.day'], \
                                dfile['start.hour'],dfile['start.minute'],int(dfile['start.second']))
        except Exception, e:
            print e
            print 'problem reading time from file, returning None'
            return None
        if dfile == None or dtime > myPtr.eTime:
            #if we dont have valid data, clean up, get out
            print '\nreached end of data'
            myPtr.ptr.close()
            return None
        #check that we're in the time window, and that we have a
        #match for the desired params
        if myPtr.sTime <= dtime <= myPtr.eTime:
            #fill the data object
            if myPtr.fType == 'grd' or myPtr.fType == 'grdex':
                myData = gridData(dataDict=dfile)
            elif myPtr.fType == 'map' or myPtr.fType == 'mapex':
                myData = mapData(dataDict=dfile)
            else:
                print 'error, unrecognized file type'
                return None
            myData.fType = myPtr.fType
            return myData