Initial commit of bin/ utilities
This commit is contained in:
parent
5d30a21e4a
commit
656c6e29cc
2 changed files with 65 additions and 0 deletions
41
bin/nexrad-archive
Executable file
41
bin/nexrad-archive
Executable file
|
@ -0,0 +1,41 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
|
||||
from nexrad.db import Database
|
||||
from nexrad.s3 import S3Bucket
|
||||
from nexrad.storm import StormReport
|
||||
from nexrad.archive import Archive
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Archive NEXRAD Level II data from Amazon S3'
|
||||
)
|
||||
|
||||
parser.add_argument('--quiet', action='store_true', help='Suppress output')
|
||||
parser.add_argument('--dry-run', action='store_true', help='Do not actually archive data')
|
||||
parser.add_argument('db', help='SQLite3 NEXRAD radar site database')
|
||||
parser.add_argument('csv-report-details', help='Compressed storm report details CSV file')
|
||||
parser.add_argument('archive-dir', help='Target archive directory')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
db = Database.connect(args.db)
|
||||
bucket = S3Bucket()
|
||||
archive = Archive(getattr(args, 'archive-dir'), bucket)
|
||||
|
||||
for report in StormReport.each_from_csv_file(getattr(args, 'csv-report-details')):
|
||||
if not report.is_radar_significant():
|
||||
continue
|
||||
|
||||
radars = report.nearby_radars(db)
|
||||
|
||||
for key in bucket.each_matching_key(radars, report.timestamp_start, report.timestamp_end):
|
||||
if archive.is_archived(key):
|
||||
if not args.quiet:
|
||||
print(f"Key {key} already archived")
|
||||
else:
|
||||
if not args.quiet:
|
||||
print(f"Archiving {key}")
|
||||
|
||||
if not args.dry_run:
|
||||
archive.archive(key)
|
24
bin/nexrad-archive-init
Executable file
24
bin/nexrad-archive-init
Executable file
|
@ -0,0 +1,24 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
|
||||
from nexrad.db import Database
|
||||
from nexrad.radar import Radar
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Initialize NEXRAD radar site database'
|
||||
)
|
||||
|
||||
parser.add_argument('db', help='Path to SQLite3 database')
|
||||
parser.add_argument('radars-tsv', help='Path to NEXRAD radar station TSV file')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
db = Database.connect(args.db)
|
||||
|
||||
db.execute('begin transaction')
|
||||
|
||||
for radar in Radar.each_from_tsv(getattr(args, 'radars-tsv')):
|
||||
radar.add_to_db(db)
|
||||
|
||||
db.commit()
|
Loading…
Add table
Reference in a new issue