Skip to content

Commit 6602cc8

Browse files
mirzaeesmirzaees
andauthored
Blockwise operation (#702)
* Use blockwise operation for round_mantissa to not overload memory * Set chunksize for round_mantissa to 1024 * remove upperbound for gdal * add docstring for chunk_rows * cast los_east, los_north, and incidence_angle to float32 --------- Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
1 parent 51bb7f5 commit 6602cc8

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

conda-env.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dependencies:
55
- python>=3.9
66
- pip>=21.3 # https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#editable-installation
77
- git # for pip install, due to setuptools_scm
8-
- gdal>=3.3,<3.11
8+
- gdal>=3.3
99
- libgdal-netcdf
1010
- libgdal-hdf5
1111
- h5py>=3.6

src/dolphin/atmosphere/ionosphere.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ def estimate_ionospheric_delay(
8888
# Read the incidence angle
8989
if "los_east" in geom_files:
9090
# ISCE3 geocoded products
91-
los_east = io.load_gdal(geom_files["los_east"])
92-
los_north = io.load_gdal(geom_files["los_north"])
91+
los_east = io.load_gdal(geom_files["los_east"]).astype(np.float32)
92+
los_north = io.load_gdal(geom_files["los_north"]).astype(np.float32)
9393
inc_angle = np.arccos(np.sqrt(1 - los_east**2 - los_north**2)) * 180 / np.pi
9494
else:
9595
# ISCE2 radar coordinate
96-
inc_angle = io.load_gdal(geom_files["incidence_angle"])
96+
inc_angle = io.load_gdal(geom_files["incidence_angle"]).astype(np.float32)
9797

9898
iono_inc_angle = incidence_angle_ground_to_iono(inc_angle)
9999

src/dolphin/io/_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def repack_rasters(
233233
)
234234

235235

236-
def round_mantissa(z: np.ndarray, keep_bits: int = 10) -> None:
236+
def round_mantissa(z: np.ndarray, keep_bits: int = 10, chunk_rows: int = 1024) -> None:
237237
"""Zero out mantissa bits of elements of array in place.
238238
239239
Drops a specified number of bits from the floating point mantissa,
@@ -248,6 +248,9 @@ def round_mantissa(z: np.ndarray, keep_bits: int = 10) -> None:
248248
Lower numbers will truncate the mantissa more and enable
249249
more compression.
250250
Default is 10.
251+
chunk_rows : int
252+
Number of rows to process at a time to limit memory usage.
253+
Default is 1024.
251254
252255
References
253256
----------
@@ -261,8 +264,8 @@ def round_mantissa(z: np.ndarray, keep_bits: int = 10) -> None:
261264
}
262265
# recurse for complex data
263266
if np.iscomplexobj(z):
264-
round_mantissa(z.real, keep_bits)
265-
round_mantissa(z.imag, keep_bits)
267+
round_mantissa(z.real, keep_bits, chunk_rows)
268+
round_mantissa(z.imag, keep_bits, chunk_rows)
266269
return
267270

268271
if not z.dtype.kind == "f" or z.dtype.itemsize > 8:
@@ -276,9 +279,10 @@ def round_mantissa(z: np.ndarray, keep_bits: int = 10) -> None:
276279
return z
277280
if keep_bits > bits:
278281
raise ValueError("keep_bits too large for given dtype")
279-
b = z.view(a_int_dtype)
280282
maskbits = bits - keep_bits
281283
mask = (all_set >> maskbits) << maskbits
282284
half_quantum1 = (1 << (maskbits - 1)) - 1
283-
b += ((b >> maskbits) & 1) + half_quantum1
284-
b &= mask
285+
for i in range(0, z.shape[0], chunk_rows):
286+
b = z[i : i + chunk_rows].view(a_int_dtype)
287+
b += ((b >> maskbits) & 1) + half_quantum1
288+
b &= mask

0 commit comments

Comments
 (0)