process satellite data from path
[JPSSData.git] / case.py
blobfc852f26b027cbe68d47cc5c389d1dd9fba75c7e
1 # General python for any case
2 from JPSSD import *
3 from interpolation import sort_dates
4 import saveload as sl
5 import datetime as dt
6 import sys
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: '
15 print ' YYYY - year'
16 print ' MM - month'
17 print ' DD - day'
18 print ' HH - hour'
19 print ' MM - minute'
20 print ' SS - second'
21 print ' * days - float, number of days of simulation (can be less than a day)'
22 sys.exit(0)
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
39 print 'Sorted?'
40 stt=sorted(tt)
41 print tt==stt
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)
50 if csv:
51 write_csv(json,bbox)
52 json2kml(json,'nofire.kml',bbox,prods,opt=opt)
53 if opt == 'granules':
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'}
62 if opt != 'granules':
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)
66 else:
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)
71 print 'saving data'
72 sl.save((data,fxlon,fxlat,map(time_iso2num,time_iso)),'data')
74 print 'run setup next'