Skip to content

Instantly share code, notes, and snippets.

@oxtoacart
Created September 10, 2020 15:43
Show Gist options
  • Save oxtoacart/89cc825ff91690cdd403bc9c49cbb7a5 to your computer and use it in GitHub Desktop.
Save oxtoacart/89cc825ff91690cdd403bc9c49cbb7a5 to your computer and use it in GitHub Desktop.
# Uses data from the GFED4.1 dataset - https://daac.ornl.gov/VEGETATION/guides/fire_emissions_v4_R1.html
import csv
import h5py # pip install h5py
with open('/tmp/burn.csv', mode='w') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csvwriter.writerow(["Year", "Area Burned"])
for year in range(1997, 2016):
print("year %s" % year)
with h5py.File('GFED4.1s_%s.hdf5' % year, 'r') as datafile:
burned_area = datafile['burned_area']
total = 0
for (month, group) in burned_area.iteritems():
print("month %s" % month)
for values in group['burned_fraction']:
total += sum(values)
csvwriter.writerow([year, round(total)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment