Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setter to fireID property in FireObj.Fire #169

Open
wants to merge 3 commits into
base: conus-dps
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions fireatlas/FireObj.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def __init__(self, t):
self.init_gdf()

# cumulative recordings
self.heritages = [] # a list of fire heritage relationships (source, target)
# a list of fire heritage relationships (source, target)
self.heritages = []
self.id_dict = (
[]
) # this list relates the list position of the fire in the allfires object to the fire id
Expand All @@ -85,9 +86,11 @@ def init_gdf(self):
@classmethod
@timed
def rehydrate(cls, tst, ted, region, allpixels=None, include_dead=False, read_location=None):
allfires_gdf = read_allfires_gdf(tst, ted, region, location=read_location)
allfires_gdf = read_allfires_gdf(
tst, ted, region, location=read_location)
if allpixels is None:
allpixels = read_allpixels(tst, ted, region, location=read_location)
allpixels = read_allpixels(
tst, ted, region, location=read_location)

dt = t2dt(ted)

Expand All @@ -113,13 +116,13 @@ def rehydrate(cls, tst, ted, region, allpixels=None, include_dead=False, read_lo
for k, v in gdf_fid_t.items():
if not isinstance(getattr(Fire, k, None), property):
setattr(f, k, v)

f.t_st = dt2t(dt_st)
f.t_ed = dt2t(dt_ed)

if f.mergeid != fid:
allfires.heritages.append((fid, f.mergeid))

if f.t_ed == ted:
if f.isignition:
allfires.fids_new.append(fid)
Expand All @@ -139,7 +142,8 @@ def update_gdf(self):

for fid, f in self.burningfires.items():
if (fid, dt) in self.gdf.index:
raise ValueError(f"Error writing gdf: {fid} already at {self.t}")
raise ValueError(
f"Error writing gdf: {fid} already at {self.t}")

for k, tp in dd.items():
if tp == "datetime64[ns]":
Expand Down Expand Up @@ -319,7 +323,8 @@ def newyear_reset(self, regnm):
fids_keep = self.fids_active + self.fids_sleeper
for i, fid in enumerate(fids_keep):
newfires[i] = self.fires[fid] # record new fireID and fire object
newfires[i].fireID = i # also update fireID attribute of fire object
# also update fireID attribute of fire object
newfires[i].fireID = i
fidmapping.append((fid, i))
self.fires = newfires

Expand Down Expand Up @@ -494,6 +499,10 @@ def isignition(self):
def fireID(self):
return self._fid

@fireID.setter
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this is the only actual change. All the other stuff was style syntax my IDE made. sorry!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's fine - comes from a lot of this being written in jupyterhub without linting enabled.

def fireID(self, newid):
self._fid = newid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really enough? Don't we need to explicitly update the backing objects to change the fid from the old one to the new one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh possibly... I can dig into this more. Are there other good fires to look at that go from Dec to Jan? Out of the last 10 years, I've only had one active fire in CA (Thomas 2017) that did that and it was barely active. Possibly some in the southern hemisphere?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am certainly not the person to ask :) maybe ask around on slack or tag people here to pull them into the conversation?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Lisa! Thanks for digging into this. I suspect we can help you find more examples of cross year fires, and actually have put this on the roadmap of things we need to deal with as we scale to global runs. Just so you know, the GSFC team is at AGU this week, so you probably won’t hear much from us in the next few days. However, we do have some southern hemisphere results and I’d be happy to generate more after the conference with an eye towards that Dec 31/Jan 1 crossover. Let’s touch base next week if needed.


@property
def pixels(self):
return self.allpixels[
Expand Down Expand Up @@ -716,16 +725,19 @@ def updatefline(self):

# calculate the fire line
if fhull is None: # if no hull, return None
raise ValueError(f"hull is not set on this fire {self.fireID} at {self.t}")
raise ValueError(
f"hull is not set on this fire {self.fireID} at {self.t}")
if fhull.geom_type == "MultiPolygon":
# extract exterior of fire perimeter
mls = MultiLineString([plg.exterior for plg in fhull.geoms])
# set fline to the part which intersects with bufferred flinelocsMP
self.fline = mls.intersection(flinelocsMP.buffer(settings.flbuffer))
self.fline = mls.intersection(
flinelocsMP.buffer(settings.flbuffer))

elif fhull.geom_type == "Polygon":
mls = fhull.exterior
self.fline = mls.intersection(flinelocsMP.buffer(settings.flbuffer))
self.fline = mls.intersection(
flinelocsMP.buffer(settings.flbuffer))
else: # if fhull type is not 'MultiPolygon' or 'Polygon', return flinelocsMP
self.fline = flinelocsMP

Expand Down
Loading