test.r3.null.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Tests for r3.null
  3. set -e
  4. set -x
  5. # We set up a specific region in the
  6. # @preprocess step of this test. We generate
  7. # voxel data with r3.mapcalc. The region setting
  8. # should work for UTM and LL test locations
  9. g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
  10. # We create several (float, double, null value) voxel map
  11. # with value = col + row + depth.
  12. r3.mapcalc expr="test_volume_float_1 = float(col() + row() + depth())"
  13. r3.mapcalc expr="test_volume_float_2 = test_volume_float_1"
  14. r3.mapcalc expr="test_volume_double_1 = double(col() + row() + depth())"
  15. r3.mapcalc expr="test_volume_double_2 = test_volume_double_1"
  16. # Add null value information
  17. r3.mapcalc expr="test_volume_float_null_1 = if(row() == 1 || row() == 5, null(), test_volume_float_1)"
  18. r3.mapcalc expr="test_volume_float_null_2 = if(row() == 1 || row() == 5, null(), test_volume_float_1)"
  19. r3.mapcalc expr="test_volume_double_null_1 = if(row() == 1 || row() == 5, null(), test_volume_double_1)"
  20. r3.mapcalc expr="test_volume_double_null_2 = if(row() == 1 || row() == 5, null(), test_volume_double_1)"
  21. # We @test r3.null to set and modify null values.
  22. # Validation is based on @files with @precision=3
  23. # First float maps
  24. r3.null map=test_volume_float_1 setnull=3,4,5
  25. r3.null map=test_volume_float_2 setnull=7,8,9
  26. r3.null map=test_volume_float_null_1 null=-1.5
  27. r3.null map=test_volume_float_null_2 null=-10.5
  28. # Double maps
  29. r3.null map=test_volume_double_1 setnull=3,4,5
  30. r3.null map=test_volume_double_2 setnull=7,8,9
  31. r3.null map=test_volume_double_null_1 null=-1.5
  32. r3.null map=test_volume_double_null_2 null=-10.5
  33. # Commands to export the references
  34. r3.out.ascii dp=3 input=test_volume_float_1 output=test_volume_float_1.txt
  35. r3.out.ascii dp=3 input=test_volume_float_2 output=test_volume_float_2.txt
  36. r3.out.ascii dp=3 input=test_volume_float_null_1 output=test_volume_float_null_1.txt
  37. r3.out.ascii dp=3 input=test_volume_float_null_2 output=test_volume_float_null_2.txt
  38. r3.out.ascii dp=3 input=test_volume_double_1 output=test_volume_double_1.txt
  39. r3.out.ascii dp=3 input=test_volume_double_2 output=test_volume_double_2.txt
  40. r3.out.ascii dp=3 input=test_volume_double_null_1 output=test_volume_double_null_1.txt
  41. r3.out.ascii dp=3 input=test_volume_double_null_2 output=test_volume_double_null_2.txt
  42. # Compare
  43. diff data/test_volume_float_1.ref test_volume_float_1.txt
  44. diff data/test_volume_float_2.ref test_volume_float_2.txt
  45. diff data/test_volume_float_null_1.ref test_volume_float_null_1.txt
  46. diff data/test_volume_float_null_2.ref test_volume_float_null_2.txt
  47. diff data/test_volume_double_1.ref test_volume_double_1.txt
  48. diff data/test_volume_double_2.ref test_volume_double_2.txt
  49. diff data/test_volume_double_null_1.ref test_volume_double_null_1.txt
  50. diff data/test_volume_double_null_2.ref test_volume_double_null_2.txt
  51. # Cleanup
  52. g.remove -f type=raster_3d name=test_volume_float_1
  53. g.remove -f type=raster_3d name=test_volume_float_2
  54. g.remove -f type=raster_3d name=test_volume_float_null_1
  55. g.remove -f type=raster_3d name=test_volume_float_null_2
  56. g.remove -f type=raster_3d name=test_volume_double_1
  57. g.remove -f type=raster_3d name=test_volume_double_2
  58. g.remove -f type=raster_3d name=test_volume_double_null_1
  59. g.remove -f type=raster_3d name=test_volume_double_null_2
  60. rm test_volume_float_1.txt
  61. rm test_volume_float_2.txt
  62. rm test_volume_float_null_1.txt
  63. rm test_volume_float_null_2.txt
  64. rm test_volume_double_1.txt
  65. rm test_volume_double_2.txt
  66. rm test_volume_double_null_1.txt
  67. rm test_volume_double_null_2.txt