test.t.sample.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #1/bin/sh
  2. # This is a test to sample a space time raster dataset with a space time vector dataset
  3. # We need to set a specific region in the
  4. # @preprocess step of this test.
  5. # The region setting should work for UTM and LL test locations
  6. g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
  7. r.mapcalc --o expr="prec_1 = rand(0, 550)"
  8. r.mapcalc --o expr="prec_2 = rand(0, 450)"
  9. r.mapcalc --o expr="prec_3 = rand(0, 320)"
  10. r.mapcalc --o expr="prec_4 = rand(0, 510)"
  11. r.mapcalc --o expr="prec_5 = rand(0, 300)"
  12. r.mapcalc --o expr="prec_6 = rand(0, 650)"
  13. v.random --o -z output=pnts1 n=20 zmin=0 zmax=100 column=height
  14. v.random --o -z output=pnts2 n=20 zmin=0 zmax=100 column=height
  15. v.random --o -z output=pnts3 n=20 zmin=0 zmax=100 column=height
  16. v.random --o -z output=pnts4 n=20 zmin=0 zmax=100 column=height
  17. v.random --o -z output=pnts5 n=20 zmin=0 zmax=100 column=height
  18. v.random --o -z output=pnts6 n=20 zmin=0 zmax=100 column=height
  19. v.random --o -z output=pnts7 n=20 zmin=0 zmax=100 column=height
  20. v.random --o -z output=pnts8 n=20 zmin=0 zmax=100 column=height
  21. n1=`g.tempfile pid=1 -d`
  22. n2=`g.tempfile pid=2 -d`
  23. n3=`g.tempfile pid=3 -d`
  24. cat > "${n1}" << EOF
  25. prec_1
  26. prec_2
  27. prec_3
  28. prec_4
  29. prec_5
  30. prec_6
  31. EOF
  32. cat > "${n2}" << EOF
  33. pnts1|2001-01-01|2001-03-01
  34. pnts2|2001-05-01|2001-07-01
  35. EOF
  36. cat > "${n3}" << EOF
  37. pnts3|2001-01-01|2001-01-05
  38. pnts4|2001-01-05|2001-01-10
  39. pnts5|2001-01-10|2001-01-15
  40. pnts6|2001-01-15|2001-01-20
  41. pnts7|2001-01-20|2001-01-25
  42. pnts8|2001-01-25|2001-01-30
  43. EOF
  44. t.create --o type=strds temporaltype=absolute output=precip_abs0 \
  45. title="A test with raster input files" descr="A test with raster input files"
  46. t.create --o type=stvds temporaltype=absolute output=pnts_abs0 \
  47. title="A test with vector input files" descr="A test with vector input files"
  48. t.create --o type=stvds temporaltype=absolute output=pnts_abs1 \
  49. title="A test with vector input files" descr="A test with vector input files"
  50. t.register --o type=rast -i input=precip_abs0 file="${n1}" start="2001-01-01" increment="1 months"
  51. t.rast.list precip_abs0 -h
  52. t.register --o type=vect input=pnts_abs0 file="${n2}"
  53. t.vect.list pnts_abs0 -h
  54. t.register --o type=vect input=pnts_abs1 file="${n3}"
  55. t.vect.list pnts_abs1 -h
  56. # The @test
  57. t.sample method=equal input=precip_abs0,precip_abs0,precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -cs
  58. t.sample method=during input=precip_abs0,precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -c
  59. t.sample method=overlap input=precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -cs
  60. t.sample method=contain input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
  61. t.sample method=precedes input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
  62. t.sample method=follows input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
  63. t.sample method=precedes,follows input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
  64. t.sample input=precip_abs0 samtype=strds sample=precip_abs0 -cs
  65. # Test with temporal point data
  66. t.register --o type=rast input=precip_abs0 file="${n1}" start="2001-01-01" increment="1 months"
  67. t.rast.list precip_abs0 -h
  68. t.sample input=precip_abs0 samtype=stvds sample=pnts_abs0 -cs
  69. t.sample input=precip_abs0 samtype=stvds sample=pnts_abs1 -cs
  70. t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
  71. t.unregister type=vect maps=pnts1,pnts2,pnts3,pnts4,pnts5,pnts6,pnts7,pnts8
  72. t.remove type=strds input=precip_abs0
  73. t.remove type=stvds input=pnts_abs0,pnts_abs1
  74. g.remove rast=prec_1,prec_2,prec_3,,prec_4,prec_5,prec_6
  75. g.remove vect=pnts1,pnts2,pnts3,pnts4,pnts5,pnts6,pnts7,pnts8