##// END OF EJS Templates
Hot fix
Hot fix

File last commit:

r1097:fefd86c58472
r1166:ce0987c48654
Show More
jroIO_mira35c.py
800 lines | 28.5 KiB | text/x-python | PythonLexer
José Chávez
sin matplotlib de los modulos de claire
r1075 import os
import sys
ebocanegra
first commit
r965 import glob
import fnmatch
import datetime
import time
import re
import h5py
import numpy
from scipy.optimize import curve_fit
José Chávez
sin matplotlib de los modulos de claire
r1075 from scipy import asarray as ar, exp
ebocanegra
first commit
r965 from scipy import stats
from numpy.ma.core import getdata
SPEED_OF_LIGHT = 299792458
SPEED_OF_LIGHT = 3e8
try:
from gevent import sleep
except:
from time import sleep
from schainpy.model.data.jrodata import Spectra
#from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
#from schainpy.model.io.jroIO_bltr import BLTRReader
from numpy import imag, shape, NaN, empty
class Header(object):
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def __init__(self):
raise NotImplementedError
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def read(self):
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 raise NotImplementedError
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def write(self):
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 raise NotImplementedError
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def printInfo(self):
José Chávez
sin matplotlib de los modulos de claire
r1075
message = "#" * 50 + "\n"
ebocanegra
first commit
r965 message += self.__class__.__name__.upper() + "\n"
José Chávez
sin matplotlib de los modulos de claire
r1075 message += "#" * 50 + "\n"
ebocanegra
first commit
r965 keyList = self.__dict__.keys()
keyList.sort()
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 for key in keyList:
José Chávez
sin matplotlib de los modulos de claire
r1075 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
ebocanegra
first commit
r965 if "size" not in keyList:
attr = getattr(self, "size")
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 if attr:
José Chávez
sin matplotlib de los modulos de claire
r1075 message += "%s = %s" % ("size", attr) + "\n"
# print message
FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
('Hname', 'a32'), # Original file name
# Date and time when the file was created
('Htime', numpy.str_, 32),
# Name of operator who created the file
('Hoper', numpy.str_, 64),
# Place where the measurements was carried out
('Hplace', numpy.str_, 128),
# Description of measurements
('Hdescr', numpy.str_, 256),
('Hdummy', numpy.str_, 512), # Reserved space
# Main chunk 8bytes
# Main chunk signature FZKF or NUIG
('Msign', numpy.str_, 4),
('MsizeData', '<i4'), # Size of data block main chunk
# Processing DSP parameters 36bytes
('PPARsign', numpy.str_, 4), # PPAR signature
('PPARsize', '<i4'), # PPAR size of block
('PPARprf', '<i4'), # Pulse repetition frequency
('PPARpdr', '<i4'), # Pulse duration
('PPARsft', '<i4'), # FFT length
# Number of spectral (in-coherent) averages
('PPARavc', '<i4'),
# Number of lowest range gate for moment estimation
('PPARihp', '<i4'),
# Count for gates for moment estimation
('PPARchg', '<i4'),
# switch on/off polarimetric measurements. Should be 1.
('PPARpol', '<i4'),
# Service DSP parameters 112bytes
# STC attenuation on the lowest ranges on/off
('SPARatt', '<i4'),
('SPARtx', '<i4'), # OBSOLETE
('SPARaddGain0', '<f4'), # OBSOLETE
('SPARaddGain1', '<f4'), # OBSOLETE
# Debug only. It normal mode it is 0.
('SPARwnd', '<i4'),
# Delay between sync pulse and tx pulse for phase corr, ns
('SPARpos', '<i4'),
# "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
('SPARadd', '<i4'),
# Time for measuring txn pulse phase. OBSOLETE
('SPARlen', '<i4'),
('SPARcal', '<i4'), # OBSOLETE
('SPARnos', '<i4'), # OBSOLETE
('SPARof0', '<i4'), # detection threshold
('SPARof1', '<i4'), # OBSOLETE
('SPARswt', '<i4'), # 2nd moment estimation threshold
('SPARsum', '<i4'), # OBSOLETE
('SPARosc', '<i4'), # flag Oscillosgram mode
('SPARtst', '<i4'), # OBSOLETE
('SPARcor', '<i4'), # OBSOLETE
('SPARofs', '<i4'), # OBSOLETE
# Hildebrand div noise detection on noise gate
('SPARhsn', '<i4'),
# Hildebrand div noise detection on all gates
('SPARhsa', '<f4'),
('SPARcalibPow_M', '<f4'), # OBSOLETE
('SPARcalibSNR_M', '<f4'), # OBSOLETE
('SPARcalibPow_S', '<f4'), # OBSOLETE
('SPARcalibSNR_S', '<f4'), # OBSOLETE
# Lowest range gate for spectra saving Raw_Gate1 >=5
('SPARrawGate1', '<i4'),
# Number of range gates with atmospheric signal
('SPARrawGate2', '<i4'),
# flag - IQ or spectra saving on/off
('SPARraw', '<i4'),
('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
ebocanegra
first commit
r965 class FileHeaderMIRA35c(Header):
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def __init__(self):
José Chávez
sin matplotlib de los modulos de claire
r1075
self.Hname = None
self.Htime = None
self.Hoper = None
self.Hplace = None
self.Hdescr = None
self.Hdummy = None
self.Msign = None
self.MsizeData = None
self.PPARsign = None
self.PPARsize = None
self.PPARprf = None
self.PPARpdr = None
self.PPARsft = None
self.PPARavc = None
self.PPARihp = None
self.PPARchg = None
self.PPARpol = None
# Service DSP parameters
self.SPARatt = None
self.SPARtx = None
self.SPARaddGain0 = None
self.SPARaddGain1 = None
self.SPARwnd = None
self.SPARpos = None
self.SPARadd = None
self.SPARlen = None
self.SPARcal = None
self.SPARnos = None
self.SPARof0 = None
self.SPARof1 = None
self.SPARswt = None
self.SPARsum = None
self.SPARosc = None
self.SPARtst = None
self.SPARcor = None
self.SPARofs = None
self.SPARhsn = None
self.SPARhsa = None
self.SPARcalibPow_M = None
self.SPARcalibSNR_M = None
self.SPARcalibPow_S = None
self.SPARcalibSNR_S = None
self.SPARrawGate1 = None
self.SPARrawGate2 = None
self.SPARraw = None
self.SPARprc = None
self.FHsize = 1180
ebocanegra
first commit
r965 def FHread(self, fp):
José Chávez
sin matplotlib de los modulos de claire
r1075
header = numpy.fromfile(fp, FILE_HEADER, 1)
ebocanegra
first commit
r965 ''' numpy.fromfile(file, dtype, count, sep='')
file : file or str
Open file object or filename.
dtype : data-type
Data type of the returned array. For binary files, it is used to determine
the size and byte-order of the items in the file.
count : int
Number of items to read. -1 means all items (i.e., the complete file).
sep : str
Separator between items if file is a text file. Empty ("") separator means
the file should be treated as binary. Spaces (" ") in the separator match zero
or more whitespace characters. A separator consisting only of spaces must match
at least one whitespace.
'''
José Chávez
sin matplotlib de los modulos de claire
r1075
self.Hname = str(header['Hname'][0])
self.Htime = str(header['Htime'][0])
self.Hoper = str(header['Hoper'][0])
self.Hplace = str(header['Hplace'][0])
self.Hdescr = str(header['Hdescr'][0])
self.Hdummy = str(header['Hdummy'][0])
# 1024
self.Msign = str(header['Msign'][0])
self.MsizeData = header['MsizeData'][0]
# 8
self.PPARsign = str(header['PPARsign'][0])
self.PPARsize = header['PPARsize'][0]
self.PPARprf = header['PPARprf'][0]
self.PPARpdr = header['PPARpdr'][0]
self.PPARsft = header['PPARsft'][0]
self.PPARavc = header['PPARavc'][0]
self.PPARihp = header['PPARihp'][0]
self.PPARchg = header['PPARchg'][0]
self.PPARpol = header['PPARpol'][0]
# Service DSP parameters
# 36
self.SPARatt = header['SPARatt'][0]
self.SPARtx = header['SPARtx'][0]
self.SPARaddGain0 = header['SPARaddGain0'][0]
self.SPARaddGain1 = header['SPARaddGain1'][0]
self.SPARwnd = header['SPARwnd'][0]
self.SPARpos = header['SPARpos'][0]
self.SPARadd = header['SPARadd'][0]
self.SPARlen = header['SPARlen'][0]
self.SPARcal = header['SPARcal'][0]
self.SPARnos = header['SPARnos'][0]
self.SPARof0 = header['SPARof0'][0]
self.SPARof1 = header['SPARof1'][0]
self.SPARswt = header['SPARswt'][0]
self.SPARsum = header['SPARsum'][0]
self.SPARosc = header['SPARosc'][0]
self.SPARtst = header['SPARtst'][0]
self.SPARcor = header['SPARcor'][0]
self.SPARofs = header['SPARofs'][0]
self.SPARhsn = header['SPARhsn'][0]
self.SPARhsa = header['SPARhsa'][0]
self.SPARcalibPow_M = header['SPARcalibPow_M'][0]
self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
self.SPARcalibPow_S = header['SPARcalibPow_S'][0]
self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
self.SPARrawGate1 = header['SPARrawGate1'][0]
self.SPARrawGate2 = header['SPARrawGate2'][0]
self.SPARraw = header['SPARraw'][0]
self.SPARprc = header['SPARprc'][0]
# 112
# 1180
# print 'Pointer fp header', fp.tell()
# print ' '
# print 'SPARrawGate'
# print self.SPARrawGate2 - self.SPARrawGate1
# print ' '
# print 'Hname'
# print self.Hname
# print ' '
# print 'Msign'
# print self.Msign
ebocanegra
first commit
r965 def write(self, fp):
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 headerTuple = (self.Hname,
self.Htime,
self.Hoper,
self.Hplace,
self.Hdescr,
self.Hdummy)
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 header = numpy.array(headerTuple, FILE_HEADER)
# numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
header.tofile(fp)
''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
fid : file or str
An open file object, or a string containing a filename.
sep : str
Separator between array items for text output. If "" (empty), a binary file is written,
equivalent to file.write(a.tobytes()).
format : str
Format string for text file output. Each entry in the array is formatted to text by
first converting it to the closest Python type, and then using "format" % item.
'''
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 return 1
José Chávez
sin matplotlib de los modulos de claire
r1075
SRVI_HEADER = numpy.dtype([
('SignatureSRVI1', numpy.str_, 4),
('SizeOfDataBlock1', '<i4'),
('DataBlockTitleSRVI1', numpy.str_, 4),
('SizeOfSRVI1', '<i4'), ])
class SRVIHeader(Header):
ebocanegra
first commit
r965 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.SignatureSRVI1 = SignatureSRVI1
self.SizeOfDataBlock1 = SizeOfDataBlock1
self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
José Chávez
sin matplotlib de los modulos de claire
r1075 self.SizeOfSRVI1 = SizeOfSRVI1
self.SRVIHsize = 16
def SRVIread(self, fp):
header = numpy.fromfile(fp, SRVI_HEADER, 1)
ebocanegra
first commit
r965
self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
José Chávez
sin matplotlib de los modulos de claire
r1075 # 16
ebocanegra
first commit
r965 print 'Pointer fp SRVIheader', fp.tell()
José Chávez
sin matplotlib de los modulos de claire
r1075 SRVI_STRUCTURE = numpy.dtype([
('frame_cnt', '<u4'),
('time_t', '<u4'), #
('tpow', '<f4'), #
('npw1', '<f4'), #
('npw2', '<f4'), #
('cpw1', '<f4'), #
('pcw2', '<f4'), #
('ps_err', '<u4'), #
('te_err', '<u4'), #
('rc_err', '<u4'), #
('grs1', '<u4'), #
('grs2', '<u4'), #
('azipos', '<f4'), #
('azivel', '<f4'), #
('elvpos', '<f4'), #
('elvvel', '<f4'), #
('northAngle', '<f4'),
('microsec', '<u4'), #
('azisetvel', '<f4'), #
('elvsetpos', '<f4'), #
('RadarConst', '<f4'), ]) #
ebocanegra
first commit
r965
class RecordHeader(Header):
José Chávez
sin matplotlib de los modulos de claire
r1075
def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0,
cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0):
ebocanegra
first commit
r965 self.frame_cnt = frame_cnt
self.dwell = time_t
self.tpow = tpow
self.npw1 = npw1
self.npw2 = npw2
self.cpw1 = cpw1
self.pcw2 = pcw2
self.ps_err = ps_err
self.te_err = te_err
self.rc_err = rc_err
self.grs1 = grs1
self.grs2 = grs2
self.azipos = azipos
self.azivel = azivel
self.elvpos = elvpos
self.elvvel = elvvel
self.northAngle = northangle
self.microsec = microsec
self.azisetvel = azisetvel
self.elvsetpos = elvsetpos
self.RadarConst = RadarConst
José Chávez
sin matplotlib de los modulos de claire
r1075 self.RHsize = 84
ebocanegra
first commit
r965 self.RecCounter = RecCounter
José Chávez
sin matplotlib de los modulos de claire
r1075 self.Off2StartNxtRec = Off2StartNxtRec
ebocanegra
first commit
r965 def RHread(self, fp):
José Chávez
sin matplotlib de los modulos de claire
r1075
# startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
ebocanegra
first commit
r965 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
#startFp.seek(OffRHeader, os.SEEK_SET)
José Chávez
sin matplotlib de los modulos de claire
r1075
# print 'Posicion del bloque: ',OffRHeader
header = numpy.fromfile(fp, SRVI_STRUCTURE, 1)
self.frame_cnt = header['frame_cnt'][0]
ebocanegra
first commit
r965 self.time_t = header['time_t'][0] #
self.tpow = header['tpow'][0] #
self.npw1 = header['npw1'][0] #
self.npw2 = header['npw2'][0] #
self.cpw1 = header['cpw1'][0] #
self.pcw2 = header['pcw2'][0] #
self.ps_err = header['ps_err'][0] #
self.te_err = header['te_err'][0] #
self.rc_err = header['rc_err'][0] #
self.grs1 = header['grs1'][0] #
self.grs2 = header['grs2'][0] #
self.azipos = header['azipos'][0] #
self.azivel = header['azivel'][0] #
self.elvpos = header['elvpos'][0] #
self.elvvel = header['elvvel'][0] #
self.northAngle = header['northAngle'][0] #
self.microsec = header['microsec'][0] #
self.azisetvel = header['azisetvel'][0] #
self.elvsetpos = header['elvsetpos'][0] #
self.RadarConst = header['RadarConst'][0] #
José Chávez
sin matplotlib de los modulos de claire
r1075 # 84
# print 'Pointer fp RECheader', fp.tell()
ebocanegra
first commit
r965 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 #self.RHsize = 180+20*self.nChannels
#self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
José Chávez
sin matplotlib de los modulos de claire
r1075 # print 'Datasize',self.Datasize
ebocanegra
first commit
r965 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 print '=============================================='
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 print '=============================================='
return 1
José Chávez
sin matplotlib de los modulos de claire
r1075
class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader):
ebocanegra
first commit
r965 path = None
startDate = None
endDate = None
startTime = None
endTime = None
walk = None
isConfig = False
José Chávez
sin matplotlib de los modulos de claire
r1075
fileList = None
# metadata
TimeZone = None
Interval = None
heightList = None
# data
data = None
utctime = None
def __init__(self, **kwargs):
# Eliminar de la base la herencia
ebocanegra
15/08/2017
r1001 ProcessingUnit.__init__(self, **kwargs)
ebocanegra
first commit
r965 self.PointerReader = 0
self.FileHeaderFlag = False
self.utc = None
self.ext = ".zspca"
self.optchar = "P"
José Chávez
sin matplotlib de los modulos de claire
r1075 self.fpFile = None
ebocanegra
first commit
r965 self.fp = None
José Chávez
sin matplotlib de los modulos de claire
r1075 self.BlockCounter = 0
ebocanegra
first commit
r965 self.dtype = None
self.fileSizeByHeader = None
self.filenameList = []
self.fileSelector = 0
José Chávez
sin matplotlib de los modulos de claire
r1075 self.Off2StartNxtRec = 0
self.RecCounter = 0
ebocanegra
first commit
r965 self.flagNoMoreFiles = 0
José Chávez
sin matplotlib de los modulos de claire
r1075 self.data_spc = None
# self.data_cspc=None
self.data_output = None
ebocanegra
first commit
r965 self.path = None
José Chávez
sin matplotlib de los modulos de claire
r1075 self.OffsetStartHeader = 0
self.Off2StartData = 0
ebocanegra
first commit
r965 self.ipp = 0
José Chávez
sin matplotlib de los modulos de claire
r1075 self.nFDTdataRecors = 0
ebocanegra
first commit
r965 self.blocksize = 0
self.dataOut = Spectra()
José Chávez
sin matplotlib de los modulos de claire
r1075 self.profileIndex = 1 # Always
self.dataOut.flagNoData = False
Juan C. Espinoza
Add __attrs__ attribute to Process clasess to improve CLI finder
r1097 self.dataOut.nRdPairs = 0
self.dataOut.data_spc = None
ebocanegra
first commit
r965 self.nextfileflag = True
self.dataOut.RadarConst = 0
self.dataOut.HSDV = []
self.dataOut.NPW = []
self.dataOut.COFA = []
Juan C. Espinoza
Add __attrs__ attribute to Process clasess to improve CLI finder
r1097 # self.dataOut.noise = 0
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def Files2Read(self, fp):
'''
Function that indicates the number of .fdt files that exist in the folder to be read.
It also creates an organized list with the names of the files to read.
'''
José Chávez
sin matplotlib de los modulos de claire
r1075 # self.__checkPath()
# Gets the list of files within the fp address
ListaData = os.listdir(fp)
# Sort the list of files from least to largest by names
ListaData = sorted(ListaData)
nFiles = 0 # File Counter
FileList = [] # A list is created that will contain the .fdt files
for IndexFile in ListaData:
if '.zspca' in IndexFile and '.gz' not in IndexFile:
ebocanegra
first commit
r965 FileList.append(IndexFile)
José Chávez
sin matplotlib de los modulos de claire
r1075 nFiles += 1
# print 'Files2Read'
# print 'Existen '+str(nFiles)+' archivos .fdt'
self.filenameList = FileList # List of files from least to largest by names
ebocanegra
first commit
r965 def run(self, **kwargs):
'''
This method will be the one that will initiate the data entry, will be called constantly.
You should first verify that your Setup () is set up and then continue to acquire
the data to be processed with getData ().
'''
if not self.isConfig:
self.setup(**kwargs)
self.isConfig = True
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.getData()
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def setup(self, path=None,
José Chávez
sin matplotlib de los modulos de claire
r1075 startDate=None,
endDate=None,
startTime=None,
endTime=None,
walk=True,
timezone='utc',
code=None,
online=False,
ReadMode=None, **kwargs):
ebocanegra
first commit
r965 self.isConfig = True
José Chávez
sin matplotlib de los modulos de claire
r1075
self.path = path
self.startDate = startDate
self.endDate = endDate
self.startTime = startTime
self.endTime = endTime
self.walk = walk
# self.ReadMode=int(ReadMode)
ebocanegra
first commit
r965 pass
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 def getData(self):
'''
Before starting this function, you should check that there is still an unread file,
If there are still blocks to read or if the data block is empty.
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 You should call the file "read".
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 '''
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 if self.flagNoMoreFiles:
self.dataOut.flagNoData = True
print 'NoData se vuelve true'
return 0
José Chávez
sin matplotlib de los modulos de claire
r1075
self.fp = self.path
ebocanegra
first commit
r965 self.Files2Read(self.fp)
self.readFile(self.fp)
José Chávez
sin matplotlib de los modulos de claire
r1075
self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy()
ebocanegra
first commit
r965 self.dataOut.RadarConst = self.RadarConst
José Chávez
sin matplotlib de los modulos de claire
r1075 self.dataOut.data_output = self.data_output
ebocanegra
15/08/2017
r1001 self.dataOut.noise = self.dataOut.getNoise()
José Chávez
sin matplotlib de los modulos de claire
r1075 # print 'ACAAAAAA', self.dataOut.noise
self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise
Juan C. Espinoza
Add __attrs__ attribute to Process clasess to improve CLI finder
r1097 self.dataOut.normFactor = 1
José Chávez
sin matplotlib de los modulos de claire
r1075 # print 'self.dataOut.noise',self.dataOut.noise
ebocanegra
first commit
r965 return self.dataOut.data_spc
José Chávez
sin matplotlib de los modulos de claire
r1075
def readFile(self, fp):
ebocanegra
first commit
r965 '''
You must indicate if you are reading in Online or Offline mode and load the
The parameters for this file reading mode.
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 Then you must do 2 actions:
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 1. Get the BLTR FileHeader.
2. Start reading the first block.
'''
José Chávez
sin matplotlib de los modulos de claire
r1075
# The address of the folder is generated the name of the .fdt file that will be read
print "File: ", self.fileSelector + 1
ebocanegra
first commit
r965 if self.fileSelector < len(self.filenameList):
José Chávez
sin matplotlib de los modulos de claire
r1075
self.fpFile = str(fp) + '/' + \
str(self.filenameList[self.fileSelector])
if self.nextfileflag == True:
self.fp = open(self.fpFile, "rb")
self.nextfileflag == False
ebocanegra
first commit
r965 '''HERE STARTING THE FILE READING'''
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.fheader = FileHeaderMIRA35c()
José Chávez
sin matplotlib de los modulos de claire
r1075 self.fheader.FHread(self.fp) # Bltr FileHeader Reading
ebocanegra
first commit
r965
self.SPARrawGate1 = self.fheader.SPARrawGate1
self.SPARrawGate2 = self.fheader.SPARrawGate2
self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
self.Num_Bins = self.fheader.PPARsft
self.dataOut.nFFTPoints = self.fheader.PPARsft
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.Num_inCoh = self.fheader.PPARavc
self.dataOut.PRF = self.fheader.PPARprf
José Chávez
sin matplotlib de los modulos de claire
r1075 self.dataOut.frequency = 34.85 * 10**9
self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency
self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF)
pulse_width = self.fheader.PPARpdr * 10**-9
ebocanegra
first commit
r965 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
José Chávez
sin matplotlib de los modulos de claire
r1075
self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2))
ebocanegra
first commit
r965 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.Ze = numpy.zeros(self.Num_Hei)
José Chávez
sin matplotlib de los modulos de claire
r1075 self.ETA = numpy.zeros(([2, self.Num_Hei]))
self.readBlock() # Block reading
ebocanegra
first commit
r965 else:
print 'readFile FlagNoData becomes true'
José Chávez
sin matplotlib de los modulos de claire
r1075 self.flagNoMoreFiles = True
ebocanegra
first commit
r965 self.dataOut.flagNoData = True
self.FileHeaderFlag == True
José Chávez
sin matplotlib de los modulos de claire
r1075 return 0
def readBlock(self):
ebocanegra
first commit
r965 '''
It should be checked if the block has data, if it is not passed to the next file.
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 Then the following is done:
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 1. Read the RecordHeader
2. Fill the buffer with the current block number.
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 '''
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 if self.PointerReader > 1180:
José Chávez
sin matplotlib de los modulos de claire
r1075 self.fp.seek(self.PointerReader, os.SEEK_SET)
ebocanegra
first commit
r965 self.FirstPoint = self.PointerReader
José Chávez
sin matplotlib de los modulos de claire
r1075
else:
ebocanegra
first commit
r965 self.FirstPoint = 1180
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.srviHeader = SRVIHeader()
José Chávez
sin matplotlib de los modulos de claire
r1075
self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI
self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
ebocanegra
first commit
r965 if self.blocksize == 148:
print 'blocksize == 148 bug'
José Chávez
sin matplotlib de los modulos de claire
r1075 jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1)
# Se obtiene la cabecera del SRVI
self.srviHeader.SRVIread(self.fp)
ebocanegra
first commit
r965 if not self.srviHeader.SizeOfSRVI1:
José Chávez
sin matplotlib de los modulos de claire
r1075 self.fileSelector += 1
self.nextfileflag == True
ebocanegra
first commit
r965 self.FileHeaderFlag == True
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.recordheader = RecordHeader()
self.recordheader.RHread(self.fp)
self.RadarConst = self.recordheader.RadarConst
dwell = self.recordheader.time_t
npw1 = self.recordheader.npw1
npw2 = self.recordheader.npw2
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
15/08/2017
r1001 self.dataOut.channelList = range(1)
José Chávez
sin matplotlib de los modulos de claire
r1075 self.dataOut.nIncohInt = self.Num_inCoh
ebocanegra
first commit
r965 self.dataOut.nProfiles = self.Num_Bins
self.dataOut.nCohInt = 1
self.dataOut.windowOfFilter = 1
self.dataOut.utctime = dwell
José Chávez
sin matplotlib de los modulos de claire
r1075 self.dataOut.timeZone = 0
ebocanegra
first commit
r965 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
José Chávez
sin matplotlib de los modulos de claire
r1075 self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \
numpy.array(range(self.Num_Hei)) * self.__deltaHeigth
self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1)
self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1)
self.HSDV_Co = numpy.fromfile(
self.fp, [('HSDV_Co', '<f4')], self.Num_Hei)
self.HSDV_Cx = numpy.fromfile(
self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei)
self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1)
self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1)
self.COFA_Co = numpy.fromfile(
self.fp, [('COFA_Co', '<f4')], self.Num_Hei)
self.COFA_Cx = numpy.fromfile(
self.fp, [('COFA_Cx', '<f4')], self.Num_Hei)
self.ZSPCsign = numpy.fromfile(
self.fp, [('ZSPCsign', numpy.str_, 4)], 1)
self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1)
self.dataOut.HSDV[0] = self.HSDV_Co[:][0]
self.dataOut.HSDV[1] = self.HSDV_Cx[:][0]
ebocanegra
first commit
r965 for irg in range(self.Num_Hei):
José Chávez
sin matplotlib de los modulos de claire
r1075 # Number of spectral sub pieces containing significant power
nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0]
ebocanegra
first commit
r965 for k in range(nspc):
José Chávez
sin matplotlib de los modulos de claire
r1075 # Index of the spectral bin where the piece is beginning
binIndex = numpy.fromfile(
self.fp, [('binIndex', 'int16')], 1)[0][0]
nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[
0][0] # Number of bins of the piece
# Co_Channel
jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[
0][0] # Spectrum piece to be normaliced
jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[
0][0] # Maximun piece to be normaliced
self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg,
binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax
# Cx_Channel
jbin = numpy.fromfile(
self.fp, [('jbin', 'uint16')], nbins)[0][0]
jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0]
self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg,
binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax
for bin in range(self.Num_Bins):
self.data_spc[:, bin, 0] = self.data_spc[:,
bin, 0] - self.dataOut.HSDV[:, 0]
self.data_spc[:, bin, 1] = self.data_spc[:,
bin, 1] - self.dataOut.HSDV[:, 1]
ebocanegra
first commit
r965 numpy.set_printoptions(threshold='nan')
José Chávez
sin matplotlib de los modulos de claire
r1075
self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx])
ebocanegra
first commit
r965 print ' '
José Chávez
sin matplotlib de los modulos de claire
r1075 print 'SPC', numpy.shape(self.dataOut.data_spc)
# print 'SPC',self.dataOut.data_spc
ebocanegra
first commit
r965 noinor1 = 713031680
noinor2 = 30
José Chávez
sin matplotlib de los modulos de claire
r1075
npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2
npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2
ebocanegra
first commit
r965 self.dataOut.NPW = numpy.array([npw1, npw2])
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 print ' '
José Chávez
sin matplotlib de los modulos de claire
r1075
self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0))
self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1)
ebocanegra
first commit
r965 self.data_spc = numpy.fliplr(self.data_spc)
José Chávez
sin matplotlib de los modulos de claire
r1075
self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei])
self.dataOut_spc[0, :, :] = self.data_spc[0, :, :]
# print 'SHAPE', self.dataOut_spc.shape
# For nyquist correction:
# fix = 20 # ~3m/s
ebocanegra
15/08/2017
r1001 #shift = self.Num_Bins/2 + fix
#self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 '''Block Reading, the Block Data is received and Reshape is used to give it
shape.
'''
José Chávez
sin matplotlib de los modulos de claire
r1075
ebocanegra
first commit
r965 self.PointerReader = self.fp.tell()