-
Notifications
You must be signed in to change notification settings - Fork 2
/
preCache.py
96 lines (82 loc) · 3.58 KB
/
preCache.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from NCStore import *
from optparse import OptionParser
import datetime
import multiprocessing as mp
option_parser = OptionParser()
option_parser.add_option('--update', default=False)
option_parser.add_option('--datapath', default='data_nc', metavar='NCFilePath')
option_parser.add_option('--SD_App', default='true')
option_parser.add_option('--timelimit', default=72)
options, args = option_parser.parse_args(sys.argv[1:])
update = False
if options.update:
update = True
# put NC_PATH enviorment
os.environ['NC_PATH'] = options.datapath
# for SD App
SD_App = True
if options.SD_App=='false':
SD_App = False
SD_Extent = [117.5,35,123.5,38.5]
timelimit = int(options.timelimit)
def walkStoreStream(obj):
method = getattr(obj[0], obj[1])
method(*obj[2:])
if __name__ == '__main__':
d1 = datetime.datetime.now()
print d1
# pool = mp.Pool(processes=mp.cpu_count())
debug = True
projection = WebMercatorProjection
model_caches = {
'WRF':{'regions':['NCS'], 'scalar':True, 'legend':True, 'imagetile':True, 'jsontile':False, 'isoline':True},
'SWAN':{'regions':['NCS'], 'scalar':True, 'legend':True, 'imagetile':False, 'jsontile':False, 'isoline':False},
'POM':{'regions':['NCS'], 'scalar':True, 'legend':True, 'imagetile':True, 'jsontile':False, 'isoline':False},
'ROMS':{'regions':['NCS'], 'scalar':True, 'legend':True, 'imagetile':True, 'jsontile':False, 'isoline':False},
'FVCOMSTM':{'regions':['BHS'], 'scalar':True, 'legend':True, 'imagetile':True, 'jsontile':False, 'isoline':False}
}
for model in model_caches:
if debug:
if model == 'FVCOMSTM':
date = datetime.date(2013,11,16)
elif model == 'SWAN':
date = datetime.date(2013,11,14)
elif model == 'WRF':
date = datetime.date(2013,11,25)
elif model == 'POM':
date = datetime.date(2013,12,10)
elif model == 'ROMS':
date = datetime.date(2013,11,15)
else:
date = datetime.date.today()
for region in model_caches[model]['regions']:
store = globals()[model+'Store'](date, region)
if SD_App and model != 'WRF' :
store.set_filter_extent(*SD_Extent)
if timelimit != 0:
store.set_filter_times(timelimit)
# store.universal_legend = False
if model_caches[model]['scalar']:
storestream = store.list_scalar_images(projection=projection, update=update)
map(walkStoreStream, storestream)
# for test, 只生成一个
# walkStoreStream(next(storestream))
# 使用多进程模式会引起netcdf底层错误
# pool.map(walkStoreStream, storestream)
if model_caches[model]['legend']:
storestream = store.list_scalar_legends(update=update)
map(walkStoreStream, storestream)
if model_caches[model]['imagetile']:
storestream = store.list_tiles('image', projection=projection, update=update)
map(walkStoreStream, storestream)
if model_caches[model]['jsontile']:
storestream = store.list_tiles('json', projection=projection, update=update)
map(walkStoreStream, storestream)
if model_caches[model]['isoline']:
storestream = store.list_scalar_isolines(update=update)
map(walkStoreStream, storestream)
d2 = datetime.datetime.now()
print d2