1 # General python for any case
3 from interpolation
import sort_dates
8 csv
=False # CSV file of fire detections
9 opt
='granules' # KML folders sorted by (pixels, granules or dates)
11 if len(sys
.argv
) != 4:
12 print 'Error: python %s wrfout start_time days' % sys
.argv
[0]
13 print ' * wrfout - string, wrfout file of WRF-SFIRE simulation'
14 print ' * start_time - string, YYYYMMDDHHMMSS where: '
21 print ' * days - float, number of days of simulation (can be less than a day)'
24 fxlon
,fxlat
,bbox
,time_esmf
=read_fire_mesh(sys
.argv
[1])
26 dti
=dt
.datetime
.strptime(sys
.argv
[2],'%Y%m%d%H%M%S')
27 time_start_iso
='%d-%02d-%02dT%02d:%02d:%02dZ' % (dti
.year
,dti
.month
,dti
.day
,dti
.hour
,dti
.minute
,dti
.second
)
28 dtf
=dti
+dt
.timedelta(days
=float(sys
.argv
[3]))
29 time_final_iso
='%d-%02d-%02dT%02d:%02d:%02dZ' % (dtf
.year
,dtf
.month
,dtf
.day
,dtf
.hour
,dtf
.minute
,dtf
.second
)
31 # cannot get starting time from wrfout
32 time_iso
=(time_start_iso
,time_final_iso
) # tuple, not array
34 data
=retrieve_af_data(bbox
,time_iso
)
36 print 'Sort the granules by dates'
37 sdata
=sort_dates(data
)
38 tt
=[ dd
[1]['time_num'] for dd
in sdata
] # array of times
43 print 'writting KML with fire detections'
44 keys
=['latitude','longitude','brightness','scan','track','acq_date','acq_time','satellite','instrument','confidence','bright_t31','frp','scan_angle']
45 dkeys
=['lat_fire','lon_fire','brig_fire','scan_fire','track_fire','acq_date','acq_time','sat_fire','instrument','conf_fire','t31_fire','frp_fire','scan_angle_fire']
46 prods
={'AF':'Active Fires','FRP':'Fire Radiative Power'}
47 if csv
or opt
!= 'granules':
48 N
=[len(data
[d
]['lat_fire']) for d
in data
]
49 json
=data2json(data
,keys
,dkeys
,N
)
52 json2kml(json
,'nofire.kml',bbox
,prods
,opt
=opt
)
54 N
=[len(d
[1]['lat_fire']) for d
in sdata
]
55 json
=sdata2json(sdata
,keys
,dkeys
,N
)
56 json2kml(json
,'fire_detections.kml',bbox
,prods
)
58 print 'writting KML with ground'
59 keys
=['latitude','longitude','scan','track','acq_date','acq_time','satellite','instrument','scan_angle']
60 dkeys
=['lat_nofire','lon_nofire','scan_nofire','track_nofire','acq_date','acq_time','sat_fire','instrument','scan_angle_nofire']
61 prods
={'NF':'No Fire'}
63 N
=[len(data
[d
]['lat_nofire']) for d
in data
]
64 json
=data2json(data
,keys
,dkeys
,N
)
65 json2kml(json
,'nofire.kml',bbox
,prods
,opt
=opt
)
67 N
=[len(d
[1]['lat_nofire']) for d
in sdata
]
68 json
=sdata2json(sdata
,keys
,dkeys
,N
)
69 json2kml(json
,'nofire.kml',bbox
,prods
)
72 sl
.save((data
,fxlon
,fxlat
,map(time_iso2num
,time_iso
)),'data')
74 print 'run setup next'