2025-02-25 10:32:31 -05:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
2025-02-25 14:45:37 -05:00
|
|
|
import argparse
|
2025-02-25 10:32:31 -05:00
|
|
|
|
|
|
|
from xmet.db import Database
|
|
|
|
from xmet.igra import IGRAReader
|
|
|
|
|
2025-02-25 14:45:37 -05:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description = 'Ingest IGRA 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('igra-sounding-file', nargs='+', help='IGRA sounding file')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
db = Database.connect(args.db)
|
2025-02-25 10:32:31 -05:00
|
|
|
db.execute('begin transaction')
|
|
|
|
|
2025-02-25 14:45:37 -05:00
|
|
|
for path in getattr(args, 'igra-sounding-file'):
|
2025-02-25 13:15:32 -05:00
|
|
|
for sounding in IGRAReader.each_sounding_from_file(path):
|
2025-02-25 14:45:37 -05:00
|
|
|
if not args.quiet:
|
|
|
|
print(f"Ingesting sounding file {path}")
|
|
|
|
|
|
|
|
if args.dry_run:
|
|
|
|
continue
|
|
|
|
|
2025-02-25 13:15:32 -05:00
|
|
|
db.add(sounding)
|
2025-02-25 10:32:31 -05:00
|
|
|
|
2025-02-25 13:15:32 -05:00
|
|
|
for sample in sounding.samples:
|
|
|
|
sample.sounding_id = sounding.id
|
|
|
|
db.add(sample)
|
2025-02-25 10:32:31 -05:00
|
|
|
|
|
|
|
db.commit()
|