Skip to content

Commit 1034327

Browse files
gshiromaGustavo H Shiromabhawkinsgmgunter
authored andcommitted
Compute statistics (#811)
* add Stats struct and computeRasterStats() function at C++ level * update cmake files with new Stats files * add pybind11 bindings to Stats struct and computeRasterStats() function * add stats computation to the GCOV workflow * add unitest * update complex operations * update RTC block mode enums to follow recently added Stats block mode enums * fix CUDA complex_operations division operator * update enum corresponding to block processing in the Y-direction * remove prefix "k" from enum class memoryModeBlockY() * rename pybind_nisar to nisar * rename pybind_nisar to nisar (2) * merge branch develop into add_stats (2) * merge branch develop into add_stats (3) * rename pybind_nisar to nisar (3) * add computation of complex-valued statistics considering real and imaginary parts separately rather than using polar representation * add stats to GSLC products * add stats to GSLC products (2) * add stats to GUNW products * add stats to RSLC products * update stats for GCOV products * fix standard deviation formula for sample standard deviation * update unitest thresholds * add Python unitest to compare results with NumPy * do not update Raster's metadata statistics * make BlockStats struct private (remove it from the header file) * remove unnecessary include * uncomment complex Stats pybind declaration * fix python docstrings identation * substitute GDAL GetStatistics() with ComputeStatistics() and make error thresholds more strict * remove complexMultiply and make complexOperations lowercase * remove complexMultiply (2) * fix identation in BlockStats * improve Stats docstrings * enable parallelization * move declaration of _compute_stats() before its use * remove file merged by mistake * run stats unitest also for GeocodeCov interp results * move _compute_stats() back to the end of the file * include pyre/journal.h * use templates in CUDA version of ComplexOperations * update docstrings for Stats and StatsRealImag structs * remove remaining ComplexMultiply.h * add docstrings to SLC writer compute_stats() * simplify assignment of block length * separate declaration of real- and complex-valued Stats struct * remove unnecessary if statement from Stats unitest in geocode.cpp * fix CUDA version of ComplexOperations * fix the namespace of CUDA complexOperations, remove operation* from GeocodeHelpers * remove unused variable output_raster_dataset * remove complexOperations from Interp1d.icc * add omp critical to getBlock() to avoid concurrence issues, improve info messages * make compute_raster_stats() template instantiation explicit by adding a suffix to the function name * update python bindings with new function names * lowercase ComplexOperation.h files * remove layoverShadowMask stats from GUNW products * reduce the number of function calls to signedRealOrComplexModulus() * Update cxx/isce3/math/Stats.h Co-authored-by: Brian P Hawkins <[email protected]> * remove schedule(dynamic) from omp directive * Update cxx/isce3/math/Stats.cpp Co-authored-by: Geoffrey M Gunter <[email protected]> * Update cxx/isce3/math/Stats.cpp Co-authored-by: Geoffrey M Gunter <[email protected]> * Update cxx/isce3/math/Stats.cpp Co-authored-by: Geoffrey M Gunter <[email protected]> * limit scope of "using operator*" to functions require it Co-authored-by: Gustavo H Shiroma <[email protected]> Co-authored-by: Brian P Hawkins <[email protected]> Co-authored-by: Geoffrey M Gunter <[email protected]>
1 parent 8b9fe7f commit 1034327

File tree

37 files changed

+1255
-158
lines changed

37 files changed

+1255
-158
lines changed

cxx/isce3/Headers.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ io/Raster.h
127127
io/Raster.icc
128128
io/Serialization.h
129129
math/Bessel.h
130-
math/ComplexMultiply.h
130+
math/complexOperations.h
131+
math/Stats.h
131132
math/detail/RootFind1dBase.h
132133
math/polyfunc.h
133134
math/RootFind1dNewton.h

cxx/isce3/Sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ io/IH5.cpp
6363
io/IH5Dataset.cpp
6464
io/Raster.cpp
6565
math/Bessel.cpp
66+
math/Stats.cpp
6667
math/polyfunc.cpp
6768
math/RootFind1dNewton.cpp
6869
math/RootFind1dSecant.cpp

cxx/isce3/core/Interp1d.icc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#include <isce3/math/ComplexMultiply.h>
1+
#include <isce3/math/complexOperations.h>
22

33
namespace isce3 { namespace core {
44

55
template<typename TK, typename TD>
66
TD interp1d(const Kernel<TK>& kernel, const TD* x, size_t length, size_t stride,
77
double t, bool periodic)
88
{
9-
using namespace isce3::math::complex_multiply;
9+
using namespace isce3::math::complex_operations;
1010
int _width = int(ceil(kernel.width()));
1111
long i0 = 0;
1212
if (_width % 2 == 0) {

cxx/isce3/cuda/Headers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ image/gpuResampSlc.h
4444
image/ResampSlc.h
4545
io/DataStream.h
4646
io/DataStream.icc
47-
math/ComplexMultiply.h
47+
math/complexOperations.h
4848
signal/forward.h
4949
signal/gpuCrossMul.h
5050
signal/gpuFilter.h

cxx/isce3/cuda/core/Interp1d.icc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#include <cmath>
22
#include <type_traits>
33

4-
#include <isce3/cuda/math/ComplexMultiply.h>
5-
64
namespace isce3 { namespace cuda { namespace core {
75

86
template<class Kernel, typename T>
97
CUDA_HOSTDEV inline T interp1d(const Kernel& kernel, const T* x, size_t length,
108
size_t stride, double t, bool periodic)
119
{
12-
using isce3::math::complex_multiply::operator*;
1310

1411
auto width = static_cast<int>(std::ceil(kernel.width()));
1512
auto i0 = (width % 2 == 0) ? static_cast<long>(std::ceil(t))

cxx/isce3/cuda/math/ComplexMultiply.h

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <thrust/complex.h>
4+
5+
#include <isce3/core/Common.h>
6+
#include <isce3/math/complexOperations.h>
7+
8+
/** Promotion rules so T * complex<U> works for {T,U} in {float,double}. */
9+
namespace isce3 { namespace cuda { namespace math { namespace complex_operations {
10+
11+
template<typename T1, typename T2>
12+
CUDA_HOSTDEV inline auto operator*(T1 t, thrust::complex<T2> u)
13+
{
14+
using U = typename std::common_type_t<T1, T2>;
15+
return U(t) * thrust::complex<U>(u);
16+
}
17+
18+
template<typename T1, typename T2>
19+
CUDA_HOSTDEV inline auto operator*(thrust::complex<T1> t, T2 u)
20+
{
21+
using U = typename std::common_type_t<T1, T2>;
22+
return thrust::complex<U>(t) * U(u);
23+
}
24+
25+
template<typename T1, typename T2>
26+
CUDA_HOSTDEV inline auto operator/(T1 t, thrust::complex<T2> u)
27+
{
28+
using U = typename std::common_type_t<T1, T2>;
29+
return U(t) / thrust::complex<U>(u);
30+
}
31+
32+
template<typename T1, typename T2>
33+
CUDA_HOSTDEV inline auto operator/(thrust::complex<T1> t, T2 u)
34+
{
35+
using U = typename std::common_type_t<T1, T2>;
36+
return thrust::complex<U>(t) / U(u);
37+
}
38+
39+
}}}} // namespace isce3::cuda::math::complex_operations

cxx/isce3/geocode/GeocodeCov.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ void Geocode<T>::geocodeInterp(
374374
if (std::isnan(rtc_geogrid_upsampling))
375375
rtc_geogrid_upsampling = 1;
376376

377-
isce3::geometry::rtcMemoryMode rtc_memory_mode =
378-
isce3::geometry::RTC_AUTO;
377+
isce3::core::MemoryModeBlockY rtc_memory_mode =
378+
isce3::core::MemoryModeBlockY::AutoBlocksY;
379379
int radar_grid_nlooks = 1;
380380
computeRtc(demRaster, *rtc_raster, radar_grid, _orbit, _doppler,
381381
_geoGridStartY, _geoGridSpacingY, _geoGridStartX,
@@ -729,6 +729,8 @@ inline void Geocode<T>::_interpolate(
729729
isce3::core::Matrix<float>& out_geo_rtc_array)
730730
{
731731

732+
using isce3::math::complex_operations::operator*;
733+
732734
size_t length = geoDataBlock.length();
733735
size_t width = geoDataBlock.width();
734736
// Add extra margin for interpolation
@@ -1677,13 +1679,13 @@ void Geocode<T>::geocodeAreaProj(
16771679
else if (std::isnan(rtc_geogrid_upsampling))
16781680
rtc_geogrid_upsampling = 2 * geogrid_upsampling;
16791681

1680-
isce3::geometry::rtcMemoryMode rtc_memory_mode;
1682+
isce3::core::MemoryModeBlockY rtc_memory_mode;
16811683
if (geocode_memory_mode == geocodeMemoryMode::AUTO)
1682-
rtc_memory_mode = isce3::geometry::RTC_AUTO;
1684+
rtc_memory_mode = isce3::core::MemoryModeBlockY::AutoBlocksY;
16831685
else if (geocode_memory_mode == geocodeMemoryMode::SINGLE_BLOCK)
1684-
rtc_memory_mode = isce3::geometry::RTC_SINGLE_BLOCK;
1686+
rtc_memory_mode = isce3::core::MemoryModeBlockY::SingleBlockY;
16851687
else
1686-
rtc_memory_mode = isce3::geometry::RTC_BLOCKS_GEOGRID;
1688+
rtc_memory_mode = isce3::core::MemoryModeBlockY::MultipleBlocksY;
16871689

16881690
computeRtc(dem_raster, *rtc_raster, radar_grid_cropped, _orbit,
16891691
_doppler, _geoGridStartY, _geoGridSpacingY, _geoGridStartX,
@@ -2015,6 +2017,8 @@ void Geocode<T>::_runBlock(
20152017
pyre::journal::info_t& info)
20162018
{
20172019

2020+
using isce3::math::complex_operations::operator*;
2021+
20182022
// start (az) and r0 at the outer edge of the first pixel
20192023
const double pixazm = radar_grid.azimuthTimeInterval();
20202024
const double start = radar_grid.sensingStart() - 0.5 * pixazm;

cxx/isce3/geocode/GeocodeHelpers.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
#pragma once
22

3-
namespace isce3 { namespace geocode {
4-
5-
6-
template<typename T1, typename T2>
7-
auto operator*(const std::complex<T1>& lhs, const T2& rhs)
8-
{
9-
using U = typename std::common_type_t<T1, T2>;
10-
return std::complex<U>(lhs) * U(rhs);
11-
}
3+
#include <isce3/math/complexOperations.h>
124

13-
template<typename T1, typename T2>
14-
auto operator*(const T1& lhs, const std::complex<T2>& rhs)
15-
{
16-
using U = typename std::common_type_t<T1, T2>;
17-
return U(lhs) * std::complex<U>(rhs);
18-
}
5+
namespace isce3 { namespace geocode {
196

207
template<typename T, typename T_out>
218
void _convertToOutputType(T a, T_out& b)
@@ -40,6 +27,9 @@ void _accumulate(T_out& band_value, T a, double b)
4027
{
4128
if (b == 0)
4229
return;
30+
31+
using isce3::math::complex_operations::operator*;
32+
4333
T_out a2;
4434
_convertToOutputType(a, a2);
4535
band_value += a2 * b;

cxx/isce3/geocode/GeocodePolygon.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ void GeocodePolygon<T>::getPolygonMean(
212212
isce3::geometry::rtcAlgorithm rtc_algorithm =
213213
isce3::geometry::rtcAlgorithm::RTC_AREA_PROJECTION;
214214

215-
isce3::geometry::rtcMemoryMode rtc_memory_mode =
216-
isce3::geometry::rtcMemoryMode::RTC_SINGLE_BLOCK;
215+
isce3::core::MemoryModeBlockY rtc_memory_mode =
216+
isce3::core::MemoryModeBlockY::SingleBlockY;
217217

218218
computeRtc(radar_grid_cropped, _orbit, input_dop, dem_raster,
219219
*rtc_raster, input_terrain_radiometry,
@@ -288,6 +288,8 @@ void GeocodePolygon<T>::_getPolygonMean(
288288

289289
pyre::journal::info_t _info("isce.geometry._getPolygonMean");
290290

291+
using isce3::math::complex_operations::operator*;
292+
291293
// number of bands in the input raster
292294
const int nbands = input_raster.numBands();
293295
_info << "nbands: " << nbands << pyre::journal::endl;

0 commit comments

Comments
 (0)