printing and reducing density
[JPSSData.git] / sugarloaf.py
blobba0ed9ab18c692f6a61073bb7e8abc8513e199dc
1 # sample data into mesh - Sugarloaf
2 # navigate to /share_home/jmandel/sugarloaf to access sample data
3 from JPSSD import *
4 from interpolation import sort_dates
5 import saveload as sl
6 import datetime as dt
7 import sys
9 csv=False # CSV file of fire detections
10 opt='granules' # KML folders sorted by (pixels, granules or dates)
12 fxlon,fxlat,bbox,time_esmf=read_fire_mesh('wrfout_d03_2018-09-03_15:00:00')
14 # cannot get starting time from wrfout
15 time_iso = ("2018-08-15T00:00:00Z", "2018-09-02T00:00:00Z") # tuple, not array
17 data=retrieve_af_data(bbox,time_iso)
19 print 'Sort the granules by dates'
20 sdata=sort_dates(data)
21 tt=[ dd[1]['time_num'] for dd in sdata ] # array of times
22 print 'Sorted?'
23 stt=sorted(tt)
24 print tt==stt
26 print 'writting KML with fire detections'
27 keys=['latitude','longitude','brightness','scan','track','acq_date','acq_time','satellite','instrument','confidence','bright_t31','frp','scan_angle']
28 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']
29 prods={'AF':'Active Fires','FRP':'Fire Radiative Power'}
30 if csv or opt != 'granules':
31 N=[len(data[d]['lat_fire']) for d in data]
32 json=data2json(data,keys,dkeys,N)
33 if csv:
34 write_csv(json,bbox)
35 json2kml(json,'nofire.kml',bbox,prods,opt=opt)
36 if opt == 'granules':
37 N=[len(d[1]['lat_fire']) for d in sdata]
38 json=sdata2json(sdata,keys,dkeys,N)
39 json2kml(json,'fire_detections.kml',bbox,prods)
41 print 'writting KML with ground'
42 keys=['latitude','longitude','scan','track','acq_date','acq_time','satellite','instrument','scan_angle']
43 dkeys=['lat_nofire','lon_nofire','scan_nofire','track_nofire','acq_date','acq_time','sat_fire','instrument','scan_angle_nofire']
44 prods={'NF':'No Fire'}
45 if opt != 'granules':
46 N=[len(data[d]['lat_nofire']) for d in data]
47 json=data2json(data,keys,dkeys,N)
48 json2kml(json,'nofire.kml',bbox,prods,opt=opt)
49 else:
50 N=[len(d[1]['lat_nofire']) for d in sdata]
51 json=sdata2json(sdata,keys,dkeys,N)
52 json2kml(json,'nofire.kml',bbox,prods)
54 print 'saving data'
55 sl.save((data,fxlon,fxlat,map(time_iso2num,time_iso)),'data')
57 print 'run setup next'