Skip to content

Instantly share code, notes, and snippets.

@Zia-
Last active May 18, 2016 10:12
Show Gist options
  • Save Zia-/a01acd54d48376f822df7f946ffd189e to your computer and use it in GitHub Desktop.
Save Zia-/a01acd54d48376f822df7f946ffd189e to your computer and use it in GitHub Desktop.
1. # Open cron command
sudo crontab -e
2. # Paste the following line at the very end to execute above script after every 5 min.
# More details about this at http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
*/5 * * * * /usr/bin/python2.7 /var/www/html/maps/firemap/realdata-geojson/viirs/pullViirsData.py
3. # That's it. It will even run on system reboot.
import os, time, csv, json
viirsGlobalUrl = "viirs global csv url"
basePath = 'viirs basepath to 194 server'
baseFileName = 'viirs data base filename'
def createElemGeojson(latitude,longitude,bright_ti4,scan,track,acq_date,acq_time,satellite,confidence,version,bright_ti5,frp,daynight):
propValue = {}
propValue['BRIGHTNESS_TEMPERATURE_CHANNEL4'] = float(bright_ti4)
propValue['SCAN'] = float(scan)
propValue['TRACK'] = float(track)
propValue['ACQUISITION_DATE'] = acq_date
propValue['ACQUISITION_TIME'] = int(acq_time)
propValue['SATELLITE'] = satellite
propValue['CONFIDENCE'] = confidence
propValue['VERSION'] = version
propValue['BRIGHTNESS_TEMPERATURE_CHANNEL5'] = float(bright_ti5)
propValue['FIRE_RADIATIVE_POWER'] = float(frp)
propValue['DAYNIGHT'] = daynight
geomValue = {}
geomValue['type'] = "Point"
coord = list()
coord.append(float(longitude))
coord.append(float(latitude))
geomValue['coordinates'] = coord
geojsonElemData = {}
geojsonElemData['type'] = "Feature"
geojsonElemData['properties'] = propValue
geojsonElemData['geometry'] = geomValue
return geojsonElemData
def genGeojson():
geojsonData = {}
geojsonData['type'] = "FeatureCollection"
crsPropValue = {}
crsPropValue['name'] = "urn:ogc:def:crs:OGC:1.3:CRS84"
crsValue = {}
crsValue['type'] = "name"
crsValue['properties'] = crsPropValue
geojsonData['crs'] = crsValue
dataList = list()
with open(basePath + baseFileName + ".csv", 'rb') as data_csv:
rows = csv.reader(data_csv, delimiter = ',')
for row in rows:
if (row[0] == "latitude" and row[1] == "longitude"):
# Ignore first row, which is attributes name.
pass;
else:
if ((32.774850 <= float(row[0]) <= 44.900607) and (20.551105 <= float(row[1]) <= 49.930658)):
dataList.append(createElemGeojson(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[11],row[12]))
geojsonData['features'] = dataList
json.dump(geojsonData, open(basePath + baseFileName + "_turkeyFiltered.geojson", 'wb'))
def process():
os.system("wget " + viirsGlobalUrl + " -P " + basePath)
genGeojson()
def main():
if (os.path.isfile(basePath + baseFileName + ".csv")):
os.remove(basePath + baseFileName + ".csv")
process()
else:
process()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment