Closed ditafaith closed 1 day ago
The bug is caused by the absence of the 'EARTH_RADIUS' key in the metadata dictionary used by MintPy. This key is crucial for calculating azimuth ground resolution. The solution involves ensuring that the 'EARTH_RADIUS' key is present in the metadata file generated by the prep_isce.py
script. If it is missing, a default value should be set. Additionally, the azimuth_ground_resolution
function in utils0.py
should be modified to handle missing keys more gracefully by using a default value.
The bug is caused by the missing 'EARTH_RADIUS' key in the metadata dictionary. The prep_isce.py
script, which prepares metadata files, does not explicitly include or check for this key. Consequently, when the azimuth_ground_resolution
function in utils0.py
attempts to access this key, it results in a KeyError
. The fallback mechanism to use a default value is not functioning as expected, leading to the error.
Modify prep_isce.py
to Include 'EARTH_RADIUS':
Add a check to ensure 'EARTH_RADIUS' is included in the metadata. If missing, set a default value.
# src/mintpy/cli/prep_isce.py
def add_earth_radius_to_metadata(metadata):
if 'EARTH_RADIUS' not in metadata:
metadata['EARTH_RADIUS'] = '6371000' # Default value in meters
return metadata
# Call this function before finalizing the metadata file
metadata = add_earth_radius_to_metadata(metadata)
Ensure Default Value Usage in utils0.py
:
Modify the azimuth_ground_resolution
function to handle missing keys more gracefully.
# src/mintpy/utils/utils0.py
def azimuth_ground_resolution(atr):
Re = float(atr.get('EARTH_RADIUS', 6371000)) # Use default if key is missing
# Rest of the function remains unchanged
prep_isce.py
script to generate metadata for ALOS2 data.KeyError
for 'EARTH_RADIUS' in the error message.Ticket Title: MintPy subset error on alosStack products
The user encountered an error when trying to subset ALOS2 data using MintPy. The error message indicated a missing 'EARTH_RADIUS' key in the metadata. The user ran ISCE2 and MintPy in the same environment, with ISCE2 installed via conda and MintPy via pip. The metadata file was generated using the prep_isce.py
command, but it lacked the necessary 'EARTH_RADIUS' key, leading to the error.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Description of the problem
I ran ISCE2 and MintPy in same environment. However, I installed ISCE2 installed using conda while MintPy using pip. We try to subset ALOS2 data generated from ISCE2 using latitude and longitude information. A metadata file, data.rsc, has been successfully generated using
prep_isce.py
command.However, it gives an error and asks for information such as 'EARTH_RADIUS' as described below.
Full error message
System information