-
Notifications
You must be signed in to change notification settings - Fork 1
/
Generate_Fire_Points.py
71 lines (56 loc) · 2.04 KB
/
Generate_Fire_Points.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
"""Generate_Fire_Points.py: Calculate nighttime fire pixels using band 7 threshold"""
from netCDF4 import Dataset
#import matplotlib
#import matplotlib.pyplot as plt
import numpy as np
import os
from pyproj import Proj
import datetime
#from mpl_toolkits.basemap import Basemap
#from osgeo import gdal
import itertools
import re
__author__ = "Nathan Pavlovic"
__email__ = "[email protected]"
__status__ = "Prototype"
__date__ = "2017-10-22"
__version__ = "0.0.1"
# List files
def generate_fire_points(infile, thresh, outdir):
C_file = Dataset(infile, 'r')
ref_ch7 = C_file.variables['CMI'][:]
dims = C_file.dimensions.keys()
# Data are stored as seconds since 2000-01-01 12:00:00
secs = int(round(C_file.variables['t'][0], 0)) # Round to nearest second
img_date = datetime.datetime(2000, 1, 1, 12) + datetime.timedelta(seconds = secs)
b = C_file.variables['CMI']
sh = C_file.variables['goes_imager_projection'].perspective_point_height
slon = C_file.variables['goes_imager_projection'].longitude_of_projection_origin
ssweep = C_file.variables['goes_imager_projection'].sweep_angle_axis
# Get coordinates
xcoords = C_file.variables['x'][:] * sh
ycoords = C_file.variables['y'][:] * sh
# Convert to lat lon
p = Proj(proj = "geos", h = sh, lon_0 = slon, sweep = ssweep)
Xs, Ys = np.meshgrid(xcoords, ycoords)
lons, lats = p(Xs, Ys, inverse = True)
# Subset to North Bay
nbb = b[325:475, 30:120]
nblons = lons[325:475, 30:120]
nblats = lats[325:475, 30:120]
# Get logical raster of fire/no fire
nbbt = nbb > thresh
# Get locations
firelat = nblats[nbbt]
firelon = nblons[nbbt]
# Join to array
dates_str = list(itertools.repeat(str(img_date), len(firelat)))
outarray = np.column_stack((dates_str,
firelat, firelon))
# Write to csv
out_file = os.path.join(outdir, "fire_points_" + re.sub(" ", "-",
re.sub(":", "-", str(img_date))) + ".csv")
np.savetxt(fname = out_file, X = outarray,
delimiter = ",", fmt = '%s, %s, %s', header = "Date, Lat, Lon")
return outarray