Mass rename 'coord' columns to 'location'
This commit is contained in:
parent
c3ac435524
commit
b4223248e5
8 changed files with 63 additions and 63 deletions
20
db/xmet.sql
20
db/xmet.sql
|
@ -11,8 +11,8 @@ create table xmet_wfo (
|
||||||
);
|
);
|
||||||
|
|
||||||
select
|
select
|
||||||
AddGeometryColumn('xmet_wfo', 'coord', 4326, 'POINT', 'XY', 1),
|
AddGeometryColumn('xmet_wfo', 'location', 4326, 'POINT', 'XY', 1),
|
||||||
CreateSpatialIndex('xmet_wfo', 'coord');
|
CreateSpatialIndex('xmet_wfo', 'location');
|
||||||
|
|
||||||
create table xmet_nexrad_radar (
|
create table xmet_nexrad_radar (
|
||||||
call TEXT PRIMARY KEY NOT NULL,
|
call TEXT PRIMARY KEY NOT NULL,
|
||||||
|
@ -23,8 +23,8 @@ create table xmet_nexrad_radar (
|
||||||
);
|
);
|
||||||
|
|
||||||
select
|
select
|
||||||
AddGeometryColumn('xmet_nexrad_radar', 'coord', 4326, 'POINT', 'XY'),
|
AddGeometryColumn('xmet_nexrad_radar', 'location', 4326, 'POINT', 'XY'),
|
||||||
CreateSpatialIndex('xmet_nexrad_radar', 'coord');
|
CreateSpatialIndex('xmet_nexrad_radar', 'location');
|
||||||
|
|
||||||
create table xmet_storm_event (
|
create table xmet_storm_event (
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
@ -46,12 +46,12 @@ create index xmet_storm_event_timestamp_start_idx on xmet_storm_event (timestamp
|
||||||
create index xmet_storm_event_timestamp_end_idx on xmet_storm_event (timestamp_end);
|
create index xmet_storm_event_timestamp_end_idx on xmet_storm_event (timestamp_end);
|
||||||
|
|
||||||
select
|
select
|
||||||
AddGeometryColumn('xmet_storm_event', 'coord_start', 4326, 'POINT', 'XY', 0),
|
AddGeometryColumn('xmet_storm_event', 'location_start', 4326, 'POINT', 'XY', 0),
|
||||||
CreateSpatialIndex('xmet_storm_event', 'coord_start');
|
CreateSpatialIndex('xmet_storm_event', 'location_start');
|
||||||
|
|
||||||
select
|
select
|
||||||
AddGeometryColumn('xmet_storm_event', 'coord_end', 4326, 'POINT', 'XY', 0),
|
AddGeometryColumn('xmet_storm_event', 'location_end', 4326, 'POINT', 'XY', 0),
|
||||||
CreateSpatialIndex('xmet_storm_event', 'coord_end');
|
CreateSpatialIndex('xmet_storm_event', 'location_end');
|
||||||
|
|
||||||
create table xmet_afos_message (
|
create table xmet_afos_message (
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
@ -113,8 +113,8 @@ create table xmet_sounding (
|
||||||
data_source_other TEXT NOT NULL
|
data_source_other TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
select AddGeometryColumn('xmet_sounding', 'coord', 4326, 'POINT'),
|
select AddGeometryColumn('xmet_sounding', 'location', 4326, 'POINT'),
|
||||||
CreateSpatialIndex('xmet_sounding', 'coord');
|
CreateSpatialIndex('xmet_sounding', 'location');
|
||||||
|
|
||||||
create table xmet_sounding_sample (
|
create table xmet_sounding_sample (
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
|
|
@ -94,8 +94,8 @@ class ArchiveProduct():
|
||||||
|
|
||||||
def is_reported(self, db: Database):
|
def is_reported(self, db: Database):
|
||||||
sql = """select count((
|
sql = """select count((
|
||||||
select ST_Distance(MakeLine(event.coord_start, event.coord_end),
|
select ST_Distance(MakeLine(event.location_start, event.location_end),
|
||||||
radar.coord,
|
radar.location,
|
||||||
true) as distance
|
true) as distance
|
||||||
from
|
from
|
||||||
xmet_storm_event as event,
|
xmet_storm_event as event,
|
||||||
|
|
|
@ -133,7 +133,7 @@ class IGRAReader():
|
||||||
sounding.timestamp_released = timestamp_release
|
sounding.timestamp_released = timestamp_release
|
||||||
sounding.data_source_pressure = match['p_src']
|
sounding.data_source_pressure = match['p_src']
|
||||||
sounding.data_source_other = match['np_src']
|
sounding.data_source_other = match['np_src']
|
||||||
sounding.coord = shapely.Point(lon, lat)
|
sounding.location = shapely.Point(lon, lat)
|
||||||
sounding.samples = list()
|
sounding.samples = list()
|
||||||
|
|
||||||
count = int(match['numlev'])
|
count = int(match['numlev'])
|
||||||
|
|
|
@ -44,36 +44,36 @@ RADAR_RANGE = 230000
|
||||||
|
|
||||||
class Radar(DatabaseTable):
|
class Radar(DatabaseTable):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'call', 'wban', 'name', 'coord', 'site_elevation', 'tower_height',
|
'call', 'wban', 'name', 'location', 'site_elevation', 'tower_height',
|
||||||
)
|
)
|
||||||
|
|
||||||
__table__ = 'xmet_nexrad_radar'
|
__table__ = 'xmet_nexrad_radar'
|
||||||
__key__ = 'call'
|
__key__ = 'call'
|
||||||
|
|
||||||
__columns__ = (
|
__columns__ = (
|
||||||
'call', 'wban', 'name', 'coord', 'site_elevation', 'tower_height'
|
'call', 'wban', 'name', 'location', 'site_elevation', 'tower_height'
|
||||||
)
|
)
|
||||||
|
|
||||||
__columns_read__ = {
|
__columns_read__ = {
|
||||||
'coord': 'ST_AsText(coord) as coord'
|
'location': 'ST_AsText(location) as location'
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_read__ = {
|
__values_read__ = {
|
||||||
'coord': shapely.from_wkt
|
'location': shapely.from_wkt
|
||||||
}
|
}
|
||||||
|
|
||||||
__columns_write__ = {
|
__columns_write__ = {
|
||||||
'coord': 'MakePoint(:coord_lon, :coord_lat, {crs})'.format(crs=COORD_SYSTEM)
|
'location': 'MakePoint(:location_lon, :location_lat, {crs})'.format(crs=COORD_SYSTEM)
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_write__ = {
|
__values_write__ = {
|
||||||
'coord': lambda v: {'coord_lon': v.x, 'coord_lat': v.y}
|
'location': lambda v: {'location_lon': v.x, 'location_lat': v.y}
|
||||||
}
|
}
|
||||||
|
|
||||||
call: str
|
call: str
|
||||||
wban: int
|
wban: int
|
||||||
name: str
|
name: str
|
||||||
coord: shapely.Point
|
location: shapely.Point
|
||||||
site_elevation: float
|
site_elevation: float
|
||||||
tower_height: float
|
tower_height: float
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class Radar(DatabaseTable):
|
||||||
radar.call = row[1]
|
radar.call = row[1]
|
||||||
radar.wban = int(row[0]) if row[0] != 'PENDING' else None
|
radar.wban = int(row[0]) if row[0] != 'PENDING' else None
|
||||||
radar.name = row[2]
|
radar.name = row[2]
|
||||||
radar.coord = parse(row[3])
|
radar.location = parse(row[3])
|
||||||
radar.site_elevation = 0.3048 * float(row[4])
|
radar.site_elevation = 0.3048 * float(row[4])
|
||||||
radar.tower_height = float(row[5])
|
radar.tower_height = float(row[5])
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ class SkewTGraph():
|
||||||
cr.save()
|
cr.save()
|
||||||
|
|
||||||
for pressure in range(PRESSURE_MIN, PRESSURE_MAX+1, PRESSURE_STEP):
|
for pressure in range(PRESSURE_MIN, PRESSURE_MAX+1, PRESSURE_STEP):
|
||||||
coord = self.graph_to_screen(-self.width / 2,
|
coords = self.graph_to_screen(-self.width / 2,
|
||||||
self.pressure_to_y(pressure))
|
self.pressure_to_y(pressure))
|
||||||
|
|
||||||
if pressure % (2*PRESSURE_STEP) == 0:
|
if pressure % (2*PRESSURE_STEP) == 0:
|
||||||
|
@ -61,7 +61,7 @@ class SkewTGraph():
|
||||||
else:
|
else:
|
||||||
cr.set_source_rgb(0.75, 0.75, 0.75)
|
cr.set_source_rgb(0.75, 0.75, 0.75)
|
||||||
|
|
||||||
cr.move_to(x + coord[0], y + coord[1])
|
cr.move_to(x + coords[0], y + coords[1])
|
||||||
cr.rel_line_to(self.width, 0)
|
cr.rel_line_to(self.width, 0)
|
||||||
cr.stroke()
|
cr.stroke()
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class SoundingSample(DatabaseTable):
|
||||||
class Sounding():
|
class Sounding():
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'id', 'station', 'timestamp_observed', 'timestamp_released',
|
'id', 'station', 'timestamp_observed', 'timestamp_released',
|
||||||
'data_source_pressure', 'data_source_other', 'samples', 'coord'
|
'data_source_pressure', 'data_source_other', 'samples', 'location'
|
||||||
)
|
)
|
||||||
|
|
||||||
__table__ = 'xmet_sounding'
|
__table__ = 'xmet_sounding'
|
||||||
|
@ -86,23 +86,23 @@ class Sounding():
|
||||||
|
|
||||||
__columns__ = (
|
__columns__ = (
|
||||||
'id', 'station', 'timestamp_observed', 'timestamp_released',
|
'id', 'station', 'timestamp_observed', 'timestamp_released',
|
||||||
'data_source_pressure', 'data_source_other', 'coord'
|
'data_source_pressure', 'data_source_other', 'location'
|
||||||
)
|
)
|
||||||
|
|
||||||
__columns_read__ = {
|
__columns_read__ = {
|
||||||
'coord': 'ST_AsText(coord) as coord'
|
'location': 'ST_AsText(location) as location'
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_read__ = {
|
__values_read__ = {
|
||||||
'coord': shapely.from_wkt
|
'location': shapely.from_wkt
|
||||||
}
|
}
|
||||||
|
|
||||||
__columns_write__ = {
|
__columns_write__ = {
|
||||||
'coord': 'ST_GeomFromText(:coord, {crs})'.format(crs=COORD_SYSTEM)
|
'location': 'ST_GeomFromText(:location, {crs})'.format(crs=COORD_SYSTEM)
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_write__ = {
|
__values_write__ = {
|
||||||
'coord': lambda v: {'coord': shapely.to_wkt(v)}
|
'location': lambda v: {'location': shapely.to_wkt(v)}
|
||||||
}
|
}
|
||||||
|
|
||||||
id: int
|
id: int
|
||||||
|
@ -111,7 +111,7 @@ class Sounding():
|
||||||
timestamp_released: datetime.datetime
|
timestamp_released: datetime.datetime
|
||||||
data_source_pressure: str
|
data_source_pressure: str
|
||||||
data_source_other: str
|
data_source_other: str
|
||||||
coord: shapely.Point
|
location: shapely.Point
|
||||||
samples: list[SoundingSample]
|
samples: list[SoundingSample]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -75,7 +75,7 @@ def timezone_from_str(text: str) -> datetime.timezone:
|
||||||
|
|
||||||
return datetime.UTC if tz is None else tz
|
return datetime.UTC if tz is None else tz
|
||||||
|
|
||||||
def coord_from_str(text_lon: str, text_lat: str):
|
def point_from_str(text_lon: str, text_lat: str):
|
||||||
if text_lon == '' or text_lat == '':
|
if text_lon == '' or text_lat == '':
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class StormEvent(DatabaseTable):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'id', 'timestamp_start', 'timestamp_end', 'episode_id',
|
'id', 'timestamp_start', 'timestamp_end', 'episode_id',
|
||||||
'state', 'event_type', 'wfo', 'locale_start', 'locale_end',
|
'state', 'event_type', 'wfo', 'locale_start', 'locale_end',
|
||||||
'tornado_f_rating', 'coord_start', 'coord_end'
|
'tornado_f_rating', 'location_start', 'location_end'
|
||||||
)
|
)
|
||||||
|
|
||||||
__table__ = 'xmet_storm_event'
|
__table__ = 'xmet_storm_event'
|
||||||
|
@ -94,29 +94,29 @@ class StormEvent(DatabaseTable):
|
||||||
__columns__ = (
|
__columns__ = (
|
||||||
'id', 'timestamp_start', 'timestamp_end', 'episode_id',
|
'id', 'timestamp_start', 'timestamp_end', 'episode_id',
|
||||||
'state', 'event_type', 'wfo', 'locale_start', 'locale_end',
|
'state', 'event_type', 'wfo', 'locale_start', 'locale_end',
|
||||||
'tornado_f_rating', 'coord_start', 'coord_end'
|
'tornado_f_rating', 'location_start', 'location_end'
|
||||||
)
|
)
|
||||||
|
|
||||||
__columns_read__ = {
|
__columns_read__ = {
|
||||||
'coord_start': 'ST_AsText(coord_start) as coord_start',
|
'location_start': 'ST_AsText(location_start) as location_start',
|
||||||
'coord_end': 'ST_AsText(coord_end) as coord_end'
|
'location_end': 'ST_AsText(location_end) as location_end'
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_read__ = {
|
__values_read__ = {
|
||||||
'timestamp_start': datetime.datetime.fromisoformat,
|
'timestamp_start': datetime.datetime.fromisoformat,
|
||||||
'timestamp_end': datetime.datetime.fromisoformat,
|
'timestamp_end': datetime.datetime.fromisoformat,
|
||||||
'coord_start': shapely.from_wkt,
|
'location_start': shapely.from_wkt,
|
||||||
'coord_end': shapely.from_wkt
|
'location_end': shapely.from_wkt
|
||||||
}
|
}
|
||||||
|
|
||||||
__columns_write__ = {
|
__columns_write__ = {
|
||||||
'coord_start': 'MakePoint(:coord_start_lon, :coord_start_lat, {crs})'.format(crs=COORD_SYSTEM),
|
'location_start': 'MakePoint(:location_start_lon, :location_start_lat, {crs})'.format(crs=COORD_SYSTEM),
|
||||||
'coord_end': 'MakePoint(:coord_end_lon, :coord_end_lat, {crs})'.format(crs=COORD_SYSTEM)
|
'location_end': 'MakePoint(:location_end_lon, :location_end_lat, {crs})'.format(crs=COORD_SYSTEM)
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_write__ = {
|
__values_write__ = {
|
||||||
'coord_start': lambda v: {'coord_start_lon': v.x, 'coord_start_lat': v.y},
|
'location_start': lambda v: {'location_start_lon': v.x, 'location_start_lat': v.y},
|
||||||
'coord_end': lambda v: {'coord_end_lon': v.x, 'coord_end_lat': v.y}
|
'location_end': lambda v: {'location_end_lon': v.x, 'location_end_lat': v.y}
|
||||||
}
|
}
|
||||||
|
|
||||||
id: int
|
id: int
|
||||||
|
@ -129,8 +129,8 @@ class StormEvent(DatabaseTable):
|
||||||
locale_start: str
|
locale_start: str
|
||||||
locale_end: str
|
locale_end: str
|
||||||
tornado_f_rating: str
|
tornado_f_rating: str
|
||||||
coord_start: shapely.Point
|
location_start: shapely.Point
|
||||||
coord_end: shapely.Point
|
location_end: shapely.Point
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_csv_row(row: dict):
|
def from_csv_row(row: dict):
|
||||||
|
@ -146,8 +146,8 @@ class StormEvent(DatabaseTable):
|
||||||
event.locale_start = row['BEGIN_LOCATION']
|
event.locale_start = row['BEGIN_LOCATION']
|
||||||
event.locale_end = row['END_LOCATION']
|
event.locale_end = row['END_LOCATION']
|
||||||
event.tornado_f_rating = row['TOR_F_SCALE']
|
event.tornado_f_rating = row['TOR_F_SCALE']
|
||||||
event.coord_start = coord_from_str(row['BEGIN_LON'], row['BEGIN_LAT'])
|
event.location_start = point_from_str(row['BEGIN_LON'], row['BEGIN_LAT'])
|
||||||
event.coord_end = coord_from_str(row['END_LON'], row['END_LAT'])
|
event.location_end = point_from_str(row['END_LON'], row['END_LAT'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
event.episode_id = int(row['EPISODE_ID'])
|
event.episode_id = int(row['EPISODE_ID'])
|
||||||
|
@ -174,14 +174,14 @@ class StormEvent(DatabaseTable):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def each_matching(db,
|
def each_matching(db,
|
||||||
coord: shapely.Point=None,
|
location: shapely.Point=None,
|
||||||
radius: float=RADAR_RANGE,
|
radius: float=RADAR_RANGE,
|
||||||
timestamp: datetime.datetime=None):
|
timestamp: datetime.datetime=None):
|
||||||
columns = StormEvent.__format_columns_select__(StormEvent)
|
columns = StormEvent.__format_columns_select__(StormEvent)
|
||||||
clauses = list()
|
clauses = list()
|
||||||
values = dict()
|
values = dict()
|
||||||
|
|
||||||
if coord is not None:
|
if location is not None:
|
||||||
columns.append("""
|
columns.append("""
|
||||||
ST_Distance(MakeLine(coord_start, coord_end),
|
ST_Distance(MakeLine(coord_start, coord_end),
|
||||||
MakePoint(:lon, :lat, :crs),
|
MakePoint(:lon, :lat, :crs),
|
||||||
|
@ -193,8 +193,8 @@ class StormEvent(DatabaseTable):
|
||||||
])
|
])
|
||||||
|
|
||||||
values.update({
|
values.update({
|
||||||
'lon': coord.x,
|
'lon': location.x,
|
||||||
'lat': coord.y,
|
'lat': location.y,
|
||||||
'crs': COORD_SYSTEM,
|
'crs': COORD_SYSTEM,
|
||||||
'radius': radius
|
'radius': radius
|
||||||
})
|
})
|
||||||
|
@ -257,7 +257,7 @@ class StormEvent(DatabaseTable):
|
||||||
id,
|
id,
|
||||||
call,
|
call,
|
||||||
ST_Distance(
|
ST_Distance(
|
||||||
coord,
|
location,
|
||||||
MakeLine(MakePoint(?, ?, {csr}),
|
MakeLine(MakePoint(?, ?, {csr}),
|
||||||
MakePoint(?, ?, {csr})),
|
MakePoint(?, ?, {csr})),
|
||||||
true) as distance
|
true) as distance
|
||||||
|
@ -272,8 +272,8 @@ class StormEvent(DatabaseTable):
|
||||||
radars = list()
|
radars = list()
|
||||||
|
|
||||||
st = db.execute(sql, (
|
st = db.execute(sql, (
|
||||||
self.coord_start.x, self.coord_start.y,
|
self.location_start.x, self.location_start.y,
|
||||||
self.coord_end.x, self.coord_end.y,
|
self.location_end.x, self.location_end.y,
|
||||||
RADAR_RANGE))
|
RADAR_RANGE))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -6,30 +6,30 @@ from xmet.coord import COORD_SYSTEM
|
||||||
|
|
||||||
class WFO(DatabaseTable):
|
class WFO(DatabaseTable):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'code', 'city', 'state', 'address', 'coord'
|
'code', 'city', 'state', 'address', 'location'
|
||||||
)
|
)
|
||||||
|
|
||||||
__table__ = 'xmet_wfo'
|
__table__ = 'xmet_wfo'
|
||||||
__key__ = 'code'
|
__key__ = 'code'
|
||||||
|
|
||||||
__columns__ = (
|
__columns__ = (
|
||||||
'code', 'city', 'state', 'address', 'coord'
|
'code', 'city', 'state', 'address', 'location'
|
||||||
)
|
)
|
||||||
|
|
||||||
__columns_read__ = {
|
__columns_read__ = {
|
||||||
'coord': 'ST_AsText(coord) as coord'
|
'location': 'ST_AsText(location) as location'
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_read__ = {
|
__values_read__ = {
|
||||||
'coord': shapely.from_wkt
|
'location': shapely.from_wkt
|
||||||
}
|
}
|
||||||
|
|
||||||
__columns_write__ = {
|
__columns_write__ = {
|
||||||
'coord': 'MakePoint(:coord_lon, :coord_lat, {crs})'.format(crs=COORD_SYSTEM)
|
'location': 'MakePoint(:location_lon, :location_lat, {crs})'.format(crs=COORD_SYSTEM)
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_write__ = {
|
__values_write__ = {
|
||||||
'coord': lambda v: {'coord_lon': v.x, 'coord_lat': v.y}
|
'location': lambda v: {'location_lon': v.x, 'location_lat': v.y}
|
||||||
}
|
}
|
||||||
|
|
||||||
id: int
|
id: int
|
||||||
|
@ -45,7 +45,7 @@ class WFO(DatabaseTable):
|
||||||
wfo.city = row[0]
|
wfo.city = row[0]
|
||||||
wfo.state = row[1]
|
wfo.state = row[1]
|
||||||
wfo.address = row[3]
|
wfo.address = row[3]
|
||||||
wfo.coord = shapely.Point(float(row[5]), float(row[4]))
|
wfo.location = shapely.Point(float(row[5]), float(row[4]))
|
||||||
|
|
||||||
return wfo
|
return wfo
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue