Skip to content

Commit b6334d2

Browse files
gshiromaGustavo H Shiromagmgunter
authored andcommitted
Add polarimetric symmetrization to the GCOV workflow (#752)
* add polsar namespace and symmetrizeCrossPolChannels() function * add python bindings * updating compiling and linking files * add c++ unitest * fix polsar import * make complex multiply more general * update GCOV SAS workflow * update GCOV YAML defaults * update GCOV YAML schema * add python unitest * substitute unitest extension .rdr with .bin * add python test to CMakeLists.txt * update calculation of nblocks and add docstrings * update calculation of nblocks and add docstrings (2) * update directory for unitest files * merge develop into update_gcov_projection (2) * Update cxx/isce3/polsar/symmetrize.h Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update tests/cxx/isce3/polsar/symmetrize.cpp Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update cxx/isce3/polsar/symmetrize.cpp Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update python/extensions/pybind_isce3/polsar/symmetrize.cpp Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update python/packages/pybind_nisar/workflows/gcov.py Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update tests/python/extensions/pybind/polsar/symmetrize.py Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update tests/python/extensions/pybind/polsar/symmetrize.py Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update tests/cxx/isce3/polsar/symmetrize.cpp Co-Authored-By: Geoffrey M Gunter <[email protected]> * Update tests/cxx/isce3/polsar/symmetrize.cpp Co-Authored-By: Geoffrey M Gunter <[email protected]> * make non-public local functions static * remove unnecessary white spaces * improve type conversions * add band arguments for cross-pol channels; improve docstrings * improve comments in gcov.py * improve type aliases in symmetrize unitest * move memory block mode to cxx/isce3/core/Constants.h * improve comments to memory block mode in the Y-direction * Improve enum memoryModeBlockY docstrings * pass std::function by const reference * substitute enum with enum class * update pybind11 enum class memory_mode_block_y docstrings * Update cxx/isce3/geometry/RTC.cpp Co-authored-by: Geoffrey M Gunter <[email protected]> * improve docstrings, add output_raster_band * add output_raster_band (2), improve dtype validation * improve comments in runconfig YAML default and schema * Update cxx/isce3/polsar/symmetrize.cpp Co-authored-by: Geoffrey M Gunter <[email protected]> * rename memoryModeBlockY to MemoryModeBlockY, improve enum class docstrings * fix typo in python/extensions/pybind_isce3/polsar/symmetrize.cpp * Update cxx/isce3/core/Constants.h Co-authored-by: Geoffrey M Gunter <[email protected]> * add band validation * remove unused line * improve symmetrizeCrossPolChannels() docstrings to explain kAutoBlocksY * Update share/nisar/defaults/gcov.yaml Co-authored-by: Geoffrey M Gunter <[email protected]> * remove k prefix from enum class MemoryModeBlockY * run "git-clang-format develop" Co-authored-by: Gustavo H Shiroma <[email protected]> Co-authored-by: Geoffrey M Gunter <[email protected]>
1 parent 8dc3f2a commit b6334d2

File tree

24 files changed

+625
-111
lines changed

24 files changed

+625
-111
lines changed

cxx/isce3/Headers.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ math/Bessel.h
135135
math/ComplexMultiply.h
136136
math/Sinc.h
137137
math/Sinc.icc
138+
polsar/symmetrize.h
138139
product/forward.h
139140
product/GeoGridParameters.h
140141
product/Metadata.h

cxx/isce3/Sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ matchtemplate/ampcor/correlators/tgtStats.cpp
7171
matchtemplate/ampcor/dom/Raster.cc
7272
matchtemplate/ampcor/dom/SLC.cc
7373
math/Bessel.cpp
74+
polsar/symmetrize.cpp
7475
product/GeoGridParameters.cpp
7576
product/Product.cpp
7677
product/RadarGridParameters.cpp

cxx/isce3/core/Constants.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ const int SINC_LEN = 8;
3434
const int SINC_ONE = 9;
3535
const int SINC_SUB = 8192;
3636

37+
/** Enumeration type to indicate memory management for processes
38+
* that require block processing in the Y direction
39+
*/
40+
enum class MemoryModeBlockY {
41+
AutoBlocksY, /**< auto mode (default value is defined by the
42+
module that is being executed) */
43+
SingleBlockY, /**< use a single block (disable block mode) */
44+
MultipleBlocksY, /**< use multiple blocks (enable block mode) */
45+
};
46+
3747
/** Convert string to dataInterpMethod */
3848
dataInterpMethod parseDataInterpMethod(const std::string & method);
3949

cxx/isce3/geocode/GeocodeCov.cpp

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ void Geocode<T>::geocodeAreaProj(
16181618

16191619
if (!std::isnan(min_nlooks))
16201620
info << "nlooks min: " << min_nlooks << pyre::journal::newline;
1621-
1621+
16221622
// create projection based on epsg code
16231623
std::unique_ptr<isce3::core::ProjectionBase> proj(
16241624
isce3::core::createProj(_epsgOut));
@@ -1632,13 +1632,13 @@ void Geocode<T>::geocodeAreaProj(
16321632
geogrid_upsampling, flag_upsample_radar_grid, dem_interp_method,
16331633
&offset_y, &offset_x, &grid_size_y, &grid_size_x);
16341634

1635-
isce3::product::RadarGridParameters radar_grid_cropped =
1636-
radar_grid.offsetAndResize(offset_y, offset_x, grid_size_y,
1637-
grid_size_x);
1635+
isce3::product::RadarGridParameters radar_grid_cropped =
1636+
radar_grid.offsetAndResize(
1637+
offset_y, offset_x, grid_size_y, grid_size_x);
16381638

16391639
bool is_radar_grid_single_block =
16401640
(geocode_memory_mode !=
1641-
geocodeMemoryMode::BLOCKS_GEOGRID_AND_RADARGRID);
1641+
geocodeMemoryMode::BLOCKS_GEOGRID_AND_RADARGRID);
16421642

16431643
// RTC
16441644
isce3::io::Raster* rtc_raster = nullptr;
@@ -1688,34 +1688,33 @@ void Geocode<T>::geocodeAreaProj(
16881688
else
16891689
rtc_memory_mode = isce3::geometry::RTC_BLOCKS_GEOGRID;
16901690

1691-
computeRtc(dem_raster, *rtc_raster, radar_grid_cropped, _orbit, _doppler,
1692-
_geoGridStartY, _geoGridSpacingY, _geoGridStartX,
1691+
computeRtc(dem_raster, *rtc_raster, radar_grid_cropped, _orbit,
1692+
_doppler, _geoGridStartY, _geoGridSpacingY, _geoGridStartX,
16931693
_geoGridSpacingX, _geoGridLength, _geoGridWidth, _epsgOut,
16941694
input_terrain_radiometry, output_terrain_radiometry,
16951695
rtc_area_mode, rtc_algorithm, rtc_geogrid_upsampling,
16961696
rtc_min_value_db, radar_grid_nlooks, nullptr, nullptr,
1697-
nullptr, rtc_memory_mode, dem_interp_method, _threshold,
1697+
nullptr, rtc_memory_mode, dem_interp_method, _threshold,
16981698
_numiter, 1.0e-8);
16991699
} else {
17001700
info << "reading pre-computed RTC..." << pyre::journal::newline;
17011701
rtc_raster = input_rtc;
17021702
}
17031703

17041704
if (is_radar_grid_single_block) {
1705-
rtc_area.resize(radar_grid_cropped.length(), radar_grid_cropped.width());
1706-
rtc_raster->getBlock(rtc_area.data(), 0, 0, radar_grid_cropped.width(),
1707-
radar_grid_cropped.length(), 1);
1705+
rtc_area.resize(
1706+
radar_grid_cropped.length(), radar_grid_cropped.width());
1707+
rtc_raster->getBlock(rtc_area.data(), 0, 0,
1708+
radar_grid_cropped.width(), radar_grid_cropped.length(), 1);
17081709
}
17091710
}
17101711

1711-
1712-
1713-
17141712
// number of bands in the input raster
17151713
info << "nbands: " << nbands << pyre::journal::newline;
17161714

17171715
info << "radar grid width: " << radar_grid_cropped.width()
1718-
<< ", length: " << radar_grid_cropped.length() << pyre::journal::newline;
1716+
<< ", length: " << radar_grid_cropped.length()
1717+
<< pyre::journal::newline;
17191718

17201719
info << "geogrid upsampling: " << geogrid_upsampling << pyre::journal::newline;
17211720

@@ -1765,15 +1764,14 @@ void Geocode<T>::geocodeAreaProj(
17651764

17661765
// read slant-range image
17671766
if (std::is_same<T, T_out>::value || nbands_off_diag_terms > 0) {
1768-
_getUpsampledBlock<T, T>(
1769-
rdrDataT, input_raster, offset_x, offset_y,
1770-
radar_grid_cropped.width(), radar_grid_cropped.length(),
1771-
flag_upsample_radar_grid, geocode_memory_mode, info);
1767+
_getUpsampledBlock<T, T>(rdrDataT, input_raster, offset_x, offset_y,
1768+
radar_grid_cropped.width(), radar_grid_cropped.length(),
1769+
flag_upsample_radar_grid, geocode_memory_mode, info);
17721770
} else {
1773-
_getUpsampledBlock<T, T_out>(
1774-
rdrData, input_raster, offset_x, offset_y,
1775-
radar_grid_cropped.width(), radar_grid_cropped.length(),
1776-
flag_upsample_radar_grid, geocode_memory_mode, info);
1771+
_getUpsampledBlock<T, T_out>(rdrData, input_raster, offset_x,
1772+
offset_y, radar_grid_cropped.width(),
1773+
radar_grid_cropped.length(), flag_upsample_radar_grid,
1774+
geocode_memory_mode, info);
17771775
}
17781776
}
17791777
int block_size_x, nblocks_x, block_size_with_upsampling_x;
@@ -1809,41 +1807,43 @@ void Geocode<T>::geocodeAreaProj(
18091807

18101808
info << "starting geocoding" << pyre::journal::endl;
18111809
if (!std::is_same<T, T_out>::value && nbands_off_diag_terms == 0) {
1812-
_Pragma("omp parallel for schedule(dynamic)")
1813-
for (int block_y = 0; block_y < nblocks_y; ++block_y) {
1810+
_Pragma("omp parallel for schedule(dynamic)") for (int block_y = 0;
1811+
block_y < nblocks_y;
1812+
++block_y)
1813+
{
18141814
for (int block_x = 0; block_x < nblocks_x; ++block_x) {
1815-
_runBlock<T_out, T_out>(
1816-
radar_grid_cropped, is_radar_grid_single_block, rdrData,
1817-
block_size_y, block_size_with_upsampling_y, block_y,
1818-
block_size_x, block_size_with_upsampling_x, block_x,
1819-
numdone, progress_block, geogrid_upsampling, nbands,
1815+
_runBlock<T_out, T_out>(radar_grid_cropped,
1816+
is_radar_grid_single_block, rdrData, block_size_y,
1817+
block_size_with_upsampling_y, block_y, block_size_x,
1818+
block_size_with_upsampling_x, block_x, numdone,
1819+
progress_block, geogrid_upsampling, nbands,
18201820
nbands_off_diag_terms, dem_interp_method, dem_raster,
18211821
out_off_diag_terms, out_geo_rdr, out_geo_dem,
18221822
out_geo_nlooks, out_geo_rtc, proj.get(), flag_apply_rtc,
18231823
rtc_raster, input_raster, offset_y, offset_x,
1824-
output_raster, rtc_area,
1825-
rtc_min_value, abs_cal_factor, clip_min, clip_max,
1826-
min_nlooks, radar_grid_nlooks, flag_upsample_radar_grid,
1827-
geocode_memory_mode, info);
1824+
output_raster, rtc_area, rtc_min_value, abs_cal_factor,
1825+
clip_min, clip_max, min_nlooks, radar_grid_nlooks,
1826+
flag_upsample_radar_grid, geocode_memory_mode, info);
18281827
}
18291828
}
18301829
} else {
1831-
_Pragma("omp parallel for schedule(dynamic)")
1832-
for (int block_y = 0; block_y < nblocks_y; ++block_y) {
1830+
_Pragma("omp parallel for schedule(dynamic)") for (int block_y = 0;
1831+
block_y < nblocks_y;
1832+
++block_y)
1833+
{
18331834
for (int block_x = 0; block_x < nblocks_x; ++block_x) {
1834-
_runBlock<T, T_out>(
1835-
radar_grid_cropped, is_radar_grid_single_block, rdrDataT,
1836-
block_size_y, block_size_with_upsampling_y, block_y,
1837-
block_size_x, block_size_with_upsampling_x, block_x,
1838-
numdone, progress_block, geogrid_upsampling, nbands,
1835+
_runBlock<T, T_out>(radar_grid_cropped,
1836+
is_radar_grid_single_block, rdrDataT, block_size_y,
1837+
block_size_with_upsampling_y, block_y, block_size_x,
1838+
block_size_with_upsampling_x, block_x, numdone,
1839+
progress_block, geogrid_upsampling, nbands,
18391840
nbands_off_diag_terms, dem_interp_method, dem_raster,
18401841
out_off_diag_terms, out_geo_rdr, out_geo_dem,
18411842
out_geo_nlooks, out_geo_rtc, proj.get(), flag_apply_rtc,
18421843
rtc_raster, input_raster, offset_y, offset_x,
1843-
output_raster, rtc_area,
1844-
rtc_min_value, abs_cal_factor, clip_min, clip_max,
1845-
min_nlooks, radar_grid_nlooks, flag_upsample_radar_grid,
1846-
geocode_memory_mode, info);
1844+
output_raster, rtc_area, rtc_min_value, abs_cal_factor,
1845+
clip_min, clip_max, min_nlooks, radar_grid_nlooks,
1846+
flag_upsample_radar_grid, geocode_memory_mode, info);
18471847
}
18481848
}
18491849
}
@@ -2333,31 +2333,28 @@ void Geocode<T>::_runBlock(
23332333
out_geo_dem_array, out_geo_nlooks, out_geo_nlooks_array,
23342334
out_geo_rtc, out_geo_rtc_array);
23352335

2336-
isce3::core::Matrix<T_out> geoDataBlock(this_block_size_y,
2337-
this_block_size_x);
2336+
isce3::core::Matrix<T_out> geoDataBlock(
2337+
this_block_size_y, this_block_size_x);
23382338

23392339
// fill both matrices with NaN
23402340
geoDataBlock.fill(nan_t_out);
23412341

23422342
for (int band = 0; band < nbands; ++band) {
23432343
_Pragma("omp critical")
23442344
{
2345-
output_raster.setBlock(
2346-
geoDataBlock.data(), block_x * block_size_x,
2347-
block_y * block_size_y, this_block_size_x,
2348-
this_block_size_y, band + 1);
2345+
output_raster.setBlock(geoDataBlock.data(),
2346+
block_x * block_size_x, block_y * block_size_y,
2347+
this_block_size_x, this_block_size_y, band + 1);
23492348
}
23502349
}
23512350

2352-
23532351
if (nbands_off_diag_terms > 0) {
23542352
for (int band = 0; band < nbands_off_diag_terms; ++band) {
23552353
_Pragma("omp critical")
23562354
{
2357-
out_off_diag_terms->setBlock(
2358-
geoDataBlock.data(), block_x * block_size_x,
2359-
block_y * block_size_y, this_block_size_x,
2360-
this_block_size_y, band + 1);
2355+
out_off_diag_terms->setBlock(geoDataBlock.data(),
2356+
block_x * block_size_x, block_y * block_size_y,
2357+
this_block_size_x, this_block_size_y, band + 1);
23612358
}
23622359
}
23632360
}
@@ -2371,16 +2368,14 @@ void Geocode<T>::_runBlock(
23712368

23722369
if (flag_apply_rtc) {
23732370

2374-
rtc_area_block.resize(radar_grid_block.length(),
2375-
radar_grid_block.width());
2371+
rtc_area_block.resize(
2372+
radar_grid_block.length(), radar_grid_block.width());
23762373
rtc_raster->getBlock(rtc_area_block.data(), offset_x, offset_y,
2377-
radar_grid_block.width(),
2378-
radar_grid_block.length(), 1);
2374+
radar_grid_block.width(), radar_grid_block.length(), 1);
23792375
}
23802376

2381-
_getUpsampledBlock<T, T2>(
2382-
rdrDataBlock, input_raster, offset_x + raster_offset_x,
2383-
offset_y + raster_offset_y,
2377+
_getUpsampledBlock<T, T2>(rdrDataBlock, input_raster,
2378+
offset_x + raster_offset_x, offset_y + raster_offset_y,
23842379
radar_grid_block.width(), radar_grid_block.length(),
23852380
flag_upsample_radar_grid, geocode_memory_mode, info);
23862381
}
@@ -2452,8 +2447,7 @@ void Geocode<T>::_runBlock(
24522447

24532448
const int jj = block_x * block_size_with_upsampling_x + j;
24542449

2455-
_Pragma("omp atomic")
2456-
numdone++;
2450+
_Pragma("omp atomic") numdone++;
24572451
if (numdone % progress_block == 0)
24582452
_Pragma("omp critical")
24592453
{

cxx/isce3/geocode/GeocodeCov.h

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ enum geocodeMemoryMode {
3737
BLOCKS_GEOGRID_AND_RADARGRID = 3
3838
};
3939

40+
constexpr static long long DEFAULT_MAX_BLOCK_SIZE = 1 << 29; // 512MB
41+
/** Compute the number of blocks and their length for block processing
42+
* in the length direction
43+
*
44+
* @param[in] array_length Length of the data to be processed
45+
* @param[in] array_width Width of the data to be processed
46+
* @param[in] nbands Number of the bands to be processed
47+
* @param[in] type_size Type size of the data to be processed
48+
* @param[in] channel Pyre info channel
49+
* @param[out] block_length Block length
50+
* @param[out] nblock_y Number of blocks in the Y direction
51+
* @param[in] max_block_size Maximum block size in Bytes (per thread)
52+
*/
53+
void getBlocksNumberAndLength(const int array_length, const int array_width,
54+
const int nbands = 1,
55+
const size_t type_size = 4, // Float32
56+
pyre::journal::info_t* channel = nullptr, int* block_length = nullptr,
57+
int* nblock_y = nullptr,
58+
const long long max_block_size = DEFAULT_MAX_BLOCK_SIZE);
59+
4060
template<class T>
4161
class Geocode {
4262
public:
@@ -309,26 +329,6 @@ class Geocode {
309329
void updateGeoGrid(const isce3::product::RadarGridParameters& radar_grid,
310330
isce3::io::Raster& dem_raster);
311331

312-
constexpr static long long DEFAULT_MAX_BLOCK_SIZE = 1 << 29; // 512MB
313-
/** Compute the number of blocks and their length for block processing
314-
* in the length direction
315-
*
316-
* @param[in] array_length Length of the data to be processed
317-
* @param[in] array_width Width of the data to be processed
318-
* @param[in] nbands Number of the bands to be processed
319-
* @param[in] type_size Type size of the data to be processed
320-
* @param[in] channel Pyre info channel
321-
* @param[out] block_length Block length
322-
* @param[out] nblock_y Number of blocks in the Y direction
323-
* @param[in] max_block_size Maximum block size in Bytes (per thread)
324-
*/
325-
void getBlocksNumberAndLength(const int array_length, const int array_width,
326-
const int nbands = 1,
327-
const size_t type_size = 4, // Float32
328-
pyre::journal::info_t* channel = nullptr,
329-
int* block_length = nullptr, int* nblock_y = nullptr,
330-
const long long max_block_size = DEFAULT_MAX_BLOCK_SIZE);
331-
332332
// Get/set data interpolator
333333
isce3::core::dataInterpMethod dataInterpolator() const
334334
{
@@ -450,33 +450,27 @@ class Geocode {
450450
isce3::geometry::DEMInterpolator& dem_interp);
451451

452452
template<class T2, class T_out>
453-
void _runBlock(
454-
const isce3::product::RadarGridParameters& radar_grid,
453+
void _runBlock(const isce3::product::RadarGridParameters& radar_grid,
455454
bool is_radar_grid_single_block,
456455
std::vector<std::unique_ptr<isce3::core::Matrix<T2>>>& rdrData,
457456
int block_size_y, int block_size_with_upsampling_y, int block_y,
458457
int block_size_x, int block_size_with_upsampling_x, int block_x,
459-
long long& numdone, const long long& progress_block,
460-
double geogrid_upsampling,
461-
int nbands, int nbands_off_diag_terms,
458+
long long& numdone, const long long& progress_block,
459+
double geogrid_upsampling, int nbands, int nbands_off_diag_terms,
462460
isce3::core::dataInterpMethod dem_interp_method,
463461
isce3::io::Raster& dem_raster,
464462
isce3::io::Raster* out_off_diag_terms,
465-
isce3::io::Raster* out_geo_rdr,
466-
isce3::io::Raster* out_geo_dem,
463+
isce3::io::Raster* out_geo_rdr, isce3::io::Raster* out_geo_dem,
467464
isce3::io::Raster* out_geo_nlooks, isce3::io::Raster* out_geo_rtc,
468-
isce3::core::ProjectionBase* proj,
469-
bool flag_apply_rtc, isce3::io::Raster* rtc_raster,
470-
isce3::io::Raster& input_raster,
465+
isce3::core::ProjectionBase* proj, bool flag_apply_rtc,
466+
isce3::io::Raster* rtc_raster, isce3::io::Raster& input_raster,
471467
int raster_offset_y, int raster_offset_x,
472468
isce3::io::Raster& output_raster,
473-
isce3::core::Matrix<float>& rtc_area,
474-
float rtc_min_value,
469+
isce3::core::Matrix<float>& rtc_area, float rtc_min_value,
475470
double abs_cal_factor, float clip_min, float clip_max,
476471
float min_nlooks, float radar_grid_nlooks,
477472
bool flag_upsample_radar_grid,
478-
geocodeMemoryMode geocode_memory_mode,
479-
pyre::journal::info_t& info);
473+
geocodeMemoryMode geocode_memory_mode, pyre::journal::info_t& info);
480474

481475
void _loadDEM(isce3::io::Raster& demRaster,
482476
isce3::geometry::DEMInterpolator& demInterp,

cxx/isce3/math/ComplexMultiply.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
#include <complex>
44

5-
/** Promotion rules so T * complex<U> works for {T,U} in {float,double}. */
65
namespace isce3 { namespace math { namespace complex_multiply {
76

8-
inline auto operator*(float t, std::complex<double> u) {
9-
return double(t) * u;
7+
template<typename T1, typename T2>
8+
auto operator*(const std::complex<T1>& lhs, const T2& rhs)
9+
{
10+
using U = typename std::common_type_t<T1, T2>;
11+
return std::complex<U>(lhs) * U(rhs);
1012
}
1113

12-
inline auto operator*(std::complex<double> t, float u) {
13-
return t * double(u);
14+
template<typename T1, typename T2>
15+
auto operator*(const T1& lhs, const std::complex<T2>& rhs)
16+
{
17+
using U = typename std::common_type_t<T1, T2>;
18+
return U(lhs) * std::complex<U>(rhs);
1419
}
1520

1621
}}}

0 commit comments

Comments
 (0)