Questions on SH Python API

Thank you in advance for your help.

To use the SH Python API, I setup a “Python scripts template” with instance as ID. I’m using WCS requests.

  1. Are my custom params (9 out of your 11) correctly defined below?

my_l8tcp = ‘return [B04,B03,B02,B08];’

l8tc_request = WcsRequest(data_source=DataSource.LANDSAT8,
layer=‘L8bands’,
bbox=taber,
time=(‘2017-04-01’, ‘2017-10-01’),
resx=‘15m’, resy=‘15m’,
maxcc=0.1,
instance_id=‘my-instance-id’,
image_format=MimeType.TIFF,
data_folder = ‘C:/POC/Ubuntu/MiddleLayer/test’,
custom_url_params={CustomUrlParam.EVALSCRIPT: my_l8tcp,
CustomUrlParam.ATMFILTER: ‘ATMCOR’,
CustomUrlParam.TRANSPARENT: True,
CustomUrlParam.SHOWLOGO: False,
CustomUrlParam.QUALITY: ‘100’,
CustomUrlParam.PREVIEW: ‘0’,
CustomUrlParam.UPSAMPLING: ‘NEAREST’,
CustomUrlParam.DOWNSAMPLING: ‘NEAREST’,
CustomUrlParam.BGCOLOR: False})

  1. Do I need to define the custom parameters for all/every layer in my above instance and also exactly define custom params (as above) in my Python script? Or will it be enough that I define just in the Python script and it will supersede any custom params defined for a layer/instance? E.g. S2 “NDVI” defined as cloud cover 50%, but in python code I define maxcc as 0.1 (i.e. 10%), or show logo in the instance but show no logo in my python call?

  2. How to correctly define these evalscripts in my Python code?

my_s2tc (S2 true color)
let gain = 2.5;
return [B04, B03, B02].map(a => gain * a);

my_s2fc (S2 false color)
let gain = 2.5;
return [B08, B04, B03].map(a => gain * a);

my_l8tcp (L8 true color pan)
return [B04,B03,B02,B08]

my_l8fcp (L8 false color pan)
return [B05,B04,B03,B08]

  1. Configuration utility gives warning that Sentinel products have different end point than Landsat/MODIS/DEM products and so different instances have to be created. Will it be enough if I create just one “Python scripts template” instance to use with Python API? Or do I need to create one “Python scripts template” for S2 and another “Python scripts template” for Landsat/MODIS/DEM?

  2. My Python code gives error for crs=EPSG:4326. But when I choose crs=CRS.WGS84, image data is returned as 'wcs_TRUE-COLOR-S2-L1C_EPSG4326_.

  3. How to use NICENAME to format downloaded image filenames? This goes into custom params? NICENAME=image-2018-04-11-MODIS.jpg

Hi @arun,

  1. I am only not sure if CustomUrlParam.BGCOLOR: False is ok. This parameter expects a color in hexadecimal code (default is 'FFFFFF'). Probably then the service just ignores your value False. All the other parameters seem to be ok.

  2. Parameters you use in a Python script will always override default parameters defined for your instance or layer in Configurator. If you use maxcc=0.1 in your script this will be used instead of default 0.5 for your layer.

  3. The scripts look ok, you just put each of them into a string an pass it as a value for CustomUrlParam.EVALSCRIPT. You might want to use image_format=MimeType.TIFF_d32fin order to receive back more precise float values.

  4. It is enough to have a single instance. The Python package handles this different endpoint in the process. As long as you specify e.g. data_source=DataSource.LANDSAT8 for a layer, defined to use Landsat 8 as a source in Configurator, the package will know which endpoint to use for download.

  5. WGS84 is just a different name for EPSG:4326. The package uses CRS.WGS84 enum constant to work with this crs. However even if you specify crs='EPSG:4326' (passed as a string) it will automatically parse the string into CRS.WGS84 and work normally. (If it doesn’t, try upgrading the package to a newer version.)

  6. At the moment this option is not supported. But it is a good idea and we will consider implementing it in next versions of the package.

1 Like

Thanks for the detailed reply.
With my evalscript I was hoping to get a 15m pan-sharpened L8 image (gdal_pansharpen.py) from SH, however I think its just returning all 4 bands (B04 B03 B02 bands @ 30 m, B8 band @ 15 m) at 15 m since I set resolution to 15 m.
my_l8tcp = ‘return [B04,B03,B02,B08]’
I had to remove some custom params to reduce filename length as I get the error that my download filename is too long (>255 characters). Other than remove some custom params or reduce length of key words, are there any tricks? Even if I point to your “custom scripts”, it’ll be very long file names.
How to format this JS script (sentinel-2/false_color_infrared/script.js) in PyCharm as I get errors?
my_s2fc =
let gain = 2.5;
return [B08, B04, B03].map(a => gain * a);

In Python you can use triple quotes for defining strings which span over multiple lines

my_s2fc = """
let gain = 2.5;
return [B08, B04, B03].map(a => gain * a);
"""
1 Like

Hi! @maleksandrov
I am getting this error, I don’t know the reason can you please help me with this?

Enum CustomUrlParam.TRANSPARENT was also removed during transition to evalscripts V3 and doesn’t exist in sentinelhub package anymore. Therefore, you can just remove it from the code.