From 665cc2c8a89739041d476f175c397c0c745b8b3d Mon Sep 17 00:00:00 2001 From: ehavazli Date: Thu, 2 Oct 2025 22:35:47 +0000 Subject: [PATCH 1/4] change variable name to follow the latest format --- src/mintpy/prep_nisar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mintpy/prep_nisar.py b/src/mintpy/prep_nisar.py index b95f22a81..c65b0e2e6 100644 --- a/src/mintpy/prep_nisar.py +++ b/src/mintpy/prep_nisar.py @@ -44,7 +44,7 @@ 'end_time' : f"{IDENTIFICATION}/referenceZeroDopplerEndTime", 'rdr_xcoord' : f"{RADARGRID_ROOT}/xCoordinates", 'rdr_ycoord' : f"{RADARGRID_ROOT}/yCoordinates", - 'rdr_slant_range': f"{RADARGRID_ROOT}/slantRange", + 'rdr_slant_range': f"{RADARGRID_ROOT}/referenceSlantRange", 'rdr_height' : f"{RADARGRID_ROOT}/heightAboveEllipsoid", 'rdr_incidence' : f"{RADARGRID_ROOT}/incidenceAngle", 'bperp' : f"{RADARGRID_ROOT}/perpendicularBaseline", From 5a3d3533450743c5259e70b629e4137e9eb3e065 Mon Sep 17 00:00:00 2001 From: ehavazli Date: Thu, 2 Oct 2025 23:04:22 +0000 Subject: [PATCH 2/4] use gdal.WarpOptions instead of kwargs to avoid GDAL Warp TypeError --- src/mintpy/prep_nisar.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/mintpy/prep_nisar.py b/src/mintpy/prep_nisar.py index c65b0e2e6..42bd63179 100644 --- a/src/mintpy/prep_nisar.py +++ b/src/mintpy/prep_nisar.py @@ -275,10 +275,20 @@ def read_and_interpolate_geometry(gunw_file, dem_file, xybbox, mask_file=None): # Warp DEM to the interferograms grid input_projection = f"EPSG:{dem_src_epsg}" output_dem = os.path.join(os.path.dirname(dem_file), 'dem_transformed.tif' ) - gdal.Warp(output_dem, dem_file, outputBounds=bounds, format='GTiff', - srcSRS=input_projection, dstSRS=output_projection, resampleAlg=gdal.GRA_Bilinear, - width=subset_cols, height=subset_rows, - options=['COMPRESS=DEFLATE']) + + warp_opts = gdal.WarpOptions( + format="GTiff", + outputBounds=bounds, + srcSRS=input_projection, + dstSRS=output_projection, + resampleAlg="bilinear", + width=subset_cols, height=subset_rows, + creationOptions=["COMPRESS=DEFLATE"] + ) + + gdal.Warp(destNameOrDestDS=output_dem, + srcDSOrSrcDSTab=dem_file, + options=warp_opts) dem_subset_array = gdal.Open(output_dem, gdal.GA_ReadOnly).ReadAsArray() From f13ccffc23c1bd3ac5f5b0ecccfb0e5e026e9b71 Mon Sep 17 00:00:00 2001 From: ehavazli Date: Mon, 6 Oct 2025 22:08:21 +0000 Subject: [PATCH 3/4] load ionosphere to MintPy --- src/mintpy/prep_nisar.py | 62 ++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/src/mintpy/prep_nisar.py b/src/mintpy/prep_nisar.py index 42bd63179..3e8d36ef3 100644 --- a/src/mintpy/prep_nisar.py +++ b/src/mintpy/prep_nisar.py @@ -28,7 +28,8 @@ 'unw' : f"{DATASET_ROOT_UNW}/POL/unwrappedPhase", 'cor' : f"{DATASET_ROOT_UNW}/POL/coherenceMagnitude", 'connComp' : f"{DATASET_ROOT_UNW}/POL/connectedComponents", - #'mask' : f"{DATASET_ROOT_UNW}/mask", + 'ion' : f"{DATASET_ROOT_UNW}/POL/ionospherePhaseScreen", + 'mask' : f"{DATASET_ROOT_UNW}/mask", 'epsg' : f"{DATASET_ROOT_UNW}/projection", 'xSpacing' : f"{DATASET_ROOT_UNW}/xCoordinateSpacing", 'ySpacing' : f"{DATASET_ROOT_UNW}/yCoordinateSpacing", @@ -71,6 +72,7 @@ def load_nisar(inps): # output filename stack_file = os.path.join(inps.out_dir, "inputs/ifgramStack.h5") geometry_file = os.path.join(inps.out_dir, "inputs/geometryGeo.h5") + ion_stack_file = os.path.join(inps.out_dir, "inputs/ionStack.h5") # get date info: date12_list date12_list = _get_date_pairs(input_files) @@ -92,6 +94,14 @@ def load_nisar(inps): date12_list=date12_list, ) + # Load ionosphere layer + prepare_stack( + outfile=ion_stack_file, + inp_files=input_files, + metadata=metadata, + bbox=bounds, + date12_list=date12_list, + ) print("Done.") return @@ -239,6 +249,7 @@ def read_subset(inp_file, bbox, geometry=False): dataset['cor_data'] = ds[DATASETS['cor']][row1:row2, col1:col2] dataset['conn_comp'] = (ds[DATASETS['connComp']][row1:row2, col1:col2]).astype(np.float32) dataset['conn_comp'][dataset['conn_comp'] > 254] = np.nan + dataset['ion_data'] = ds[DATASETS['ion']][row1:row2, col1:col2] dataset['pbase'] = np.nanmean(ds[PROCESSINFO['bperp']][()]) return dataset @@ -436,26 +447,47 @@ def prepare_stack( # writing data to HDF5 file print(f"writing data to HDF5 file {outfile} with a mode ...") + if "inputs/ifgramStack.h5" in outfile: + with h5py.File(outfile, "a") as f: + prog_bar = ptime.progressBar(maxValue=num_pair) + for i, file in enumerate(inp_files): + dataset = read_subset(file, bbox) - with h5py.File(outfile, "a") as f: - prog_bar = ptime.progressBar(maxValue=num_pair) - for i, file in enumerate(inp_files): - dataset = read_subset(file, bbox) + # read/write *.unw file + f["unwrapPhase"][i] = dataset['unw_data'] + + # read/write *.cor file + f["coherence"][i] = dataset['cor_data'] + + # read/write *.unw.conncomp file + f["connectComponent"][i] = dataset['conn_comp'] + + # read/write perpendicular baseline file + f['bperp'][i] = dataset['pbase'] + + prog_bar.update(i + 1, suffix=date12_list[i]) + else: + import pdb + pdb.set_trace() + with h5py.File(outfile, "a") as f: + prog_bar = ptime.progressBar(maxValue=num_pair) + for i, file in enumerate(inp_files): + dataset = read_subset(file, bbox) - # read/write *.unw file - f["unwrapPhase"][i] = dataset['unw_data'] + # read/write *.unw file + f["unwrapPhase"][i] = dataset['ion_data'] - # read/write *.cor file - f["coherence"][i] = dataset['cor_data'] + # read/write *.cor file + f["coherence"][i] = dataset['cor_data'] - # read/write *.unw.conncomp file - f["connectComponent"][i] = dataset['conn_comp'] + # read/write *.unw.conncomp file + f["connectComponent"][i] = dataset['conn_comp'] - # read/write perpendicular baseline file - f['bperp'][i] = dataset['pbase'] + # read/write perpendicular baseline file + f['bperp'][i] = dataset['pbase'] - prog_bar.update(i + 1, suffix=date12_list[i]) - prog_bar.close() + prog_bar.update(i + 1, suffix=date12_list[i]) + prog_bar.close() print(f"finished writing to HDF5 file: {outfile}") return outfile From dde21b29af690a9dd355f09a633d4c6c0329b9a2 Mon Sep 17 00:00:00 2001 From: ehavazli Date: Wed, 8 Oct 2025 23:17:17 +0000 Subject: [PATCH 4/4] fix pair datetime extraction --- src/mintpy/prep_nisar.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mintpy/prep_nisar.py b/src/mintpy/prep_nisar.py index 3e8d36ef3..bf2360a9c 100644 --- a/src/mintpy/prep_nisar.py +++ b/src/mintpy/prep_nisar.py @@ -362,7 +362,7 @@ def interpolate_geometry(X_2d, Y_2d, dem, rdr_coords): def _get_date_pairs(filenames): str_list = [Path(f).stem for f in filenames] - return [str(f.split('_')[13]) + '_' + str(f.split('_')[11]) for f in str_list] + return [str(f.split('_')[13].split('T')[0]) + '_' + str(f.split('_')[11].split('T')[0]) for f in str_list] def prepare_geometry( @@ -467,8 +467,6 @@ def prepare_stack( prog_bar.update(i + 1, suffix=date12_list[i]) else: - import pdb - pdb.set_trace() with h5py.File(outfile, "a") as f: prog_bar = ptime.progressBar(maxValue=num_pair) for i, file in enumerate(inp_files):