Commit f9a6086c authored by Cresson Remi's avatar Cresson Remi
Browse files

ADD: pickle serialization

1 merge request!9Serialize collection
Pipeline #33257 passed with stages
in 1 minute and 31 seconds
Showing with 28 additions and 3 deletions
+28 -3
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
A set of utils to deal with DRS products A set of utils to deal with DRS products
""" """
import tqdm import tqdm
import pickle
from scenes import spot, utils from scenes import spot, utils
...@@ -17,8 +18,8 @@ def find_all_dimaps(pth): ...@@ -17,8 +18,8 @@ def find_all_dimaps(pth):
def get_spot67_scenes(root_dir): def get_spot67_scenes(root_dir):
""" """
Return the list of pairs of PAN/XS DIMAPS Return the list of pairs of PAN/XS DIMAPS
:param root_dir: directory :param root_dir: directory containing "MS" and "PAN" subdirectories
:return: list of pairs of filenames :return: list of Spot67Scenes instances
""" """
# List files # List files
look_dir = root_dir + "/MS" look_dir = root_dir + "/MS"
...@@ -59,3 +60,23 @@ def get_spot67_scenes(root_dir): ...@@ -59,3 +60,23 @@ def get_spot67_scenes(root_dir):
print("\t{}".format(error)) print("\t{}".format(error))
return scenes return scenes
def save_scenes(scenes_list, pickle_file):
"""
Use pickle to save scenes
:param scenes_list: a list of Scene instances
:param pickle_file: pickle file
"""
pickle.dump(scenes_list, open(pickle_file, "wb"))
def load_scenes(pickle_file):
"""
Use pickle to save Spot-6/7 scenes
:param pickle_file: pickle file
:return: list of Scene instances
"""
return pickle.load(open(pickle_file, "rb"))
...@@ -4,7 +4,11 @@ from scenes import drs ...@@ -4,7 +4,11 @@ from scenes import drs
# Arguments # Arguments
parser = argparse.ArgumentParser(description="Test",) parser = argparse.ArgumentParser(description="Test",)
parser.add_argument("--root_dir", help="Root directory containing MS and PAN folders", required=True) parser.add_argument("--root_dir", help="Root directory containing MS and PAN folders", required=True)
parser.add_argument("--out_pickle", help="Output pickle file", required=True)
params = parser.parse_args() params = parser.parse_args()
# Find pairs of DIMAPS # Get all scenes in the root_dir
scenes = drs.get_spot67_scenes(params.root_dir) scenes = drs.get_spot67_scenes(params.root_dir)
# Save scenes in a pickle file
drs.save_scenes(scenes, params.out_pickle)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment