Created
January 9, 2023 09:41
-
-
Save mraspaud/9ad43e2001f8244adff4ef49bc28b028 to your computer and use it in GitHub Desktop.
Read olci level 1 data remotely and create a true_color image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This program is free software: you can redistribute it and/or modify it under | |
the terms of the GNU General Public License as published by the Free Software | |
Foundation, either version 3 of the License, or (at your option) any later | |
version. | |
This program is distributed in the hope that it will be useful, but WITHOUT | |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License along with | |
this program. If not, see <http://www.gnu.org/licenses/>. | |
""" | |
from fsspec.implementations.zip import ZipFileSystem | |
import fsspec | |
from satpy.readers import FSFile | |
from satpy import Scene | |
from satpy.utils import debug_on | |
import netrc | |
from aiohttp import BasicAuth | |
from urllib.parse import urlparse | |
def create_file_list(link, packing): | |
hostname = urlparse(link).hostname | |
login, _, password = netrc.netrc().authenticators(hostname) | |
of = fsspec.open("simplecache::" + link, | |
simplecache={"cache_storage": "/tmp/simplecache"}, | |
https={"client_kwargs": {"auth": BasicAuth(login, password)}}) | |
packfs = fsspec.get_filesystem_class(packing)(of) | |
filelist = packfs.find("/") | |
satpy_files = [] | |
for file in filelist: | |
fsfile = FSFile(file, packfs) | |
satpy_files.append(fsfile) | |
return satpy_files | |
if __name__ == '__main__': | |
debug_on() | |
link = "https://scihub.copernicus.eu/dhus/odata/v1/Products('161774fc-48a4-4e37-aca8-542a3e8dacf7')/$value" | |
packing = "zip" | |
satpy_files = create_file_list(link, packing) | |
scn = Scene(filenames=satpy_files, reader="olci_l1b") | |
composite = "true_color" | |
scn.load([composite]) | |
scn.save_datasets() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment