Newer
Older
""" set the CONNECTIVITY_FIRE_KM value (km) for a given fire. Within this
buffer of the fire exterior, new pixels will be appended to the fire.
Constants
---------
CONT_opt : int
option number of CONNECTIVITY_FIRE_KM calculation
CONT_preset : float
the preset CONNECTIVITY_FIRE_KM value for option 0
CONT_CA : dict
the preset CONNECTIVITY_FIRE_KM lookup table for option 1
FTYP_Glb : dict
the preset CONNECTIVITY_FIRE_KM lookup table for option 2
Parameters
----------
fire : fire object
the fire associated with the CONNECTIVITY_FIRE_KM
Returns
-------
v : float
the CONNECTIVITY_FIRE_KM (km)
elif CONT_opt == 2: # use lookup table for global universal run
fnpix = min(fire.n_pixels, 25) # set an upper limit
if ftype == "Temp Forest":
v = fnpix * 2 / 25 + 0.8 # 0.8 (0) - 2.8 (25)
elif ftype == "Trop Forest":
v = fnpix * 0.7 / 25 + 0.7 # 0.7 (0) - 1.4 (25)
elif ftype == "Bore Forest":
v = fnpix * 3.2 / 25 + 1.0 # 1.0 (0) - 4.2 (25)
elif ftype == "Savana":
v = fnpix * 2.5 / 25 + 0.9 # 0.9 (0) - 3.4 (25)
""" get the connectivity spatial threshold for initial clustering
Returns:
--------
CONNECTIVITY_CLUSTER_KM : float
the connectivity spatial threshold for initial clustering, km
CONNECTIVITY_CLUSTER_KM = 0.7
return CONNECTIVITY_CLUSTER_KM
Returns:
--------
CONNECTIVITY_SLEEPER_KM : float
the connectivity spatial threshold (to previous fire line), km
CONNECTIVITY_SLEEPER_KM = 1 # 1km
return CONNECTIVITY_SLEEPER_KM
""" set fire type and dominant LCT for newly activated fires
Parameters
----------
fire : fire object
the fire associated with the CONNECTIVITY_FIRE_KM
from FireConsts import FTYP_opt
import FireIO
from datetime import date
# 0 - use preset ftype (defined as FTYP_preset in FireConsts) for all fires
# 1 - use the CA type classification (dtermined using LCTmax)
# 2 - use the global type classfication (need more work...)
elif FTYP_opt == 1: # use CA type classifications (determined using LCTmax)
uselocs = fire.newlocs_geo
else:
# we can do a random sample of 1000 new pixels (it's likely going to be a forest fire anyways)
uselocs = random.sample(fire.newlocs_geo, 1000)
uselocs
) # call get_LCT to get all LCT for the fire pixels
try:
LCTmax = max(
set(vLCT), key=vLCT.count) # extract the LCT with most pixel counts
except:
print('No LCT data available, setting ftype to 0...')
ftype = 0
return ftype
ignct = fire.ignlocsMP.centroid # ignition centroid
loc = (ignct.y, ignct.x) # (lat,lon)
try: stFM1000 = FireIO.get_FM1000(t, loc)
except:
#print('FM1000 data is unavailable at this time.')
stFM1000 = 0
# determine the fire type using the land cover type and stFM1000
if LCTmax in [0, 11, 31]: #'NoData', 'Water', 'Barren' -> 'Other'
elif LCTmax in [82]: # 'Agriculture' -> 'Agriculture'
elif LCTmax in [42]: # 'Forest' ->
if stFM1000 > 12: # 'Forest manage'
elif LCTmax in [52, 71]: # 'Shrub', 'Grassland' ->
else:
print(f"Unknown land cover type {LCTmax}. Setting ftype to 0.")
ftype = 0
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# update or read LCTmax; calculated using all newlocs
if fire.n_newpixels < 1000:
uselocs = fire.newlocs_geo
else:
# we can do a random sample of 1000 new pixels (it's likely going to be a forest fire anyways)
uselocs = random.sample(fire.newlocs_geo, 1000)
vLCT = FireIO.get_LCT_Global(
uselocs
) # call get_LCT to get all LCT for the fire pixels
try:
LCTmax = max(
set(vLCT), key=vLCT.count) # extract the LCT with most pixel counts
except:
print('No LCT data available, setting ftype to 0...')
ftype = 0
return ftype
#print("LCTMAX:",LCTmax)
if LCTmax in [0, 50, 60, 70, 80, 90, 100, 200]:
ftype = 0
# ^^^ current catch-all for 'Other'.
# See: https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_Landcover_100m_Proba-V-C3_Global
elif LCTmax in [20]: # Shrub --> Savanna
ftype = 4
elif LCTmax in [40]: # Agriculture class
ftype = 5
else: # begin forested class
lat_list = [xy[1] for xy in uselocs]
lat_mean = abs(np.nanmean(lat_list))
# Forest Classifications based on: https://ucmp.berkeley.edu/exhibits/biomes/forests.php
if lat_mean < 23.5:
ftype = 2 # tropical
elif lat_mean < 50:
ftype = 1 # temperate
else:
ftype = 3 # boreal
Parameters
----------
fire : fire object
the fire associated with the CONNECTIVITY_FIRE_KM
Returns
-------
ftname : str
the fire type name of the given fire
elif FTYP_opt == 1: # use CA type classifications (determined using LCTmax)
ftname = FTYP_CA[fire.ftype]
elif FTYP_opt == 2: # global type classification
from FireConsts import FTYP_Glb