-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_goes_meso_sector.py
executable file
·69 lines (61 loc) · 3.06 KB
/
get_goes_meso_sector.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
import sys
import os
import datetime
import shutil
numargs = len(sys.argv) - 1
print("numargs = %d" % (numargs))
if numargs != 3:
print("Useage: %s [start(YYYYMMDDHHMM)] [end(YYYYMMDDHHMM)] [sector(1 or 2)]" % (sys.argv[0]))
exit()
else:
print("You are good to go")
start = sys.argv[1]
startObj = datetime.datetime.strptime(start,'%Y%m%d%H%M')
#startUnix = int(startObj.strftime("%s"))
startDate = startObj.strftime("%Y%m%d")
startYear = startObj.strftime("%Y")
end = sys.argv[2]
endObj = datetime.datetime.strptime(end,'%Y%m%d%H%M')
#endUnix = int(endObj.strftime("%s"))
endDate = endObj.strftime("%Y%m%d")
sector = sys.argv[3]
print("startObj = %s, endObj = %s, sector = %s" % (startObj,endObj,sector))
base_in_dir = '/home/disk/data/satellite/GOES/GRB16/ABI/Mesoscale-'+sector
base_save_dir = '/home/disk/bob/impacts/raw/goes16/Mesoscale-'+sector
#channels = ['Channel01','Channel13']
channels = ['Channel01','Channel02','Channel03','Channel04','Channel05','Channel06','Channel07','Channel08','Channel09','Channel10','Channel11','Channel12','Channel13','Channel14','Channel15','Channel16']
#channels = ['Channel09','Channel10','Channel11','Channel12','Channel14','Channel15','Channel16']
prefix = 'OR_ABI-L1b-RadM'
for ichan in range(0,len(channels)):
indir = base_in_dir+'/'+channels[ichan]
outdir = base_save_dir+'/'+channels[ichan]
if not os.path.isdir(outdir):
os.makedirs(outdir)
print ("ichan = %d and indir = %s and outdir = %s" % (ichan,indir,outdir))
dirlist = os.listdir(indir)
for dir in dirlist:
if dir.startswith(startYear):
dirDate = dir
dirDateObj = datetime.datetime.strptime(dir,'%Y%m%d')
dirDateUnix = int(dirDateObj.strftime("%s"))
if dirDate >= startDate and dirDate <= endDate:
if not os.path.isdir(outdir+'/'+dirDate):
os.mkdir(outdir+'/'+dirDate)
os.chdir(indir+'/'+dirDate)
filelist = os.listdir('.')
for file in filelist:
if file.startswith(prefix):
parts = file.split('_')
for part in parts:
if part.startswith('s'):
fileDateTime = part[1:-1] # format sYYYYJJJHHMMSSs
fileDateTimeObj = datetime.datetime.strptime(fileDateTime,'%Y%j%H%M%S')
#fileDateTimeUnix = int(fileDateTimeObj.strftime("%s"))
#if fileDateTimeUnix >= startUnix and fileDateTimeUnix <= endUnix:
if fileDateTimeObj >= startObj and fileDateTimeObj <= endObj:
if file not in os.listdir(outdir+'/'+dirDate):
shutil.copy(file,outdir+'/'+dirDate)
print(file,'copied')
else:
print(file,'already copied')