Skip to content

Commit

Permalink
Lint and format (#164)
Browse files Browse the repository at this point in the history
* Lint and format
  • Loading branch information
thodson-usgs authored Sep 25, 2024
1 parent 9f09525 commit 35de892
Show file tree
Hide file tree
Showing 17 changed files with 1,147 additions and 973 deletions.
4 changes: 2 additions & 2 deletions dataretrieval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
from dataretrieval.wqp import *

try:
__version__ = version('dataretrieval')
__version__ = version("dataretrieval")
except PackageNotFoundError:
__version__ = 'version-unknown'
__version__ = "version-unknown"
201 changes: 101 additions & 100 deletions dataretrieval/codes/states.py
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
"""List of 2-digit state codes with commented full names."""

state_codes = {
"Alabama": "al",
"Alaska": "ak",
"Arizona": "az",
"Arkansas": "ar",
"California": "ca",
"Colorado": "co",
"Connecticut": "ct",
"Delaware": "de",
"Alabama": "al",
"Alaska": "ak",
"Arizona": "az",
"Arkansas": "ar",
"California": "ca",
"Colorado": "co",
"Connecticut": "ct",
"Delaware": "de",
"District of Columbia": "dc",
"Florida": "fl",
"Georgia": "ga",
"Hawaii": "hi",
"Idaho": "id",
"Illinois": "il",
"Indiana": "in",
"Iowa": "ia",
"Kansas": "ks",
"Kentucky": "ky",
"Louisiana": "la",
"Maine": "me",
"Maryland": "md",
"Massachusetts": "ma",
"Michigan": "mi",
"Minnesota": "mn",
"Mississippi": "ms",
"Missouri": "mo",
"Montana": "mt",
"Nebraska": "ne",
"Nevada": "nv",
"New Hampshire": "nh",
"New Jersey": "nj",
"New Mexico": "nm",
"New York": "ny",
"North Carolina": "nc",
"North Dakota": "nd",
"Ohio": "oh",
"Oklahoma": "ok",
"Oregon": "or",
"Pennsylvania": "pa",
"Rhode Island": "ri",
"South Carolina": "sc",
"South Dakota": "sd",
"Tennessee": "tn",
"Texas": "tx",
"Utah": "ut",
"Vermont": "vt",
"Virginia": "va",
"Washington": "wa",
"West Virginia": "wv",
"Wisconsin": "wi",
"Wyoming": "wy",
"Florida": "fl",
"Georgia": "ga",
"Hawaii": "hi",
"Idaho": "id",
"Illinois": "il",
"Indiana": "in",
"Iowa": "ia",
"Kansas": "ks",
"Kentucky": "ky",
"Louisiana": "la",
"Maine": "me",
"Maryland": "md",
"Massachusetts": "ma",
"Michigan": "mi",
"Minnesota": "mn",
"Mississippi": "ms",
"Missouri": "mo",
"Montana": "mt",
"Nebraska": "ne",
"Nevada": "nv",
"New Hampshire": "nh",
"New Jersey": "nj",
"New Mexico": "nm",
"New York": "ny",
"North Carolina": "nc",
"North Dakota": "nd",
"Ohio": "oh",
"Oklahoma": "ok",
"Oregon": "or",
"Pennsylvania": "pa",
"Rhode Island": "ri",
"South Carolina": "sc",
"South Dakota": "sd",
"Tennessee": "tn",
"Texas": "tx",
"Utah": "ut",
"Vermont": "vt",
"Virginia": "va",
"Washington": "wa",
"West Virginia": "wv",
"Wisconsin": "wi",
"Wyoming": "wy",
}

fips_codes = {
"Alabama": "01",
"Alaska": "02",
"Arizona": "04",
"Arkansas": "05",
"California": "06",
"Colorado": "08",
"Connecticut": "09",
"Delaware": "10",
"Alabama": "01",
"Alaska": "02",
"Arizona": "04",
"Arkansas": "05",
"California": "06",
"Colorado": "08",
"Connecticut": "09",
"Delaware": "10",
"District of Columbia": "11",
"Florida": "12",
"Georgia": "13",
"Hawaii": "15",
"Idaho": "16",
"Illinois": "17",
"Indiana": "18",
"Iowa": "19",
"Kansas": "20",
"Kentucky": "21",
"Louisiana": "22",
"Maine": "23",
"Maryland": "24",
"Massachusetts": "25",
"Michigan": "26",
"Minnesota": "27",
"Mississippi": "28",
"Missouri": "29",
"Montana": "30",
"Nebraska": "31",
"Nevada": "32",
"New Hampshire": "33",
"New Jersey": "34",
"New Mexico": "35",
"New York": "36",
"North Carolina": "37",
"North Dakota": "38",
"Ohio": "39",
"Oklahoma": "40",
"Oregon": "41",
"Pennsylvania": "42",
"Rhode Island": "44",
"South Carolina": "45",
"South Dakota": "46",
"Tennessee": "47",
"Texas": "48",
"Utah": "49",
"Vermont": "50",
"Virginia": "51",
"Washington": "53",
"West Virginia": "54",
"Wisconsin": "55",
"Wyoming": "56",
"Florida": "12",
"Georgia": "13",
"Hawaii": "15",
"Idaho": "16",
"Illinois": "17",
"Indiana": "18",
"Iowa": "19",
"Kansas": "20",
"Kentucky": "21",
"Louisiana": "22",
"Maine": "23",
"Maryland": "24",
"Massachusetts": "25",
"Michigan": "26",
"Minnesota": "27",
"Mississippi": "28",
"Missouri": "29",
"Montana": "30",
"Nebraska": "31",
"Nevada": "32",
"New Hampshire": "33",
"New Jersey": "34",
"New Mexico": "35",
"New York": "36",
"North Carolina": "37",
"North Dakota": "38",
"Ohio": "39",
"Oklahoma": "40",
"Oregon": "41",
"Pennsylvania": "42",
"Rhode Island": "44",
"South Carolina": "45",
"South Dakota": "46",
"Tennessee": "47",
"Texas": "48",
"Utah": "49",
"Vermont": "50",
"Virginia": "51",
"Washington": "53",
"West Virginia": "54",
"Wisconsin": "55",
"Wyoming": "56",
}
6 changes: 3 additions & 3 deletions dataretrieval/codes/timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Time zone information
"""

tz_str = '''-1200 Y
tz_str = """-1200 Y
-1100 X NUT SST
-1000 W CKT HAST HST TAHT TKT
-0900 V AKST GAMT GIT HADT HNY
Expand Down Expand Up @@ -39,10 +39,10 @@
-0230 HAT NDT
-0330 HNT NST NT
-0430 HLV VET
-0930 MART MIT'''
-0930 MART MIT"""

tz = {}
for tz_descr in map(str.split, tz_str.split('\n')):
for tz_descr in map(str.split, tz_str.split("\n")):
tz_offset = tz_descr[0]
for tz_code in tz_descr[1:]:
tz[tz_code] = tz_offset
54 changes: 27 additions & 27 deletions dataretrieval/nadp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@

import requests

NADP_URL = 'https://nadp.slh.wisc.edu'
NADP_MAP_EXT = 'filelib/maps'
NADP_URL = "https://nadp.slh.wisc.edu"
NADP_MAP_EXT = "filelib/maps"

NTN_CONC_PARAMS = ['pH', 'So4', 'NO3', 'NH4', 'Ca', 'Mg', 'K', 'Na', 'Cl', 'Br']
NTN_CONC_PARAMS = ["pH", "So4", "NO3", "NH4", "Ca", "Mg", "K", "Na", "Cl", "Br"]
NTN_DEP_PARAMS = [
'H',
'So4',
'NO3',
'NH4',
'Ca',
'Mg',
'K',
'Na',
'Cl',
'Br',
'N',
'SPlusN',
"H",
"So4",
"NO3",
"NH4",
"Ca",
"Mg",
"K",
"Na",
"Cl",
"Br",
"N",
"SPlusN",
]

NTN_MEAS_TYPE = ['conc', 'dep', 'precip'] # concentration or deposition
NTN_MEAS_TYPE = ["conc", "dep", "precip"] # concentration or deposition


class NADP_ZipFile(zipfile.ZipFile):
Expand All @@ -65,7 +65,7 @@ class NADP_ZipFile(zipfile.ZipFile):
def tif_name(self):
"""Get the name of the tif file in the zip file."""
filenames = self.namelist()
r = re.compile('.*tif$')
r = re.compile(".*tif$")
tif_list = list(filter(r.match, filenames))
return tif_list[0]

Expand Down Expand Up @@ -105,23 +105,23 @@ def get_annual_MDN_map(measurement_type, year, path):
>>> # get map of mercury concentration in 2010 and extract it to a path
>>> data_path = dataretrieval.nadp.get_annual_MDN_map(
... measurement_type='conc', year='2010', path='somepath'
... measurement_type="conc", year="2010", path="somepath"
... )
"""
url = f'{NADP_URL}/{NADP_MAP_EXT}/MDN/grids/'
url = f"{NADP_URL}/{NADP_MAP_EXT}/MDN/grids/"

filename = f'Hg_{measurement_type}_{year}.zip'
filename = f"Hg_{measurement_type}_{year}.zip"

z = get_zip(url, filename)

if path:
z.extractall(path)

return f'{path}{os.sep}{basename(filename)}'
return f"{path}{os.sep}{basename(filename)}"


def get_annual_NTN_map(measurement_type, measurement=None, year=None, path='.'):
def get_annual_NTN_map(measurement_type, measurement=None, year=None, path="."):
"""Download a NTN map from NDAP.
This function looks for a zip file containing gridded information at:
Expand Down Expand Up @@ -158,23 +158,23 @@ def get_annual_NTN_map(measurement_type, measurement=None, year=None, path='.'):
>>> # get a map of precipitation in 2015 and extract it to a path
>>> data_path = dataretrieval.nadp.get_annual_NTN_map(
... measurement_type='Precip', year='2015', path='somepath'
... measurement_type="Precip", year="2015", path="somepath"
... )
"""
url = f'{NADP_URL}/{NADP_MAP_EXT}/NTN/grids/{year}/'
url = f"{NADP_URL}/{NADP_MAP_EXT}/NTN/grids/{year}/"

filename = f'{measurement_type}_{year}.zip'
filename = f"{measurement_type}_{year}.zip"

if measurement:
filename = f'{measurement}_{filename}'
filename = f"{measurement}_{filename}"

z = get_zip(url, filename)

if path:
z.extractall(path)

return f'{path}{os.sep}{basename(filename)}'
return f"{path}{os.sep}{basename(filename)}"


def get_zip(url, filename):
Expand Down
Loading

0 comments on commit 35de892

Please sign in to comment.