Skip to content

Commit

Permalink
Pybind resamp (#524)
Browse files Browse the repository at this point in the history
* buildable untested CPU pybind of ResampSlc

* added RadarGridParameters constructor

This constructor is more direct than making a lambda constructor in pybind.

* bound new RadarGridParameter constructor and linesPerTile property

* test code for pybind CPU resamp

* adding RadarGridParameters constructor to CUDA ResampSlc

* buildable untested CUDA pybind of ResampSlc

* test code for pybind CUDA resamp
  • Loading branch information
Liang Yu authored and GitHub Enterprise committed Aug 14, 2020
1 parent fa3d0a4 commit 5151f15
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cxx/isce3/cuda/image/ResampSlc.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// -*- C++ -*-
// -*- coding: utf-8 -*-
//
// Author: Liang Yu
// Copyright 2018

#pragma once

#include "forward.h"
Expand All @@ -26,7 +20,20 @@ class isce3::cuda::image::ResampSlc : public isce3::image::ResampSlc {
char frequency = 'A') :
isce3::image::ResampSlc(product, refProduct, frequency) {}

// Constructor from individual components (no flattening)
/** Constructor from an isce3::product::RadarGridParameters (no flattening) */
inline ResampSlc(const isce3::product::RadarGridParameters & rdr_grid,
const isce3::core::LUT2d<double> & doppler,
double wvl) :
isce3::image::ResampSlc(rdr_grid, doppler, wvl) {}

/** Constructor from an isce3::product::RadarGridParameters and reference radar grid (flattening) */
inline ResampSlc(const isce3::product::RadarGridParameters & rdr_grid,
const isce3::product::RadarGridParameters & ref_rdr_grid,
const isce3::core::LUT2d<double> & doppler,
double wvl, double ref_wvl) :
isce3::image::ResampSlc(rdr_grid, ref_rdr_grid, doppler, wvl, ref_wvl) {}

// Constructor from individual components (no flattening)
inline ResampSlc(const isce3::core::LUT2d<double> & doppler,
double startingRange, double rangePixelSpacing,
double sensingStart, double prf, double wvl) :
Expand Down
12 changes: 12 additions & 0 deletions cxx/isce3/image/ResampSlc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// isce3::product
#include <isce3/product/Product.h>
#include <isce3/product/RadarGridParameters.h>

// Definition
class isce3::image::ResampSlc {
Expand All @@ -51,6 +52,17 @@ class isce3::image::ResampSlc {
inline ResampSlc(const isce3::product::Swath & swath,
const isce3::product::Swath & refSwath);

/** Constructor from an isce3::product::RadarGridParameters (no flattening) */
inline ResampSlc(const isce3::product::RadarGridParameters & rdr_grid,
const isce3::core::LUT2d<double> & doppler,
double wvl);

/** Constructor from an isce3::product::RadarGridParameters and reference radar grid (flattening) */
inline ResampSlc(const isce3::product::RadarGridParameters & rdr_grid,
const isce3::product::RadarGridParameters & ref_rdr_grid,
const isce3::core::LUT2d<double> & doppler,
double wvl, double ref_wvl);

/** Constructor from individual components (no flattening) */
inline ResampSlc(const isce3::core::LUT2d<double> & doppler,
double startingRange, double rangePixelSpacing,
Expand Down
24 changes: 24 additions & 0 deletions cxx/isce3/image/ResampSlc.icc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ ResampSlc(const isce3::product::Swath & swath, const isce3::product::Swath & ref
_setRefDataFromSwath(refSwath);
}

/** Constructor from an isce3::product::RadarGridParameters (no flattening) */
isce3::image::ResampSlc::
ResampSlc(const isce3::product::RadarGridParameters & rdr_grid,
const isce3::core::LUT2d<double> & doppler, double wvl) :
_haveRefData(false), _dopplerLUT(doppler),
_startingRange(rdr_grid.startingRange()),
_rangePixelSpacing(rdr_grid.rangePixelSpacing()),
_sensingStart(rdr_grid.sensingStart()),
_prf(rdr_grid.prf()), _wavelength(wvl) {}

/** Constructor from an isce3::product::RadarGridParameters and reference radar grid (flattening) */
isce3::image::ResampSlc::
ResampSlc(const isce3::product::RadarGridParameters & rdr_grid,
const isce3::product::RadarGridParameters & ref_rdr_grid,
const isce3::core::LUT2d<double> & doppler,
double wvl, double ref_wvl) :
_haveRefData(true), _dopplerLUT(doppler),
_rangePixelSpacing(rdr_grid.rangePixelSpacing()),
_sensingStart(rdr_grid.sensingStart()),
_startingRange(rdr_grid.startingRange()),
_refRangePixelSpacing(ref_rdr_grid.rangePixelSpacing()),
_refStartingRange(ref_rdr_grid.startingRange()),
_prf(rdr_grid.prf()), _wavelength(wvl), _refWavelength(ref_wvl) {}

/** Constructor from individual components (no flattening) */
isce3::image::ResampSlc::
ResampSlc(const isce3::core::LUT2d<double> & doppler, double startingRange,
Expand Down
4 changes: 4 additions & 0 deletions python/extensions/pybind_isce3/Sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ geometry/geometry.cpp
geometry/geo2rdr.cpp
geometry/rdr2geo.cpp
geometry/RTC.cpp
image/image.cpp
image/ResampSlc.cpp
io/gdal/Dataset.cpp
io/gdal/GDALAccess.cpp
io/gdal/GDALDataType.cpp
Expand Down Expand Up @@ -56,5 +58,7 @@ if(WITH_CUDA)
cuda/geometry/rdr2geo.cpp
cuda/focus/Backproject.cpp
cuda/focus/focus.cpp
cuda/image/image.cpp
cuda/image/ResampSlc.cpp
)
endif()
2 changes: 2 additions & 0 deletions python/extensions/pybind_isce3/cuda/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "core/core.h"
#include "focus/focus.h"
#include "geometry/geometry.h"
#include "image/image.h"

namespace py = pybind11;

Expand All @@ -13,4 +14,5 @@ void addsubmodule_cuda(py::module& m)
addsubmodule_cuda_core(m_cuda);
addsubmodule_cuda_focus(m_cuda);
addsubmodule_cuda_geometry(m_cuda);
addsubmodule_cuda_image(m_cuda);
}
85 changes: 85 additions & 0 deletions python/extensions/pybind_isce3/cuda/image/ResampSlc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "ResampSlc.h"

#include <isce3/core/Constants.h>
#include <isce3/core/LUT2d.h>
#include <isce3/io/Raster.h>

using isce3::cuda::image::ResampSlc;

namespace py = pybind11;

void addbinding(py::class_<ResampSlc> & pyResampSlc)
{
pyResampSlc
.def(py::init<const isce3::core::LUT2d<double> &, double, double,
double, double, double>(),
py::arg("doppler"),
py::arg("start_range"),
py::arg("range_pixel_spacing"),
py::arg("sensing_start"),
py::arg("prf"),
py::arg("wavelength"))
.def(py::init<const isce3::core::LUT2d<double> &, double, double,
double, double, double, double, double, double>(),
py::arg("doppler"),
py::arg("start_range"),
py::arg("range_pixel_spacing"),
py::arg("sensing_start"),
py::arg("prf"),
py::arg("wavelength"),
py::arg("ref_start_range"),
py::arg("ref_range_pixel_spacing"),
py::arg("ref_wavelength"))
.def(py::init<const isce3::product::RadarGridParameters &,
const isce3::core::LUT2d<double> &, double>(),
py::arg("rdr_grid"),
py::arg("doppler"),
py::arg("wavelength"))
.def(py::init<const isce3::product::RadarGridParameters &,
const isce3::product::RadarGridParameters &,
const isce3::core::LUT2d<double> &, double, double>(),
py::arg("rdr_grid"),
py::arg("ref_rdr_grid"),
py::arg("doppler"),
py::arg("ref_wavelength"),
py::arg("wavelength"))
.def_property("doppler",
py::overload_cast<>(&ResampSlc::doppler, py::const_),
&ResampSlc::doppler)
.def_property("lines_per_tile",
py::overload_cast<>(&ResampSlc::linesPerTile, py::const_),
py::overload_cast<size_t>(&ResampSlc::linesPerTile))
.def_property_readonly("start_range", &ResampSlc::startingRange)
.def_property_readonly("range_pixel_spacing", &ResampSlc::rangePixelSpacing)
.def_property_readonly("sensing_start", &ResampSlc::sensingStart)
.def_property_readonly("prf", &ResampSlc::prf)
.def_property_readonly("wavelength", &ResampSlc::wavelength)
.def_property_readonly("ref_start_range", &ResampSlc::refStartingRange)
.def_property_readonly("ref_range_pixel_spacing", &ResampSlc::refRangePixelSpacing)
.def_property_readonly("ref_wavelength", &ResampSlc::refWavelength)
.def("resamp", py::overload_cast<isce3::io::Raster &, isce3::io::Raster &,
isce3::io::Raster &, isce3::io::Raster &,
int, bool, bool, int , int>(&ResampSlc::resamp),
py::arg("input_slc"),
py::arg("output_slc"),
py::arg("rg_offset_raster"),
py::arg("az_offset_raster"),
py::arg("input_band") = 1,
py::arg("flatten") = false,
py::arg("is_complex") = true,
py::arg("row_buffer") = 40,
py::arg("chip_size") = isce3::core::SINC_ONE)
.def("resamp", py::overload_cast<const std::string &, const std::string &,
const std::string & , const std::string &,
int, bool, bool, int, int>(&ResampSlc::resamp),
py::arg("input_filename"),
py::arg("output_filename"),
py::arg("rg_offset_filename"),
py::arg("az_offset_filename"),
py::arg("input_band") = 1,
py::arg("flatten") = false,
py::arg("is_complex") = true,
py::arg("row_buffer") = 40,
py::arg("chip_size") = isce3::core::SINC_ONE)
;
}
6 changes: 6 additions & 0 deletions python/extensions/pybind_isce3/cuda/image/ResampSlc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <isce3/cuda/image/ResampSlc.h>
#include <pybind11/pybind11.h>

void addbinding(pybind11::class_<isce3::cuda::image::ResampSlc>&);
16 changes: 16 additions & 0 deletions python/extensions/pybind_isce3/cuda/image/image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "image.h"

#include "ResampSlc.h"

namespace py = pybind11;

void addsubmodule_cuda_image(py::module & m)
{
py::module m_image = m.def_submodule("image");

// forward declare bound classes
py::class_<isce3::cuda::image::ResampSlc> pyResampSlc(m_image, "ResampSlc");

// add bindings
addbinding(pyResampSlc);
}
5 changes: 5 additions & 0 deletions python/extensions/pybind_isce3/cuda/image/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <pybind11/pybind11.h>

void addsubmodule_cuda_image(pybind11::module &);
85 changes: 85 additions & 0 deletions python/extensions/pybind_isce3/image/ResampSlc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "ResampSlc.h"

#include <isce3/core/Constants.h>
#include <isce3/core/LUT2d.h>
#include <isce3/io/Raster.h>

using isce3::image::ResampSlc;

namespace py = pybind11;

void addbinding(py::class_<ResampSlc> & pyResampSlc)
{
pyResampSlc
.def(py::init<const isce3::core::LUT2d<double> &, double, double,
double, double, double>(),
py::arg("doppler"),
py::arg("start_range"),
py::arg("range_pixel_spacing"),
py::arg("sensing_start"),
py::arg("prf"),
py::arg("wavelength"))
.def(py::init<const isce3::core::LUT2d<double> &, double, double,
double, double, double, double, double, double>(),
py::arg("doppler"),
py::arg("start_range"),
py::arg("range_pixel_spacing"),
py::arg("sensing_start"),
py::arg("prf"),
py::arg("wavelength"),
py::arg("ref_start_range"),
py::arg("ref_range_pixel_spacing"),
py::arg("ref_wavelength"))
.def(py::init<const isce3::product::RadarGridParameters &,
const isce3::core::LUT2d<double> &, double>(),
py::arg("rdr_grid"),
py::arg("doppler"),
py::arg("wavelength"))
.def(py::init<const isce3::product::RadarGridParameters &,
const isce3::product::RadarGridParameters &,
const isce3::core::LUT2d<double> &, double, double>(),
py::arg("rdr_grid"),
py::arg("ref_rdr_grid"),
py::arg("doppler"),
py::arg("ref_wavelength"),
py::arg("wavelength"))
.def_property("doppler",
py::overload_cast<>(&ResampSlc::doppler, py::const_),
&ResampSlc::doppler)
.def_property("lines_per_tile",
py::overload_cast<>(&ResampSlc::linesPerTile, py::const_),
py::overload_cast<size_t>(&ResampSlc::linesPerTile))
.def_property_readonly("start_range", &ResampSlc::startingRange)
.def_property_readonly("range_pixel_spacing", &ResampSlc::rangePixelSpacing)
.def_property_readonly("sensing_start", &ResampSlc::sensingStart)
.def_property_readonly("prf", &ResampSlc::prf)
.def_property_readonly("wavelength", &ResampSlc::wavelength)
.def_property_readonly("ref_start_range", &ResampSlc::refStartingRange)
.def_property_readonly("ref_range_pixel_spacing", &ResampSlc::refRangePixelSpacing)
.def_property_readonly("ref_wavelength", &ResampSlc::refWavelength)
.def("resamp", py::overload_cast<isce3::io::Raster &, isce3::io::Raster &,
isce3::io::Raster &, isce3::io::Raster &,
int, bool, bool, int , int>(&ResampSlc::resamp),
py::arg("input_slc"),
py::arg("output_slc"),
py::arg("rg_offset_raster"),
py::arg("az_offset_raster"),
py::arg("input_band") = 1,
py::arg("flatten") = false,
py::arg("is_complex") = true,
py::arg("row_buffer") = 40,
py::arg("chip_size") = isce3::core::SINC_ONE)
.def("resamp", py::overload_cast<const std::string &, const std::string &,
const std::string & , const std::string &,
int, bool, bool, int, int>(&ResampSlc::resamp),
py::arg("input_filename"),
py::arg("output_filename"),
py::arg("rg_offset_filename"),
py::arg("az_offset_filename"),
py::arg("input_band") = 1,
py::arg("flatten") = false,
py::arg("is_complex") = true,
py::arg("row_buffer") = 40,
py::arg("chip_size") = isce3::core::SINC_ONE)
;
}
6 changes: 6 additions & 0 deletions python/extensions/pybind_isce3/image/ResampSlc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <isce3/image/ResampSlc.h>
#include <pybind11/pybind11.h>

void addbinding(pybind11::class_<isce3::image::ResampSlc>&);
16 changes: 16 additions & 0 deletions python/extensions/pybind_isce3/image/image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "image.h"

#include "ResampSlc.h"

namespace py = pybind11;

void addsubmodule_image(py::module & m)
{
py::module m_image = m.def_submodule("image");

// forward declare bound classes
py::class_<isce3::image::ResampSlc> pyResampSlc(m_image, "ResampSlc");

// add bindings
addbinding(pyResampSlc);
}
5 changes: 5 additions & 0 deletions python/extensions/pybind_isce3/image/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <pybind11/pybind11.h>

void addsubmodule_image(pybind11::module &);
2 changes: 2 additions & 0 deletions python/extensions/pybind_isce3/isce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "focus/focus.h"
#include "geocode/geocode.h"
#include "geometry/geometry.h"
#include "image/image.h"
#include "io/io.h"
#include "signal/signal.h"
#include "product/product.h"
Expand All @@ -19,6 +20,7 @@ PYBIND11_MODULE(pybind_isce3, m) {
addsubmodule_core(m);
addsubmodule_geocode(m);
addsubmodule_geometry(m);
addsubmodule_image(m);
addsubmodule_io(m);
addsubmodule_signal(m);
addsubmodule_product(m);
Expand Down
2 changes: 2 additions & 0 deletions tests/python/extensions/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ geometry/dem.py
geometry/geocode.py
geometry/geo2rdr.py
geometry/rdr2geo.py
image/resamp.py
io/gdal/dataset.py
io/gdal/raster.py
io/raster.py
Expand All @@ -33,6 +34,7 @@ if(WITH_CUDA)
cuda/focus/backproject.py
cuda/geometry/geo2rdr.py
cuda/geometry/rdr2geo.py
cuda/image/resamp.py
)
endif()

Expand Down
Loading

0 comments on commit 5151f15

Please sign in to comment.