##// END OF EJS Templates
CIRI_offline_version
Alexander Valdez -
r590:06fbccacd1e7
parent child
Show More
@@ -0,0 +1,163
1 from schainpy.model.data.jrodata import *
2 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
3 from schainpy.model.io.jroIO_base import *
4
5 import scipy.io as sio
6 import pprint
7 import numpy as np
8 from os import listdir
9 from os.path import isfile, join
10 import datetime
11 import cmath
12
13 class matoffReader(ProcessingUnit):
14
15 index=None
16 list=None
17 firsttime=True
18 utccounter=None
19 utcfiletime=None
20 utcmatcounter=0
21 utcfirst=None
22 utclist=None
23
24 def __init__(self):
25 self.dataOut = Spectra()
26 return
27
28
29 def run(self,path=None,startDate=None, endDate=None,startTime=datetime.time(0,0,0),
30 endTime=datetime.time(23,59,59),walk=True,timezone='ut',
31 all=0,online=False,ext=None,**kwargs):
32
33 self.path=path
34 self.ext=ext
35 self.startDate=startDate
36 self.endDate=endDate
37 self.startTime=startTime
38 self.endTime=endTime
39
40
41 startsearch1=datetime.datetime.combine(startDate,startTime)
42 startsearch2=(startsearch1-datetime.datetime(1970,1,1)).total_seconds()
43 endsearch1=datetime.datetime.combine(endDate,endTime)
44 endsearch2=(endsearch1-datetime.datetime(1970,1,1)).total_seconds()
45
46
47 filelist = [ f for f in listdir(path)]
48
49 secondlist=[]
50 thirdlist=[]
51 utclist=[]
52
53 if (self.firsttime==True):
54
55 self.utclist=utclist
56
57 for g in range(len(filelist)):
58
59 strsplit=filelist[g].split('.')
60 timeints=[int(i) for i in strsplit]
61 timelist=datetime.datetime(timeints[0],timeints[1],timeints[2],timeints[3],timeints[4],timeints[5])
62 utctime=(timelist-datetime.datetime(1970,1,1)).total_seconds()
63
64 if (utctime<=endsearch2):
65 if (utctime>=startsearch2):
66 secondlist.append(filelist[g])
67 self.utclist.append(utctime)
68
69
70
71
72 for k in range(len(secondlist)):
73
74 path1=os.path.join(self.path,secondlist[k])
75
76 filecounter=len([name for name in os.listdir(path1)])
77 # print "Reading from this dir:" +path1
78 for r in range(filecounter):
79 matname=str(r)+'.mat'
80 bork=os.path.join(path1,matname)
81 thirdlist.append(os.path.join(path1,matname))
82
83
84 self.utcfirst=utclist[0]
85 self.firsttime=False
86 self.index=0
87 self.list=thirdlist
88
89
90 currentfile=self.list[self.index]
91 print "Reading from this file:" + currentfile
92
93 #filesplit=currentfile.split("\\")
94 filesplit=currentfile.split("/")
95 newsplit=filesplit[-2]
96 newnewsplit=newsplit.split(".")
97 newnewsplit=[int(i) for i in newnewsplit]
98 gooblist=datetime.datetime(newnewsplit[0],newnewsplit[1],newnewsplit[2],newnewsplit[3],newnewsplit[4],newnewsplit[5])
99 self.utcfirst=(gooblist-datetime.datetime(1970,1,1)).total_seconds()
100
101
102 newsplit=filesplit[-1]
103 newnewsplit=newsplit.split(".")
104 goobnum=newnewsplit[0]
105 goobnum=int(goobnum)
106
107 self.utcfirst=self.utcfirst+goobnum*2
108 # if (currentfile[43:]=='0.mat'):
109 # self.utcmatcounter=0
110 # self.utcfirst=self.utclist[self.index]
111
112 # if (self.utcmatcounter>60):
113 # self.utcmatcounter=0
114
115 # print self.utcmatcounter
116 print self.utcfirst
117
118 datastuff=sio.loadmat(currentfile)
119 dataphase=datastuff.get('phase')
120 data3=datastuff.get('doppler0')
121 data4=datastuff.get('doppler1')
122 data3= np.array(data3)
123 data4 = np.array(data4)
124 datacoh=datastuff.get('coherence2')
125
126 datacohphase=datacoh*np.exp(-dataphase*1j)
127 # data31 = np.fliplr(data3)
128 # data41 = np.fliplr(data4)
129
130 data31 = data3.reshape((1,data3.shape[0],data3.shape[1]))
131 data41 = data4.reshape((1,data4.shape[0],data4.shape[1]))
132 datacohphase1 = datacohphase.reshape((1,datacoh.shape[0],datacoh.shape[1]))
133
134 datastack = np.vstack((data31,data41))
135
136 self.dataOut.pairsList=[(0,1)]
137 self.dataOut.data_cspc=datacohphase1.copy()
138 self.dataOut.data_spc = datastack.copy()
139 self.dataOut.channelList = range(2)
140 self.dataOut.nProfiles = 25 #this!
141 self.dataOut.nIncohInt = 1
142 self.dataOut.nCohInt = 1 #this!
143 self.dataOut.ippSeconds = 0.004 #this!
144 self.dataOut.nFFTPoints = 25
145 self.dataOut.utctime = self.utcfirst
146 self.dataOut.heightList = np.array(datastuff.get('hts'))
147
148 self.dataOut.flagNoData = False
149
150
151
152 # self.utcmatcounter=2
153 # self.utcfirst+=self.utcmatcounter
154 self.index+=1
155
156 if (self.index>len(self.list)):
157 return 0
158
159
160
161
162 return 1
163 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now