thank you for your quick reply. Your answers in previous threads were very useful to me. I was able to find a workaround for the issue in the post and now the basic test code is working as follows.
import os
# Set the environment variables
os.environ['JAVA_HOME'] = '/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home'
os.environ['SNAP_HOME'] = '/Applications/esa-snap'
# Verifying the variables
print("JAVA_HOME:", os.environ.get('JAVA_HOME'))
print("SNAP_HOME:", os.environ.get('SNAP_HOME'))
import sys
sys.path.append('/Users/User/.snap/snap-python') # esa_snappy directory
from esa_snappy import ProductIO,GPF
p = ProductIO.readProduct('/Users/User/.snap/snap-python/esa_snappy/testdata/MER_FRS_L1B_SUBSET.dim')
print(list(p.getBandNames()))
After verifying I can import esa_snappy, I wanted to write a basic script that converts .tiff file to .png.
Here is the code that I tried:
# Path to .tiff file
tiff_file = '/Users/PATHTOFILE/S1A_IW_GRDH_1SDV_20240822T032941_20240822T033015_055320_06BECC_2CDD_COG.SAFE/measurement/s1a-iw-grd-vv-20240822t032941-20240822t033015-055320-06becc-001-cog.tiff'
# Load the .tiff file as a product using esa_snappy
product = ProductIO.readProduct(tiff_file)
Output:
RuntimeError Traceback (most recent call last)
Cell In[160], line 8
5 tiff_file = '/Users/PATHTOFILE/TASK_1/S1A_IW_GRDH_1SDV_20240822T032941_20240822T033015_055320_06BECC_2CDD_COG.SAFE/measurement/s1a-iw-grd-vv-20240822t032941-20240822t033015-055320-06becc-001-cog.tiff'
7 # Load the .tiff file as a product using esa_snappy
----> 8 product = ProductIO.readProduct(tiff_file)
RuntimeError: java.lang.NoClassDefFoundError: Could not initialize class org.esa.snap.dataio.gdal.reader.GDALProductReader
I also tried verifying that I can view .tiff files on the SNAP software but the software didn’t allow me. I’d be grateful if you can assist me with this.
good to hear that you could solve your original problem with the hints which were given in this forum.
However, your new problem does not seem to be related to esa_snappy. As you say that you cannot even open that tif file with SNAP desktop, it sounds like a problem in the SNAP core modules. Thus I suggest that you also report the issue in the more general part of the forum, e.g. here. Apart from that I’ll ask colleagues if they might know about the problem.
I located the GDAL folder in the directory you mentioned, and after deleting it, I was able to successfully view the TIFF file using the SNAP software. However, I noticed that the GDAL folder reappears after running SNAP.Here arethe contents of the gdal folder for your reference
The gdal folder is recreated by SNAP if it does not exist. Sometimes it can happen that its content becomes corrupted, and for this reason, it needs to be deleted.
If I understood correctly, you are able to open TIFF files with SNAP, but not from your python script.
Could you remove these to lines and try again? export GDAL_DATA=“/opt/homebrew/share/gdal” export GDAL_LIBRARY_PATH=“/opt/homebrew/lib”