-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCNET_ArgosMake2WeekFile_16032020.py
47 lines (42 loc) · 1.81 KB
/
GCNET_ArgosMake2WeekFile_16032020.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
#%%%% 14 Day Data File Creation %%%%
#% This function checks if a station csv file exists and reads the last
#% 24hr * 14 days = 336 lines it then outputs to a csv
#% file with the _v (for visualation) suffix
#%written by Derek Houtz Birmensdorf, Modified 15.10.2018
#converted to python
import numpy as np
import datetime
def WriteCFile(fid,DatasetN):
if len(DatasetN)!=0:
formstr = '%i,%4i,%.4f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f'
np.savetxt(fid,DatasetN,fmt=formstr)
else:
np.savetxt(fid,DatasetN)
AStation_numbers = np.array([4,5,7,22,31,32,33])
stations = AStation_numbers;
numlines = 24*14; #this is 2 weeks of data assuming max transmission every hour
today = datetime.datetime.now()
doynow = (today - datetime.datetime(today.year, 1, 1)).days + 1
yearn = today.year
#2 weeks will not be longer than this length
for i in range(len(stations)):
filename = str(stations[i])+'.csv'
#find if there are at least numlines in file
with open(filename,"rb") as f:
lines = f.readlines()
lineCount = len(lines)
if lineCount >=numlines:
twoweeks = np.genfromtxt(lines[-numlines:],delimiter=',')# get the lines from
#file without reading whole csv into memory
doyv = twoweeks[:,2]
yrv = twoweeks[:,1]
if doynow>14:
twoweeks=twoweeks[(doyv>=doynow-14) & (yrv==yearn),:]
else:
twoweeks=twoweeks[(doyv>=365-14+doynow) & (yrv>=yearn-1),:]
else:
twoweeks = np.array([])
newfilename = str(stations[i])+'_v.csv'
with open(newfilename,'w') as fidn:
WriteCFile(fidn,twoweeks)