Skip to content

Commit

Permalink
Pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Jun 19, 2022
1 parent 86de98f commit 02498aa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 56 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Download wildfires data from NOAA satellites

Hourly scrapes powered by a GitHub Action are stored in the `data` directory.

## Installation

```sh
Expand Down Expand Up @@ -42,19 +40,19 @@ noaawildfires hms-smoke
Import the library.

```python
>>> import noaa_wildfires
import noaa_wildfires
```

Download the latest fires from Hazard Mapping System satellites.

```python
>>> data = noaa_wildfires.get_hms_fires()
noaa_wildfires.get_hms_fires()
```

Download the latest smoke data from Hazard Mapping System satellites.

```python
>>> data = noaa_wildfires.get_hms_smoke()
noaa_wildfires.get_hms_smoke()
```

## Contributing
Expand All @@ -68,19 +66,13 @@ pipenv install --dev
Run tests.

```sh
make test
```

Ship new version to PyPI.

```sh
make ship
pipenv run python test.py
```

## Developing the CLI

The command-line interface is implemented using Click and setuptools. To install it locally for development inside your virtual environment, run the following installation command, as [prescribed by the Click documentation](https://click.palletsprojects.com/en/7.x/setuptools/#setuptools-integration).

```sh
pip install --editable .
pipenv run pip install --editable .
```
33 changes: 17 additions & 16 deletions noaa_wildfires/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import io
import csv
import fiona
import io
import zipfile

import fiona
import requests
from geojson import Feature, FeatureCollection, Point

Expand All @@ -12,20 +13,20 @@ def get_hms_fires():
"""
# Read CSV
r = requests.get("https://satepsanone.nesdis.noaa.gov/pub/FIRE/HMS/latesthms.txt")
lines = r.content.decode('utf-8').splitlines()
reader = csv.DictReader(lines, delimiter=',')
lines = r.content.decode("utf-8").splitlines()
reader = csv.DictReader(lines, delimiter=",")

# Tidy it up
tidy_reader = []
for row in reader:
tidy_row = dict((k.strip(), v.strip()) for k, v in row.items())
tidy_row = {k.strip(): v.strip() for k, v in row.items()}
tidy_reader.append(tidy_row)

# Convert it to GeoJSON
features = [Feature(
geometry=Point(map(float, [r['Lon'], r['Lat']])),
properties=r
) for r in tidy_reader]
features = [
Feature(geometry=Point(map(float, [r["Lon"], r["Lat"]])), properties=r)
for r in tidy_reader
]

# Return it
return FeatureCollection(features)
Expand All @@ -35,11 +36,7 @@ def get_hms_smoke():
"""
Get the latest smoke data from Hazard Mapping System satellites.
"""
files = [
'latest_smoke.shp',
'latest_smoke.dbf',
'latest_smoke.shx'
]
files = ["latest_smoke.shp", "latest_smoke.dbf", "latest_smoke.shx"]
return _parse_shapefiles(files)


Expand All @@ -54,12 +51,16 @@ def _parse_shapefiles(files):
with zipfile.ZipFile(buffer, mode="w", compression=zipfile.ZIP_DEFLATED) as zf:
# Download each piece of the shapefile ...
for name in files:
r = requests.get(f"https://satepsanone.nesdis.noaa.gov/pub/FIRE/HMS/GIS/{name}")
r = requests.get(
f"https://satepsanone.nesdis.noaa.gov/pub/FIRE/HMS/GIS/{name}"
)
# ... and add it to the in-memory zipfile
zf.writestr(name, bytes(r.content))

# Feed the in-memory file to fiona, which can read the shapefile
shp = fiona.BytesCollection(buffer.getvalue())

# Convert the shapefile to GeoJSON and return it
return FeatureCollection([Feature(geometry=d['geometry'], properties=d) for d in shp])
return FeatureCollection(
[Feature(geometry=d["geometry"], properties=d) for d in shp]
)
3 changes: 2 additions & 1 deletion noaa_wildfires/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click

from noaa_wildfires import get_hms_fires, get_hms_smoke


Expand All @@ -22,5 +23,5 @@ def hms_smoke():
click.echo(get_hms_smoke())


if __name__ == '__main__':
if __name__ == "__main__":
cmd()
42 changes: 19 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from setuptools import setup


Expand Down Expand Up @@ -39,39 +40,34 @@ def local_version(version):


setup(
name='noaa-wildfires',
name="noaa-wildfires",
description="Download wildfires data from NOAA satellites",
long_description=read('README.md'),
long_description_content_type='text/markdown',
author='Ben Welsh',
author_email='[email protected]',
url='https://palewi.re/docs/noaa-wildfires',
long_description=read("README.md"),
long_description_content_type="text/markdown",
author="Ben Welsh",
author_email="[email protected]",
url="https://palewi.re/docs/noaa-wildfires",
license="MIT",
packages=("noaa_wildfires",),
install_requires=[
"fiona",
"geojson",
"click",
"requests"
],
install_requires=["fiona", "geojson", "click", "requests"],
entry_points="""
[console_scripts]
noaawildfires=noaa_wildfires.cli:cmd
""",
use_scm_version={"version_scheme": version_scheme, "local_scheme": local_version},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'License :: OSI Approved :: MIT License',
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
],
project_urls={
'Maintainer': 'https://github.com/datadesk',
'Source': 'https://github.com/datadesk/noaa-wildfires',
'Tracker': 'https://github.com/datadesk/noaa-wildfires/issues'
"Maintainer": "https://github.com/datadesk",
"Source": "https://github.com/datadesk/noaa-wildfires",
"Tracker": "https://github.com/datadesk/noaa-wildfires/issues",
},
)
5 changes: 2 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import unittest

import noaa_wildfires


class MyUnitTest(unittest.TestCase):

def test_fires(self):
noaa_wildfires.get_hms_fires()

def test_smoke(self):
noaa_wildfires.get_hms_smoke()


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()

0 comments on commit 02498aa

Please sign in to comment.