Open rburghol opened 4 months ago
/opt/model/meta_model/run_model raster_met nldas2 "2023-12-31" auto met
/opt/model/meta_model/run_model raster_met nldas2 "2024-01-01" auto met
Manually insert a draft hourly fraction raster set. To be replaced for daily imports later.
delete from dh_timeseries_weather where varid in (select hydroid from dh_variabledefinition where varkey = 'nldas2_precip_daily_frac');
--This sums all of our raster points, so 24 rasters, into one, this creates a single raster of the full days rain
create temp table tmp_nldas2_daily_precip as
select min(a.tstime), max(a.tsendtime) as tsendtime, a.featureid, a.entity_type, ST_Union(a.rast, 'SUM') as rast
from dh_timeseries_weather as a
left outer join dh_variabledefinition as b
on (a.varid = b.hydroid and b.varkey='nldas2_obs_hourly')
WHERE b.varkey = 'nldas2_obs_hourly'
GROUP BY a.featureid, a.entity_type, date(to_timestamp(a.tsendtime));
--We take our hourly raster and our daily raster and figure out the fraction of rain for each hour, for each raster
create temp table tmp_fraction_raster as
SELECT hourly_table.featureid, hourly_table.entity_type, hourly_table.tstime, hourly_table.tsendtime,
st_mapalgebra(hourly_table.rast, 1, ST_SetBandNoDataValue(daily_table.rast,0), 1, '[rast1] / [rast2]') as rast
from dh_timeseries_weather as hourly_table
left outer join tmp_nldas2_daily_precip as daily_table
on (
DATE(to_timestamp(daily_table.tsendtime)) = DATE(to_timestamp(hourly_table.tsendtime))
)
left outer join dh_variabledefinition as b
on (hourly_table.varid = b.hydroid and b.varkey='nldas2_obs_hourly')
WHERE b.varkey = 'nldas2_obs_hourly';
dh_timeseries_weather
tableinsert into dh_timeseries_weather(featureid, entity_type, varid, tstime, tsendtime, rast)
select a.featureid, a.entity_type, b.hydroid as varid, a.tstime, a.tsendtime, a.rast
from dh_variabledefinition as b, tmp_fraction_raster as a
where b.varkey = 'nldas2_precip_daily_frac'
@mwdunlap2004 Hint: how to turn a text date (YYYY-MM-DD) into a Unix timestamp? Something like this:
select extract(epoch from ('2021-05-01'::timestamp));
Tasks
met -> import -> 04_hourly_fractions
#98$ddate
and$datasource
variables populated automatically$ddate
can be converted totsendtime
(see example in https://github.com/HARPgroup/meta_model/blob/amalgamate/models/raster_met/met/import/03_db_import )tstime
would betsendtime - 86400
varkey = 'nldas2_precip_daily'
tsendtime
is the field that signifies the appropriatedate
of an hourly entryconfig/control/met/[data source].con
Overview
run_model raster_met [data source(required)] [date(required)] [working dir(default=auto)] met [step=all]
/opt/model/meta_model/run_model raster_met nldas2 "2024-01-01" auto met
nldas2
,daymet
,PRISM
download
00_init
02_download
: defaults to NLDAS2, but variants: PRISM and daymet (and others) have an independent scrip with anif
02_download_PRISM
02_download_daymet
99_cleanup
process
:01_reproject
02_clip
03_set_time
import
03_db_import
04_hourly_fractions
#98