CSTARS / spatial-cimis

New repository for the DWR Spatial CIMIS program
MIT License
0 stars 1 forks source link

Long Term station infomation. #13

Closed qjhart closed 7 years ago

qjhart commented 7 years ago

For each pixel that contains CIMIS stations, would it be possible to get daily long-term averages of solar radiation, ETo, k, tmax, and tmin.

The format is: Stn#, date, Julian date, lat, long, eto, Rs, k, tmax, tmin. Rso, Tdew

qjhart commented 7 years ago

It's possible to compute the daily long term averages for each day within grass. You could then just pick out the stations that you are interested in. For example, the following script calculates Tx long-term.

for i in `seq 0 365`; do 
 md=`date --date="2004-01-01 + $i days" +%m-%d`; s=''; 
 for d in `echo ????-$md`; do 
  if [[ -f $d/cellhd/Tx ]] ; then 
    s=$s"Tx@$d,"; 
  fi; 
 done; 
 s=${s%?};
 r.series input="$s" output=${md}_avg method=average; 
done

However, this takes awhile and is probably overkill for getting just 200 or so locations. So instead you are probably better off simply getting the individual pixels for all the dates that we have. The following command will do that for you:

echo date,x,y,z,station_id,ETo,Tx,Tn,Tdew,Rso,Rs,K,U2 > ~/station_pixel.csv; 
for d in 2???-??-??; do 
 echo $d; 
 v.out.ascii input=et@2017-07-01 fs=' ' | \
 r.what  input=ETo@$d,Tx@$d,Tn@$d,Tdew@$d,Rso@$d,Rs@$d,K@$d,U2@$d fs=' ' |\
   sed -e "s/^/$d /" | tr ' ' ',' >> ~/station_pixel.csv;
done

This gives you all the pixel data for all the stations (as described on 2017-07-01).

qjhart commented 7 years ago

Then you could calculate the averages in something like postgres.

create table station (date date,x float,y float,z float,station_id integer, ETo float, Tx float,Tn float,Tdew float,Rso float,Rs float,K float, U2 float);
\COPY station from ~/Downloads/station_pixel.csv with csv header;

\COPY (select station_id,extract(month from date) as month,extract(day from date) as day,avg(ETo)::decimal(6,2) as ETo, avg(Tx)::decimal(6,2) as Tx,avg(Tn)::decimal(6,2) as Tn,avg(Tdew)::decimal(6,2) as Tdew,avg(Rso)::decimal(6,2) as Rso,avg(Rs)::decimal(6,2) as Rs,avg(K)::decimal(6,2) as K,avg(U2)::decimal(6,2) as U2 from station group by 1,2,3 order by  1,2,3) to station_avg.csv with csv header

Then add the station location with

\COPY (with a as (select distinct station_id,x,y from station), b as (select station_id,st_transform(st_setsrid(st_makepoint(x,y),3310),4269) as ll from a) select station_id,x,y,st_x(ll) as lon,st_y(ll) as lat from a join b using (station_id)) to ~/Downloads/station_loc.csv with csv header
qjhart commented 7 years ago

These data can be found in this zipfile