2025-03-02 17:06:45 -05:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
2025-04-03 21:47:45 -04:00
|
|
|
from xmet.config import Config
|
|
|
|
from xmet.db import Database
|
|
|
|
from xmet.raob import RAOBReader
|
|
|
|
from xmet.igra import IGRAStation
|
2025-03-02 17:06:45 -05:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2025-03-02 17:07:24 -05:00
|
|
|
description = 'Ingest RAOB soundings'
|
2025-03-02 17:06:45 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument('--quiet', action='store_true', help='Suppress output')
|
|
|
|
parser.add_argument('--dry-run', action='store_true', help='Do not actually ingest data')
|
|
|
|
|
2025-03-02 17:07:24 -05:00
|
|
|
parser.add_argument('raob-sounding-file', nargs='+', help='RAOB sounding file')
|
2025-03-02 17:06:45 -05:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2025-04-03 21:47:45 -04:00
|
|
|
config = Config.load()
|
|
|
|
db = Database.from_config(config)
|
2025-03-02 17:06:45 -05:00
|
|
|
|
2025-03-02 17:07:24 -05:00
|
|
|
if not args.dry_run:
|
|
|
|
db.execute('begin transaction')
|
|
|
|
|
|
|
|
for path in getattr(args, 'raob-sounding-file'):
|
2025-03-02 17:06:45 -05:00
|
|
|
if not args.quiet:
|
|
|
|
print(f"Ingesting sounding file {path}")
|
|
|
|
|
2025-03-02 17:07:24 -05:00
|
|
|
for sounding in RAOBReader.each_sounding_from_file(path):
|
2025-03-02 20:02:09 -05:00
|
|
|
station = IGRAStation.find_station(db, sounding.station)
|
|
|
|
|
|
|
|
if station is not None:
|
2025-03-26 23:14:06 -04:00
|
|
|
sounding.station = station.code
|
|
|
|
sounding.location = station.location
|
2025-03-02 20:02:09 -05:00
|
|
|
|
2025-03-02 20:56:24 -05:00
|
|
|
if not args.dry_run:
|
|
|
|
db.add(sounding)
|
2025-03-02 17:06:45 -05:00
|
|
|
|
|
|
|
for sample in sounding.samples:
|
|
|
|
sample.sounding_id = sounding.id
|
2025-03-02 20:56:24 -05:00
|
|
|
|
|
|
|
if not args.dry_run:
|
|
|
|
db.add(sample)
|
2025-03-02 17:06:45 -05:00
|
|
|
|
2025-03-02 17:07:24 -05:00
|
|
|
if not args.dry_run:
|
|
|
|
db.commit()
|