Skip to content

Commit 7dea92f

Browse files
gmgunterGitHub Enterprise
authored andcommitted
Replace direct imports from 'pybind_isce3' with 'isce3' (#887)
A number of scripts in the 'nisar' package were directly importing from the 'pybind_isce3' package instead of the wrapper 'isce3' package. This update redirects these imports to use the python wrapper (since 'pybind_isce3' is intended to just be used internally by isce3 as an interface with the C++ library). This update also exposes the 'isce3.cuda.matchtemplate' submodule, which had previously only been exposed in 'pybind_isce3'.
1 parent 5d82bd0 commit 7dea92f

24 files changed

+106
-104
lines changed

python/packages/isce3/cuda/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from . import geometry
55
from . import image
66
from . import signal
7+
from . import matchtemplate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from pybind_isce3.cuda.matchtemplate import *

python/packages/nisar/products/readers/Base/Base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import journal
66
import pyre
7-
import pybind_isce3 as isce3
7+
import isce3
88
from ..protocols import ProductReader
99

1010

python/packages/nisar/products/readers/Base/Identification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def unpack(self, h5grp):
5252
Populate self with hdf5 group.
5353
'''
5454
from nisar.h5 import extractScalar, bytestring, extractWithIterator
55-
import pybind_isce3 as isce3
55+
import isce3
5656

5757
self.missionId = extractScalar(h5grp, 'missionId',
5858
bytestring, self.context['info'],

python/packages/nisar/products/readers/Raw/Raw.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import pyre
88
import journal
9-
import pybind_isce3 as isce
9+
import isce3
1010
import re
1111

1212
# TODO some CSV logger
@@ -126,7 +126,7 @@ def getChirpParameters(self, frequency: str = 'A', tx: str = 'H'):
126126
T = group["chirpDuration"][()]
127127
K = group["chirpSlope"][()]
128128
dr = group["slantRangeSpacing"][()]
129-
fs = isce.core.speed_of_light / (2 * dr)
129+
fs = isce3.core.speed_of_light / (2 * dr)
130130
fc = self.getCenterFrequency(frequency, tx)
131131
return fc, fs, K, T
132132

@@ -139,13 +139,13 @@ def TelemetryPath(self):
139139
def getOrbit(self):
140140
path = f"{self.TelemetryPath}/orbit"
141141
with h5py.File(self.filename, 'r', libver='latest', swmr=True) as f:
142-
orbit = isce.core.Orbit.load_from_h5(f[path])
142+
orbit = isce3.core.Orbit.load_from_h5(f[path])
143143
return orbit
144144

145145
def getAttitude(self):
146146
path = f"{self.TelemetryPath}/attitude"
147147
with h5py.File(self.filename, 'r', libver='latest', swmr=True) as f:
148-
q = isce.core.Attitude.load_from_h5(f[path])
148+
q = isce3.core.Attitude.load_from_h5(f[path])
149149
return q
150150

151151
def getRanges(self, frequency='A', tx='H'):
@@ -155,7 +155,7 @@ def getRanges(self, frequency='A', tx='H'):
155155
r = np.asarray(group["slantRange"])
156156
dr = group["slantRangeSpacing"][()]
157157
nr = len(r)
158-
out = isce.core.Linspace(r[0], dr, nr)
158+
out = isce3.core.Linspace(r[0], dr, nr)
159159
assert np.isclose(out[-1], r[-1])
160160
return out
161161

@@ -186,7 +186,7 @@ def getPulseTimes(self, frequency='A', tx='H'):
186186
# FIXME product spec changed UTCTime -> UTCtime
187187
name = find_case_insensitive(f[txpath], "UTCtime")
188188
t = np.asarray(f[txpath][name])
189-
epoch = isce.io.get_ref_epoch(f[txpath], name)
189+
epoch = isce3.io.get_ref_epoch(f[txpath], name)
190190
return epoch, t
191191

192192

@@ -202,7 +202,7 @@ def getCenterFrequency(self, frequency: str = 'A', tx: str = None):
202202
# since PRF isn't necessarily constant. Return pulse times with grid?
203203
def getRadarGrid(self, frequency='A', tx='H', prf=None):
204204
fc = self.getCenterFrequency(frequency, tx)
205-
wvl = isce.core.speed_of_light / fc
205+
wvl = isce3.core.speed_of_light / fc
206206
r = self.getRanges(frequency, tx)
207207
epoch, t = self.getPulseTimes(frequency, tx)
208208
nt = len(t)
@@ -212,7 +212,7 @@ def getRadarGrid(self, frequency='A', tx='H', prf=None):
212212
else:
213213
prf = (nt - 1) / (t[-1] - t[0])
214214
side = self.identification.lookDirection
215-
grid = isce.product.RadarGridParameters(
215+
grid = isce3.product.RadarGridParameters(
216216
t[0], wvl, prf, r[0], r.spacing, side, nt, len(r), epoch)
217217
return t, grid
218218

python/packages/nisar/products/readers/antenna/antenna_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import collections as cl
66
import numpy as np
77

8-
from pybind_isce3 import antenna as ant
8+
from isce3 import antenna as ant
99

1010

1111
class AntennaParser:

python/packages/nisar/products/writers/SLC.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from numpy.testing import assert_allclose
55
import os
66
import isce3
7-
from pybind_isce3.core import LUT2d, DateTime, Orbit, Attitude, EulerAngles
8-
from pybind_isce3.product import RadarGridParameters
9-
from pybind_isce3.geometry import DEMInterpolator
7+
from isce3.core import LUT2d, DateTime, Orbit, Attitude, EulerAngles
8+
from isce3.product import RadarGridParameters
9+
from isce3.geometry import DEMInterpolator
1010
from nisar.h5 import set_string
1111
from nisar.types import complex32
1212
from nisar.products.readers.Raw import Raw

python/packages/nisar/workflows/crossmul.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import h5py
1010
import journal
11-
import pybind_isce3 as isce3
11+
import isce3
1212
from nisar.products.readers import SLC
1313
from nisar.workflows import gpu_check, h5_prep
1414
from nisar.workflows.crossmul_runconfig import CrossmulRunConfig

python/packages/nisar/workflows/dense_offsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import journal
99
import numpy as np
10-
import pybind_isce3 as isce3
10+
import isce3
1111
from osgeo import gdal
1212
from nisar.products.readers import SLC
1313
from nisar.workflows import gpu_check, h5_prep

python/packages/nisar/workflows/focus.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from nisar.types import to_complex32
99
from nisar.workflows import gpu_check
1010
import numpy as np
11-
import pybind_isce3 as isce
12-
from pybind_isce3.core import DateTime, LUT2d
13-
from pybind_isce3.io.gdal import Raster, GDT_CFloat32
11+
import isce3
12+
from isce3.core import DateTime, LUT2d
13+
from isce3.io.gdal import Raster, GDT_CFloat32
1414
from nisar.workflows.yaml_argparse import YamlArgparse
1515
import nisar.workflows.helpers as helpers
1616
from ruamel.yaml import YAML
@@ -100,9 +100,9 @@ def get_chirp(cfg: Struct, raw: Raw, frequency: str, tx: str):
100100

101101

102102
def parse_rangecomp_mode(mode: str):
103-
lut = {"full": isce.focus.RangeComp.Mode.Full,
104-
"same": isce.focus.RangeComp.Mode.Same,
105-
"valid": isce.focus.RangeComp.Mode.Valid}
103+
lut = {"full": isce3.focus.RangeComp.Mode.Full,
104+
"same": isce3.focus.RangeComp.Mode.Same,
105+
"valid": isce3.focus.RangeComp.Mode.Valid}
106106
mode = mode.lower()
107107
if mode not in lut:
108108
raise ValueError(f"Invalid RangeComp mode {mode}")
@@ -140,8 +140,8 @@ def get_total_grid_bounds(rawfiles: List[str], frequency='A'):
140140
times.append(raw.getPulseTimes(frequency, tx=pol[0]))
141141
rmin = min(r[0] for r in ranges)
142142
rmax = max(r[-1] for r in ranges)
143-
dtmin = min(epoch + isce.core.TimeDelta(t[0]) for (epoch, t) in times)
144-
dtmax = max(epoch + isce.core.TimeDelta(t[-1]) for (epoch, t) in times)
143+
dtmin = min(epoch + isce3.core.TimeDelta(t[0]) for (epoch, t) in times)
144+
dtmax = max(epoch + isce3.core.TimeDelta(t[-1]) for (epoch, t) in times)
145145
epoch = min(epoch for (epoch, t) in times)
146146
tmin = (dtmin - epoch).total_seconds()
147147
tmax = (dtmax - epoch).total_seconds()
@@ -152,8 +152,8 @@ def get_total_grid(rawfiles: List[str], dt, dr, frequency='A'):
152152
epoch, tmin, tmax, rmin, rmax = get_total_grid_bounds(rawfiles, frequency)
153153
nt = int(np.ceil((tmax - tmin) / dt))
154154
nr = int(np.ceil((rmax - rmin) / dr))
155-
t = isce.core.Linspace(tmin, dt, nt)
156-
r = isce.core.Linspace(rmin, dr, nr)
155+
t = isce3.core.Linspace(tmin, dt, nt)
156+
r = isce3.core.Linspace(rmin, dr, nr)
157157
return epoch, t, r
158158

159159

@@ -172,11 +172,11 @@ def squint(t, r, orbit, attitude, side, angle=0.0, dem=None, **kw):
172172
f"inferred side={inferred_side} based on orientation "
173173
f"(Y_RCS.dot(V) = {axis.dot(v)})")
174174
if dem is None:
175-
dem = isce.geometry.DEMInterpolator()
175+
dem = isce3.geometry.DEMInterpolator()
176176
# NOTE Here "left" means an acute, positive look angle by right-handed
177177
# rotation about `axis`. Since axis will flip sign, always use "left" to
178178
# get the requested side in the sense of velocity vector.
179-
xyz = isce.geometry.rdr2geo_cone(p, axis, angle, r, dem, "left", **kw)
179+
xyz = isce3.geometry.rdr2geo_cone(p, axis, angle, r, dem, "left", **kw)
180180
look = (xyz - p) / np.linalg.norm(xyz - p)
181181
vhat = v / np.linalg.norm(v)
182182
return np.arcsin(look.dot(vhat))
@@ -187,12 +187,12 @@ def squint_to_doppler(squint, wvl, vmag):
187187

188188

189189
def convert_epoch(t: List[float], epoch_in, epoch_out):
190-
TD = isce.core.TimeDelta
190+
TD = isce3.core.TimeDelta
191191
return [(epoch_in - epoch_out + TD(ti)).total_seconds() for ti in t]
192192

193193

194194
def get_dem(cfg: Struct):
195-
dem = isce.geometry.DEMInterpolator(
195+
dem = isce3.geometry.DEMInterpolator(
196196
height=cfg.processing.dem.reference_height,
197197
method=cfg.processing.dem.interp_method)
198198
fn = cfg.DynamicAncillaryFileGroup.DEMFile
@@ -206,9 +206,9 @@ def get_dem(cfg: Struct):
206206

207207
def make_doppler_lut(rawfiles: List[str],
208208
az: float = 0.0,
209-
orbit: isce.core.Orbit = None,
210-
attitude: isce.core.Attitude = None,
211-
dem: isce.geometry.DEMInterpolator = None,
209+
orbit: isce3.core.Orbit = None,
210+
attitude: isce3.core.Attitude = None,
211+
dem: isce3.geometry.DEMInterpolator = None,
212212
azimuth_spacing: float = 1.0,
213213
range_spacing: float = 1e3,
214214
frequency: str = "A",
@@ -259,13 +259,13 @@ def make_doppler_lut(rawfiles: List[str],
259259
if attitude is None:
260260
attitude = raw.getAttitude()
261261
if dem is None:
262-
dem = isce.geometry.DEMInterpolator()
262+
dem = isce3.geometry.DEMInterpolator()
263263
# Assume look side and center frequency constant across files.
264264
side = raw.identification.lookDirection
265265
fc = raw.getCenterFrequency(frequency)
266266

267267
# Now do the actual calculations.
268-
wvl = isce.core.speed_of_light / fc
268+
wvl = isce3.core.speed_of_light / fc
269269
epoch, t, r = get_total_grid(rawfiles, azimuth_spacing, range_spacing)
270270
t = convert_epoch(t, epoch, orbit.reference_epoch)
271271
dop = np.zeros((len(t), len(r)))
@@ -349,9 +349,9 @@ def make_output_grid(cfg: Struct, igrid):
349349
nr = int(np.round((r1 - r0) / dr))
350350
nt = int(np.round((t1 - t0) * prf))
351351
assert (nr > 0) and (nt > 0)
352-
ogrid = isce.product.RadarGridParameters(t0, igrid.wavelength, prf, r0,
353-
dr, igrid.lookside, nt, nr,
354-
igrid.ref_epoch)
352+
ogrid = isce3.product.RadarGridParameters(t0, igrid.wavelength, prf, r0,
353+
dr, igrid.lookside, nt, nr,
354+
igrid.ref_epoch)
355355
return ogrid
356356

357357

@@ -362,9 +362,9 @@ def get_kernel(cfg: Struct):
362362
if opt.type.lower() != 'knab':
363363
raise NotImplementedError("Only Knab kernel implemented.")
364364
n = 1 + 2 * opt.halfwidth
365-
kernel = isce.core.KnabKernel(n, 1 / 1.2)
365+
kernel = isce3.core.KnabKernel(n, 1 / 1.2)
366366
assert opt.fit.lower() == "table"
367-
table = isce.core.TabulatedKernelF32(kernel, opt.fit_order)
367+
table = isce3.core.TabulatedKernelF32(kernel, opt.fit_order)
368368
return table
369369

370370

@@ -380,8 +380,8 @@ def verify_uniform_pri(t: np.ndarray, atol=0.0, rtol=0.001):
380380

381381

382382
def resample(raw: np.ndarray, t: np.ndarray,
383-
grid: isce.product.RadarGridParameters, swaths: np.ndarray,
384-
orbit: isce.core.Orbit, doppler: isce.core.LUT2d, L=12.0,
383+
grid: isce3.product.RadarGridParameters, swaths: np.ndarray,
384+
orbit: isce3.core.Orbit, doppler: isce3.core.LUT2d, L=12.0,
385385
fn="regridded.c8"):
386386
"""
387387
Fill gaps and resample raw data to uniform grid using BLU method.
@@ -425,10 +425,10 @@ def resample(raw: np.ndarray, t: np.ndarray,
425425
# Get velocity for scaling autocorrelation function. Won't change much
426426
# but update every pulse to avoid artifacts across images.
427427
v = np.linalg.norm(orbit.interpolate(tout)[1])
428-
acor = isce.core.AzimuthKernel(L / v)
428+
acor = isce3.core.AzimuthKernel(L / v)
429429
# Figure out what pulses are in play by computing weights without mask.
430430
# TODO All we really need is offset and len(weights)... maybe refactor.
431-
offset, weights = isce.focus.get_presum_weights(acor, t, tout)
431+
offset, weights = isce3.focus.get_presum_weights(acor, t, tout)
432432
nw = len(weights)
433433
# Compute valid data mask (transposed).
434434
# NOTE Could store the whole mask instead of recomputing blocks.
@@ -451,14 +451,14 @@ def resample(raw: np.ndarray, t: np.ndarray,
451451
valid = (uid & twiddle).astype(bool)
452452
# Pull out valid times for this mask config and compute weights.
453453
tj = t[offset:offset+nw][valid]
454-
joff, jwgt = isce.focus.get_presum_weights(acor, tj, tout)
454+
joff, jwgt = isce3.focus.get_presum_weights(acor, tj, tout)
455455
assert joff == 0
456456
# Now insert zeros where data is invalid to get full-length weights.
457457
jwgt_full = np.zeros_like(weights)
458458
jwgt_full[valid] = jwgt
459459
lut[uid] = jwgt_full
460460
# Fill weights for entire block using look up table.
461-
w = isce.focus.fill_weights(ids, lut)
461+
w = isce3.focus.fill_weights(ids, lut)
462462
# Read raw data.
463463
block = np.s_[offset:offset+nw, :]
464464
x = raw[block]
@@ -479,7 +479,7 @@ def delete_safely(filename):
479479
pass
480480

481481

482-
def get_range_deramp(grid: isce.product.RadarGridParameters) -> np.ndarray:
482+
def get_range_deramp(grid: isce3.product.RadarGridParameters) -> np.ndarray:
483483
"""Compute the phase ramp required to shift a backprojected grid to
484484
baseband in range.
485485
"""
@@ -502,7 +502,7 @@ def focus(runconfig):
502502
orbit = get_orbit(cfg)
503503
attitude = get_attitude(cfg)
504504
fc_ref, dop_ref = make_doppler(cfg)
505-
zerodop = isce.core.LUT2d()
505+
zerodop = isce3.core.LUT2d()
506506
azres = cfg.processing.azcomp.azimuth_resolution
507507
atmos = cfg.processing.dry_troposphere_model or "nodelay"
508508
kernel = get_kernel(cfg)
@@ -519,14 +519,14 @@ def focus(runconfig):
519519
use_gpu = gpu_check.use_gpu(cfg.worker.gpu_enabled, cfg.worker.gpu_id)
520520
if use_gpu:
521521
# Set the current CUDA device.
522-
device = isce.cuda.core.Device(cfg.worker.gpu_id)
523-
isce.cuda.core.set_device(device)
522+
device = isce3.cuda.core.Device(cfg.worker.gpu_id)
523+
isce3.cuda.core.set_device(device)
524524

525525
log.info(f"Processing using CUDA device {device.id} ({device.name})")
526526

527-
backproject = isce.cuda.focus.backproject
527+
backproject = isce3.cuda.focus.backproject
528528
else:
529-
backproject = isce.focus.backproject
529+
backproject = isce3.focus.backproject
530530

531531
# Generate reference output grid based on highest bandwidth, always A.
532532
log.info(f"Available polarizations: {raw.polarizations}")
@@ -548,8 +548,8 @@ def focus(runconfig):
548548
ogrid["B"] = ogrid["A"][:, ::rskip]
549549
log.info("Output grid B is %s", ogrid["B"])
550550

551-
polygon = isce.geometry.get_geo_perimeter_wkt(ogrid["A"], orbit,
552-
zerodop, dem)
551+
polygon = isce3.geometry.get_geo_perimeter_wkt(ogrid["A"], orbit,
552+
zerodop, dem)
553553

554554
output_slc_path = os.path.abspath(cfg.ProductPathGroup.SASOutputFile)
555555

@@ -639,15 +639,15 @@ def temp(suffix):
639639

640640
rcmode = parse_rangecomp_mode(cfg.processing.rangecomp.mode)
641641
log.info(f"Preparing range compressor with {rcmode}")
642-
rc = isce.focus.RangeComp(chirp, nr, maxbatch=na, mode=rcmode)
642+
rc = isce3.focus.RangeComp(chirp, nr, maxbatch=na, mode=rcmode)
643643

644644
# Rangecomp modifies range grid. Also update wavelength.
645645
rc_grid = raw_grid.copy()
646646
rc_grid.starting_range -= (
647647
rc_grid.range_pixel_spacing * rc.first_valid_sample)
648648
rc_grid.width = rc.output_size
649-
rc_grid.wavelength = isce.core.speed_of_light / fc
650-
igeom = isce.container.RadarGeometry(rc_grid, orbit, dop[frequency])
649+
rc_grid.wavelength = isce3.core.speed_of_light / fc
650+
igeom = isce3.container.RadarGeometry(rc_grid, orbit, dop[frequency])
651651

652652
fd = temp("_rc.c8")
653653
log.info(f"Writing range compressed data to {fd.name}")
@@ -683,7 +683,7 @@ def temp(suffix):
683683
block = np.s_[i:imax, j:jmax]
684684
log.info(f"Azcomp block at (i, j) = ({i}, {j})")
685685
bgrid = ogrid[frequency][block]
686-
ogeom = isce.container.RadarGeometry(bgrid, orbit, zerodop)
686+
ogeom = isce3.container.RadarGeometry(bgrid, orbit, zerodop)
687687
z = np.zeros(bgrid.shape, 'c8')
688688
backproject(z, ogeom, rcfile.data, igeom, dem, fc, azres,
689689
kernel, atmos, vars(cfg.processing.azcomp.rdr2geo),

0 commit comments

Comments
 (0)