Rename archive.py to nexrad.py
This commit is contained in:
parent
9cc168d24d
commit
6d1b47ebee
2 changed files with 21 additions and 21 deletions
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from xmet.config import Config
|
from xmet.config import Config
|
||||||
from xmet.db import Database
|
from xmet.db import Database
|
||||||
from xmet.s3 import S3Bucket
|
from xmet.s3 import S3Bucket
|
||||||
from xmet.storm import StormEvent
|
from xmet.storm import StormEvent
|
||||||
from xmet.archive import Archive
|
from xmet.nexrad import NEXRADArchive
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description = 'Archive NEXRAD Level II data from Amazon S3'
|
description = 'Archive NEXRAD Level II data from Amazon S3'
|
||||||
|
@ -27,7 +27,7 @@ args = parser.parse_args()
|
||||||
config = Config.load()
|
config = Config.load()
|
||||||
db = Database.from_config(config)
|
db = Database.from_config(config)
|
||||||
bucket = S3Bucket()
|
bucket = S3Bucket()
|
||||||
archive = Archive(getattr(args, 'archive-dir'), bucket)
|
archive = NEXRADArchive(getattr(args, 'archive-dir'), bucket)
|
||||||
exclude = None
|
exclude = None
|
||||||
types = None
|
types = None
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from xmet.db import Database
|
||||||
from xmet.s3 import S3Bucket, S3_KEY_RE
|
from xmet.s3 import S3Bucket, S3_KEY_RE
|
||||||
from xmet.radar import RADAR_RANGE
|
from xmet.radar import RADAR_RANGE
|
||||||
|
|
||||||
class ArchiveDateError(Exception):
|
class NEXRADArchiveDateError(Exception):
|
||||||
def __init__(self, supplied: str, missing: str):
|
def __init__(self, supplied: str, missing: str):
|
||||||
self.supplied = supplied
|
self.supplied = supplied
|
||||||
self.missing = missing
|
self.missing = missing
|
||||||
|
@ -15,15 +15,15 @@ class ArchiveDateError(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Archive {self.supplied} was supplied, but required {self.missing} is missing"
|
return "Archive {self.supplied} was supplied, but required {self.missing} is missing"
|
||||||
|
|
||||||
class ArchiveProductType(enum.Enum):
|
class NEXRADArchiveProductType(enum.Enum):
|
||||||
DEFAULT = 1
|
DEFAULT = 1
|
||||||
V03 = 3
|
V03 = 3
|
||||||
V04 = 4
|
V04 = 4
|
||||||
|
|
||||||
class ArchiveProduct():
|
class NEXRADArchiveProduct():
|
||||||
__slots__ = 'typeof', 'radar', 'timestamp',
|
__slots__ = 'typeof', 'radar', 'timestamp',
|
||||||
|
|
||||||
typeof: ArchiveProductType
|
typeof: NEXRADArchiveProductType
|
||||||
radar: str
|
radar: str
|
||||||
timestamp: datetime.datetime
|
timestamp: datetime.datetime
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ class ArchiveProduct():
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
ret = '/'.join(self.__parts__())
|
ret = '/'.join(self.__parts__())
|
||||||
|
|
||||||
if self.typeof == ArchiveProductType.V03:
|
if self.typeof == NEXRADArchiveProductType.V03:
|
||||||
ret += "_V03"
|
ret += "_V03"
|
||||||
elif self.typeof == ArchiveProductType.V04:
|
elif self.typeof == NEXRADArchiveProductType.V04:
|
||||||
ret += "_V04"
|
ret += "_V04"
|
||||||
|
|
||||||
ret += ".gz"
|
ret += ".gz"
|
||||||
|
@ -56,9 +56,9 @@ class ArchiveProduct():
|
||||||
parts = self.__parts__()
|
parts = self.__parts__()
|
||||||
ret = os.path.join(*parts)
|
ret = os.path.join(*parts)
|
||||||
|
|
||||||
if self.typeof == ArchiveProductType.V03:
|
if self.typeof == NEXRADArchiveProductType.V03:
|
||||||
ret += "_V03"
|
ret += "_V03"
|
||||||
elif self.typeof == ArchiveProductType.V04:
|
elif self.typeof == NEXRADArchiveProductType.V04:
|
||||||
ret += "_V04"
|
ret += "_V04"
|
||||||
|
|
||||||
ret += ".gz"
|
ret += ".gz"
|
||||||
|
@ -70,7 +70,7 @@ class ArchiveProduct():
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_s3_key(key: str):
|
def from_s3_key(key: str):
|
||||||
product = ArchiveProduct()
|
product = NEXRADArchiveProduct()
|
||||||
match = S3_KEY_RE.match(key)
|
match = S3_KEY_RE.match(key)
|
||||||
|
|
||||||
product.timestamp = datetime.datetime(
|
product.timestamp = datetime.datetime(
|
||||||
|
@ -84,8 +84,8 @@ class ArchiveProduct():
|
||||||
)
|
)
|
||||||
|
|
||||||
product.radar = match[4]
|
product.radar = match[4]
|
||||||
product.typeof = ArchiveProductType.V03 \
|
product.typeof = NEXRADArchiveProductType.V03 \
|
||||||
if key[-7:] == '_V03.gz' else ArchiveProductType.DEFAULT
|
if key[-7:] == '_V03.gz' else NEXRADArchiveProductType.DEFAULT
|
||||||
|
|
||||||
return product
|
return product
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class ArchiveProduct():
|
||||||
|
|
||||||
return result['num'] == 1
|
return result['num'] == 1
|
||||||
|
|
||||||
class Archive():
|
class NEXRADArchive():
|
||||||
path: str
|
path: str
|
||||||
bucket: S3Bucket
|
bucket: S3Bucket
|
||||||
|
|
||||||
|
@ -148,10 +148,10 @@ class Archive():
|
||||||
parts = [self.path]
|
parts = [self.path]
|
||||||
|
|
||||||
if day is not None and month is None:
|
if day is not None and month is None:
|
||||||
raise ArchiveDateError('day', 'month')
|
raise NEXRADArchiveDateError('day', 'month')
|
||||||
|
|
||||||
if month is not None and year is None:
|
if month is not None and year is None:
|
||||||
raise ArchiveDateError('month', 'year')
|
raise NEXRADArchiveDateError('month', 'year')
|
||||||
|
|
||||||
for cur_year in os.scandir(os.path.join(*parts)):
|
for cur_year in os.scandir(os.path.join(*parts)):
|
||||||
if not (cur_year.is_dir() and self.RE_YEAR.match(cur_year.name)):
|
if not (cur_year.is_dir() and self.RE_YEAR.match(cur_year.name)):
|
||||||
|
@ -205,4 +205,4 @@ class Archive():
|
||||||
month: int=None,
|
month: int=None,
|
||||||
day: int=None):
|
day: int=None):
|
||||||
for key in self.each_downloaded_key(year, month, day):
|
for key in self.each_downloaded_key(year, month, day):
|
||||||
yield ArchiveProduct.from_s3_key(key)
|
yield NEXRADArchiveProduct.from_s3_key(key)
|
Loading…
Add table
Reference in a new issue