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

If statement specifying only "Wildfire" types #28

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
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
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
Loading