Compare commits
3 commits
6d317f4037
...
8fb9f67a25
Author | SHA1 | Date | |
---|---|---|---|
|
8fb9f67a25 | ||
|
3fa26aca83 | ||
|
bbb2a62636 |
5 changed files with 82 additions and 6 deletions
|
@ -9,7 +9,7 @@ RUN mkdir -p /var/opt/nexrad-archive/lib/nexrad
|
|||
RUN mkdir -p /var/opt/nexrad-archive/bin
|
||||
RUN mkdir -p /var/lib/nexrad-archive
|
||||
|
||||
COPY db/nexrad.sql doc/radars.tsv /tmp
|
||||
COPY db/nexrad.sql doc/radars.tsv doc/wfo.tsv /tmp
|
||||
COPY lib/nexrad/*.py /var/opt/nexrad-archive/lib/nexrad
|
||||
COPY bin/nexrad-archive bin/nexrad-archive-init /var/opt/nexrad-archive/bin
|
||||
|
||||
|
@ -19,6 +19,7 @@ RUN sqlite3 -init /tmp/nexrad.sql /var/lib/nexrad-archive/nexrad.db .quit
|
|||
|
||||
RUN /var/opt/nexrad-archive/bin/nexrad-archive-init \
|
||||
/var/lib/nexrad-archive/nexrad.db \
|
||||
/tmp/radars.tsv
|
||||
/tmp/radars.tsv \
|
||||
/tmp/wfo.tsv
|
||||
|
||||
ENTRYPOINT ["/var/opt/nexrad-archive/bin/nexrad-archive", "/var/lib/nexrad-archive/nexrad.db"]
|
||||
|
|
|
@ -4,6 +4,7 @@ import argparse
|
|||
|
||||
from nexrad.db import Database
|
||||
from nexrad.radar import Radar
|
||||
from nexrad.wfo import WFO
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Initialize NEXRAD radar site database'
|
||||
|
@ -11,6 +12,7 @@ parser = argparse.ArgumentParser(
|
|||
|
||||
parser.add_argument('db', help='Path to SQLite3 database')
|
||||
parser.add_argument('radars-tsv', help='Path to NEXRAD radar station TSV file')
|
||||
parser.add_argument('wfo-tsv', help='Path to forecast office TSV file')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -21,4 +23,7 @@ db.execute('begin transaction')
|
|||
for radar in Radar.each_from_tsv(getattr(args, 'radars-tsv')):
|
||||
db.add(radar)
|
||||
|
||||
for wfo in WFO.each_from_tsv(getattr(args, 'wfo-tsv')):
|
||||
db.add(wfo)
|
||||
|
||||
db.commit()
|
||||
|
|
|
@ -3,8 +3,18 @@ select InitSpatialMetadata(1);
|
|||
|
||||
begin transaction;
|
||||
|
||||
create table nexrad_wfo (
|
||||
code TEXT NOT NULL,
|
||||
city TEXT NOT NULL,
|
||||
state TEXT NOT NULL,
|
||||
address TEXT NOT NULL
|
||||
);
|
||||
|
||||
select
|
||||
AddGeometryColumn('nexrad_wfo', 'coord', 4326, 'POINT', 'XY', 1),
|
||||
CreateSpatialIndex('nexrad_wfo', 'coord');
|
||||
|
||||
create table nexrad_radar (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
wban INTEGER,
|
||||
call TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
CITY STATE CODE ADDRESS LAT LON
|
||||
Anchorage Alaska AFC 6930 Sand Lake Rd, Anchorage, AK 99502 61.156492370724614 -149.984866989923
|
||||
Fairbanks Alaska AFG UAF-Akasofu Building, Fairbanks, AK 99775-7345 64.85954039959843 -147.85081435064103
|
||||
Juneau Alaska AJK 8500 Mendenhall Loop Rd, Juneau, AK 99801 58.400186605569566 -134.5698323492324
|
||||
|
@ -41,13 +40,13 @@ Milwaukee/Sullivan Wisconsin MKX N3533 Hardscrabble Road Dousman, WI 53118 42
|
|||
Cheyenne Wyoming CYS 1301 Airport Parkway Cheyenne, WY 82001 41.15184622590132 -104.80565491122367
|
||||
Riverton Wyoming RIW 12744 West US Highway 26 Riverton, WY 82501 43.065362064691406 -108.47772444457411
|
||||
Caribou Maine CAR 810 Main St, Caribou, ME 04736 46.868418901451186 -68.01350750728945
|
||||
Gray/Portland Maine GYX 1 Weather Ln, Gray, ME 04039 43.89277767707327, -70.25436437606977
|
||||
Gray/Portland Maine GYX 1 Weather Ln, Gray, ME 04039 43.89277767707327 -70.25436437606977
|
||||
Boston/Norton Massachusetts BOX 46 Commerce Way, Norton, MA 02766 41.95644795174152 -71.13953329885862
|
||||
Mount Holly/Philadelphia New Jersey PHI 732 Woodlane Rd, Mt Holly, NJ 08060 40.01344254057813 -74.81747958926773
|
||||
Albany New York ALY ETEC - National Weather Service 1400 Washington Avenue, Albany, NY 12222 42.68051926994165 -73.81591958704975
|
||||
Binghamton New York BGM 32 Dawes Dr, Johnson City, NY 13790 42.2118372285952 -75.98573678958357
|
||||
Buffalo New York BUF 587 Aero Drive, Cheektowaga, NY 14225 42.94140940215387 -78.71929036013498
|
||||
New York/Upton New York OKX 175 Brookhaven Ave, Upton, NY 11973 40.865599365688844, -72.86465879727432
|
||||
New York/Upton New York OKX 175 Brookhaven Ave, Upton, NY 11973 40.865599365688844 -72.86465879727432
|
||||
Newport/Morehead City North Carolina MHX 533 Roberts Rd, Newport, NC 28570 34.7763203047587 -76.87660449225505
|
||||
Raleigh North Carolina RAH 1005 Capability Dr #300, Raleigh, NC 27606 35.77066096052944 -78.68108963405056
|
||||
Wilmington North Carolina ILM 2015 Gardner Dr, Wilmington, NC 28405 34.27635112344196 -77.91286795169097
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 44.
|
61
lib/nexrad/wfo.py
Normal file
61
lib/nexrad/wfo.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
import csv
|
||||
import shapely
|
||||
|
||||
from nexrad.db import DatabaseTable
|
||||
from nexrad.coord import COORD_SYSTEM
|
||||
|
||||
class WFO(DatabaseTable):
|
||||
__slots__ = (
|
||||
'code', 'city', 'state', 'address', 'coord'
|
||||
)
|
||||
|
||||
__table__ = 'nexrad_wfo'
|
||||
__key__ = 'code'
|
||||
|
||||
__columns__ = (
|
||||
'code', 'city', 'state', 'address', 'coord'
|
||||
)
|
||||
|
||||
__columns_read__ = {
|
||||
'coord': 'ST_AsText(coord) as coord'
|
||||
}
|
||||
|
||||
__values_read__ = {
|
||||
'coord': shapely.from_wkt
|
||||
}
|
||||
|
||||
__columns_write__ = {
|
||||
'coord': 'MakePoint(:coord_lon, :coord_lat, {crs})'.format(crs=COORD_SYSTEM)
|
||||
}
|
||||
|
||||
__values_write__ = {
|
||||
'coord': lambda v: {'coord_lon': v.x, 'coord_lat': v.y}
|
||||
}
|
||||
|
||||
id: int
|
||||
code: str
|
||||
city: str
|
||||
state: str
|
||||
adadress: str
|
||||
|
||||
@staticmethod
|
||||
def from_tsv_row(row: list):
|
||||
wfo = WFO()
|
||||
wfo.code = row[2]
|
||||
wfo.city = row[0]
|
||||
wfo.state = row[1]
|
||||
wfo.address = row[3]
|
||||
wfo.coord = shapely.Point(float(row[5]), float(row[4]))
|
||||
|
||||
return wfo
|
||||
|
||||
@staticmethod
|
||||
def each_from_tsv(file: str):
|
||||
with open(file) as fh:
|
||||
reader = csv.reader(fh, delimiter='\t')
|
||||
|
||||
for row in reader:
|
||||
for i in range(0, len(row)):
|
||||
row[i] = row[i].rstrip()
|
||||
|
||||
yield WFO.from_tsv_row(row)
|
Loading…
Add table
Reference in a new issue