Compare commits

...

3 commits

3 changed files with 59 additions and 5 deletions

View file

@ -18,7 +18,9 @@ parser.add_argument('igra-sounding-file', nargs='+', help='IGRA sounding file')
args = parser.parse_args()
db = Database.connect(args.db)
db.execute('begin transaction')
if not args.dry_run:
db.execute('begin transaction')
for path in getattr(args, 'igra-sounding-file'):
if not args.quiet:
@ -34,4 +36,5 @@ for path in getattr(args, 'igra-sounding-file'):
sample.sounding_id = sounding.id
db.add(sample)
db.commit()
if not args.dry_run:
db.commit()

40
bin/xmet-raob-ingest Executable file
View file

@ -0,0 +1,40 @@
#! /usr/bin/env python3
import argparse
from xmet.db import Database
from xmet.raob import RAOBReader
parser = argparse.ArgumentParser(
description = 'Ingest RAOB soundings'
)
parser.add_argument('--quiet', action='store_true', help='Suppress output')
parser.add_argument('--dry-run', action='store_true', help='Do not actually ingest data')
parser.add_argument('db', help='XMET SQLite3 database')
parser.add_argument('raob-sounding-file', nargs='+', help='RAOB sounding file')
args = parser.parse_args()
db = Database.connect(args.db)
if not args.dry_run:
db.execute('begin transaction')
for path in getattr(args, 'raob-sounding-file'):
if not args.quiet:
print(f"Ingesting sounding file {path}")
for sounding in RAOBReader.each_sounding_from_file(path):
if args.dry_run:
continue
db.add(sounding)
for sample in sounding.samples:
sample.sounding_id = sounding.id
db.add(sample)
if not args.dry_run:
db.commit()

View file

@ -86,16 +86,16 @@ class RAOBObs():
if token[0:2] == '//':
wind_dir = None
else:
wind_dir = float(token[0:3]) + base_dir
wind_dir = meters_second(float(token[0:3]) + base_dir)
if token[3:5] == '//':
wind_speed = None
else:
wind_speed = float(token[3:5]) + base_speed
wind_speed = meters_second(float(token[3:5]) + base_speed)
return {
'dir': wind_dir,
'speed': meters_second(wind_speed)
'speed': wind_speed
}
TTAA_PRESSURES = {
@ -379,3 +379,14 @@ class RAOBReader():
def each_sounding(self):
for chunk in self.each_chunk():
yield from chunk.each_sounding()
@staticmethod
def each_sounding_from_fh(fh: io.TextIOBase):
reader = RAOBReader(fh)
yield from reader.each_sounding()
@staticmethod
def each_sounding_from_file(path: str):
with open(path, 'r') as fh:
yield from RAOBReader.each_sounding_from_fh(fh)