Page 1 of 1

Issue with Polymer (Sentinel-2 and Sentinel-3)

Posted: Tue Apr 23, 2024 8:10 am
by nicola.ghirardi
Hello everyone, I have encountered a problem with Polymer.
One of my colleagues passed me two scripts to process Sentinel-2 and Sentinel-3 images, however on my computer they don't seem to work. Below is a description of the error (I report the example for S3 images).

After installing Polymer (the following steps from the "readme" file on Github: 1.1, 1.2 and 1.3) I ran the following commands:

(base) nicola@polymer:~$ cd /home/nicola/Scaricati/polymer-master
(base) nicola@polymer:~/Scaricati/polymer-master$ conda activate polymer
(polymer) nicola@polymer:~/Scaricati/polymer-master$ python3
Traceback (most recent call last):
File "/home/nicola/Scaricati/polymer-master/", line 7, in <module>
from polymer.main import run_atm_corr, Level1, Level2
ImportError: cannot import name 'Level1' from 'polymer.main' (/home/nicola/Scaricati/polymer-master/polymer/

Following is the script for S3 images:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import glob
import datetime

from polymer.main import run_atm_corr, Level1, Level2
from polymer.level2_hdf import Level2_HDF
from polymer.level2_nc import Level2_NETCDF
from polymer.level1_ascii import Level1_ASCII
from polymer.level1_nasa import Level1_NASA
from polymer.level1_msi import Level1_MSI
from polymer.level1_olci import Level1_OLCI
from polymer.gsw import GSW
from polymer.ancillary import Ancillary_NASA
from polymer.ancillary_era5 import Ancillary_ERA5

source_folder = "/home/nicola/Scaricati/Input_S3"
output_folder = "/home/nicola/Scaricati/Output"

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

def process():
product_paths = glob.glob(source_folder + "*.SEN3")

index = 0

for product_path in product_paths:
print(bcolors.OKGREEN + '{} {}/{} done'.format(datetime.datetime.utcnow().isoformat(), index + 1, len(product_paths)) + bcolors.ENDC)
index += 1
#if index >= 3:

# polymer(Level1_OLCI('/mnt/d/polymer/S3A_OL_1_EFR____20160426T093603_20160426T093803_20161217T004355_0119_003_250______MR1_R_NT_002.SEN3'),
# Level2_NETCDF(filename=''),
# #Level2(filename='test.hdf'),
# multiprocessing=0, # activate multiprocessing
# )

# * netcdf4 output can be selected with
# Level2(filename='', fmt='netcdf4')
# * instead of the generic Level1 and Level2 you can use directly
# the appropriate Level1 and Level2 classes (see other examples)

def process_product(product_path):
print(bcolors.OKBLUE + '{} Processing {}'.format(datetime.datetime.utcnow().isoformat(), product_path) + bcolors.ENDC)

basename = os.path.basename(product_path)

if basename.endswith('.SEN3'):
basename = basename[:-5]

output_name = output_folder + basename + '.nc'


Level1_OLCI(product_path, ancillary=Ancillary_ERA5(),landmask=GSW(agg=8)),
Level2_NETCDF(filename=output_name, tmpdir='/tmp/'),
except Exception as e:
print(bcolors.FAIL, end='')
print(bcolors.ENDC, end='')

if __name__ == "__main__":
if not os.path.exists(output_folder):



Re: Issue with Polymer (Sentinel-2 and Sentinel-3)

Posted: Sun Apr 28, 2024 2:16 pm
by wxfei19whu
ImportError: cannot import name 'Level1' from 'polymer.main'

you should change the
from polymer.main import run_atm_corr, Level1, Level2
from polymer.main import run_atm_corr
from polymer.level1 import Level1
from polymer.level2 import Level2

I am a newbee with polymer, and I also puzzled why the code in exist error.
maybe the code in write in old version.

Re: Issue with Polymer (Sentinel-2 and Sentinel-3)

Posted: Thu May 02, 2024 12:43 pm
by nicola.ghirardi
Hi @wxfei19whu,
Unfortunately, it didn't work (same error)
Do you have any other ideas?

Re: Issue with Polymer (Sentinel-2 and Sentinel-3)

Posted: Tue Jun 11, 2024 3:52 pm
by fsteinmetz
Apologies for the late answer, I have made some changes in which was indeed based on an older version.
The fix indicated by wxfei19whu should indeed fix the problem, at least you shouldn't receive an error such as :
ImportError: cannot import name 'Level1' from 'polymer.main'
These changes are also included on the latest github version.
If this error is still present, could you post the error message ?
Cheers, François