isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Geocode.h
1 //-*- C++ -*-
2 //-*- coding: utf-8 -*-
3 //
4 // Author: Heresh Fattahi, Gustavo H. X. Shiroma
5 // Copyright 2019-
6 
7 #pragma once
8 
9 // pyre
10 #include <pyre/journal.h>
11 
12 // isce3::core
13 #include <isce3/core/Orbit.h>
14 #include <isce3/core/Ellipsoid.h>
15 #include <isce3/core/LUT2d.h>
16 #include <isce3/core/Constants.h>
17 
18 // isce3::io
19 #include <isce3/io/Raster.h>
20 
21 // isce3::product
22 #include <isce3/product/Product.h>
23 #include <isce3/product/RadarGridParameters.h>
24 
25 // isce3::geometry
26 #include <isce3/geometry/RTC.h>
27 
28 #include "geometry.h"
29 
30 namespace isce3 {
31 namespace geometry {
32 
35  INTERP = 0,
36  AREA_PROJECTION = 1,
37  AREA_PROJECTION_GAMMA_NAUGHT = 2
38 };
39 
42  AUTO = 0,
43  SINGLE_BLOCK = 1,
44  BLOCKS_GEOGRID = 2,
45  BLOCKS_GEOGRID_AND_RADARGRID = 3
46 };
47 
48 template<class T> class Geocode {
49 public:
50 
91  void
93  isce3::io::Raster& input_raster, isce3::io::Raster& output_raster,
94  isce3::io::Raster& dem_raster,
96  isce3::geometry::geocodeOutputMode::INTERP,
97  double geogrid_upsampling = 1,
98  isce3::geometry::rtcInputRadiometry input_radiometry =
99  isce3::geometry::rtcInputRadiometry::BETA_NAUGHT,
100  int exponent = 0,
101  float rtc_min_value_db = std::numeric_limits<float>::quiet_NaN(),
102  double rtc_geogrid_upsampling =
103  std::numeric_limits<double>::quiet_NaN(),
104  rtcAlgorithm rtc_algorithm = rtcAlgorithm::RTC_AREA_PROJECTION,
105  double abs_cal_factor = 1,
106  float clip_min = std::numeric_limits<float>::quiet_NaN(),
107  float clip_max = std::numeric_limits<float>::quiet_NaN(),
108  float min_nlooks = std::numeric_limits<float>::quiet_NaN(),
109  float radar_grid_nlooks = 1,
110  isce3::io::Raster* out_geo_vertices = nullptr,
111  isce3::io::Raster* out_dem_vertices = nullptr,
112  isce3::io::Raster* out_geo_nlooks = nullptr,
113  isce3::io::Raster* out_geo_rtc = nullptr,
114  isce3::io::Raster* input_rtc = nullptr,
115  isce3::io::Raster* output_rtc = nullptr,
116  geocodeMemoryMode geocode_memory_mode = geocodeMemoryMode::AUTO,
117  isce3::core::dataInterpMethod interp_method =
118  isce3::core::dataInterpMethod::BIQUINTIC_METHOD);
119 
127  template<class T_out>
128  void geocodeInterp(const isce3::product::RadarGridParameters& radar_grid,
129  isce3::io::Raster& input_raster,
130  isce3::io::Raster& output_raster,
131  isce3::io::Raster& demRaster);
132 
169  template<class T_out>
170  void geocodeAreaProj(
171  const isce3::product::RadarGridParameters& radar_grid,
172  isce3::io::Raster& input_raster, isce3::io::Raster& output_raster,
173  isce3::io::Raster& dem_raster,
175  isce3::geometry::geocodeOutputMode::AREA_PROJECTION,
176  double geogrid_upsampling = 1,
177  isce3::geometry::rtcInputRadiometry input_radiometry =
178  isce3::geometry::rtcInputRadiometry::BETA_NAUGHT,
179  float rtc_min_value_db = std::numeric_limits<float>::quiet_NaN(),
180  double rtc_geogrid_upsampling =
181  std::numeric_limits<double>::quiet_NaN(),
182  rtcAlgorithm rtc_algorithm = rtcAlgorithm::RTC_AREA_PROJECTION,
183  double abs_cal_factor = 1,
184  float clip_min = std::numeric_limits<float>::quiet_NaN(),
185  float clip_max = std::numeric_limits<float>::quiet_NaN(),
186  float min_nlooks = std::numeric_limits<float>::quiet_NaN(),
187  float radar_grid_nlooks = 1,
188  isce3::io::Raster* out_geo_vertices = nullptr,
189  isce3::io::Raster* out_dem_vertices = nullptr,
190  isce3::io::Raster* out_geo_nlooks = nullptr,
191  isce3::io::Raster* out_geo_rtc = nullptr,
192  isce3::io::Raster* input_rtc = nullptr,
193  isce3::io::Raster* output_rtc = nullptr,
194  geocodeMemoryMode geocode_memory_mode = geocodeMemoryMode::AUTO,
195  isce3::core::dataInterpMethod interp_method =
196  isce3::core::dataInterpMethod::BIQUINTIC_METHOD);
197 
209  void geoGrid(double geoGridStartX, double geoGridStartY,
210  double geoGridSpacingX, double geoGridSpacingY, int width,
211  int length, int epsgcode);
212 
217  void updateGeoGrid(const isce3::product::RadarGridParameters& radar_grid,
218  isce3::io::Raster& dem_raster);
219 
220  // Set interpolator
221  void interpolator(isce3::core::dataInterpMethod method) {
222  _interp_method = method;
223  }
224 
225  void doppler(isce3::core::LUT2d<double> doppler) { _doppler = doppler; }
226 
227  void orbit(isce3::core::Orbit& orbit) { _orbit = orbit; }
228 
229  void ellipsoid(isce3::core::Ellipsoid& ellipsoid) { _ellipsoid = ellipsoid; }
230 
231  void thresholdGeo2rdr(double threshold) { _threshold = threshold; }
232 
233  void numiterGeo2rdr(int numiter) { _numiter = numiter; }
234 
235  void linesPerBlock(size_t linesPerBlock) { _linesPerBlock = linesPerBlock; }
236 
237  void demBlockMargin(double demBlockMargin) {
238  _demBlockMargin = demBlockMargin;
239  }
240 
241  void radarBlockMargin(int radarBlockMargin) {
242  _radarBlockMargin = radarBlockMargin;
243  }
244 
245  // start X position for the output geogrid
246  double geoGridStartX() const { return _geoGridStartX; }
247 
248  // start Y position for the output geogrid
249  double geoGridStartY() const { return _geoGridStartY; }
250 
251  // X spacing for the output geogrid
252  double geoGridSpacingX() const { return _geoGridSpacingX; }
253 
254  // Y spacing for the output geogrid
255  double geoGridSpacingY() const { return _geoGridSpacingY; }
256 
257  // number of pixels in east-west direction (X direction)
258  int geoGridWidth() const { return _geoGridWidth; }
259 
260  // number of lines in north-south direction (Y direction)
261  int geoGridLength() const { return _geoGridLength; }
262 
263 private:
264  void _GetRadarPositionVect(
265  double dem_y1, const int k_start, const int k_end,
266  double geogrid_upsampling, double& a11, double& r11, double& a_min,
267  double& r_min, double& a_max, double& r_max,
268  std::vector<double>& a_last, std::vector<double>& r_last,
269  std::vector<Vec3>& dem_last,
270  const isce3::product::RadarGridParameters& radar_grid,
271  isce3::core::ProjectionBase* proj, DEMInterpolator& dem_interp_block,
272  bool flag_direction_line);
273 
274  template<class T_out>
275  void
276  _RunBlock(const isce3::product::RadarGridParameters& radar_grid,
277  bool is_radar_grid_single_block,
278  std::vector<std::unique_ptr<isce3::core::Matrix<T_out>>>& rdrData,
279  const int jmax, int block_size, int block_size_with_upsampling,
280  int block, int& numdone, int progress_block,
281  double geogrid_upsampling, int nbands,
282  isce3::core::dataInterpMethod interp_method,
283  isce3::io::Raster& dem_raster, isce3::io::Raster* out_geo_vertices,
284  isce3::io::Raster* out_dem_vertices,
285  isce3::io::Raster* out_geo_nlooks, isce3::io::Raster* out_geo_rtc,
286  const double start, const double pixazm, const double dr,
287  double r0, int xbound, int ybound,
289  isce3::core::Matrix<float>& rtc_area,
290  isce3::io::Raster& input_raster, isce3::io::Raster& output_raster,
292  float rtc_min_value, double abs_cal_factor, float clip_min,
293  float clip_max, float min_nlooks, float radar_grid_nlooks,
294  pyre::journal::info_t& info);
295 
296  void _loadDEM(isce3::io::Raster& demRaster, DEMInterpolator& demInterp,
297  isce3::core::ProjectionBase* _proj, int lineStart,
298  int blockLength, int blockWidth, double demMargin);
299 
300  std::string _get_nbytes_str(long nbytes);
301 
302  void _geo2rdr(const isce3::product::RadarGridParameters& radar_grid,
303  double x, double y, double& azimuthTime, double& slantRange,
304  DEMInterpolator& demInterp, isce3::core::ProjectionBase* proj);
305 
306  template<class T_out>
307  void
308  _interpolate(isce3::core::Matrix<T_out>& rdrDataBlock,
309  isce3::core::Matrix<T_out>& geoDataBlock,
310  std::valarray<double>& radarX, std::valarray<double>& radarY,
311  int rdrBlockWidth, int rdrBlockLength, int azimuthFirstLine,
312  int rangeFirstPixel, isce3::core::Interpolator<T_out>* interp);
313 
314  // isce3::core objects
315  isce3::core::Orbit _orbit;
316  isce3::core::Ellipsoid _ellipsoid;
317 
318  // Optimization options
319  double _threshold;
320  int _numiter;
321  size_t _linesPerBlock = 1000;
322 
323  // radar grids parameters
325 
326  // start X position for the output geogrid
327  double _geoGridStartX = std::numeric_limits<double>::quiet_NaN();
328 
329  // start Y position for the output geogrid
330  double _geoGridStartY = std::numeric_limits<double>::quiet_NaN();
331 
332  // X spacing for the output geogrid
333  double _geoGridSpacingX = std::numeric_limits<double>::quiet_NaN();
334 
335  // Y spacing for the output geogrid
336  double _geoGridSpacingY = std::numeric_limits<double>::quiet_NaN();
337 
338  // number of pixels in east-west direction (X direction)
339  int _geoGridWidth = -32768;
340 
341  // number of lines in north-south direction (Y direction)
342  int _geoGridLength = -32768;
343 
344  // epsg code for the output geogrid
345  int _epsgOut = 0;
346 
347  // margin around a computed bounding box for DEM (in degrees)
348  double _demBlockMargin;
349 
350  // margin around the computed bounding box for radar dara (integer number of
351  // lines/pixels)
352  int _radarBlockMargin;
353 
354  // interpolator
355  isce3::core::dataInterpMethod _interp_method =
356  isce3::core::dataInterpMethod::BIQUINTIC_METHOD;
357 };
358 
359 std::vector<float> getGeoAreaElementMean(
360  const std::vector<double>& x_vect, const std::vector<double>& y_vect,
361  const isce3::product::RadarGridParameters& radar_grid,
362  const isce3::core::Orbit& orbit,
363  const isce3::core::LUT2d<double>& input_dop,
364  isce3::io::Raster& input_raster, isce3::io::Raster& dem_raster,
365  isce3::geometry::rtcInputRadiometry input_radiometry =
366  isce3::geometry::rtcInputRadiometry::BETA_NAUGHT,
367  int exponent = 0,
369  isce3::geometry::geocodeOutputMode::AREA_PROJECTION,
370  double geogrid_upsampling = std::numeric_limits<double>::quiet_NaN(),
371  float rtc_min_value_db = std::numeric_limits<float>::quiet_NaN(),
372  double abs_cal_factor = 1, float radar_grid_nlooks = 1,
373  float* out_nlooks = nullptr,
374  isce3::core::dataInterpMethod interp_method =
375  isce3::core::dataInterpMethod::BIQUINTIC_METHOD,
376  double threshold = 1e-4, int num_iter = 100, double delta_range = 1e-4);
377 
378 template<typename T>
379 std::vector<float> _getGeoAreaElementMean(
380  const std::vector<double>& r_vect, const std::vector<double>& a_vect,
381  int x_min, int y_min, isce3::core::Matrix<float>& rtc_area,
382  const isce3::product::RadarGridParameters& radar_grid,
383  isce3::io::Raster& input_raster,
385  isce3::geometry::geocodeOutputMode::AREA_PROJECTION,
386  float rtc_min_value = 0, float* out_nlooks = nullptr,
387  double abs_cal_factor = 1, float radar_grid_nlooks = 1);
388 
389 } // namespace geometry
390 } // namespace isce3
391 
392 // Get inline implementations for Geocode
393 #define ISCE_GEOMETRY_GEOCODE_ICC
394 #include "Geocode.icc"
395 #undef ISCE_GEOMETRY_GEOCODE_ICC
geocodeMemoryMode
Enumeration type to indicate memory management.
Definition: Geocode.h:41
dataInterpMethod
Enumeration type to indicate interpolation method.
Definition: Constants.h:23
Data structure to store Ellipsoid information.
Definition: Ellipsoid.h:20
void geocodeInterp(const isce3::product::RadarGridParameters &radar_grid, isce3::io::Raster &input_raster, isce3::io::Raster &output_raster, isce3::io::Raster &demRaster)
Geocode using the interpolation algorithm.
Definition: Geocode.cpp:199
Definition: RadarGridParameters.h:15
void updateGeoGrid(const isce3::product::RadarGridParameters &radar_grid, isce3::io::Raster &dem_raster)
Update the output geogrid with radar grid and DEM attributes.
Definition: Geocode.cpp:71
Data structure for a 2D row-major matrix.
Definition: forward.h:31
rtcAlgorithm
Enumeration type to select RTC algorithm (RTC_DAVID_SMALL or RTC_AREA_PROJECTION) ...
Definition: RTC.h:36
void geocode(const isce3::product::RadarGridParameters &radar_grid, isce3::io::Raster &input_raster, isce3::io::Raster &output_raster, isce3::io::Raster &dem_raster, isce3::geometry::geocodeOutputMode output_mode=isce3::geometry::geocodeOutputMode::INTERP, double geogrid_upsampling=1, isce3::geometry::rtcInputRadiometry input_radiometry=isce3::geometry::rtcInputRadiometry::BETA_NAUGHT, int exponent=0, float rtc_min_value_db=std::numeric_limits< float >::quiet_NaN(), double rtc_geogrid_upsampling=std::numeric_limits< double >::quiet_NaN(), rtcAlgorithm rtc_algorithm=rtcAlgorithm::RTC_AREA_PROJECTION, double abs_cal_factor=1, float clip_min=std::numeric_limits< float >::quiet_NaN(), float clip_max=std::numeric_limits< float >::quiet_NaN(), float min_nlooks=std::numeric_limits< float >::quiet_NaN(), float radar_grid_nlooks=1, isce3::io::Raster *out_geo_vertices=nullptr, isce3::io::Raster *out_dem_vertices=nullptr, isce3::io::Raster *out_geo_nlooks=nullptr, isce3::io::Raster *out_geo_rtc=nullptr, isce3::io::Raster *input_rtc=nullptr, isce3::io::Raster *output_rtc=nullptr, geocodeMemoryMode geocode_memory_mode=geocodeMemoryMode::AUTO, isce3::core::dataInterpMethod interp_method=isce3::core::dataInterpMethod::BIQUINTIC_METHOD)
Geocode data from slant-range to map coordinates.
Definition: Geocode.cpp:131
Abstract base class for individual projections.
Definition: Projections.h:22
void geoGrid(double geoGridStartX, double geoGridStartY, double geoGridSpacingX, double geoGridSpacingY, int width, int length, int epsgcode)
Set the output geogrid.
Definition: Geocode.cpp:104
geocodeOutputMode
Enumeration type to indicate the algorithm used for geocoding.
Definition: Geocode.h:34
void geocodeAreaProj(const isce3::product::RadarGridParameters &radar_grid, isce3::io::Raster &input_raster, isce3::io::Raster &output_raster, isce3::io::Raster &dem_raster, isce3::geometry::geocodeOutputMode output_mode=isce3::geometry::geocodeOutputMode::AREA_PROJECTION, double geogrid_upsampling=1, isce3::geometry::rtcInputRadiometry input_radiometry=isce3::geometry::rtcInputRadiometry::BETA_NAUGHT, float rtc_min_value_db=std::numeric_limits< float >::quiet_NaN(), double rtc_geogrid_upsampling=std::numeric_limits< double >::quiet_NaN(), rtcAlgorithm rtc_algorithm=rtcAlgorithm::RTC_AREA_PROJECTION, double abs_cal_factor=1, float clip_min=std::numeric_limits< float >::quiet_NaN(), float clip_max=std::numeric_limits< float >::quiet_NaN(), float min_nlooks=std::numeric_limits< float >::quiet_NaN(), float radar_grid_nlooks=1, isce3::io::Raster *out_geo_vertices=nullptr, isce3::io::Raster *out_dem_vertices=nullptr, isce3::io::Raster *out_geo_nlooks=nullptr, isce3::io::Raster *out_geo_rtc=nullptr, isce3::io::Raster *input_rtc=nullptr, isce3::io::Raster *output_rtc=nullptr, geocodeMemoryMode geocode_memory_mode=geocodeMemoryMode::AUTO, isce3::core::dataInterpMethod interp_method=isce3::core::dataInterpMethod::BIQUINTIC_METHOD)
Geocode using the area projection algorithm (adaptive multilooking)
Definition: Geocode.cpp:556
Collection of simple commonly used geometry functions.
Sequence of platform ephemeris samples (state vectors) with uniform temporal spacing, supporting efficient lookup and interpolation.
Definition: Orbit.h:43
rtcInputRadiometry
Enumeration type to indicate input terrain radiometry (for RTC)
Definition: RTC.h:19
Data structure meant to handle Raster I/O operations.
Definition: Raster.h:34
Definition of parent Interpolator.
Definition: forward.h:33

Generated for ISCE3.0 by doxygen 1.8.5.