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