esa-snappy 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. esa_snappy-1.0.0/LICENSE +21 -0
  2. esa_snappy-1.0.0/PKG-INFO +53 -0
  3. esa_snappy-1.0.0/README.md +20 -0
  4. esa_snappy-1.0.0/esa_snappy/__init__.py +382 -0
  5. esa_snappy-1.0.0/esa_snappy/examples/__init__.py +0 -0
  6. esa_snappy-1.0.0/esa_snappy/examples/snappy_bmaths.py +63 -0
  7. esa_snappy-1.0.0/esa_snappy/examples/snappy_flh.py +57 -0
  8. esa_snappy-1.0.0/esa_snappy/examples/snappy_geo_roi.py +57 -0
  9. esa_snappy-1.0.0/esa_snappy/examples/snappy_ndvi.py +81 -0
  10. esa_snappy-1.0.0/esa_snappy/examples/snappy_ndvi_with_masks.py +77 -0
  11. esa_snappy-1.0.0/esa_snappy/examples/snappy_reader_writer_formats.py +25 -0
  12. esa_snappy-1.0.0/esa_snappy/examples/snappy_subset.py +37 -0
  13. esa_snappy-1.0.0/esa_snappy/examples/snappy_write_image.py +107 -0
  14. esa_snappy-1.0.0/esa_snappy/snapista/__init__.py +6 -0
  15. esa_snappy-1.0.0/esa_snappy/snapista/binning/__init__.py +5 -0
  16. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregator_avg.py +68 -0
  17. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregator_avg_outlier.py +46 -0
  18. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregator_minmax.py +46 -0
  19. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregator_on_max_set.py +47 -0
  20. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregator_percentile.py +56 -0
  21. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregator_sum.py +46 -0
  22. esa_snappy-1.0.0/esa_snappy/snapista/binning/aggregators.py +23 -0
  23. esa_snappy-1.0.0/esa_snappy/snapista/binning/binning_band.py +39 -0
  24. esa_snappy-1.0.0/esa_snappy/snapista/binning/binning_variable.py +52 -0
  25. esa_snappy-1.0.0/esa_snappy/snapista/binning/binning_variables.py +34 -0
  26. esa_snappy-1.0.0/esa_snappy/snapista/binning/output_bands.py +34 -0
  27. esa_snappy-1.0.0/esa_snappy/snapista/graph.py +446 -0
  28. esa_snappy-1.0.0/esa_snappy/snapista/graph_io.py +19 -0
  29. esa_snappy-1.0.0/esa_snappy/snapista/operator.py +99 -0
  30. esa_snappy-1.0.0/esa_snappy/snapista/operatorparams.py +47 -0
  31. esa_snappy-1.0.0/esa_snappy/snapista/target_band.py +44 -0
  32. esa_snappy-1.0.0/esa_snappy/snapista/target_band_descriptors.py +19 -0
  33. esa_snappy-1.0.0/esa_snappy/snappyutil.py +325 -0
  34. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/detector_index.hdr +13 -0
  35. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/detector_index.img +0 -0
  36. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/l1_flags.hdr +13 -0
  37. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/l1_flags.img +1 -0
  38. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_1.hdr +14 -0
  39. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_1.img +0 -0
  40. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_10.hdr +14 -0
  41. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_10.img +0 -0
  42. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_11.hdr +14 -0
  43. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_11.img +0 -0
  44. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_12.hdr +14 -0
  45. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_12.img +0 -0
  46. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_13.hdr +14 -0
  47. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_13.img +0 -0
  48. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_14.hdr +14 -0
  49. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_14.img +0 -0
  50. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_15.hdr +14 -0
  51. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_15.img +0 -0
  52. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_2.hdr +14 -0
  53. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_2.img +0 -0
  54. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_3.hdr +14 -0
  55. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_3.img +0 -0
  56. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_4.hdr +14 -0
  57. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_4.img +0 -0
  58. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_5.hdr +14 -0
  59. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_5.img +0 -0
  60. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_6.hdr +14 -0
  61. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_6.img +0 -0
  62. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_7.hdr +14 -0
  63. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_7.img +0 -0
  64. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_8.hdr +14 -0
  65. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_8.img +0 -0
  66. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_9.hdr +14 -0
  67. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/radiance_9.img +0 -0
  68. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/atm_press.hdr +13 -0
  69. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/atm_press.img +0 -0
  70. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/dem_alt.hdr +13 -0
  71. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/dem_alt.img +0 -0
  72. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/dem_rough.hdr +13 -0
  73. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/dem_rough.img +0 -0
  74. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/lat_corr.hdr +13 -0
  75. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/lat_corr.img +0 -0
  76. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/latitude.hdr +13 -0
  77. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/latitude.img +0 -0
  78. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/lon_corr.hdr +13 -0
  79. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/lon_corr.img +0 -0
  80. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/longitude.hdr +13 -0
  81. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/longitude.img +2 -0
  82. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/merid_wind.hdr +13 -0
  83. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/merid_wind.img +0 -0
  84. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/ozone.hdr +13 -0
  85. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/ozone.img +3 -0
  86. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/rel_hum.hdr +13 -0
  87. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/rel_hum.img +0 -0
  88. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/sun_azimuth.hdr +13 -0
  89. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/sun_azimuth.img +1 -0
  90. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/sun_zenith.hdr +13 -0
  91. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/sun_zenith.img +1 -0
  92. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/view_azimuth.hdr +13 -0
  93. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/view_azimuth.img +1 -0
  94. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/view_zenith.hdr +13 -0
  95. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/view_zenith.img +0 -0
  96. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/zonal_wind.hdr +13 -0
  97. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/tie_point_grids/zonal_wind.img +0 -0
  98. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/vector_data/ground_control_points.csv +2 -0
  99. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.data/vector_data/pins.csv +2 -0
  100. esa_snappy-1.0.0/esa_snappy/testdata/MER_FRS_L1B_SUBSET.dim +1209 -0
  101. esa_snappy-1.0.0/esa_snappy/tests/__init__.py +1 -0
  102. esa_snappy-1.0.0/esa_snappy/tests/test_snappy_mem.py +34 -0
  103. esa_snappy-1.0.0/esa_snappy/tests/test_snappy_perf.py +63 -0
  104. esa_snappy-1.0.0/esa_snappy/tests/test_snappy_product.py +103 -0
  105. esa_snappy-1.0.0/esa_snappy.egg-info/PKG-INFO +53 -0
  106. esa_snappy-1.0.0/esa_snappy.egg-info/SOURCES.txt +109 -0
  107. esa_snappy-1.0.0/esa_snappy.egg-info/dependency_links.txt +1 -0
  108. esa_snappy-1.0.0/esa_snappy.egg-info/requires.txt +3 -0
  109. esa_snappy-1.0.0/esa_snappy.egg-info/top_level.txt +2 -0
  110. esa_snappy-1.0.0/pyproject.toml +64 -0
  111. esa_snappy-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Brockmann Consult Development
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.2
2
+ Name: esa_snappy
3
+ Version: 1.0.0
4
+ Summary: The Python part of the SNAP Java-Python bridge.
5
+ Author: Olaf Danne, Norman Fomferra (Brockmann Consult GmbH)
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/pypa/sampleproject
8
+ Project-URL: Issues, https://github.com/pypa/sampleproject/issues
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Typing :: Typed
23
+ Classifier: Operating System :: Microsoft :: Windows
24
+ Classifier: Operating System :: POSIX
25
+ Classifier: Operating System :: Unix
26
+ Classifier: Operating System :: MacOS
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: lxml
31
+ Requires-Dist: attrs
32
+ Requires-Dist: requests
33
+
34
+ # ESA_SNAPPY Package
35
+
36
+ This is the *esa_snappy* Python package. It provides the Python part of the SNAP Python support, which is
37
+ basically realized by the components:
38
+
39
+ - Java module for the configuration of the SNAP - Python interaction.
40
+ - Java-Python bridge *jpy* that enables calls from Python into a Java virtual machine.
41
+ and, at the same time, the other way round. This bridge is implemented by the
42
+ [jpy Project](https://deephaven.io/core/docs/how-to-guides/use-jpy/) and is independent of esa_snappy.
43
+ - **This package**, which provides:
44
+ - Integration of *jpy* and configuration and initialization of the Java-Python bridge for usage with SNAP.
45
+ - Extended support for using SNAP functionalities from Python, e.g. running chains of SNAP GPT operators from
46
+ xml graphs. Formerly hosted as *SNAPISTA* by [Terradue](https://www.terradue.com/), now integrated into the
47
+ *esa_snappy* Python package.
48
+
49
+ ## Further reading:
50
+
51
+ [Using SNAP in your Python programs](https://senbox.atlassian.net/wiki/spaces/SNAP/pages/24051781/Using+SNAP+in+your+Python+programs)
52
+
53
+ [What to consider when writing an Operator in Python](https://senbox.atlassian.net/wiki/spaces/SNAP/pages/42041346/What+to+consider+when+writing+an+Operator+in+Python)
@@ -0,0 +1,20 @@
1
+ # ESA_SNAPPY Package
2
+
3
+ This is the *esa_snappy* Python package. It provides the Python part of the SNAP Python support, which is
4
+ basically realized by the components:
5
+
6
+ - Java module for the configuration of the SNAP - Python interaction.
7
+ - Java-Python bridge *jpy* that enables calls from Python into a Java virtual machine.
8
+ and, at the same time, the other way round. This bridge is implemented by the
9
+ [jpy Project](https://deephaven.io/core/docs/how-to-guides/use-jpy/) and is independent of esa_snappy.
10
+ - **This package**, which provides:
11
+ - Integration of *jpy* and configuration and initialization of the Java-Python bridge for usage with SNAP.
12
+ - Extended support for using SNAP functionalities from Python, e.g. running chains of SNAP GPT operators from
13
+ xml graphs. Formerly hosted as *SNAPISTA* by [Terradue](https://www.terradue.com/), now integrated into the
14
+ *esa_snappy* Python package.
15
+
16
+ ## Further reading:
17
+
18
+ [Using SNAP in your Python programs](https://senbox.atlassian.net/wiki/spaces/SNAP/pages/24051781/Using+SNAP+in+your+Python+programs)
19
+
20
+ [What to consider when writing an Operator in Python](https://senbox.atlassian.net/wiki/spaces/SNAP/pages/42041346/What+to+consider+when+writing+an+Operator+in+Python)
@@ -0,0 +1,382 @@
1
+ """
2
+ The esa_snappy module provides access to the Java SE APIs and SNAP Java APIs.
3
+
4
+ You can configure esa_snappy by using a file named snappy.ini as follows:
5
+
6
+ [DEFAULT]
7
+ snap_home: C:/Program Files/snap
8
+ java_class_path: target/classes
9
+ java_library_path: target/lib/amd64
10
+ java_options: -Djava.awt.headless=true
11
+ java_max_mem: 4G
12
+ debug: False
13
+
14
+ You can place snappy.ini next to <python3>/site-packages/snappy.py or put it in your current working directory.
15
+ The 'snap_home' options and all options starting with 'java_' are only used if you use the SNAP API from Python
16
+ and a new Java Virtual Machine is created. They are ignored if the SNAP API is called from SNAP itself
17
+ (e.g. SNAP command-line or GUI).
18
+
19
+ 'esa_snappy' uses a bundled 'jpy' module, see documentation at http://jpy.readthedocs.org/en/latest
20
+ and source code at https://github.com/bcdev/jpy
21
+ """
22
+
23
+ EXCLUDED_NB_CLUSTERS = {'platform', 'ide', 'bin', 'etc'}
24
+
25
+ EXCLUDED_DIR_NAMES = {'org.esa.snap.snap-worldwind', 'org.esa.snap.snap-rcp', 'org.esa.snap.snap-product-library',
26
+ 'org.esa.snap.snap-sta-ui'}
27
+
28
+ EXCLUDED_JAR_NAMES = {'org-esa-snap-netbeans-docwin.jar', 'org-esa-snap-netbeans-tile.jar',
29
+ 'org-esa-snap-snap-worldwind.jar', 'org-esa-snap-snap-tango.jar', 'org-esa-snap-snap-rcp.jar',
30
+ 'org-esa-snap-snap-ui.jar', 'org-esa-snap-snap-graph-builder.jar',
31
+ 'org-esa-snap-snap-branding.jar'}
32
+
33
+ import glob
34
+ import os
35
+
36
+ import sys
37
+
38
+ if sys.version_info >= (3, 0, 0,):
39
+ # noinspection PyUnresolvedReferences
40
+ import configparser as cp
41
+ else:
42
+ # noinspection PyUnresolvedReferences
43
+ import ConfigParser as cp
44
+
45
+ module_dir = os.path.dirname(os.path.realpath(__file__))
46
+ module_ini = os.path.basename(module_dir) + '.ini'
47
+
48
+ # Read configuration *.ini file from either '.', '<module_dir>/..', '<module_dir>' in this order
49
+ config = cp.ConfigParser()
50
+ config.read([os.path.join(module_dir, module_ini),
51
+ os.path.join(os.path.join(module_dir, '..'), module_ini),
52
+ module_ini
53
+ ])
54
+
55
+ debug = False
56
+ if config.has_option('DEFAULT', 'debug'):
57
+ debug = config.getboolean('DEFAULT', 'debug')
58
+
59
+ # Pre-load Java VM shared library and import 'jpy', the Java-Python bridge
60
+ if module_dir not in sys.path:
61
+ sys.path.append(module_dir)
62
+ import jpyutil
63
+
64
+ jpyutil.preload_jvm_dll()
65
+ import jpy
66
+
67
+ if debug:
68
+ # jpy.diag.F_OFF 0x00
69
+ # jpy.diag.F_TYPE 0x01
70
+ # jpy.diag.F_METH 0x02
71
+ # jpy.diag.F_EXEC 0x04
72
+ # jpy.diag.F_MEM 0x08
73
+ # jpy.diag.F_JVM 0x10
74
+ # jpy.diag.F_ERR 0x20
75
+ # jpy.diag.F_ALL 0xff
76
+ jpy.diag.flags = jpy.diag.F_EXEC + jpy.diag.F_ERR
77
+
78
+
79
+ #
80
+ # Recursively searches for JAR files in 'dir_path' and appends them to the first member of the
81
+ # 'env' tuple (env[0] is the classpath). Also searches for 'lib/LIB_PLATFORM_NAMES[i]' and if one
82
+ # exists, appends it to the second member of the 'env' tuple (env[1] is the java.library.path)
83
+ # Note: Sub-directories named 'locale' or 'docs' are not searched and
84
+ # JAR files ending with '-ui.jar' or '-examples.jar' are excluded.
85
+ #
86
+ # Note: This function is called only if the 'esa_snappy' module is not imported from Java.
87
+ #
88
+ def _collect_snap_jvm_env(dir_path, env):
89
+ for name in os.listdir(dir_path):
90
+ path = os.path.join(dir_path, name)
91
+ if os.path.isfile(path) and name.endswith('.jar'):
92
+ if not (name.endswith('-ui.jar') or name in EXCLUDED_JAR_NAMES):
93
+ env[0][name] = path
94
+ elif os.path.isdir(path) and name not in EXCLUDED_DIR_NAMES:
95
+ if name == 'lib':
96
+ import platform
97
+
98
+ os_arch = platform.machine().lower()
99
+ os_name = platform.system().lower()
100
+ lib_os_arch_path = os.path.join(path, os_arch)
101
+ if os.path.exists(lib_os_arch_path):
102
+ lib_os_name_path = os.path.join(lib_os_arch_path, os_name)
103
+ if os.path.exists(lib_os_name_path):
104
+ env[1].append(lib_os_name_path)
105
+ env[1].append(lib_os_arch_path)
106
+ env[1].append(path)
107
+ if not (name == 'locale' or name == 'docs'):
108
+ _collect_snap_jvm_env(path, env)
109
+
110
+
111
+ #
112
+ # Get the NetBeans user directory for installed extra modules
113
+ #
114
+ def _get_nb_user_modules_dir():
115
+ import platform
116
+ from os.path import expanduser
117
+
118
+ home_dir = expanduser('~')
119
+ nb_user_dir = None
120
+ if platform.system() == 'Windows':
121
+ if home_dir:
122
+ nb_user_dir = os.path.join(home_dir, 'AppData\\Roaming\\SNAP')
123
+ else:
124
+ if home_dir:
125
+ nb_user_dir = os.path.join(home_dir, '.snap/system')
126
+
127
+ if nb_user_dir:
128
+ return os.path.join(nb_user_dir, 'modules')
129
+
130
+ return None
131
+
132
+
133
+ #
134
+ # Searches for *.jar files in directory given by global 'snap_home' variable and returns them as a list.
135
+ #
136
+ # Note: This function is called only if the 'esa_snappy' module is not imported from Java.
137
+ #
138
+ def _get_snap_jvm_env():
139
+ dir_names = []
140
+ for name in os.listdir(snap_home):
141
+ if os.path.isdir(os.path.join(snap_home, name)):
142
+ dir_names.append(name)
143
+
144
+ java_module_dirs = []
145
+
146
+ if 'bin' in dir_names and 'etc' in dir_names and 'snap' in dir_names:
147
+ # SNAP Desktop Distribution Directory
148
+ for dir_name in dir_names:
149
+ if dir_name not in EXCLUDED_NB_CLUSTERS:
150
+ dir_path = os.path.join(snap_home, dir_name, 'modules')
151
+ if os.path.isdir(dir_path):
152
+ java_module_dirs.append(dir_path)
153
+ elif 'lib' in dir_names and 'modules' in dir_names:
154
+ # SNAP Engine Distribution Directory
155
+ java_module_dirs = [os.path.join(snap_home, 'modules'), os.path.join(snap_home, 'lib')]
156
+ elif glob.glob(snap_home + '/*snap-python*.jar'):
157
+ java_module_dirs = [snap_home]
158
+ else:
159
+ raise RuntimeError('does not seem to be a valid SNAP distribution directory: ' + snap_home)
160
+
161
+ # NetBeans modules dir will be scaned as last. It contains the latest module updates and they shall replace
162
+ # older modules
163
+ nb_user_modules_dir = _get_nb_user_modules_dir()
164
+ if nb_user_modules_dir and os.path.isdir(nb_user_modules_dir):
165
+ java_module_dirs.append(nb_user_modules_dir)
166
+
167
+ if debug:
168
+ import pprint
169
+
170
+ print(module_dir + ': java_module_dirs = ')
171
+ pprint.pprint(java_module_dirs)
172
+
173
+ env = (dict(), [])
174
+ for path in java_module_dirs:
175
+ _collect_snap_jvm_env(path, env)
176
+
177
+ if debug:
178
+ import pprint
179
+
180
+ print(module_dir + ': env =')
181
+ pprint.pprint(env)
182
+
183
+ return env
184
+
185
+
186
+ #
187
+ # Creates a list of Java JVM options, including the Java classpath derived from the global 'snap_home' variable.
188
+ #
189
+ # Note: This function is called only if the 'esa_snappy' module is not imported from Java.
190
+ #
191
+ def _get_snap_jvm_options():
192
+ global snap_home
193
+
194
+ if config.has_option('DEFAULT', 'snap_home'):
195
+ snap_home = config.get('DEFAULT', 'snap_home')
196
+ else:
197
+ snap_home = os.getenv('SNAP_HOME')
198
+
199
+ if snap_home is None or not os.path.isdir(snap_home):
200
+ raise IOError("Can't find SNAP distribution directory. Either configure variable 'snap_home' " +
201
+ "in file './snappy.ini' or set environment variable 'SNAP_HOME' to an " +
202
+ "existing SNAP distribution directory.")
203
+
204
+ env = _get_snap_jvm_env()
205
+ class_path = list(env[0].values())
206
+ library_path = env[1]
207
+
208
+ if config.has_option('DEFAULT', 'java_class_path'):
209
+ extra_class_path = config.get('DEFAULT', 'java_class_path')
210
+ class_path += extra_class_path.split(os.pathsep)
211
+
212
+ if config.has_option('DEFAULT', 'java_library_path'):
213
+ extra_library_path = config.get('DEFAULT', 'java_library_path')
214
+ library_path += extra_library_path.split(os.pathsep)
215
+
216
+ max_mem = '512M'
217
+ if config.has_option('DEFAULT', 'java_max_mem'):
218
+ max_mem = config.get('DEFAULT', 'java_max_mem')
219
+
220
+ options = ['-Djava.awt.headless=true',
221
+ '-Djava.class.path=' + os.pathsep.join(class_path),
222
+ '-Djava.library.path=' + os.pathsep.join(library_path),
223
+ '-Dsnap.home=' + snap_home,
224
+ '-Xmx' + max_mem]
225
+
226
+ if config.has_option('DEFAULT', 'java_options'):
227
+ extra_options = config.get('DEFAULT', 'java_options')
228
+ options += extra_options.split('|')
229
+
230
+ return options
231
+
232
+
233
+ # Figure out if this module is called from a Java VM. If not, derive a list of Java VM options and create the Java VM.
234
+ called_from_java = jpy.has_jvm()
235
+ if not called_from_java:
236
+ jpy.create_jvm(options=_get_snap_jvm_options())
237
+
238
+
239
+ # Don't need these functions anymore
240
+ del _get_snap_jvm_options
241
+ del _get_snap_jvm_env
242
+ del _collect_snap_jvm_env
243
+
244
+
245
+ # noinspection PyUnusedLocal
246
+ def annotate_RasterDataNode_methods(type_name, method):
247
+ index = -1
248
+
249
+ if sys.version_info >= (3, 0, 0,):
250
+ arr_z_type_str = "<class '[Z'>"
251
+ arr_i_type_str = "<class '[I'>"
252
+ arr_f_type_str = "<class '[F'>"
253
+ arr_d_type_str = "<class '[D'>"
254
+ else:
255
+ arr_z_type_str = "<type '[Z'>"
256
+ arr_i_type_str = "<type '[I'>"
257
+ arr_f_type_str = "<type '[F'>"
258
+ arr_d_type_str = "<type '[D'>"
259
+
260
+ if method.name == 'readPixels' and method.param_count >= 5:
261
+ index = 4
262
+ param_type_str = str(method.get_param_type(index))
263
+ if param_type_str == arr_i_type_str \
264
+ or param_type_str == arr_f_type_str \
265
+ or param_type_str == arr_d_type_str:
266
+ method.set_param_mutable(index, True)
267
+ method.set_param_output(index, True)
268
+ method.set_param_return(index, True)
269
+
270
+ if method.name == 'readValidMask' and method.param_count == 5:
271
+ index = 4
272
+ param_type_str = str(method.get_param_type(index))
273
+ if param_type_str == arr_z_type_str:
274
+ method.set_param_mutable(index, True)
275
+ method.set_param_output(index, True)
276
+ method.set_param_return(index, True)
277
+
278
+ if index >= 0 and debug:
279
+ print('annotate_RasterDataNode_methods: Method "{0}": '
280
+ 'modified parameter {1:d}: mutable = {2}, return = {3}'
281
+ .format(method.name, index, method.is_param_mutable(index), method.is_param_return(index)))
282
+
283
+ return True
284
+
285
+
286
+ jpy.type_callbacks['org.esa.snap.core.datamodel.RasterDataNode'] = annotate_RasterDataNode_methods
287
+ jpy.type_callbacks['org.esa.snap.core.datamodel.AbstractBand'] = annotate_RasterDataNode_methods
288
+ jpy.type_callbacks['org.esa.snap.core.datamodel.Band'] = annotate_RasterDataNode_methods
289
+ jpy.type_callbacks['org.esa.snap.core.datamodel.VirtualBand'] = annotate_RasterDataNode_methods
290
+
291
+ #
292
+ # Preload and assign frequently used Java classes from the Java SE and SNAP Java API.
293
+ #
294
+
295
+ try:
296
+ # Note we may later want to read pre-defined types from a configuration file (snappy.ini)
297
+
298
+ # Frequently used classes & interfaces from JRE
299
+ String = jpy.get_type('java.lang.String')
300
+ File = jpy.get_type('java.io.File')
301
+ Point = jpy.get_type('java.awt.Point')
302
+ Rectangle = jpy.get_type('java.awt.Rectangle')
303
+ Arrays = jpy.get_type('java.util.Arrays')
304
+ Collections = jpy.get_type('java.util.Collections')
305
+ List = jpy.get_type('java.util.List')
306
+ Map = jpy.get_type('java.util.Map')
307
+ Set = jpy.get_type('java.util.Set')
308
+ ArrayList = jpy.get_type('java.util.ArrayList')
309
+ HashMap = jpy.get_type('java.util.HashMap')
310
+ HashSet = jpy.get_type('java.util.HashSet')
311
+
312
+ #
313
+ # Frequently used classes & interfaces from SNAP Engine
314
+ #
315
+
316
+ # Product tree & associates
317
+ Product = jpy.get_type('org.esa.snap.core.datamodel.Product')
318
+ VectorDataNode = jpy.get_type('org.esa.snap.core.datamodel.VectorDataNode')
319
+ RasterDataNode = jpy.get_type('org.esa.snap.core.datamodel.RasterDataNode')
320
+ TiePointGrid = jpy.get_type('org.esa.snap.core.datamodel.TiePointGrid')
321
+ AbstractBand = jpy.get_type('org.esa.snap.core.datamodel.AbstractBand')
322
+ Band = jpy.get_type('org.esa.snap.core.datamodel.Band')
323
+ VirtualBand = jpy.get_type('org.esa.snap.core.datamodel.VirtualBand')
324
+ Mask = jpy.get_type('org.esa.snap.core.datamodel.Mask')
325
+ GeneralFilterBand = jpy.get_type('org.esa.snap.core.datamodel.GeneralFilterBand')
326
+ ConvolutionFilterBand = jpy.get_type('org.esa.snap.core.datamodel.ConvolutionFilterBand')
327
+
328
+ # Product tree associates
329
+ ProductData = jpy.get_type('org.esa.snap.core.datamodel.ProductData')
330
+ GeoCoding = jpy.get_type('org.esa.snap.core.datamodel.GeoCoding')
331
+ TiePointGeoCoding = jpy.get_type('org.esa.snap.core.datamodel.TiePointGeoCoding')
332
+ ComponentGeoCoding = jpy.get_type('org.esa.snap.core.dataio.geocoding.ComponentGeoCoding')
333
+ CrsGeoCoding = jpy.get_type('org.esa.snap.core.datamodel.CrsGeoCoding')
334
+ GeoPos = jpy.get_type('org.esa.snap.core.datamodel.GeoPos')
335
+ PixelPos = jpy.get_type('org.esa.snap.core.datamodel.PixelPos')
336
+ FlagCoding = jpy.get_type('org.esa.snap.core.datamodel.FlagCoding')
337
+ ProductNodeGroup = jpy.get_type('org.esa.snap.core.datamodel.ProductNodeGroup')
338
+
339
+ # Graph Processing Framework
340
+ GPF = jpy.get_type('org.esa.snap.core.gpf.GPF')
341
+ Operator = jpy.get_type('org.esa.snap.core.gpf.Operator')
342
+ Tile = jpy.get_type('org.esa.snap.core.gpf.Tile')
343
+
344
+ # Utilities
345
+ EngineConfig = jpy.get_type('org.esa.snap.runtime.EngineConfig')
346
+ Engine = jpy.get_type('org.esa.snap.runtime.Engine')
347
+ SystemUtils = jpy.get_type('org.esa.snap.core.util.SystemUtils')
348
+ ProductIO = jpy.get_type('org.esa.snap.core.dataio.ProductIO')
349
+ ProductUtils = jpy.get_type('org.esa.snap.core.util.ProductUtils')
350
+ GeoUtils = jpy.get_type('org.esa.snap.core.util.GeoUtils')
351
+ ProgressMonitor = jpy.get_type('com.bc.ceres.core.ProgressMonitor')
352
+ PlainFeatureFactory = jpy.get_type('org.esa.snap.core.datamodel.PlainFeatureFactory')
353
+ FeatureUtils = jpy.get_type('org.esa.snap.core.util.FeatureUtils')
354
+
355
+ # GeoTools
356
+ DefaultGeographicCRS = jpy.get_type('org.geotools.referencing.crs.DefaultGeographicCRS')
357
+ ListFeatureCollection = jpy.get_type('org.geotools.data.collection.ListFeatureCollection')
358
+ SimpleFeatureBuilder = jpy.get_type('org.geotools.feature.simple.SimpleFeatureBuilder')
359
+
360
+ # JTS
361
+ Geometry = jpy.get_type('org.locationtech.jts.geom.Geometry')
362
+ WKTReader = jpy.get_type('org.locationtech.jts.io.WKTReader')
363
+
364
+
365
+ except Exception:
366
+ jpy.destroy_jvm()
367
+ raise
368
+
369
+
370
+ # Note: use the following code to initialise SNAP's 3rd party libraries, JAI and GeoTools.
371
+ # Only needed, if SNAP Python API is not called from Java (e.g. from SNAP gpt or SNAP desktop).
372
+ if not called_from_java:
373
+ EngineConfig.instance().load()
374
+ SystemUtils.init3rdPartyLibs(None)
375
+
376
+ start_snap_engine = True
377
+ if config.has_option('DEFAULT', 'snap_start_engine'):
378
+ start_snap_engine = config.getboolean('DEFAULT', 'snap_start_engine')
379
+
380
+ if start_snap_engine:
381
+ Engine.start()
382
+
File without changes
@@ -0,0 +1,63 @@
1
+ import sys
2
+
3
+ # This example requires a MERIS L1b product as input
4
+
5
+ # This relative path is for the esa_snappy test setup only, as the esa_snappy module is located two folder levels above.
6
+ # Adapt this path if script shall be run from a different location!
7
+ sys.path.append('../../')
8
+
9
+ from esa_snappy import GPF
10
+ from esa_snappy import HashMap
11
+ from esa_snappy import ProductIO
12
+ from esa_snappy import jpy
13
+
14
+ if len(sys.argv) != 2:
15
+ print("usage: %s <file>" % sys.argv[0])
16
+ sys.exit(1)
17
+
18
+ file = sys.argv[1]
19
+
20
+ print("Reading...")
21
+ product = ProductIO.readProduct(file)
22
+ width = product.getSceneRasterWidth()
23
+ height = product.getSceneRasterHeight()
24
+ name = product.getName()
25
+ description = product.getDescription()
26
+ band_names = product.getBandNames()
27
+
28
+ print("Product: %s, %d x %d pixels, %s" % (name, width, height, description))
29
+ print("Bands: %s" % (list(band_names)))
30
+
31
+ GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
32
+
33
+ BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
34
+
35
+ targetBand1 = BandDescriptor()
36
+ targetBand1.name = 'band_1'
37
+ targetBand1.type = 'float32'
38
+ targetBand1.expression = '(radiance_10 - radiance_7) / (radiance_10 + radiance_7)'
39
+
40
+ targetBand2 = BandDescriptor()
41
+ targetBand2.name = 'band_2'
42
+ targetBand2.type = 'float32'
43
+ targetBand2.expression = '(radiance_9 - radiance_6) / (radiance_9 + radiance_6)'
44
+
45
+ if product.getBand('radiance_10') is None:
46
+ # probably 4RP
47
+ targetBand1.expression = '(M10_radiance - M07_radiance) / (M10_radiance + M07_radiance)'
48
+ targetBand2.expression = '(M09_radiance - M06_radiance) / (M09_radiance + M06_radiance)'
49
+
50
+ targetBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 2)
51
+ targetBands[0] = targetBand1
52
+ targetBands[1] = targetBand2
53
+
54
+ parameters = HashMap()
55
+ parameters.put('targetBands', targetBands)
56
+
57
+ result = GPF.createProduct('BandMaths', parameters, product)
58
+
59
+ print("Writing...")
60
+
61
+ ProductIO.writeProduct(result, 'snappy_bmaths_output.dim', 'BEAM-DIMAP')
62
+
63
+ print("Done.")
@@ -0,0 +1,57 @@
1
+ import numpy
2
+ import sys
3
+
4
+ # This example requires a MERIS L2 water product as input
5
+
6
+ # This relative path is for the esa_snappy test setup only, as the esa_snappy module is located two folder levels above.
7
+ # Adapt this path if script shall be run from a different location!
8
+ sys.path.append('../../')
9
+
10
+ from esa_snappy import Product
11
+ from esa_snappy import ProductData
12
+ from esa_snappy import ProductIO
13
+ from esa_snappy import ProductUtils
14
+ from esa_snappy import String
15
+
16
+
17
+ if len(sys.argv) != 2:
18
+ print("usage: %s <file>" % sys.argv[0]);
19
+ sys.exit(1)
20
+
21
+ print("Reading...")
22
+ sourceProduct = ProductIO.readProduct(sys.argv[1])
23
+ b1 = sourceProduct.getBand('reflec_5')
24
+ b2 = sourceProduct.getBand('reflec_7')
25
+ b3 = sourceProduct.getBand('reflec_9')
26
+ w1 = b1.getSpectralWavelength()
27
+ w2 = b2.getSpectralWavelength()
28
+ w3 = b3.getSpectralWavelength()
29
+ a = (w2 - w1) / (w3 - w1)
30
+ k = 1.03
31
+
32
+ width = sourceProduct.getSceneRasterWidth()
33
+ height = sourceProduct.getSceneRasterHeight()
34
+ targetProduct = Product('FLH_Product', 'FLH_Type', width, height)
35
+ targetBand = targetProduct.addBand('FLH', ProductData.TYPE_FLOAT32)
36
+ ProductUtils.copyGeoCoding(sourceProduct, targetProduct)
37
+ targetProduct.setProductWriter(ProductIO.getProductWriter('GeoTIFF'))
38
+
39
+ targetProduct.writeHeader(String('snappy_flh_output.tif'))
40
+
41
+ r1 = numpy.zeros(width, dtype=numpy.float32)
42
+ r2 = numpy.zeros(width, dtype=numpy.float32)
43
+ r3 = numpy.zeros(width, dtype=numpy.float32)
44
+
45
+ print("Writing...")
46
+
47
+ for y in range(height):
48
+ b1.readPixels(0, y, width, 1, r1)
49
+ b2.readPixels(0, y, width, 1, r2)
50
+ b2.readPixels(0, y, width, 1, r3)
51
+ print("processing line ", y, " of ", height)
52
+ FLH = r2 - k * (r1 + a * (r3 - r1))
53
+ targetBand.writePixels(0, y, width, 1, FLH)
54
+
55
+ targetProduct.closeIO()
56
+
57
+ print("Done.")
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import sys
4
+
5
+ # This relative path is for the esa_snappy test setup only, as the esa_snappy module is located two folder levels above.
6
+ # Adapt this path if script shall be run from a different location!
7
+ sys.path.append('../../')
8
+
9
+ from esa_snappy import (ProgressMonitor, VectorDataNode,
10
+ WKTReader, ProductIO, PlainFeatureFactory,
11
+ SimpleFeatureBuilder, DefaultGeographicCRS,
12
+ ListFeatureCollection, FeatureUtils)
13
+
14
+ if len(sys.argv) != 3:
15
+ print("usage: %s <inputProduct> <wkt>" % sys.argv[0])
16
+ sys.exit(1)
17
+
18
+ input = sys.argv[1]
19
+ inputFileName = input[input.rfind('/')+1:]
20
+
21
+ wellKnownText = sys.argv[2]
22
+
23
+ try:
24
+ geometry = WKTReader().read(wellKnownText)
25
+ except:
26
+ geometry = None
27
+ print('Failed to convert WKT into geometry')
28
+ sys.exit(2)
29
+
30
+ product = ProductIO.readProduct(input)
31
+
32
+ wktFeatureType = PlainFeatureFactory.createDefaultFeatureType(DefaultGeographicCRS.WGS84)
33
+ featureBuilder = SimpleFeatureBuilder(wktFeatureType)
34
+ wktFeature = featureBuilder.buildFeature('shape')
35
+ wktFeature.setDefaultGeometry(geometry)
36
+
37
+ newCollection = ListFeatureCollection(wktFeatureType)
38
+ newCollection.add(wktFeature)
39
+
40
+ productFeatures = FeatureUtils.clipFeatureCollectionToProductBounds(newCollection, product, None, ProgressMonitor.NULL)
41
+
42
+ node = VectorDataNode('shape', productFeatures)
43
+ print ('Num features = ', node.getFeatureCollection().size())
44
+
45
+ product.getVectorDataGroup().add(node)
46
+
47
+ vdGroup = product.getVectorDataGroup()
48
+ for i in range(vdGroup.getNodeCount()):
49
+ print('Vector data = ', vdGroup.get(i).getName())
50
+
51
+ maskGroup = product.getMaskGroup()
52
+ for i in range(maskGroup.getNodeCount()):
53
+ print('Mask = ', maskGroup.get(i).getName())
54
+
55
+
56
+
57
+