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

Fixing bugs #24

Merged
merged 1 commit into from
Oct 2, 2023
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
167 changes: 87 additions & 80 deletions pyraws/raw/raw_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,52 @@ def from_path(self, raw_dir_path, bands_list, verbose=True):
bands list. If None, all bands are used and sorted according to the datasheet order. Defaults to None.
verbose (bool, optional): if True, if True, verbose mode is used. Defaults to True.
"""
if bands_list is None:
bands_list = list(BANDS_RAW_SHAPE_DICT.keys())
try:
(
granules_collection,
granules_paths,
polygon_coordinates_list,
cloud_percentages_list,
) = read_Raw_event_from_path(
raw_dir_path, bands_list, verbose, self.__device
)
except: # noqa: E722
raise ValueError(
"Impossible to open the raw file at: "
+ colored(raw_dir_path, "red")
+ "."
)

granule_names = find_granules_names(granules_paths)
self.__bands_names = bands_list
# These pieces of information are not available since the event is not read from database.
self.__raw_useful_granules_idx = []
self.__raw_complementary_granules_idx = []
self.__event_class = None
self.__useful_granule_bounding_box_dict = {}

for granule, n in zip(granules_collection, range(len(granules_collection))):
new_granule = Raw_granule(device=self.__device)
along_track_size = geopy.distance.geodesic(
polygon_coordinates_list[n][0], polygon_coordinates_list[n][1]
).km
new_granule.create_granule(
bands_list,
granule,
granule_names[n],
polygon_coordinates_list[n],
along_track_size,
cloud_percentages_list[n],
)
self.__granules_collection.append(new_granule)
if not(self.is_void()):
print("Impossible to create a new event from path: " +colored(raw_dir_path, "blue")+". " + colored("Event already instantiated.", "red"))
else:
if bands_list is None:
bands_list = list(BANDS_RAW_SHAPE_DICT.keys())
try:
(
granules_collection,
granules_paths,
polygon_coordinates_list,
cloud_percentages_list,
) = read_Raw_event_from_path(
raw_dir_path, bands_list, verbose, self.__device
)
except: # noqa: E722
raise ValueError(
"Impossible to open the raw file at: "
+ colored(raw_dir_path, "red")
+ "."
)

self.n_granules = len(self.__granules_collection)
granule_names = find_granules_names(granules_paths)
self.__bands_names = bands_list
# These pieces of information are not available since the event is not read from database.
self.__raw_useful_granules_idx = []
self.__raw_complementary_granules_idx = []
self.__event_class = None
self.__useful_granule_bounding_box_dict = {}

for granule, n in zip(granules_collection, range(len(granules_collection))):
new_granule = Raw_granule(device=self.__device)
along_track_size = geopy.distance.geodesic(
polygon_coordinates_list[n][0], polygon_coordinates_list[n][1]
).km
new_granule.create_granule(
bands_list,
granule,
granule_names[n],
polygon_coordinates_list[n],
along_track_size,
cloud_percentages_list[n],
)
self.__granules_collection.append(new_granule)

self.n_granules = len(self.__granules_collection)

def from_database(
self,
Expand All @@ -148,49 +152,52 @@ def from_database(
verbose (bool, optional): if True, if True, verbose mode is used. Defaults to True.
database (string, optional): database name. Defaults to "THRAWS".
"""
if bands_list is None:
bands_list = list(BANDS_RAW_SHAPE_DICT.keys())

(
granules_collection,
event_class,
granule_names,
raw_useful_granules,
raw_complementary_granules,
polygon_coordinates_list,
cloud_percentages_list,
useful_granule_bounding_box_dict,
) = read_Raw_event_from_database(
id_event,
bands_list,
cfg_file_dict,
id_raw_l1_dict,
database,
verbose,
device=self.__device,
)
self.__bands_names = bands_list
self.__raw_useful_granules_idx = raw_useful_granules
self.__raw_complementary_granules_idx = raw_complementary_granules
self.__event_class = event_class
self.__useful_granule_bounding_box_dict = useful_granule_bounding_box_dict

for granule, n in zip(granules_collection, range(len(granules_collection))):
new_granule = Raw_granule(device=self.__device)
along_track_size = geopy.distance.geodesic(
polygon_coordinates_list[n][0], polygon_coordinates_list[n][1]
).km
new_granule.create_granule(
if not(self.is_void()):
print("Impossible to create a new event from: " +colored(id_event, "blue")+". " + colored("Event already instantiated.", "red"))
else:
if bands_list is None:
bands_list = list(BANDS_RAW_SHAPE_DICT.keys())

(
granules_collection,
event_class,
granule_names,
raw_useful_granules,
raw_complementary_granules,
polygon_coordinates_list,
cloud_percentages_list,
useful_granule_bounding_box_dict,
) = read_Raw_event_from_database(
id_event,
bands_list,
granule,
granule_names[n],
polygon_coordinates_list[n],
along_track_size,
cloud_percentages_list[n],
cfg_file_dict,
id_raw_l1_dict,
database,
verbose,
device=self.__device,
)
self.__granules_collection.append(new_granule)
self.__bands_names = bands_list
self.__raw_useful_granules_idx = raw_useful_granules
self.__raw_complementary_granules_idx = raw_complementary_granules
self.__event_class = event_class
self.__useful_granule_bounding_box_dict = useful_granule_bounding_box_dict

self.n_granules = len(self.__granules_collection)
for granule, n in zip(granules_collection, range(len(granules_collection))):
new_granule = Raw_granule(device=self.__device)
along_track_size = geopy.distance.geodesic(
polygon_coordinates_list[n][0], polygon_coordinates_list[n][1]
).km
new_granule.create_granule(
bands_list,
granule,
granule_names[n],
polygon_coordinates_list[n],
along_track_size,
cloud_percentages_list[n],
)
self.__granules_collection.append(new_granule)

self.n_granules = len(self.__granules_collection)

def get_bands_list(self):
"""Returns the list of bands of every Raw_granule object in the collection.
Expand Down
11 changes: 5 additions & 6 deletions pyraws/utils/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,18 @@ def parse_string(str, skip_marks=True, return_int=False):
)
+ "."
)

if (raw_useful_granules_str is not None) and (len(raw_useful_granules_str) != 0):
raw_useful_granules_str = (
raw_useful_granules_str[1:-1].replace(" ", "").split("],")
)
if not ("[" in raw_useful_granules_str) and not (
"]" in raw_useful_granules_str
): # Single granules list
if len(raw_useful_granules_str) == 1:
# Single granules list
raw_useful_granules = [
int(x[0]) if ((x[0] is not None) and (x[0] != "None")) else [None]
for x in [x.split(",") for x in raw_useful_granules_str]
int(x) if ((x is not None) and (x != "None")) else None
for x in raw_useful_granules_str[0].split(",")
]
else:
print(raw_useful_granules_str)
raw_useful_granules = [
[int(x), int(y)] if (x != "None") and (y != "None") else [None, None]
for [x, y] in [
Expand Down