pygmtsar icon indicating copy to clipboard operation
pygmtsar copied to clipboard

[Bug]: PRM.py

Open kjz1997 opened this issue 7 months ago • 18 comments

Describe the bug hello professor, when I use the read_SLC_int function of the PRM.py, it report the error, here is the error File "c:\Users\kjzha\.conda\envs\pygmt\Lib\runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\kjzha\.conda\envs\pygmt\Lib\runpy.py", line 88, in _run_code exec(code, run_globals) File "c:\Users\kjzha\.vscode\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module> cli.main() File "c:\Users\kjzha\.vscode\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main run() File "c:\Users\kjzha\.vscode\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file runpy.run_path(target, run_name="__main__") File "c:\Users\kjzha\.vscode\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\kjzha\.vscode\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "c:\Users\kjzha\.vscode\extensions\ms-python.debugpy-2024.8.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "F:\下载文件\pygmtsar-pygmtsar2\pygmtsar-pygmtsar2\pygmtsar\temp2.py", line 44, in <module> block = dask.array.from_delayed( ^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: from_delayed() missing 1 required positional argument: 'shape' It seems that the return value of the read_SLC-block function does not meet the requirements of dask.array.for_delayed, so I change the code, just like values = dask.delayed(read_SLC_block(slc_file, start, stop))(2 * (stop - start)) block = dask.array.from_delayed( values, shape=(2 * (stop - start),), dtype=np.int16, ) then the code works

here is my all code :

import dask.delayed import pygmt import numpy as np import xarray as xr import numpy as np import dask, dask.array import os import warnings

def read_SLC_block(slc_filename, start, stop): return np.memmap( slc_filename, dtype=np.int16, mode="r", offset=start * 4, shape=(2 * (stop - start),), ) grd = r"F:\2018009_2018021\corr.grd" slc_file = r"F:\raw\S1_20180110_ALL_F2.SLC" scale=2.5e-07
xdim = 25272 ydim = 12192 chunksize = 2048 blocksize = chunksize * xdim blocks = int(np.ceil(ydim * xdim / blocksize)) res = [] ims = [] for i in range(blocks): start = i * blocksize stop = min((i + 1) * blocksize, ydim * xdim) values = dask.delayed(read_SLC_block(slc_file, start, stop))(2 * (stop - start)) block = dask.array.from_delayed( values, shape=(2 * (stop - start),), dtype=np.int16, ) res.append(block[::2]) ims.append(block[1::2]) del block re = dask.array.concatenate(res).reshape((-1, xdim))[:ydim, :] im = dask.array.concatenate(ims).reshape((-1, xdim))[:ydim, :] del res, ims coords = {"y": np.arange(ydim) + 0.5, "x": np.arange(xdim) + 0.5} re = xr.DataArray(re, coords=coords).rename("re") im = xr.DataArray(im, coords=coords).rename("im") da = scale * (xr.merge([re, im]).astype(np.float32))

but I found the result is strange here is my result:

<xarray.Dataset> Size: 2GB Dimensions: (y: 12192, x: 25272) Coordinates:

  • y (y) float64 98kB 0.5 1.5 2.5 3.5 ... 1.219e+04 1.219e+04 1.219e+04
  • x (x) float64 202kB 0.5 1.5 2.5 3.5 ... 2.527e+04 2.527e+04 2.527e+04 Data variables: re (y, x) float32 1GB dask.array<chunksize=(2048, 25272), meta=np.ndarray> im (y, x) float32 1GB dask.array<chunksize=(2048, 25272), meta=np.ndarray> it seems that the reuslt is not the SLC`s value, it's more like an offset of row and column numbers. can you give me some suggestion? look forward to your reply

kjz1997 avatar Jul 25 '24 16:07 kjz1997