Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue96 sentinel 1 2 l1 #97

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions geospaas_processing/converters/idf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ class Sentinel1IDFConverter(MultiFilesIDFConverter):
"""IDF converter for Sentinel-1 datasets"""

PARAMETER_SELECTORS = (
ParameterSelector(matches=lambda d: re.match('^S1[AB]_[A-Z0-9]{2}_OCN.*$', d.entry_id),
parameter_files=('sentinel1_l2_rvl',)),
ParameterSelector(
matches=lambda d: re.match('^S1[AB]_[A-Z0-9]{2}_OCN.*$', d.entry_id),
parameter_files=('sentinel1_l2_rvl',)),
ParameterSelector(
matches=lambda d: re.match('^S1[AB]_[A-Z0-9]{2}_(GRD|SLC).*$', d.entry_id),
parameter_files=('sentinel1_l1',)),
)

@staticmethod
Expand All @@ -157,6 +161,33 @@ def list_files_to_convert(dataset_file_path):
f"Could not find a measurement directory inside {dataset_file_path}") from error


@IDFConversionManager.register()
class Sentinel2IDFConverter(MultiFilesIDFConverter):
"""IDF converter for Sentinel-2 datasets"""

PARAMETER_SELECTORS = (
ParameterSelector(
matches=lambda d: re.match('^S2[AB]_MSIL1C.*$', d.entry_id),
parameter_files=('sentinel2_l1',)),
)

@staticmethod
def list_files_to_convert(dataset_file_path):
"""Returns the path to the granule L1C directory of the
dataset
"""
measurement_dir = os.path.join(dataset_file_path, 'GRANULE')
try:
return [
os.path.join(measurement_dir, path)
for path in os.listdir(measurement_dir)
if path.startswith('L1C')
]
except (FileNotFoundError, NotADirectoryError) as error:
raise ConversionError(
f"Could not find a GRANULE directory inside {dataset_file_path}") from error


@IDFConversionManager.register()
class Sentinel3SLSTRL2WSTIDFConverter(MultiFilesIDFConverter):
"""IDF converter for Sentinel 3 SLSTR L2 WST datasets"""
Expand Down
3 changes: 3 additions & 0 deletions geospaas_processing/converters/idf/parameters/sentinel1_l1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-t sentinel1/L1
-o path = seacope/data
collection = sentinel1_l1
3 changes: 3 additions & 0 deletions geospaas_processing/converters/idf/parameters/sentinel2_l1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-t sentinel2/L1
-o path = seacope/data
collection = sentinel2_l1
32 changes: 32 additions & 0 deletions tests/converters/test_idf_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,38 @@ def test_list_files_to_convert_error(self):
self.converter.list_files_to_convert('')


class Sentinel2IDFConverterTestCase(unittest.TestCase):
"""Tests for the Sentinel2IDFConverter class"""

def setUp(self):
self.converter = idf_converter.Sentinel2IDFConverter([])

def test_list_files_to_convert(self):
"""list_files_to_convert() should return all the files
contained in the "measurement" subdirectory of the dataset
directory
"""
contents = ['L1C_T33TVJ_A032566_20230601T095606']

with mock.patch('os.listdir', return_value=contents):
self.assertListEqual(
['dataset_dir/GRANULE/L1C_T33TVJ_A032566_20230601T095606'],
self.converter.list_files_to_convert('dataset_dir')
)

def test_list_files_to_convert_error(self):
"""list_files_to_convert() should raise a ConversionError when
the measurement directory is not present or is not a directory
"""
with mock.patch('os.listdir', side_effect=FileNotFoundError):
with self.assertRaises(converters_base.ConversionError):
self.converter.list_files_to_convert('')

with mock.patch('os.listdir', side_effect=NotADirectoryError):
with self.assertRaises(converters_base.ConversionError):
self.converter.list_files_to_convert('')


class Sentinel3SLSTRL2WSTIDFConverterTestCase(unittest.TestCase):
"""Tests for the Sentinel3SLSTRL2WSTIDFConverter class"""

Expand Down
Loading