Skip to content

Commit

Permalink
Merge pull request #28 from datadesk/no-prescribed-fire
Browse files Browse the repository at this point in the history
If statement specifying only "Wildfire" types
  • Loading branch information
vnessamartinez authored May 21, 2024
2 parents 2bbc045 + fa933b9 commit 0858d5b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
6 changes: 6 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Download active fire incidents from inciweb.
inciwebwildfires incidents
```

Download prescribed fire incidents from inciweb.
```sh
inciwebwildfires prescribed_fires
```


## Python usage

Import the library.
Expand Down
51 changes: 39 additions & 12 deletions inciweb_wildfires/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
from geojson import Feature, FeatureCollection, Point


def get_incidents() -> FeatureCollection:
def get_data(t) -> FeatureCollection:
"""
Get active incidents data from InciWeb.
Get all incidents data from InciWeb.
Passes in 't' parameter used to specify type of data (Wildfire, Prescribed Fire)
Incident Types
Returns GeoJson FeatureCollection.
"""
Expand All @@ -28,19 +31,43 @@ def get_incidents() -> FeatureCollection:
# Loop through all the placemarks
feature_list = []
for d in data:
# Reformat as GeoJSON
x = convert_coords(d["long_deg"], d["long_min"], d["long_sec"])
y = convert_coords(d["lat_deg"], d["lat_min"], d["lat_sec"])
if x > 0:
x = -x
p = Point((x, y))
f = Feature(geometry=p, properties=d)
# Only type specified
if d['type'] == t:
# Reformat as GeoJSON
x = convert_coords(d["long_deg"], d["long_min"], d["long_sec"])
y = convert_coords(d["lat_deg"], d["lat_min"], d["lat_sec"])
if x > 0:
x = -x
p = Point((x, y))
f = Feature(geometry=p, properties=d)
# Add it to the list
feature_list.append(f)
else:
continue
# Pass it out
return FeatureCollection(feature_list)


# Add it to the list
feature_list.append(f)
def get_incidents() -> FeatureCollection:
"""
Get all active wildfire incidents from InciWeb.
Returns GeoJson FeatureCollection.
"""
features = get_data("Wildfire")

# Pass it out
return FeatureCollection(feature_list)
return features


def get_prescribed_fires() -> FeatureCollection:
"""
Get all active prescribed fire incidents from InciWeb.
Returns GeoJson FeatureCollection.
"""
features = get_data("Prescribed Fire")

# Pass it out
return features


def convert_coords(deg: str, min: str, sec: str) -> float:
Expand Down
7 changes: 6 additions & 1 deletion inciweb_wildfires/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click

from inciweb_wildfires import get_incidents
from inciweb_wildfires import get_incidents, get_prescribed_fires


@click.group()
Expand All @@ -18,5 +18,10 @@ def incidents():
click.echo(get_incidents())


@cmd.command(help="Download prescribed fire incidents from InciWeb")
def prescribed_fires():
click.echo(get_prescribed_fires())


if __name__ == "__main__":
cmd()
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import unittest

from inciweb_wildfires import get_incidents
from inciweb_wildfires import get_incidents, get_prescribed_fires


class InciwebWildfiresUnitTest(unittest.TestCase):
def test_inciweb(self):
get_incidents()
get_prescribed_fires()


if __name__ == "__main__":
Expand Down

0 comments on commit 0858d5b

Please sign in to comment.