Skip to content

Commit 0858d5b

Browse files
Merge pull request #28 from datadesk/no-prescribed-fire
If statement specifying only "Wildfire" types
2 parents 2bbc045 + fa933b9 commit 0858d5b

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

docs/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Download active fire incidents from inciweb.
3535
inciwebwildfires incidents
3636
```
3737

38+
Download prescribed fire incidents from inciweb.
39+
```sh
40+
inciwebwildfires prescribed_fires
41+
```
42+
43+
3844
## Python usage
3945

4046
Import the library.

inciweb_wildfires/__init__.py

+39-12
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
from geojson import Feature, FeatureCollection, Point
77

88

9-
def get_incidents() -> FeatureCollection:
9+
def get_data(t) -> FeatureCollection:
1010
"""
11-
Get active incidents data from InciWeb.
11+
Get all incidents data from InciWeb.
12+
13+
Passes in 't' parameter used to specify type of data (Wildfire, Prescribed Fire)
14+
Incident Types
1215
1316
Returns GeoJson FeatureCollection.
1417
"""
@@ -28,19 +31,43 @@ def get_incidents() -> FeatureCollection:
2831
# Loop through all the placemarks
2932
feature_list = []
3033
for d in data:
31-
# Reformat as GeoJSON
32-
x = convert_coords(d["long_deg"], d["long_min"], d["long_sec"])
33-
y = convert_coords(d["lat_deg"], d["lat_min"], d["lat_sec"])
34-
if x > 0:
35-
x = -x
36-
p = Point((x, y))
37-
f = Feature(geometry=p, properties=d)
34+
# Only type specified
35+
if d['type'] == t:
36+
# Reformat as GeoJSON
37+
x = convert_coords(d["long_deg"], d["long_min"], d["long_sec"])
38+
y = convert_coords(d["lat_deg"], d["lat_min"], d["lat_sec"])
39+
if x > 0:
40+
x = -x
41+
p = Point((x, y))
42+
f = Feature(geometry=p, properties=d)
43+
# Add it to the list
44+
feature_list.append(f)
45+
else:
46+
continue
47+
# Pass it out
48+
return FeatureCollection(feature_list)
49+
3850

39-
# Add it to the list
40-
feature_list.append(f)
51+
def get_incidents() -> FeatureCollection:
52+
"""
53+
Get all active wildfire incidents from InciWeb.
54+
Returns GeoJson FeatureCollection.
55+
"""
56+
features = get_data("Wildfire")
4157

4258
# Pass it out
43-
return FeatureCollection(feature_list)
59+
return features
60+
61+
62+
def get_prescribed_fires() -> FeatureCollection:
63+
"""
64+
Get all active prescribed fire incidents from InciWeb.
65+
Returns GeoJson FeatureCollection.
66+
"""
67+
features = get_data("Prescribed Fire")
68+
69+
# Pass it out
70+
return features
4471

4572

4673
def convert_coords(deg: str, min: str, sec: str) -> float:

inciweb_wildfires/cli.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import click
22

3-
from inciweb_wildfires import get_incidents
3+
from inciweb_wildfires import get_incidents, get_prescribed_fires
44

55

66
@click.group()
@@ -18,5 +18,10 @@ def incidents():
1818
click.echo(get_incidents())
1919

2020

21+
@cmd.command(help="Download prescribed fire incidents from InciWeb")
22+
def prescribed_fires():
23+
click.echo(get_prescribed_fires())
24+
25+
2126
if __name__ == "__main__":
2227
cmd()

test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import unittest
22

3-
from inciweb_wildfires import get_incidents
3+
from inciweb_wildfires import get_incidents, get_prescribed_fires
44

55

66
class InciwebWildfiresUnitTest(unittest.TestCase):
77
def test_inciweb(self):
88
get_incidents()
9+
get_prescribed_fires()
910

1011

1112
if __name__ == "__main__":

0 commit comments

Comments
 (0)