Repository navigation
Expand file tree
/
Copy pathprocess_junocam.py
More file actions
executable file
·196 lines (158 loc) · 7.98 KB
/
Copy pathprocess_junocam.py
File metadata and controls
executable file
·196 lines (158 loc) · 7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python
import os
import sys
import re
import argparse
from glob import glob
import json
import zipfile
from shutil import copyfile
from sciimg.isis3 import info
from sciimg.isis3 import _core
from sciimg.processes.junocam_conversions import png_to_img
from sciimg.pipelines.junocam import processing
from sciimg.pipelines.junocam import jcspice
from sciimg.pipelines.junocam import modeling
import multiprocessing
def print_if_verbose(s, is_verbose=True):
if is_verbose:
print(s)
def extract(file):
zip_ref = zipfile.ZipFile(file, 'r')
zip_ref.extractall(".")
zip_ref.close()
def decompress_and_copy_file(archive_glob_pattern, file_glob_pattern, verbose=False):
zipfile_list = glob(archive_glob_pattern)
if len(zipfile_list) == 0:
print("Archive file not found")
sys.exit(1)
if verbose:
print("Extracting file '%s'"%zipfile_list[0])
extract(zipfile_list[0])
file_list = glob(file_glob_pattern)
if len(file_list) == 0:
print("Extracted file not found")
sys.exit(1)
if verbose:
print("Copying file '%s'"%file_list[0])
copyfile(file_list[0], "./%s"%(os.path.basename(file_list[0])))
return os.path.basename(file_list[0])
def decompress_image_set(verbose=False):
png_file = decompress_and_copy_file("*ImageSet.zip", "ImageSet/*raw.png", verbose)
if verbose:
print("Found raw PNG file: %s"%png_file)
return png_file
def decompress_metadata(verbose=False):
metadata_file = decompress_and_copy_file("*Data.zip", "DataSet/*-Metadata.json", verbose)
if verbose:
print("Found metadata file: %s"%metadata_file)
return metadata_file
if __name__ == "__main__":
try:
_core.is_isis3_initialized()
except:
print("ISIS3 has not been initialized. Please do so. Now.")
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="Verbose output", action="store_true")
parser.add_argument("-o", "--option", help="Mission-specific option(s)", required=False, type=str, nargs='+')
parser.add_argument("-n", "--nocleanup", help="Don't clean up, leave temp files", action="store_true")
parser.add_argument("-f", "--fill", help="Fill dead pixels", action="store_true")
parser.add_argument("-d", "--decompand", help="Decompand pixel values", action="store_true")
parser.add_argument("-F", "--flat", help="Apply flat fields (Don't use)", action="store_true")
parser.add_argument("-r", "--redweight", help="Apply a weight for the red band", type=float, default=0.902) # 0.510
parser.add_argument("-g", "--greenweight", help="Apply a weight for the green band", type=float,
default=1.0) # 0.630
parser.add_argument("-b", "--blueweight", help="Apply a weight for the blue band", type=float,
default=1.8879) # 1.0
parser.add_argument("-k", "--kernelbase", help="Base directory for spice kernels", required=False, type=str,
default=os.environ["ISISDATA"])
parser.add_argument("-p", "--predicted", help="Utilize predicted kernels", action="store_true")
parser.add_argument("-s", "--scale", help="Mesh Scalar", required=False, type=float, default=1.0)
parser.add_argument("-S", "--skipexisting", help="Skip steps if output files already exist", action="store_true")
parser.add_argument("-t", "--threads", help="Number of threads to use", required=False, type=int, default=multiprocessing.cpu_count())
parser.add_argument("-l", "--linear", help="Use linear colorspace for output", action="store_true")
parser.add_argument("-L", "--limitlon", help="Limit longitude 360 degrees", action="store_true")
parser.add_argument("-B", "--fixbiterror", help="Detect and fix flipped bits", action="store_true")
args = parser.parse_args()
is_verbose = args.verbose
nocleanup = args.nocleanup
fill_dead_pixels = args.fill
do_decompand = args.decompand
do_flat_fields = args.flat
use_red_weight = args.redweight
use_green_weight = args.greenweight
use_blue_weight = args.blueweight
kernelbase = args.kernelbase
allow_predicted = args.predicted
scalar = args.scale
skip_existing = args.skipexisting
num_threads = args.threads
linear_colorspace = args.linear
limit_longitude = args.limitlon
fix_bit_error = args.fixbiterror
additional_options = {}
if is_verbose:
print("Loading spice kernels...")
jcspice.load_kernels(kernelbase, allow_predicted)
if type(args.option) == list:
for option in args.option:
if re.match("^[0-9a-zA-Z_]+=[0-9a-zA-Z]+$", option) is not None:
parts = option.split("=")
additional_options[parts[0]] = parts[1]
else:
print("Invalid option format:", option)
sys.exit(1)
png_file = decompress_image_set(is_verbose)
metadata_file = decompress_metadata(is_verbose)
predicted_product_id = png_file[0:25]
predicted_label_file = "%s-raw-adjusted.lbl"%predicted_product_id
predicted_img_file ="%s-raw-adjusted.img"%predicted_product_id
max_value = None
if skip_existing and os.path.exists(predicted_label_file) and os.path.exists(predicted_img_file):
label_file = predicted_label_file
img_file = predicted_img_file
else:
label_file, img_file, max_value = png_to_img(png_file, metadata_file,
fill_dead_pixels=fill_dead_pixels,
do_decompand=do_decompand,
do_flat_fields=do_flat_fields,
use_red_weight=use_red_weight,
use_green_weight=use_green_weight,
use_blue_weight=use_blue_weight,
doSRGB=not linear_colorspace,
fix_bit_error=fix_bit_error,
verbose=is_verbose)
if is_verbose:
print("Label file created: %s"%label_file)
print("PDS IMG file created: %s"%img_file)
if is_verbose:
print("Processing...")
product_id = info.get_product_id(label_file)
cube_file_red = "%s_%s_Mosaic.cub" % (product_id, "RED")
out_file_map_rgb_cub = "%s_Mosaic_RGB.cub" % product_id
out_file_map_rgb_tiff = "%s_Mosaic_RGB.tif" % product_id
if not (skip_existing and os.path.exists(out_file_map_rgb_cub) and os.path.exists(out_file_map_rgb_tiff)):
out_file_map_rgb_tiff = processing.process_pds_data_file(label_file,
is_verbose=is_verbose,
skip_if_cub_exists=False,
init_spice=True,
nocleanup=nocleanup,
additional_options=additional_options,
num_threads=num_threads,
max_value=max_value,
limit_longitude=limit_longitude)
if is_verbose:
print("Creating output model...")
obj_file_path = "%s_model.obj"%product_id
model_spec_file_path = "%s_model-spec.json" % product_id
if is_verbose:
print("Creating Wavefront OBJ file: %s"%obj_file_path)
model_spec_dict = modeling.create_obj(label_file, out_file_map_rgb_cub, obj_file_path, scalar=scalar, verbose=is_verbose, limit_longitude=limit_longitude)
model_spec_dict["rgb_map_tiff"] = out_file_map_rgb_tiff
model_spec_dict["obj_file"] = obj_file_path
f = open(model_spec_file_path, "w")
f.write(json.dumps(model_spec_dict, indent=4))
f.close()
if os.path.exists("print.prt"):
os.unlink("print.prt")