Using Wekeo HDA API with snappy

Hello @marpet and everyone!
I am using the HDA API from Wekeo to access Sentinel-2 and -3 data and I wanted to know if there is a way to read the product without writing it on the disk. Right now, I’m using ZipFile, but I don’t know how to parse it to the ProductIO reader.

Example code with url and headers retrieved from the HDA API to access an OLCI L1B product :

import requests
from snappy import ProductIO
from zipfile import ZipFile
from io import BytesIO

response = requests.get(url, headers=headers)
zipfile = ZipFile(BytesIO(response.content))
xmlname = [zf for zf in zipfile.namelist() if (‘xml’ in zf and ‘S3’ in zf)]
product = ProductIO.readProduct(zipfile.read(xmlname[0]))

My code is maybe a bit stupid as I provide only the content of the xml file but maybe you have a solution. Right now, I just write the file on the disk but it would be great to skip this step!
Thanks in advance for your reply!
Vincent

I think ProductIO.readProduct expects a path to a file as an argument, so probably it is not possible to wrap the return value of zipfile.read into another BytesIO. What might work is creating a temporary file using https://docs.python.org/3.6/library/tempfile.html on a tmpfs (https://en.wikipedia.org/wiki/Tmpfs), which is actually in RAM.

One problem might be that ProductIO.readProduct does not actually read the file in memory, but only references it on disk. So the temporary file needs to exist as long as you are using the product.

Thanks for your reply gbaier!

I guess I’ll just temporarily write the file to the disk then.