EO4Atlantic services may be executed locally outside of the platform. This is currently achieved by means of Jupyter notebooks, which leverage eo4a.development module functions provided by the service framework, and is the recommended method for local service development prior to deployment in the platform.
This notebook demonstrates how to execute the example services provided in the EO4Atlantic service development repository, and may be used as a starting point for executing other (new) services.
In [1]:
# Required imports from service development module.
from eo4a.development import create_wps, describe_service, list_services, monitor_execution, reload_services
As described in the user guide, each EO4Atlantic service is hosted as an OGC Web Processing Service (WPS). When creating the development service container, any WPS definitions found in $EO4A_SERVICES_DIR
will be made available. The following demonstrates how to list the available services.
In [2]:
wps = create_wps() # This reference is instantiated first, and used in most subsequent calls.
reload_services(wps) # This can be used to reload services when local code changes are made.
list_services(wps)
Full details of individual services, including their WPS input and output parameters, can be achieved as follows (the details are loaded from the corresponding wps.py
module), using the id value returned by list_services()
:
In [3]:
describe_service('sentinel2-rgb', wps)
Services are typically executed as follows:
describe_service()
output (taken from the corresponding wps.py
definition).The first example uses the gdalinfo
service to retrieve information about a test raster. First, get the list of service inputs:
In [4]:
describe_service('gdalinfo', wps)
Next, prepare the required inputs, execute the service, and parse the outputs.
In [5]:
inputs = [
('datasetname', '/opt/eo4a/services/gdaltools/tests/data/raster_1k_1k.tif'),
('json', 'false'),
('mm', 'true'),
('stats', 'true'),
('approx_stats', 'true'),
('hist', 'true'),
('nogcp', 'true'),
('nomd', 'false'),
('norat', 'true'),
('noct', 'true'),
('checksum', 'true'),
('listmdd', 'true'),
('mdd', 'all'),
('nofl', 'true'),
('proj4', 'true'),
]
# Synchronous execution
execution = wps.execute('gdalinfo', inputs)
# Check the description for the outputs provided by the service
# Only one output for this service
print('gdalinfo output:')
output = execution.processOutputs[0]
print('%s: %s' % (output.identifier, output.data[0]))
In [6]:
describe_service('gdalwarp', wps)
Again, prepare the required inputs, execute the service, and parse the outputs.
In [7]:
inputs = [
('srcfile', '/opt/eo4a/services/gdaltools/tests/data/raster_1k_1k.tif'),
('dstfile', '/tmp/raster_2k_2k.tif'),
('tr', '2000 2000'),
('co', 'COMPRESS=LZW'),
('overwrite', 'true'),
]
# Synchronous execution
execution = wps.execute('gdalwarp', inputs)
# Check the description for the outputs provided by the service
# Only one output for this service
print('gdalwarp output:')
output = execution.processOutputs[0]
output_raster = output.data[0]
print('%s: %s' % (output.identifier, output_raster))
The resolution of this file can be checked with the gdalinfo
service (check the Pixel Size
values in the output):
In [8]:
inputs = [
('datasetname', output_raster),
('json', 'false'),
('mm', 'true'),
('stats', 'true'),
('approx_stats', 'true'),
('hist', 'true'),
('nogcp', 'true'),
('nomd', 'false'),
('norat', 'true'),
('noct', 'true'),
('checksum', 'true'),
('listmdd', 'true'),
('mdd', 'all'),
('nofl', 'true'),
('proj4', 'true'),
]
# Synchronous execution
execution = wps.execute('gdalinfo', inputs)
# Check the description for the outputs provided by the service
# Only one output for this service
print('gdalinfo output:')
output = execution.processOutputs[0]
print('%s: %s' % (output.identifier, output.data[0]))
It is also possible to execute services asynchronously, where this is recommended for services that may be time-consuming. Note: services are always executed asynchronously when hosted in the EO4Atlantic platform.
The process is similar to synchronous execution:
describe_service()
output (taken from the corresponding wps.py
definition).execute()
.The next example uses the sentinel2-rgb
service to generate a composite RGB raster for a particular Sentinel-2 product. It is executed asynchronously. It assumes that a test product has been previously copied to the host data volume ($EO4A_DATA_DIR/service/test_s2products
). Using directories in $EO4A_DATA_DIR/service
is the recommended approach for local execution of services using real products.
In [9]:
inputs = [
('s2_product_dir', 'test_s2products'), # Location relative to $EO4A_DATA_DIR/service on the host
('r_band', '4'),
('g_band', '3'),
('b_band', '2'),
('resolution', '60'),
]
# Aynchronous execution - note the specification of the 'output' reference
execution = wps.execute('sentinel2-rgb', inputs, output='output_reference')
monitor_execution(execution, sleep_secs=5) # Check every 3 seconds by default
execution.getOutput()
# Check the description for the outputs provided by the service
# Only one output for this service
print('RGB output is available at (relative to $EO4A_DATA_DIR/service):')
output = execution.processOutputs[0]
print('%s: %s' % (output.identifier, output.data[0]))
In [ ]: