Skip to content

Commit

Permalink
updated results for water year 2015 & 2016
Browse files Browse the repository at this point in the history
  • Loading branch information
andybell committed May 24, 2017
1 parent e12a9b7 commit 16b19e8
Show file tree
Hide file tree
Showing 13 changed files with 79,438 additions and 79,379 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ et_wy2015.tif:et_wy%.tif:
iet_wy2015.tif:iet_wy%.tif:
gdal_translate -of GTiff -co "COMPRESS=DEFLATE" \
"PG:host='localhost' user='ssj' dbname='ssj' schema='calsimetaw' table='et_raster' mode='1' where='type=\'iet\' and year=$*'" $@

et_wy2016.tif:et_wy%.tif:
gdal_translate -of GTiff -co "COMPRESS=DEFLATE" \
"PG:host='localhost' user='ssj' dbname='ssj' schema='calsimetaw' table='et_raster_wy2016' mode='1' where='type=\\'et\\' and year=$*'" $@

iet_wy2016.tif:iet_wy%.tif:
gdal_translate -of GTiff -co "COMPRESS=DEFLATE" \
"PG:host='localhost' user='ssj' dbname='ssj' schema='calsimetaw' table='et_raster_wy2016' mode='1' where='type=\'iet\' and year=$*'" $@

# Getting DWR values
#for i in `psql service=ssj -A -t --pset=footer -c 'with a as (select dwr_id,boundary,wkb_geometry,(st_area(st_intersection(g.boundary,b.wkb_geometry)))::int as area from calsimetaw.calsimetaw g join overview.bbox b on st_intersects(g.boundary,b.wkb_geometry)) select dwr_id from a where area > 0 order by dwr_id' `; do rsync ../weather/cimis_$i.csv . -v ; done
2 changes: 1 addition & 1 deletion landuse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ from calsimetaw.model_output_wy2015
group by dauco,year,mon,day,doy
order by dauco,doy;


create table calsimetaw.crosswalk as
select * from
(VALUES
Expand All @@ -102,6 +101,7 @@ select * from
('Corn','Corn'),
('Cucurbits','Cucurbit'),
('Fallow','Fallow'),
('Fallow', 'Summer Fallow'),
('Fallow','Upland Herbaceous'),
('Pasture','Wet herbaceous/sub irrigated pasture'),
('Olives','Olives'),
Expand Down
75,922 changes: 37,961 additions & 37,961 deletions model_output/wy2015/model_output.csv

Large diffs are not rendered by default.

82,718 changes: 41,359 additions & 41,359 deletions model_output/wy2016/model_output.csv

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions raster_wy2016.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
-- These scripts perform the rasterization of the CalSIMETAW data for water year 2016

-- First, create a temporary table holding all the ETO data. Note: 2016 is leap year
create temp table eto_poly as
with p as (
select b,(st_dumpAsPolygons(rast,b)).*
from cimis.eto_wy2016,generate_series(1,366) as b
)
select b as dowy,
val as eto,
st_x(st_centroid(geom)) as east,
st_y(st_centroid(geom)) as north
from p;

-- create table of dauco intersected with cimis pixels.
create temp table dauco_ew as
select
dauco,east,north,
st_intersection(d.geom,c.boundary) as boundary
from calsimetaw.dauco d
join calsimetaw.cimis c on st_intersects(d.geom,c.boundary);

-- create a table that summarizes model_output by month using cimis_pixel eto
-- instead of dauco output
create temp table dauco_ew_com_et as
with m as (
select (year||'-'||mon||'-'||day)::date,*
from calsimetaw.model_output_wy2016
),
n as (
select m.*,
date-'2015-09-30'::date as dowy
from m
),
r as (
select
extract(month from date) as month,
dauco,east,north,
commodity,
count(*),
sum(ikc*c.eto) as iet,
sum(okc*c.eto) as oet,
sum(kc*c.eto) as et
from dauco_ew d join n using (dauco)
join eto_poly c using (east,north,dowy)
group by 1,2,3,4,5
)
select * from r;

-- Smaller table using array of data
create temp table dauco_ew_com_et_bytearray as
select
dauco,east,north,commodity,
array_agg((iet*10/count)::integer order by (month::integer+2)%12)
as daily_iet,
array_agg((oet*10/count)::integer order by (month::integer+2)%12)
as daily_oet,
array_agg((et*10/count)::integer order by (month::integer+2)%12)
as daily_et,
sum(iet) as yearly_iet,
sum(oet) as yearly_oet,
sum(et) as yearly_et
from dauco_ew_com_et
group by dauco,east,north,commodity;


-- Intersection of landuse data with calsimetaw data.
create table calsimetaw.et_wy2016 as
select
dauco,east,north,c.level_2,
daily_et,daily_iet,daily_oet,
yearly_et,yearly_iet,yearly_oet,
st_intersection(d.boundary,l.boundary) as boundary
from dauco_ew_com_et_bytearray
join dauco_ew d using (dauco,east,north)
join calsimetaw.crosswalk c using (commodity)
join landuse_2016 l on (c.level_2=l.level_2
and st_intersects(d.boundary,l.boundary));


-- Raster version.
create table calsimetaw.et_raster_wy2016 as
with r as (select raster_template() as rast),
v(bt,nv) as (
VALUES(ARRAY['8BSI','8BSI','8BSI','8BSI','8BSI','8BSI','8BSI',
'8BSI','8BSI','8BSI','8BSI','8BSI'],
ARRAY[-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127])
)
select 2016 as year,
'et'::text as type,
st_union(st_asRaster(
st_transform(boundary,(st_metadata(r.rast)).srid),r.rast,bt,daily_et,nv)
) as rast
from calsimetaw.et_wy2016,r,v
union
select 2016 as year,
'iet'::text as type,
st_union(st_asRaster(
st_transform(boundary,(st_metadata(r.rast)).srid),r.rast,bt,daily_iet,nv)
) as rast
from calsimetaw.et_wy2016,r,v;


23 changes: 0 additions & 23 deletions results/cdl/wy2015/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions results/cdl/wy2015/daily/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions results/cdl/wy2015/monthly/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions results/nasa/wy2015/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions results/nasa/wy2015/daily/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions results/nasa/wy2015/monthly/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions results/wy2016/monthly/et_wy2016.tif
Git LFS file not shown
3 changes: 3 additions & 0 deletions results/wy2016/monthly/iet_wy2016.tif
Git LFS file not shown

0 comments on commit 16b19e8

Please sign in to comment.