Skip to content

Commit 919ed1d

Browse files
gshiromagmgunter
authored andcommitted
Assign NaN to invalid pixel values during geocoding (#942)
* update the GeocodeSlc module to assign NaN to invalid pixels * update the GeocodeInterp module to assign NaN to invalid pixels in the RTC ANF map * set _FillValue to NaN so that NETCDF drivers assign NaN to invalid pixels * only assign nan to _FillValue if dtype is float (_FillValue = nan) or complex (_FillValue = nan + 0j) * substitute complex nan with nan + 1j * nan * Update python/packages/nisar/workflows/h5_prep.py Co-authored-by: Geoffrey M Gunter <[email protected]> Co-authored-by: Geoffrey M Gunter <[email protected]>
1 parent 71b1598 commit 919ed1d

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

cxx/isce3/geocode/GeocodeCov.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ inline void Geocode<T>::_interpolate(
760760
// (NaN, NaN)
761761
using T_out_real = typename isce3::real<T_out>::type;
762762
geoDataBlock(i, j) *= std::numeric_limits<T_out_real>::quiet_NaN();
763+
if (flag_apply_rtc && out_geo_rtc != nullptr) {
764+
out_geo_rtc_array(i, j) = std::numeric_limits<float>::quiet_NaN();
765+
}
763766
continue;
764767
}
765768

@@ -774,7 +777,6 @@ inline void Geocode<T>::_interpolate(
774777
rtc_area(int(rdrY + azimuthFirstLine), int(rdrX + rangeFirstPixel));
775778
val /= std::sqrt(rtc_value);
776779
if (out_geo_rtc != nullptr) {
777-
#pragma omp atomic write
778780
out_geo_rtc_array(i, j) = rtc_value;
779781
}
780782
}

cxx/isce3/geocode/interpolate.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ void isce3::geocode::interpolate(
3232
const double fracX = rdrX - intX;
3333
const double fracY = rdrY - intY;
3434

35-
if ((intX < chipHalf) || (intX >= (inWidth - chipHalf)))
35+
if ((intX < chipHalf) || (intX >= (inWidth - chipHalf))) {
36+
geoDataBlock(i, j) *= std::numeric_limits<float>::quiet_NaN();
3637
continue;
37-
if ((intY < chipHalf) || (intY >= (inLength - chipHalf)))
38+
}
39+
if ((intY < chipHalf) || (intY >= (inLength - chipHalf))) {
40+
geoDataBlock(i, j) *= std::numeric_limits<float>::quiet_NaN();
3841
continue;
42+
}
3943

4044
// Slant Range at the current output pixel
4145
const double rng =
@@ -46,8 +50,10 @@ void isce3::geocode::interpolate(
4650
const double az = radarGrid.sensingStart() +
4751
radarY[i * width + j] / radarGrid.prf();
4852

49-
if (not dopplerLUT.contains(az, rng))
53+
if (not dopplerLUT.contains(az, rng)) {
54+
geoDataBlock(i, j) *= std::numeric_limits<float>::quiet_NaN();
5055
continue;
56+
}
5157

5258
// Evaluate Doppler at current range and azimuth time
5359
const double dop =

python/packages/nisar/workflows/gcov.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ def _save_hdf5_dataset(ds_filename, h5py_obj, root_path,
536536

537537
if fill_value is not None:
538538
dset.attrs.create('_FillValue', data=fill_value)
539+
elif 'cfloat' in gdal.GetDataTypeName(raster.datatype()).lower():
540+
dset.attrs.create('_FillValue', data=np.nan + 1j * np.nan)
541+
elif 'float' in gdal.GetDataTypeName(raster.datatype()).lower():
542+
dset.attrs.create('_FillValue', data=np.nan)
539543

540544
if stats_vector is not None:
541545
stats_obj = stats_vector[band]

python/packages/nisar/workflows/h5_prep.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ def _get_raster_from_hdf5_ds(group, ds_name, dtype, shape,
12141214
del group[ds_name]
12151215

12161216
# create dataset
1217-
dset = group.create_dataset(ds_name, dtype=np.float64, shape=shape)
1217+
dset = group.create_dataset(ds_name, dtype=dtype, shape=shape)
12181218

12191219
if zds is not None:
12201220
dset.dims[0].attach_scale(zds)
@@ -1239,6 +1239,10 @@ def _get_raster_from_hdf5_ds(group, ds_name, dtype, shape,
12391239

12401240
if fill_value is not None:
12411241
dset.attrs.create('_FillValue', data=fill_value)
1242+
elif np.issubdtype(dtype, np.floating):
1243+
dset.attrs.create('_FillValue', data=np.nan)
1244+
elif np.issubdtype(dtype, np.complexfloating):
1245+
dset.attrs.create('_FillValue', data=np.nan + 1j * np.nan)
12421246

12431247
if valid_min is not None:
12441248
dset.attrs.create('valid_min', data=valid_min)

0 commit comments

Comments
 (0)