Fix a bug in projecting water to cryosphere radargrid#253
Fix a bug in projecting water to cryosphere radargrid#253oberonia78 wants to merge 3 commits intoisce-framework:developfrom
Conversation
| try: | ||
| dst_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER) | ||
| raster_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER) | ||
| except Exception: |
| else: | ||
| tx_to_bbox = osr.CoordinateTransformation(raster_srs, dst_srs) | ||
|
|
||
| # transform two neighboring source points to estimate target resolution | ||
| p00 = tx_to_bbox.TransformPoint(x0, y0)[:2] | ||
| p10 = tx_to_bbox.TransformPoint(x0 + dx, y0)[:2] |
There was a problem hiding this comment.
Revise from here to line 350
hfattahi
left a comment
There was a problem hiding this comment.
Thanks @oberonia78 . Please double check how come project_map_to_radar works between 4326 and UTM and not between polar stereo and 4326! Few more comments below as we discussed in PR review.
| raise RuntimeError("Could not determine raster EPSG from projection.") | ||
| raster_epsg = int(raster_epsg) | ||
|
|
||
| xmin, ymin, xmax, ymax = map(float, bbox) |
There was a problem hiding this comment.
Is this a type?
| xmin, ymin, xmax, ymax = map(float, bbox) | |
| xmin, ymin, xmax, ymax = map(bbox) |
| try: | ||
| raster_srs.AutoIdentifyEPSG() | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
what is this helping with?
| try: | ||
| dst_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER) | ||
| raster_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER) | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
Looks like the order of axis is important for us. If that is the case then you should not pass but raise an exception.
| xmin_src, xmax_src = min(xs), max(xs) | ||
| ymin_src, ymax_src = min(ys), max(ys) |
There was a problem hiding this comment.
Does this work for crossing dateline? Please see the stage_dem.py where we do similar transformations and I think we were more careful crossing dateline.
| # fallback in case estimate becomes zero or numerically unstable | ||
| if not np.isfinite(est_dx) or est_dx <= 0: | ||
| est_dx = max((xmax - xmin) / 1000.0, 1e-6) | ||
| if not np.isfinite(est_dy) or est_dy <= 0: | ||
| est_dy = max((ymax - ymin) / 1000.0, 1e-6) |
There was a problem hiding this comment.
This does not make sense. What is going here?
| # Use source pixel size magnitude to define output resolution in target CRS. | ||
| # This keeps behavior simple and avoids very strange defaults from Warp. | ||
| # For your case (bbox_epsg=4326), output grid becomes lon/lat. | ||
| if bbox_epsg == raster_epsg: | ||
| out_xres = abs(dx) | ||
| out_yres = abs(dy) | ||
| else: | ||
| tx_to_bbox = osr.CoordinateTransformation(raster_srs, dst_srs) | ||
|
|
||
| # transform two neighboring source points to estimate target resolution | ||
| p00 = tx_to_bbox.TransformPoint(x0, y0)[:2] | ||
| p10 = tx_to_bbox.TransformPoint(x0 + dx, y0)[:2] | ||
| p01 = tx_to_bbox.TransformPoint(x0, y0 + dy)[:2] | ||
|
|
||
| est_dx = abs(p10[0] - p00[0]) | ||
| est_dy = abs(p01[1] - p00[1]) |
There was a problem hiding this comment.
Please double check and clean up.
| if "water" in mask_type and filter_bool: | ||
| water_mask_path = cfg[ | ||
| "dynamic_ancillary_file_group"]["water_mask_file"] |
There was a problem hiding this comment.
what if the water_mask_path is None? please do the check
| warped_band = warped_ds.GetRasterBand(1) | ||
| if warped_band is None: | ||
| raise RuntimeError("Failed to access warped raster band.") | ||
|
|
||
| arr = warped_band.ReadAsArray() | ||
| if arr is None: | ||
| raise RuntimeError("Failed to read warped raster window.") | ||
|
|
||
| warped_gt = warped_ds.GetGeoTransform() | ||
| if warped_gt is None: | ||
| raise RuntimeError("Warped raster geotransform is missing.") |
There was a problem hiding this comment.
In addition to raising the RuntimeError, please use journal to log those error.
This PR fixes three issues related to the use of water masks in ionospheric processing:
When applying the water mask for ionosphere estimation on the main and side bands, the process failed because Frequency A was hard-coded. This PR updates the logic to dynamically select the appropriate projection based on whether the Frequency B radar grid is used.
The processing also failed when using water masks in EPSG:3413 or EPSG:3031, because the code incorrectly assumed an EPSG:4326 projection. This PR fixes the issue by properly handling the input projection and performing the necessary coordinate transformation.
insar.pydeletes the intermediate files but some of them is required for water projection. This PR moves the steps deleting the intermediate files.