Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

xy2ij.sh 2.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  1. #!/usr/bin/env bash
  2. #
  3. # Test to make sure the (x,y) <--> (i,j) macros work correctly
  4. # We use -R0/5/0/5 -I1 for pixel and gridline registrations
  5. # Points are prepared that will land in various tiles, some will
  6. # fall exactly on tile boundaries. One point will fall outside -R
  7. # but should be considered for the gridline registrated case.
  8. ps=xy2ij.ps
  9. # Set up the four answer files:
  10. cat << EOF > pixel_ij_answer.txt
  11. 0.5 4.5 0
  12. 4.5 4.5 6
  13. 0.5 3.5 4
  14. 2.5 3.5 5
  15. 4.5 3.5 8
  16. 0.5 2.5 3
  17. 2.5 2.5 7
  18. 1.5 1.5 2
  19. 2.5 1.5 9
  20. 0.5 0.5 1
  21. EOF
  22. cat << EOF > pixel_xy_answer.txt
  23. 0 4.1 0
  24. 4.67 4 6
  25. 0.69 3.33 4
  26. 2 3.3 5
  27. 5 3.35 8
  28. 0.25 2.25 3
  29. 3 2 7
  30. 1.33 1.8 2
  31. 3 1.3 9
  32. 0.65 0.7 1
  33. EOF
  34. cat << EOF > pixel.txt
  35. 0.0 4.1 0
  36. 0.65 0.7 1
  37. 1.33 1.8 2
  38. 0.25 2.25 3
  39. 0.69 3.33 4
  40. 2.0 3.3 5
  41. 4.67 4.0 6
  42. 3.0 2.0 7
  43. 5.0 3.35 8
  44. 3.0 1.3 9
  45. EOF
  46. cat << EOF > grid_ij_answer.txt
  47. 0 4 0
  48. 1 4 4
  49. 2 4 5
  50. 4 4 6
  51. 1 3 3
  52. 2 3 9
  53. 4 2 7
  54. 2 1 2
  55. 1 0 1
  56. EOF
  57. cat << EOF > grid_xy_answer.txt
  58. -0.5 4.1 0
  59. 1.19 3.83 4
  60. 2.5 3.8 5
  61. 4.167 3.5 6
  62. 0.75 2.75 3
  63. 1.5 2.8 9
  64. 3.5 2.5 7
  65. 1.83 1.3 2
  66. 1.15 0.2 1
  67. EOF
  68. # blockman uses GMT_x|y_to_i|j to determine which tiles
  69. # Using -C gives tile centers via (i,j) -> (x,y)
  70. gmt blockmean -R0/5/0/5 -I1 -r -C pixel.txt > pixel_ij.txt
  71. gmt blockmean -R0/5/0/5 -I1 -r pixel.txt > pixel_xy.txt
  72. # Do gridline registration with a similar data set (mostly offset by 0.5)
  73. cat << EOF > grid.txt
  74. -0.5 4.1 0
  75. 1.15 0.2 1
  76. 1.83 1.3 2
  77. 0.75 2.75 3
  78. 1.19 3.83 4
  79. 2.5 3.8 5
  80. 4.167 3.5 6
  81. 3.5 2.5 7
  82. 5.5 3.35 8
  83. 1.5 2.8 9
  84. EOF
  85. gmt blockmean -R0/5/0/5 -I1 -C grid.txt > grid_ij.txt
  86. gmt blockmean -R0/5/0/5 -I1 grid.txt > grid_xy.txt
  87. diff pixel_xy.txt pixel_xy_answer.txt --strip-trailing-cr > fail
  88. diff pixel_ij.txt pixel_ij_answer.txt --strip-trailing-cr >> fail
  89. diff grid_xy.txt grid_xy_answer.txt --strip-trailing-cr >> fail
  90. diff grid_ij.txt grid_ij_answer.txt --strip-trailing-cr >> fail
  91. # Connect the original point and the corresponding tile center
  92. paste pixel_xy.txt pixel_ij.txt | $AWK '{if (NF == 6) printf ">\n%s\t%s\n%s\t%s\n", $1, $2, $4, $5}' \
  93. | gmt psxy -R0/5/0/5 -JX4.5i -P -B1g1 -BWSne -Wdefault -K -Y0.5i -X2i > $ps
  94. # Plot and label the points
  95. gmt psxy -R -J pixel.txt -Sc0.125 -Gwhite -Wfaint -O -K -N >> $ps
  96. gmt pstext -R -J pixel.txt -F+f8p -O -K -N >> $ps
  97. gmt psxy -R -J pixel_ij.txt -Sc0.15 -Gblack -O -K -N >> $ps
  98. gmt pstext -R -J pixel_ij.txt -F+f8p,white -O -K -N >> $ps
  99. # Now do the same with gridline orientation
  100. gmt psbasemap -R0.5/5.5/0.5/5.5 -J -O -Bg1 -K -Y4.7 >> $ps
  101. paste grid_xy.txt grid_ij.txt | $AWK '{if (NF == 6) printf ">\n%s\t%s\n%s\t%s\n", $1, $2, $4, $5}' \
  102. | gmt psxy -R0/5/0/5 -J -O -B1 -BWsne -Wdefault -K >> $ps
  103. gmt psxy -R -J grid.txt -Sc0.125 -Gwhite -Wfaint -O -K -N >> $ps
  104. gmt pstext -R -J grid.txt -F+f8p -O -K -N >> $ps
  105. gmt psxy -R -J grid_ij.txt -Sc0.15 -Gblack -O -K -N >> $ps
  106. gmt pstext -R -J grid_ij.txt -F+f8p,white -O -N >> $ps
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...