Hello,
I am using the following code to analyze a small section of the sentinel-2 image utilizing the "sline" and "endline" commands to select the boundary. Despite the code running without error and producing an output file in .nc format, it is named with the extension ".SAFE.nc" and cannot be opened. I am wondering if anyone has experience using sline and endline with MSI2 images and if they have found a solution to this issue.
Thank you!
import polymer as polymer
from polymer.main import run_atm_corr
from polymer.level1 import Level1
from polymer.level2 import Level2
from polymer.level1_msi import Level1_MSI
from polymer.level2_nc import Level2_NETCDF
from polymer.ancillary import Ancillary_NASA
run_atm_corr(Level1_MSI('/Users/Desktop/S2A_MSIL1C_20230708T170851_N0509_R112_T15TVN_20230708T223109.SAFE/GRANULE/L1C_T15TVN_A042008_20230708T171755',
resolution='20',
ancillary=Ancillary_NASA(),
sline=5000,
eline=4000,
scol=5000,
ecol=4000),
Level2_NETCDF(outdir='/Users/Desktop')
)
Initialize MSI projection EPSG:32615
/Users....../lib/python3.10/site-packages/pyproj/crs/crs.py:141: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable ... -in-proj-6
in_crs_string = _prepare_from_proj_string(in_crs_string)
Starting processing at 2023-08-01 13:28:39.987322
Initializing output file "/Users/Desktop/S2A_MSIL1C_20230708T170851_N0509_R112_T15TVN_20230708T223109.SAFE.nc"
Done in 0:00:01.497200
<polymer.level2_nc.Level2_NETCDF at 0x1669ef670>
MSI2 Sline Endline command error
-
- Posts: 25
- Joined: Mon Mar 07, 2022 9:54 am
- company / institution: Finnish Environment Institute
- Location: Helsinki, Finland
Re: MSI2 Sline Endline command error
S and E signify "start" and "end". Are your start and end the wrong way around since your eline is smaller than sline and ecol smaller than scol...?
-
- Posts: 4
- Joined: Mon Feb 06, 2023 7:14 pm
- company / institution: Boston University
- Location: United States
Re: MSI2 Sline Endline command error
Hi Sakvaka_env,
Thank you for getting back to me. I attempted to use a lower starting line and larger end line but encountered the error attached below. However, when I reversed the start and end lines, the code successfully ran and generated an output file. Unfortunately, the file seems to be corrupted and only 8 kb. I would greatly appreciate any assistance you could provide.
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[1], line 53
50 input_folder = "/Users/........Sentinel_2_unzip"
51 output_folder = "/Users/.......Satellite_images"
---> 53 apply_polymer(input_folder, output_folder)
Cell In[1], line 38, in apply_polymer(input_folder, output_folder)
35 level1c_file = os.path.join(granule_folder, granule_files[0])
37 # Run the atmospheric correction with the Level-1C file
---> 38 run_atm_corr(
39 Level1_MSI(level1c_file,
40 resolution='20',
41 ancillary=Ancillary_NASA(),
42 sline=4000,
43 eline=5000,
44 scol=4000,
45 ecol=5000),
46 Level2_NETCDF(outdir=output_folder), multiprocessing = -1
47 )
File ~/polymer-v4.16.1/polymer/main.py:521, in run_atm_corr(level1, level2, **kwargs)
517 block_iter = imap(process_block,
518 blockiterator(l1, params, False))
520 # loop over the blocks
--> 521 for block in block_iter:
522 l2.write(block)
524 # finalize level2 file and include global attributes
File ~/miniconda3/envs/lakesense/lib/python3.10/multiprocessing/pool.py:873, in IMapIterator.next(self, timeout)
871 if success:
872 return value
--> 873 raise value
AssertionError: (198, 999) != (198, 1000)
Thank you for getting back to me. I attempted to use a lower starting line and larger end line but encountered the error attached below. However, when I reversed the start and end lines, the code successfully ran and generated an output file. Unfortunately, the file seems to be corrupted and only 8 kb. I would greatly appreciate any assistance you could provide.
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[1], line 53
50 input_folder = "/Users/........Sentinel_2_unzip"
51 output_folder = "/Users/.......Satellite_images"
---> 53 apply_polymer(input_folder, output_folder)
Cell In[1], line 38, in apply_polymer(input_folder, output_folder)
35 level1c_file = os.path.join(granule_folder, granule_files[0])
37 # Run the atmospheric correction with the Level-1C file
---> 38 run_atm_corr(
39 Level1_MSI(level1c_file,
40 resolution='20',
41 ancillary=Ancillary_NASA(),
42 sline=4000,
43 eline=5000,
44 scol=4000,
45 ecol=5000),
46 Level2_NETCDF(outdir=output_folder), multiprocessing = -1
47 )
File ~/polymer-v4.16.1/polymer/main.py:521, in run_atm_corr(level1, level2, **kwargs)
517 block_iter = imap(process_block,
518 blockiterator(l1, params, False))
520 # loop over the blocks
--> 521 for block in block_iter:
522 l2.write(block)
524 # finalize level2 file and include global attributes
File ~/miniconda3/envs/lakesense/lib/python3.10/multiprocessing/pool.py:873, in IMapIterator.next(self, timeout)
871 if success:
872 return value
--> 873 raise value
AssertionError: (198, 999) != (198, 1000)
-
- Posts: 4
- Joined: Mon Feb 06, 2023 7:14 pm
- company / institution: Boston University
- Location: United States
Re: MSI2 Sline Endline command error
Hello,
I was able to find a solution to the problem, but it may not be the most convenient one for selecting the exact bounding box. I observed that the non-subsetting MSI-2 run processes the images in 198x198 pixel blocks. Therefore, I ran the MSI-2 image subsetting with 198 blocks or multiples of it, and it successfully resolved the issue. Any input on how to subset a precise bound box will be greatly appreciated.
run_atm_corr(Level1_MSI('/Users/.../S2A_MSIL1C_20230608T170851_N0509_R112_T15TVN_20230608T221214.SAFE/GRANULE/L1C_T15TVN_A041579_20230608T171514/',
resolution='20',
ancillary=Ancillary_NASA(),
sline=0,
eline=198,
scol=0,
ecol=594),
Level2_NETCDF(outdir='/Users/....../Sentinel_2_unzip')
)
Starting processing at 2023-08-04 10:40:30.236931
Initializing output file "/Users/........./S2A_MSIL1C_20230608T170851_N0509_R112_T15TVN_20230608T221214.SAFE.nc"
Processing block: size (198, 594), offset (0, 0)
Done in 0:00:07.117374
Best,
-Sachini
I was able to find a solution to the problem, but it may not be the most convenient one for selecting the exact bounding box. I observed that the non-subsetting MSI-2 run processes the images in 198x198 pixel blocks. Therefore, I ran the MSI-2 image subsetting with 198 blocks or multiples of it, and it successfully resolved the issue. Any input on how to subset a precise bound box will be greatly appreciated.
run_atm_corr(Level1_MSI('/Users/.../S2A_MSIL1C_20230608T170851_N0509_R112_T15TVN_20230608T221214.SAFE/GRANULE/L1C_T15TVN_A041579_20230608T171514/',
resolution='20',
ancillary=Ancillary_NASA(),
sline=0,
eline=198,
scol=0,
ecol=594),
Level2_NETCDF(outdir='/Users/....../Sentinel_2_unzip')
)
Starting processing at 2023-08-04 10:40:30.236931
Initializing output file "/Users/........./S2A_MSIL1C_20230608T170851_N0509_R112_T15TVN_20230608T221214.SAFE.nc"
Processing block: size (198, 594), offset (0, 0)
Done in 0:00:07.117374
Best,
-Sachini
- fsteinmetz
- Site Admin
- Posts: 306
- Joined: Fri Sep 07, 2018 1:34 pm
- company / institution: Hygeos
- Location: Lille, France
- Contact:
Re: MSI2 Sline Endline command error
Hi,
The answer to your question is in the Level1_MSI docstring ; I agree it may not be the most visible
In your case (resolution=20), eline-sline and ecol-scol must be a multiple of 3, which give you more flexibility than the multiples of 198 you have successfully tested.
Cheers,
François
The answer to your question is in the Level1_MSI docstring ; I agree it may not be the most visible
Code: Select all
sline, eline, scol, ecol refers to the coordinate of the area to process:
* in the 1830x1830 grid at 60m resolution
* in the 5490x5490 grid at 20m resolution
=> eline-sline and ecol-scol must be a multiple of 3
* in the 10980x10980 grid at 10m resolution
=> eline-sline and ecol-scol must be a multiple of 6
Cheers,
François