Commit dd907b8
authored
* Fix COG overview generation poisoned by nodata sentinel (#1613)
The NaN-to-sentinel rewrite in to_geotiff and write_geotiff_gpu ran
before _make_overview / make_overview_gpu, so np.nanmean and the GPU
counterparts saw the sentinel as a finite value and biased every
overview pixel. A raster with NaN pixels and nodata=-9999 produced
overview cells like -4998.75 where the correct nan-aware mean was 1.5.
Thread a nodata kwarg through the reducers so they mask the sentinel
back to NaN before aggregating. The writer's overview loop passes
nodata in, then rewrites any all-sentinel cells (which surface as NaN
from the reducer) back to the sentinel for the on-disk pyramid.
CPU and GPU paths both fixed. New regression tests cover mean / min /
max / median, partial-NaN blocks, all-NaN blocks, integer dtype
passthrough, and CPU-GPU agreement.
* Address Copilot review on #1618
- Drop redundant np.isfinite gate in _block_reduce_2d (CPU + GPU) so
nodata=+/-inf is masked back to NaN like a finite sentinel, matching
the upstream NaN->sentinel rewrite gate (`not np.isnan(nodata)` used
at _writer.py:1171,1525,1620).
- Suppress RuntimeWarning from nanmean/nanmin/nanmax/nanmedian on
all-NaN blocks locally; the all-NaN output is the desired signal
that the overview loop rewrites to the sentinel, so the warning was
noise on every nodata-border COG write.
- Fix the comment above the overview loop: NaN from an all-sentinel
reduction is rewritten back to the sentinel before _write_tiled /
_write_stripped runs, not serialised as NaN.
- Add regression tests covering nodata=inf (CPU + GPU) and the
warning-suppression contract for all-NaN blocks.
1 parent 4c8a5d2 commit dd907b8
5 files changed
Lines changed: 433 additions & 28 deletions
File tree
- .claude
- xrspatial/geotiff
- tests
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2919 | 2919 | | |
2920 | 2920 | | |
2921 | 2921 | | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
2922 | 2929 | | |
2923 | 2930 | | |
2924 | | - | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
2925 | 2941 | | |
2926 | 2942 | | |
2927 | 2943 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2891 | 2891 | | |
2892 | 2892 | | |
2893 | 2893 | | |
2894 | | - | |
2895 | | - | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
2896 | 2903 | | |
| 2904 | + | |
2897 | 2905 | | |
2898 | 2906 | | |
2899 | 2907 | | |
| |||
2908 | 2916 | | |
2909 | 2917 | | |
2910 | 2918 | | |
2911 | | - | |
| 2919 | + | |
2912 | 2920 | | |
2913 | 2921 | | |
2914 | 2922 | | |
2915 | 2923 | | |
2916 | 2924 | | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
2917 | 2938 | | |
2918 | 2939 | | |
2919 | 2940 | | |
| |||
2936 | 2957 | | |
2937 | 2958 | | |
2938 | 2959 | | |
2939 | | - | |
| 2960 | + | |
2940 | 2961 | | |
2941 | 2962 | | |
2942 | 2963 | | |
| |||
2946 | 2967 | | |
2947 | 2968 | | |
2948 | 2969 | | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
2949 | 2976 | | |
2950 | 2977 | | |
2951 | 2978 | | |
| |||
2955 | 2982 | | |
2956 | 2983 | | |
2957 | 2984 | | |
2958 | | - | |
| 2985 | + | |
2959 | 2986 | | |
2960 | 2987 | | |
2961 | | - | |
| 2988 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
143 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
144 | 154 | | |
145 | 155 | | |
146 | 156 | | |
| |||
177 | 187 | | |
178 | 188 | | |
179 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
180 | 208 | | |
181 | 209 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
196 | 235 | | |
197 | 236 | | |
198 | 237 | | |
199 | 238 | | |
200 | 239 | | |
201 | 240 | | |
202 | | - | |
| 241 | + | |
| 242 | + | |
203 | 243 | | |
204 | 244 | | |
205 | 245 | | |
| |||
209 | 249 | | |
210 | 250 | | |
211 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
212 | 258 | | |
213 | 259 | | |
214 | 260 | | |
215 | 261 | | |
216 | 262 | | |
217 | 263 | | |
218 | 264 | | |
219 | | - | |
| 265 | + | |
| 266 | + | |
220 | 267 | | |
221 | | - | |
| 268 | + | |
222 | 269 | | |
223 | 270 | | |
224 | 271 | | |
| |||
1100 | 1147 | | |
1101 | 1148 | | |
1102 | 1149 | | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
1103 | 1163 | | |
1104 | 1164 | | |
1105 | | - | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
1106 | 1180 | | |
1107 | 1181 | | |
1108 | 1182 | | |
| |||
0 commit comments