Skip to content

Commit

Permalink
v2 results for wy 2015
Browse files Browse the repository at this point in the history
  • Loading branch information
andybell committed May 23, 2017
1 parent 47263a0 commit 3646f40
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
20 changes: 10 additions & 10 deletions landuse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ dau_code,ansi,st_intersection(d.geom,c.geom) as geom
from calsimetaw.dau d join calsimetaw.counties c on (st_intersects(d.geom,c.geom) and st_area(st_intersection(d.geom,c.geom))>1)
where dau_code in ('185','186') order by 1,3;

create materialized view calsimetaw.dau_landuse as
create materialized view calsimetaw.dau_landuse_wy2015 as
select
level_1,level_2,dauco,
sum(st_area(st_intersection(d.geom,l.geom)))
from calsimetaw.dauco d join landuse l on (st_intersects(d.geom,l.geom))
from calsimetaw.dauco d join landuse_2015 l on (st_intersects(d.geom,l.geom))
group by 1,2,3;


create or replace view level_1_ct as
create or replace view level_1_ct_wy2015 as
select * from crosstab(
'select level_1,dauco,sum(sum)::integer from calsimetaw.dau_landuse group by 1,2 order by 1,2',
'select distinct dauco from calsimetaw.dau_landuse order by 1'
'select level_1,dauco,sum(sum)::integer from calsimetaw.dau_landuse_wy2015 group by 1,2 order by 1,2',
'select distinct dauco from calsimetaw.dau_landuse_wy2015 order by 1'
) as (
level_1 text,
"DAUCo18501GA" integer,
Expand All @@ -42,10 +42,10 @@ select * from crosstab(
"DAUCo18657GA" integer
);

create or replace view level_2_ct as
create or replace view level_2_ct_wy2015 as
select * from crosstab(
'select level_2,dauco,sum(sum)::integer from calsimetaw.dau_landuse group by 1,2 order by 1,2',
'select distinct dauco from calsimetaw.dau_landuse order by 1'
'select level_2,dauco,sum(sum)::integer from calsimetaw.dau_landuse_wy2015 group by 1,2 order by 1,2',
'select distinct dauco from calsimetaw.dau_landuse_wy2015 order by 1'
) as (
level_2 text,
"DAUCo18501GA" integer,
Expand All @@ -57,7 +57,7 @@ select * from crosstab(
);

-- Fixup the model_output for fallow?
insert into calsimetaw.model_output
insert into calsimetaw.model_output_wy2015
(dauco,commodity,year,mon,day,doy,okc,ikc,kc)
select
dauco,
Expand All @@ -66,7 +66,7 @@ year,mon,day,doy,
min(okc) as okc,
0 as ikc,
min(okc) as kc
from calsimetaw.model_output
from calsimetaw.model_output_wy2015
group by dauco,year,mon,day,doy
order by dauco,doy;

Expand Down
12 changes: 6 additions & 6 deletions raster.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
create temp table eto_poly as
with p as (
select b,(st_dumpAsPolygons(rast,b)).*
from cimis.eto,generate_series(1,365) as b
from cimis.eto_wy2015,generate_series(1,365) as b
)
select b as dowy,
val as eto,
Expand All @@ -25,7 +25,7 @@ join calsimetaw.cimis c on st_intersects(d.geom,c.boundary);
create temp table dauco_ew_com_et as
with m as (
select (year||'-'||mon||'-'||day)::date,*
from calsimetaw.model_output
from calsimetaw.model_output_wy2015
),
n as (
select m.*,
Expand Down Expand Up @@ -64,7 +64,7 @@ from dauco_ew_com_et
group by dauco,east,north,commodity;

-- Intersection of landuse data with calsimetaw data.
create table calsimetaw.et as
create table calsimetaw.et_wy2015 as
select
dauco,east,north,c.level_2,
daily_et,daily_iet,daily_oet,
Expand All @@ -73,7 +73,7 @@ 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 l on (c.level_2=l.level_2
join landuse_2015 l on (c.level_2=l.level_2
and st_intersects(d.boundary,l.boundary));

-- Raster version.
Expand All @@ -89,12 +89,12 @@ select 2015 as year,
st_union(st_asRaster(
st_transform(boundary,(st_metadata(r.rast)).srid),r.rast,bt,daily_et,nv)
) as rast
from calsimetaw.et,r,v
from calsimetaw.et_wy2015,r,v
union
select 2015 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,r,v;
from calsimetaw.et_wy2015,r,v;

3 changes: 3 additions & 0 deletions results/wy2015/monthly/et_wy2015.tif
Git LFS file not shown
3 changes: 3 additions & 0 deletions results/wy2015/monthly/iet_wy2015.tif
Git LFS file not shown

0 comments on commit 3646f40

Please sign in to comment.