Compare commits

..

No commits in common. "6d1b47ebee166ca3fbdbdbb3311e838fbb804528" and "540555e4b53431ef1a649ec6688ce9a96601a505" have entirely different histories.

3 changed files with 22 additions and 22 deletions

View file

@ -6,7 +6,7 @@ from xmet.config import Config
from xmet.db import Database
from xmet.s3 import S3Bucket
from xmet.storm import StormEvent
from xmet.nexrad import NEXRADArchive
from xmet.archive import Archive
parser = argparse.ArgumentParser(
description = 'Archive NEXRAD Level II data from Amazon S3'
@ -27,7 +27,7 @@ args = parser.parse_args()
config = Config.load()
db = Database.from_config(config)
bucket = S3Bucket()
archive = NEXRADArchive(getattr(args, 'archive-dir'), bucket)
archive = Archive(getattr(args, 'archive-dir'), bucket)
exclude = None
types = None

View file

@ -85,7 +85,7 @@ args = argparser.parse_args()
config = Config.load()
db = Database.from_config(config)
conus = SPCOutlookMap(dark=args.dark)
conus = SPCOutlookMap(args.dark)
if args.file is None:
if args.valid is None or args.day is None:

View file

@ -7,7 +7,7 @@ from xmet.db import Database
from xmet.s3 import S3Bucket, S3_KEY_RE
from xmet.radar import RADAR_RANGE
class NEXRADArchiveDateError(Exception):
class ArchiveDateError(Exception):
def __init__(self, supplied: str, missing: str):
self.supplied = supplied
self.missing = missing
@ -15,15 +15,15 @@ class NEXRADArchiveDateError(Exception):
def __str__(self):
return "Archive {self.supplied} was supplied, but required {self.missing} is missing"
class NEXRADArchiveProductType(enum.Enum):
class ArchiveProductType(enum.Enum):
DEFAULT = 1
V03 = 3
V04 = 4
class NEXRADArchiveProduct():
class ArchiveProduct():
__slots__ = 'typeof', 'radar', 'timestamp',
typeof: NEXRADArchiveProductType
typeof: ArchiveProductType
radar: str
timestamp: datetime.datetime
@ -43,9 +43,9 @@ class NEXRADArchiveProduct():
def __str__(self):
ret = '/'.join(self.__parts__())
if self.typeof == NEXRADArchiveProductType.V03:
if self.typeof == ArchiveProductType.V03:
ret += "_V03"
elif self.typeof == NEXRADArchiveProductType.V04:
elif self.typeof == ArchiveProductType.V04:
ret += "_V04"
ret += ".gz"
@ -56,9 +56,9 @@ class NEXRADArchiveProduct():
parts = self.__parts__()
ret = os.path.join(*parts)
if self.typeof == NEXRADArchiveProductType.V03:
if self.typeof == ArchiveProductType.V03:
ret += "_V03"
elif self.typeof == NEXRADArchiveProductType.V04:
elif self.typeof == ArchiveProductType.V04:
ret += "_V04"
ret += ".gz"
@ -70,7 +70,7 @@ class NEXRADArchiveProduct():
@staticmethod
def from_s3_key(key: str):
product = NEXRADArchiveProduct()
product = ArchiveProduct()
match = S3_KEY_RE.match(key)
product.timestamp = datetime.datetime(
@ -84,8 +84,8 @@ class NEXRADArchiveProduct():
)
product.radar = match[4]
product.typeof = NEXRADArchiveProductType.V03 \
if key[-7:] == '_V03.gz' else NEXRADArchiveProductType.DEFAULT
product.typeof = ArchiveProductType.V03 \
if key[-7:] == '_V03.gz' else ArchiveProductType.DEFAULT
return product
@ -116,7 +116,7 @@ class NEXRADArchiveProduct():
return result['num'] == 1
class NEXRADArchive():
class Archive():
path: str
bucket: S3Bucket
@ -148,10 +148,10 @@ class NEXRADArchive():
parts = [self.path]
if day is not None and month is None:
raise NEXRADArchiveDateError('day', 'month')
raise ArchiveDateError('day', 'month')
if month is not None and year is None:
raise NEXRADArchiveDateError('month', 'year')
raise ArchiveDateError('month', 'year')
for cur_year in os.scandir(os.path.join(*parts)):
if not (cur_year.is_dir() and self.RE_YEAR.match(cur_year.name)):
@ -205,4 +205,4 @@ class NEXRADArchive():
month: int=None,
day: int=None):
for key in self.each_downloaded_key(year, month, day):
yield NEXRADArchiveProduct.from_s3_key(key)
yield ArchiveProduct.from_s3_key(key)