[GRASSLIST:2526] Re: Interpolate from database

Radim Blazek blazek at itc.it
Mon Feb 9 09:47:21 EST 2004


On Saturday 07 February 2004 16:11, Hamish wrote:
> > I have a bunch of meteorological stations (157) on a
> > postgres table and their respective DAILY data
> > (precip, temp, wind) on another table. The thing is, I
> > need to create daily surface maps, interpolating those
> > points in the database. Is there a way to do this in
> > GRASS, that is, input the points from the SQL table,
> > interpolate the data for one day and get a surface,
> > change the day and interpolate again, and again, for
> > about 1 year worth of data? Do I need grass 5.7? 5.3?
>
> Yea, sure. Works really well once you have a script written.
> Time to learn some bash scripting though!
>
> You can use 5.0, but I suggest using 5.3+, so that you can compile
> r.series which lets you do stats on the year's worth of resultant maps
> (after increasing r.series' MAXFILES to something bigger than 365!).
>
> general idea is to extract a single day's data to a sites file, do the
> interpolation, & repeat.
>
> If you have Markus & Helena's hardbound GRASS book, there's an example
> there regarding r.sun I think.
>
>
> general idea:
>
> #!/bin/bash
> i=1
> while [ $i -le 365 ] ; do
>     # generate map names convenient for xganim or r.out.mpeg
>     DAY=`echo $i | awk '{printf "%03i", $1}'`
>     echo
>     echo "Computing radiation for day $DAY..."
>
>     sql_extraction_command day=$i sites_out=rain.$DAY
> # maybe dump to temp. file & feed that into s.in.ascii ?
>     s.surf.idw sites_in=rain.$DAY rast_out=insitu_data.$DAY
>
>     i=`expr $i + 1`
> done
> r.series input="`g.mlist pattern='insitu_data.*' sep=,`" \
>     output=insitu_data.stddev method=stddev

It should be possible to do this without sql_extraction_command with
standard modules only:

v.in.db driver=pg database=my table=ms x=x y=y output=ms
i=1
while [ $i -le 365 ] ; do
     v.extract input=ms output=ms_tmp where="day=$i"
     s.surf.idw input=ms_tmp output=rain_$DAY field=xxx # or v.surf.rst
     i=`expr $i + 1`
done

Radim




More information about the grass-user mailing list