Skip to content

Commit bb3c726

Browse files
authored
Merge pull request #264 from akrherz/iemre_sa
IEMRE South America
2 parents dcb016c + 8ca0171 commit bb3c726

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed

.github/workflows/etchosts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
127.0.0.1 iemdb-iemre.local
77
127.0.0.1 iemdb-iemre_europe.local
88
127.0.0.1 iemdb-iemre_china.local
9+
127.0.0.1 iemdb-iemre_sa.local
910
127.0.0.1 iemdb2.local
1011
127.0.0.1 iemdb-postgis.local
1112
127.0.0.1 iemdb-mesosite.local

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ci:
22
autoupdate_schedule: quarterly
33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
5-
rev: "v0.9.10"
5+
rev: "v0.11.0"
66
hooks:
77
- id: ruff
88
args: [--fix, --exit-non-zero-on-fix]

bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ done
99

1010
for db in afos mesosite postgis snet talltowers \
1111
asos asos1min hads hml mos rwis squaw \
12-
awos iem other scan wepp raob id3b iemre_china iemre_europe \
12+
awos iem other scan wepp raob id3b iemre_china iemre_europe iemre_sa \
1313
coop isuag portfolio smos iemre radar nldn sustainablecorn td idep uscrn
1414
do
1515
/usr/bin/psql -v "ON_ERROR_STOP=1" -c "create database $db;" -h localhost -U postgres || exit 2

init/iemre_sa.sql

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
-- We want Postgis
2+
CREATE EXTENSION postgis;
3+
4+
-- bandaid
5+
insert into spatial_ref_sys
6+
select 9311, 'EPSG', 9311, srtext, proj4text from spatial_ref_sys
7+
where srid = 2163;
8+
9+
-- Boilerplate IEM schema_manager_version, the version gets incremented each
10+
-- time we make an upgrade script
11+
CREATE TABLE iem_schema_manager_version(
12+
version int,
13+
updated timestamptz
14+
);
15+
INSERT into iem_schema_manager_version values (-1, now());
16+
17+
-- Our baseline grid
18+
CREATE TABLE iemre_grid(
19+
gid int NOT NULL, -- (gridx + gridy * 488) - 1
20+
cell_center geometry(Point, 4326),
21+
cell_polygon geometry(Polygon, 4326),
22+
hasdata boolean,
23+
gridx int,
24+
gridy int
25+
);
26+
GRANT ALL on iemre_grid to mesonet,ldm;
27+
GRANT SELECT on iemre_grid to nobody;
28+
29+
-- fill out the grid, since we can
30+
do
31+
$do$
32+
declare
33+
x int;
34+
y int;
35+
begin
36+
for x in 0..379
37+
loop
38+
for y in 0..547
39+
loop
40+
execute format($f$
41+
INSERT into iemre_grid(gid, cell_center, hasdata, gridx, gridy,
42+
cell_polygon)
43+
VALUES (%s, ST_Point(%s, %s, 4326), 't', %s, %s,
44+
ST_MakeEnvelope(%s, %s, %s, %s, 4326))
45+
$f$, x + y * 560, 70.0625 + x * 0.125, 15.0625 + y * 0.125, x, y,
46+
70.0625 + x * 0.125 - 0.0625, 15.0625 + y * 0.125 - 0.0625,
47+
70.0625 + x * 0.125 + 0.0625, 15.0625 + y * 0.125 + 0.0625
48+
);
49+
end loop;
50+
end loop;
51+
end;
52+
$do$;
53+
54+
55+
-- Create indices
56+
CREATE INDEX iemre_grid_gix ON iemre_grid USING GIST (cell_center);
57+
CREATE INDEX iemre_grid_cell_gix ON iemre_grid USING GIST (cell_polygon);
58+
CREATE UNIQUE INDEX iemre_grid_gid_idx on iemre_grid(gid);
59+
CREATE UNIQUE INDEX iemre_grid_idx on iemre_grid(gridx, gridy);
60+
61+
-- _______________________________________________________________________
62+
-- Storage of daily analysis
63+
CREATE TABLE iemre_daily(
64+
gid int REFERENCES iemre_grid(gid),
65+
valid date,
66+
high_tmpk real,
67+
low_tmpk real,
68+
high_tmpk_12z real,
69+
low_tmpk_12z real,
70+
p01d real,
71+
p01d_12z real,
72+
rsds real,
73+
snow_12z real,
74+
snowd_12z real,
75+
avg_dwpk real,
76+
wind_speed real,
77+
power_swdn real,
78+
min_rh real,
79+
max_rh real,
80+
high_soil4t real,
81+
low_soil4t real
82+
) PARTITION by RANGE (valid);
83+
ALTER TABLE iemre_daily OWNER to mesonet;
84+
GRANT ALL on iemre_daily to ldm;
85+
GRANT SELECT on iemre_daily to nobody;
86+
87+
CREATE INDEX on iemre_daily(valid);
88+
CREATE INDEX on iemre_daily(gid);
89+
90+
91+
do
92+
$do$
93+
declare
94+
year int;
95+
begin
96+
for year in 1893..2030
97+
loop
98+
execute format($f$
99+
create table iemre_daily_%s partition of iemre_daily
100+
for values from ('%s-01-01') to ('%s-01-01')
101+
$f$, year, year, year + 1);
102+
execute format($f$
103+
GRANT ALL on iemre_daily_%s to mesonet,ldm
104+
$f$, year);
105+
execute format($f$
106+
GRANT SELECT on iemre_daily_%s to nobody
107+
$f$, year);
108+
end loop;
109+
end;
110+
$do$;
111+
112+
-- _______________________________________________________________________
113+
-- Storage of CFS forecast
114+
CREATE TABLE iemre_daily_forecast(
115+
gid int REFERENCES iemre_grid(gid),
116+
valid date,
117+
high_tmpk real,
118+
low_tmpk real,
119+
p01d real,
120+
rsds real
121+
);
122+
ALTER TABLE iemre_daily_forecast OWNER to mesonet;
123+
GRANT ALL on iemre_daily_forecast to mesonet,ldm;
124+
GRANT SELECT on iemre_daily_forecast to nobody;
125+
126+
CREATE INDEX on iemre_daily_forecast(valid);
127+
CREATE INDEX on iemre_daily_forecast(gid);
128+
129+
-- _______________________________________________________________________
130+
-- Storage of daily climatology
131+
CREATE TABLE iemre_dailyc(
132+
gid int REFERENCES iemre_grid(gid),
133+
valid date,
134+
high_tmpk real,
135+
low_tmpk real,
136+
p01d real
137+
);
138+
ALTER TABLE iemre_dailyc OWNER to mesonet;
139+
GRANT ALL on iemre_dailyc to mesonet,ldm;
140+
GRANT SELECT on iemre_dailyc to nobody;
141+
142+
CREATE INDEX on iemre_dailyc(valid);
143+
CREATE INDEX on iemre_dailyc(gid);

0 commit comments

Comments
 (0)