Cannot find the Python API in the latest beta release of SNAP

Hi,

Is it possible to use the python snap api with the new beta release?

I installed it on Ubuntu, but I cannot find the python scripts folder (only the jar file, no python scripts)…
Although, when I compiled Sentinel1 toolbox from the source as suggested on the Github repo, the python api folder could easily be located inside /snap-engine/snap-python.

Thanks.

Is it possible to use the python snap api with the new beta release?

Yes. Well, this was at least the intention.

I installed it on Ubuntu, but I cannot find the python scripts folder (only the jar file, no python scripts).

The JAR (snap/modules/*-snap-python.jar) is a SNAP Java plugin which establishes the bridge of SNAP to Python which is called snappy. Because various Python versions (2.7, 3.3, 3.4) are supported, SNAP must be configured w.r.t. a given Python interpreter. Furthermore, the SNAP Python API will not be activated as long as there is no installed plugin that uses it. However, you can force the configuration of the SNAP Python API by using the command-line as described in Where is snappy?.
It is a weird command-line I confess, we’ll try to make it easier later, e.g. using a dedicated configuration tool with or without GUI.

Thanks a lot for your response.
I re-installed the Sentinel-1 toolbox using the command in the link you shared:

./snap.sh --nogui --nosplash --python /usr/bin/python

Now, ./snap/config/Modules/org-esa-snap-snap-python.xml shows:

<module name="org.esa.snap.snap.python">
    <param name="autoload">false</param>
    <param name="eager">false</param>
    <param name="enabled">**true**</param>
    <param name="jar">modules/org-esa-snap-snap-python.jar</param>
    <param name="reloadable">false</param>
</module>

The Snap Python Bridge seems to be enabled now (I’m not sure though), but the folder that appeared in .snap is snap-jython and it’s empty.

I could not find any python examples after the installation (find . -name *py* didn’t return any python file).

Note that I’m using Python 2.7.

Thanks.
Keep up the good work!

…using the command in the link you shared:

When executing the command-line, SNAP should print out whether the command was successful or not. On success, it prints also where snappy has been installed and how you can import it into your Python code. Did you see anything like it?
Could you please also send me your ${SNAP_INSTALL_DIR}/etc/snap.conf or just paste its contents here.
You may also check the .snap/var/log folder (if any) for log entries that provide more info about the problem.

…is snap-jython and it’s empty.

Actuallly, Jython is used as another SNAP Java-Python bridge, but it is irrelevant for the issue you have.

Keep up the good work!

:slight_smile:

It didn’t print anything related to that… That’s what I got in the end of the install:

Which is your preferred Python version?

If you are a Python developer, you can use the SNAP Java API from Python or
you can even develop Python extensions for SNAP. Here you can specify your
preferred Python version by the given Python executable to be used. Only
Python versions 2.7, 3.3 and 3.4 are supported.
Force SNAP to use the given Python version ?
Yes [y], No [n, Enter]
y
Python executable:
[]
/usr/bin/python
Depending on your system, you can type python, python3, or an absolute path
to a python interpreter execuatble.
Extracting files ...
Downloading ...
  57.3 MB of 57.3 MB (100.0%) at 61,615.9 kb/s
Extracting files ...

Setup has finished installing ESA SNAP on your computer.

Run SNAP Desktop?
Yes [y, Enter], No [n]
n

Please also consider visiting the STEP website. STEP is the Science Toolbox
Exploitation Platform which provides news, documentation, tutorials, and a
vibrant user forum for ESA's free open source Earth Observation toolboxes.
Finishing installation ...
# ${HOME} will be replaced by user home directory according to platform
default_userdir="${HOME}/.snap"
#
# Options used by the launcher by default, can be overridden by explicit command line switches
default_options="--branding snap --jdkhome \"/home/ubuntu/snap/jre\" --locale en_GB -J-XX:+AggressiveOpts -J-Xverify:none -J-Xms256M -J-Xmx5G -J-Dnetbeans.mainclass=org.esa.snap.main.Main -J-Dsun.java2d.noddraw=true -J-Dsun.awt.nopixfmt=true -J-Dsun.java2d.dpiaware=false"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea
#
# Extra cluster paths separated by colon ':'
#extraclusters=""

The .snap folder doesn’t get created until I run snap desktop.
I cannot find any error inside .snap/var/log/messages.log anyway. I have an issue when running Snap Desktop on Amazon EC2 (using xrdp), but that’s a totally different problem (something related to jvm seemingly), and It doesn’t theoritically affect the installation of the Snap python bridge.

Thanks.

After installing SNAP into ${SNAP_INSTALL_DIR}, you can execute the command-line

>  ${SNAP_INSTALL_DIR}/bin/snap.sh --nogui --nosplash --python /usr/bin/python

in order to configure Python. Then please tell me what it prints out.

I have an issue when running Snap Desktop on Amazon EC2 (using xrdp), …

Interesting, please report!

1 Like

Thanks a lot, the .snap/snap-python/ folder got created now, and snappy is imported well from the python prompt after installing it (python setup.py install).

But, it’s actually ${SNAP_INSTALL_DIR}/bin/snap --nogui --nosplash --python /usr/bin/python not snap.sh, that I typed after the normal GUI installation (I guess it’s just a typo).

I will report this issue in another topic, since it’s not related to the current one.

oops, yes we just recognised that the .sh extension is not appended to the executables anymore. We’ll have a look.

Regarding the EC2 issue, consider using the “SNAP” forum as it is probably a common issue to all toolboxes.

Update: since SNAP 2 beta 7, we have included a SNAP Python configuration tool bin/snappy-conf. It should ease configuring a given Python version (2.7, 3.3, or 3.4) with SNAP. It is also run by the installer, if the Python option is selected.

1 Like

Thanks.
Just to confirm that the <snap-dir>/bin/snappy-conf script worked well for me on Ubuntu 14 (64bits).

Thanks for the feedback, hakim!

As I just installed snappy successfully (at least “import snappy” works well in the python command line) with snap beta 7 on Windows 7 64-bit with Python 3.4 64-bit, I just wanted to share a few things:
After installing SNAP I only needed to copy the snappy folder (located in C:\Users<user name>.snap\snap-python\ to the site packages folder in the python directory (this advice was given during snap installation) - so it seems the use of snappy-conf.bat and “python setup.py install” is not necessary anymore
I also ran the three python-scripts for testing (like described here https://github.com/senbox-org/snap-engine/tree/master/snap-python/src/main/resources), but changed the data location in each file to

test_product_file = 'MER_FRS_L1B_SUBSET.dim'

after having put the dim file in the same folder as the python files. Two scripts ran fine, while the “test_snappy_product.py” was not successful. Here the output (I am pretty new to Python, so I cannot really say what it means, can someone clarify?)

C:\Python34\Lib\site-packages\snappy\tests>python test_snappy_product.py
..FFFFF
======================================================================
FAIL: test_getSceneRasterWidthAndHeight (__main__.TestBeamIO)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_snappy_product.py", line 48, in test_getSceneRasterWidthAndHeight
    self.assertEqual(w, 1121)
AssertionError: 221 != 1121

======================================================================
FAIL: test_readPixels_with_java_array (__main__.TestBeamIO)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_snappy_product.py", line 58, in test_readPixels_with_java_array
    self.assertTrue(a[0] == 0.0)
AssertionError: False is not true

======================================================================
FAIL: test_readPixels_with_numpy_array (__main__.TestBeamIO)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_snappy_product.py", line 82, in test_readPixels_with_numpy_array
    self.assertTrue(a[0] == 0.0)
AssertionError: False is not true

======================================================================
FAIL: test_readPixels_with_python_array (__main__.TestBeamIO)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_snappy_product.py", line 72, in test_readPixels_with_python_array
    self.assertTrue(a[0] == 0.0)
AssertionError: False is not true

======================================================================
FAIL: test_readValidMask_with_numpy_array (__main__.TestBeamIO)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_snappy_product.py", line 94, in test_readValidMask_with_numpy_array

    self.assertEqual(a[0], 0)
AssertionError: 1 != 0

----------------------------------------------------------------------
Ran 7 tests in 1.924s

FAILED (failures=5)

Furthermore it would be interesting to know if everyone is using snappy with 64-bit-Python? For numpy I had to install an unofficial version from this website: http://www.lfd.uci.edu/~gohlke/pythonlibs/