Created
September 10, 2020 15:43
-
-
Save oxtoacart/89cc825ff91690cdd403bc9c49cbb7a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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