isce2 icon indicating copy to clipboard operation
isce2 copied to clipboard

Incompatibility with python3.10

Open sssangha opened this issue 3 years ago • 23 comments

In the rangecoreg step, topsApp crashes with the following error message:

....
  File "/u/trappist-r0/ssangha/conda_installation/stable_mach14_2022/envs/ARIA-tools/lib/python3.10/site-packages/isce/components/iscesys/C
omponent/Component.py", line 179, in __call__
    return getattr(self, self.__class__.__name__.lower())(*args)
  File "/u/trappist-r0/ssangha/conda_installation/stable_mach14_2022/envs/ARIA-tools/lib/python3.10/site-packages/isce/components/mroipac/a
mpcor/Ampcor.py", line 335, in ampcor
    self.setState()
  File "/u/trappist-r0/ssangha/conda_installation/stable_mach14_2022/envs/ARIA-tools/lib/python3.10/site-packages/isce/components/mroipac/a
mpcor/Ampcor.py", line 484, in setState
    ampcor.setImageDataType1_Py(str(self.imageDataType1))
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

As documented in other cases (https://stackoverflow.com/questions/70705404/systemerror-py-ssize-t-clean-macro-must-be-defined-for-formats), this error results from isce not being compatible with python3.10.

However, I've confirmed this error is circumvented with using an earlier version (python 3.9.10). So until this compatibility issue is resolved, <python3.10 dependencies should be enforced.

sssangha avatar Mar 15 '22 08:03 sssangha

While I suggested a change to the readme in PR #459 , we need to also impose a hard constraint for now in the conda distribution, with which I experienced these issues

sssangha avatar Mar 15 '22 08:03 sssangha

I pushed a commit to https://github.com/isce-framework/isce2/pull/424 to try to fix this, can you try again on that branch and see if it works now?

rtburns-jpl avatar Mar 24 '22 20:03 rtburns-jpl

I got the similar SystemError: PY_SSIZE_T_CLEAN as below while running dem.py using conda installed isce2 in python 3.10.

dem.py -a stitch -b 37 40 -119 -114 -r -s 1 -c
...
API open (WR): demLat_N37_N40_Lon_W119_W114.dem.wgs84
Traceback (most recent call last):
  File "/home/zyunjun/tools/miniconda3/envs/insar/lib/python3.10/site-packages/isce/applications/dem.py", line 171, in <module>
    sys.exit(main())
  File "/home/zyunjun/tools/miniconda3/envs/insar/lib/python3.10/site-packages/isce/applications/dem.py", line 141, in main
    demImg = ds.correct()
  File "/home/zyunjun/tools/miniconda3/envs/insar/lib/python3.10/site-packages/isce/components/contrib/demUtils/DemStitcher.py", line 862, in correct
    return cg(image,conversionType) if image else cg(self._image,conversionType)
  File "/home/zyunjun/tools/miniconda3/envs/insar/lib/python3.10/site-packages/isce/components/contrib/demUtils/Correct_geoid_i2_srtm.py", line 182, in __call__
    self.correct_geoid_i2_srtm()
  File "/home/zyunjun/tools/miniconda3/envs/insar/lib/python3.10/site-packages/isce/components/contrib/demUtils/Correct_geoid_i2_srtm.py", line 196, in correct_geoid_i2_srtm
    self.setState()
  File "/home/zyunjun/tools/miniconda3/envs/insar/lib/python3.10/site-packages/isce/components/contrib/demUtils/Correct_geoid_i2_srtm.py", line 239, in setState
    correct_geoid_i2_srtm.setGeoidFilename_Py(self.geoidFilename)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I tried to add #define PY_SSIZE_T_CLEAN to correct_geoid_i2_srtmmodule.cpp#L30, then the following Segmentation fault error came out instead:

API open (R): ./demLat_N37_N40_Lon_W119_W114.dem
API close:  ./demLat_N37_N40_Lon_W119_W114.dem
Writing geotrans to VRT for ./demLat_N37_N40_Lon_W119_W114.dem
GDAL open (R): ./demLat_N37_N40_Lon_W119_W114.dem.vrt
API open (WR): demLat_N37_N40_Lon_W119_W114.dem.wgs84
Segmentation fault

yunjunz avatar May 17 '22 03:05 yunjunz

I hit this problem with a Python 3.10 installed by Anaconda also. Is there a way to define the required PY_SSIZE_T_CLEAN globally in all of ISCE2 to make it compatible with Python 3.10? Or does it require other changes?

EJFielding avatar Jul 19 '22 14:07 EJFielding

If you're using cmake, you can try export CFLAGS=-DPY_SSIZE_T_CLEAN and export CXXFLAGS=-DPY_SSIZE_T_CLEAN before running cmake configure, that should set those macros globally for all C/C++ code. Is that sufficient to make it compatible?

rtburns-jpl avatar Jul 19 '22 19:07 rtburns-jpl

I ran into this problem in the NISAR On-demand system where the environment setup notebook installs ISCE2 (and ISCE3) with Anaconda and a yml file that lists isce2 and all the dependencies. Anaconda defaults to Python 3.10 now.

EJFielding avatar Jul 20 '22 02:07 EJFielding

@yunjunz I think I figured out why you're getting a segfault here. Python3.10 changed the size type, so any time we use PyArg_ParseTuple with a 's#' argument we need to change the result var from an int to a Py_ssize_t. Can you check if defining PY_SSIZE_T_CLEAN along with this patch this fixes your dem.py workflow?

--- a/contrib/demUtils/correct_geoid_i2_srtm/bindings/correct_geoid_i2_srtmmodule.cpp
+++ b/contrib/demUtils/correct_geoid_i2_srtm/bindings/correct_geoid_i2_srtmmodule.cpp
@@ -172,12 +172,13 @@ PyObject * setConversionType_C(PyObject* self, PyObject* args)
 PyObject * setGeoidFilename_C(PyObject* self, PyObject* args)
 {
     char * varChar;
-    int  var;
+    Py_ssize_t var;
     if(!PyArg_ParseTuple(args, "s#", &varChar ,&var))
     {
         return NULL;
     }
-    setGeoidFilename_f(varChar,&var);
+    int ivar = var;
+    setGeoidFilename_f(varChar, &ivar);
     return Py_BuildValue("i", 0);
 }

I'll try to fix the other occurrences of this in isce2 to hopefully get us working with python 3.10.

rtburns-jpl avatar Jul 20 '22 17:07 rtburns-jpl

Thank you for fixing @rtburns-jpl. I was trying to test it, but there is a problem while downloading SRTM from the USGS website, so I could not confirm if the fix works or not.

yunjunz avatar Jul 21 '22 17:07 yunjunz

Thank you for fixing @rtburns-jpl. I was trying to test it, but there is a problem while downloading SRTM from the USGS website, so I could not confirm if the fix works or not.

Yeh, @yunjunz, right now, it shows an URL error for me

curl -n  -L -c $HOME/.earthdatacookie -b $HOME/.earthdatacookie -k -f -O http://e4ftl01.cr.usgs.gov/MEASURES/SRTMGL1.003/2000.02.11/N4
1W125.SRTMGL1.hgt.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   299    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 503
2022-07-21 12:48:57,859 - isce.contrib.demUtils.DemStitcher - WARNING - There was a problem in retrieving the file  http://e4ftl01.cr.
usgs.gov/MEASURES/SRTMGL1.003/2000.02.11/N41W125.SRTMGL1.hgt.zip. Exception

yuankailiu avatar Jul 21 '22 20:07 yuankailiu

That's unfortunate. I thought this was a temporary outage but maybe their download url format has changed? Should we open a separate issue for that?

rtburns-jpl avatar Jul 22 '22 19:07 rtburns-jpl

If they changed the SRTM download URLs, then I would recommend a new issue. I was going to open one earlier this week but then it worked for me again at least once. I did not find any announcements about changes but they tend to change it about every two years.

EJFielding avatar Jul 22 '22 19:07 EJFielding

If they changed the SRTM download URLs, then I would recommend a new issue. I was going to open one earlier this week but then it worked for me again at least once. I did not find any announcements about changes but they tend to change it about every two years.

A recently updated thread regarding the connectivity issues: https://forum.earthdata.nasa.gov/viewtopic.php?t=2262#p11891

AhmetMA avatar Jul 24 '22 04:07 AhmetMA

I have had this error for about a month now. Has anyone encountered this error before and solved it

18ea23c6-aff8-4a23-a556-0cc8537178c8

sisi-ali avatar Aug 04 '22 12:08 sisi-ali

I have had this error for about a month now. Has anyone encountered this error before and solved it

Hi sisi-ali,

Yes, we are all getting similar errors. It seems the Land Processes DAAC servers are overloaded for a long time. It works occasionally.

EJFielding avatar Aug 04 '22 21:08 EJFielding

thank for reply me But I can't download even though I'm always trying. You have no solution for this problem. I really need this problem to be solved so that I can move forward with my work

sisi-ali avatar Aug 05 '22 05:08 sisi-ali

@yunjunz I think I figured out why you're getting a segfault here. Python3.10 changed the size type, so any time we use PyArg_ParseTuple with a 's#' argument we need to change the result var from an int to a Py_ssize_t. Can you check if defining PY_SSIZE_T_CLEAN along with this patch this fixes your dem.py workflow?

--- a/contrib/demUtils/correct_geoid_i2_srtm/bindings/correct_geoid_i2_srtmmodule.cpp
+++ b/contrib/demUtils/correct_geoid_i2_srtm/bindings/correct_geoid_i2_srtmmodule.cpp
@@ -172,12 +172,13 @@ PyObject * setConversionType_C(PyObject* self, PyObject* args)
 PyObject * setGeoidFilename_C(PyObject* self, PyObject* args)
 {
     char * varChar;
-    int  var;
+    Py_ssize_t var;
     if(!PyArg_ParseTuple(args, "s#", &varChar ,&var))
     {
         return NULL;
     }
-    setGeoidFilename_f(varChar,&var);
+    int ivar = var;
+    setGeoidFilename_f(varChar, &ivar);
     return Py_BuildValue("i", 0);
 }

I'll try to fix the other occurrences of this in isce2 to hopefully get us working with python 3.10.

@rtburns-jpl with https://github.com/isce-framework/isce2/pull/560 being merged, I confirmed dem.py works fine under python 3.10 with the changes you laid out. Thank you and cheers!

yunjunz avatar Aug 10 '22 21:08 yunjunz

@sisi-ali Please get the new version of ISCE2. We have finally found the necessary change to the DEM downloading code in #560.

EJFielding avatar Aug 10 '22 22:08 EJFielding

Hi everyone I want to calculate the closure_phase_bias.py using the MintPy software that I per-processed on ISCE, but I cant calculate with (https://github.com/insarlab/MintPy/blob/main/mintpy/closure_phase_bias.py) I would be grateful if you could guide me

sisi-ali avatar Aug 21 '22 08:08 sisi-ali

@sisi-ali It would be better to ask on the MintPy discussion site https://github.com/insarlab/MintPy/discussions or on their Google Group.

EJFielding avatar Aug 22 '22 00:08 EJFielding

hi dear Eric Fielding

I want to calculate the closure_phase_bias.py using the MintPy software that I per-processed on ISCE, but I cant calculate with ( https://github.com/insarlab/MintPy/blob/main/mintpy/closure_phase_bias.py) I would be grateful if you could guide me

‫‪Eric Fielding‬‏ @.***‬‏> در تاریخ پنجشنبه ۱۱ اوت ۲۰۲۲ ساعت ۲:۵۳ نوشت:‬

@sisi-ali https://github.com/sisi-ali Please get the new version of ISCE2. We have finally found the necessary change to the DEM downloading code in #560 https://github.com/isce-framework/isce2/pull/560.

— Reply to this email directly, view it on GitHub https://github.com/isce-framework/isce2/issues/458#issuecomment-1211344296, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ3AKUSOWIULYCD26XTE3T3VYQTW7ANCNFSM5QX4THTA . You are receiving this because you were mentioned.Message ID: @.***>

sisi-ali avatar Oct 11 '22 08:10 sisi-ali

Hello,

I running ISCE 2.6.1. The topsApp.py crashes at the DEM steps when it is trying to convert to DEM.

I am getting the same error "SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats"

Is anyone able to help me with this? Thanks!

krive050 avatar Oct 21 '22 20:10 krive050

@krive050 The easy workaround is to change your Python to version 3.9 instead of version 3.10.

EJFielding avatar Oct 21 '22 21:10 EJFielding

@krive050 Please check if https://github.com/isce-framework/isce2/pull/534 resolves your issue. I will merge that PR once I have verification that any workflow is fixed by it.

rtburns-jpl avatar Nov 01 '22 20:11 rtburns-jpl

@yunjunz Hi Dr.Yunjun! I met the same question when using dem.py with Python's version = 3.10. I've tried to add #define PY_SSIZE_T_CLEAN to [correct_geoid_i2_srtmmodule.cpp#L30] but nothing changed at all. Could you please give me hints on solving this problem? Many thanks!

JolinnaYoung avatar Dec 25 '23 08:12 JolinnaYoung

@yunjunz Hi Dr.Yunjun! I met the same question when using dem.py with Python's version = 3.10. I've tried to add #define PY_SSIZE_T_CLEAN to [correct_geoid_i2_srtmmodule.cpp#L30] but nothing changed at all. Could you please give me hints on solving this problem? Many thanks!

Hi Jolinna, you should upgrade to ISCE2 version 2.6.3. It has been updated to work with Python 3.10.

EJFielding avatar Dec 25 '23 19:12 EJFielding

@yunjunz Hi Dr.Yunjun! I met the same question when using dem.py with Python's version = 3.10. I've tried to add #define PY_SSIZE_T_CLEAN to [correct_geoid_i2_srtmmodule.cpp#L30] but nothing changed at all. Could you please give me hints on solving this problem? Many thanks!

Hi Jolinna, you should upgrade to ISCE2 version 2.6.3. It has been updated to work with Python 3.10.

Hi Eric, thanks for your kind reply! I'll try it!

JolinnaYoung avatar Dec 26 '23 02:12 JolinnaYoung