Skip to content

Commit

Permalink
mask AEP emissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Feb 20, 2022
1 parent a98e2b1 commit ba21702
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions inmaputil/inmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ func setEmissionsAEP(inventoryConfig *aeputil.InventoryConfig, spatialConfig *ae
recs, _, err = inventoryConfig.ReadEmissions() // Remember to check error below.
}

if mask != nil { // Remove records that do not overlap with mask.
mb := mask.Bounds()
for s, srecs := range recs {
i := 0 // output index
for _, r := range srecs {
if r.Location().Bounds().Overlaps(mb) {
// copy and increment index
srecs[i] = r
i++
}
}
// Prevent memory leak by erasing truncated values
for j := i; j < len(srecs); j++ {
srecs[j] = nil
}
srecs = srecs[:i]
recs[s] = srecs
}
}

return func(d *inmap.InMAP) error {
if err != nil { // Check error from ReadEmissions
return err
Expand Down

0 comments on commit ba21702

Please sign in to comment.