memicemir / ndvi_to_variable_N_application

Use of NDVI (or EVI) index for producing site-specific nitrogen application maps in agriculture.
MIT License
0 stars 0 forks source link

Error when trying to calculate the NDVI and EVI of Sentinel-2. #1

Open hiewliwen opened 3 weeks ago

hiewliwen commented 3 weeks ago

Error when trying to calculate the NDVI and EVI of Sentinel-2. Satellite image: S2B_MSIL1C_20230316T031519_N0509_R118_T48NUG_20230316T055529.SAFE Full traceback.

An error has occurred while executing Python code: 
AttributeError: 'NoneType' object has no attribute 'group' 
Traceback (most recent call last):
  File "C:\Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ndvi_and_evi_index_calculator\ndvi_and_evi_index_calculator.py", line 438, in calculate_ndvi
    date = datetime.strptime(match.group(), '%Y-%m-%d').date()
                             ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'group'

Python version: 3.12.3 (main, Apr 14 2024, 17:21:43) [MSC v.1938 64 bit (AMD64)] 
QGIS version: 3.36.3-Maidenhead Maidenhead, 2df96554 
Python Path:
•   C:/PROGRA~1/QGIS33~2.3/apps/qgis/./python
•   C:/Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python
•   C:/Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
•   C:/PROGRA~1/QGIS33~2.3/apps/qgis/./python/plugins
•   C:\PROGRA~1\QGIS33~2.3\apps\grass\grass83\etc\python
•   C:\Users\xxxxx\Documents
•   C:\Program Files\QGIS 3.36.3\bin\python312.zip
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\DLLs
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib
•   C:\Program Files\QGIS 3.36.3\bin
•   C:\Users\xxxxx\AppData\Roaming\Python\Python312\site-packages
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages\win32
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages\win32\lib
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages\Pythonwin
•   C:/Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python
•   C:\Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\CloudMasking\libs
•   C:\Users\xxxxx\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\DigitizingTools\tools
•   C:\Users\xxxxx\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\DigitizingTools
•   C:/Users/xxxxx/Desktop/SCP
hiewliwen commented 3 weeks ago

Tried on the sample images and the error persists.

An error has occurred while executing Python code: 
TypeError: setValue(self, value: int): argument 1 has unexpected type 'float' 
Traceback (most recent call last):
  File "C:\Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ndvi_and_evi_index_calculator\ndvi_and_evi_index_calculator.py", line 454, in progress_changed
    self.dlg.progressBar.setValue(progress)
TypeError: setValue(self, value: int): argument 1 has unexpected type 'float'

Python version: 3.12.3 (main, Apr 14 2024, 17:21:43) [MSC v.1938 64 bit (AMD64)] 
QGIS version: 3.36.3-Maidenhead Maidenhead, 2df96554 
Python Path:
•   C:/PROGRA~1/QGIS33~2.3/apps/qgis/./python
•   C:/Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python
•   C:/Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
•   C:/PROGRA~1/QGIS33~2.3/apps/qgis/./python/plugins
•   C:\PROGRA~1\QGIS33~2.3\apps\grass\grass83\etc\python
•   C:\Users\xxxxx\Documents
•   C:\Program Files\QGIS 3.36.3\bin\python312.zip
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\DLLs
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib
•   C:\Program Files\QGIS 3.36.3\bin
•   C:\Users\xxxxx\AppData\Roaming\Python\Python312\site-packages
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages\win32
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages\win32\lib
•   C:\PROGRA~1\QGIS33~2.3\apps\Python312\Lib\site-packages\Pythonwin
•   C:/Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python
•   C:\Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\CloudMasking\libs
•   C:\Users\xxxxx\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\DigitizingTools\tools
•   C:\Users\xxxxx\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\DigitizingTools
•   C:/Users/xxxxx/Desktop/SCP
memicemir commented 3 weeks ago

Hi HIEW Li Wen, I will have to download the "QGIS version: 3.36.3-Maidenhead" and install it on my PC, in order to try and reproduce the error... and hopefully figure out what might be the problem... Will look into it today and let you know... Emir

memicemir commented 3 weeks ago

Hi HIEW Li Wen, I installed the new version and i did get the same error regarding the progress bar: "self.dlg.progressBar.setValue(progress) - >TypeError: setValue(self, value: int): argument 1 has unexpected type 'float'"

This error should not prevent you from producing ndvi or evi with the plugin i think.. (at least with my sample image). The solution is simple. Are you familiar with editing and building qgis plugin code? If yes, then all you have to do is in "ndvi_and_evi_index_calculator.py" script in lines: 454 and 513: replace self.dlg.progressBar.setValue(progress) with self.dlg.progressBar.setValue(int(progress))

If you are NOT familiar with editing qgis plugin code and rebuilding it, I can upload new version to my github with this fix, that you could install on your PC in plugin managment as "Install from ZIP".

I will have this fix integrated in next QGIS plugin upload in official qgis repository ... (this option takes more time, since i need to wait for approval).... Emir

memicemir commented 3 weeks ago

Hi HIEW Li Wen, I have uploaded a new version (0.3) here in github that can be installed in qgis plugin mangment "Install from ZIP", and i submitted the new version to official qgis repository (i dont know when that one will be approved for official repository).

I looked into the other error that you mentioned, and have implemented potential solution that might work, since i was not able to reproduce the exact error on my PC (but similar). You can give it a try and let me know if it worked for your error too...

"Traceback (most recent call last): File "C:\Users/xxxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ndvi_and_evi_index_calculator\ndvi_and_evi_index_calculator.py", line 438, in calculate_ndvi date = datetime.strptime(match.group(), '%Y-%m-%d').date() ^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'group'"

hiewliwen commented 2 weeks ago

Hello. The update plugin isn't working. The python error went away, but I spotted a few more issues..

  1. The output of NDVI and EVI are not within -1 to 1.
  2. EVI file not saved.
  3. Progress bar stops at 75%

For reference, the S2 data I am using is S2A_MSIL1C_20240514T031541_N0510_R118_T48NUG_20240514T055452.SAFE

memicemir commented 2 weeks ago

Hi, did you test the plugin with my sample image shared in github, and did it work?

How do you download this image "S2A_MSIL1C_20240514T031541_N0510_R118_T48NUG_20240514T055452.SAFE" so i can try to download it and try to reproduce error on my PC? Can you write me here short download instruction?