-
Notifications
You must be signed in to change notification settings - Fork 5
/
render_junocam_cube.py
executable file
·636 lines (500 loc) · 23.1 KB
/
render_junocam_cube.py
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
#!/usr/bin/env python2
import spiceypy as spice
import math
import numpy as np
from PIL import Image
Image.MAX_IMAGE_PIXELS = 5013249900
import argparse
import glob
from scipy.misc import imresize
from sciimg.isis3 import info
from sciimg.isis3 import scripting
from sciimg.isis3 import importexport
from sciimg.isis3 import _core
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.GL import *
def get_screen_dimensions(default=(1024,1024)):
try:
import Tkinter
root = Tkinter.Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
return (width, height)
except:
return default
class Texture:
def __init__(self, cube_file=None):
self.__cube_file = cube_file
self.__tiff_file = self.cube_to_tiff(cube_file)
self.__tex_id = None
def is_loaded(self):
return self.__tex_id is not None
def load(self):
if self.is_loaded():
return
self.load_texture(self.__tiff_file, from16bitTiff=True)
def unload(self):
if not self.is_loaded():
return
# Delete the textures outright. Be rid of the memory
glDeleteTextures(1, (self.__tex_id,))
self.__tex_id = None
def bind(self):
self.load()
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, self.__tex_id)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
def cube_to_tiff(self, cube_file):
source_dirname = os.path.dirname(cube_file)
if source_dirname == "":
source_dirname = "."
work_dir = "%s/work" % source_dirname
if not os.path.exists(work_dir):
os.mkdir(work_dir)
bn = os.path.basename(cube_file)
output_file = "%s/%s.tif" % (work_dir, bn[:-4])
if os.path.exists(output_file):
return output_file
print("Converting", cube_file, "to tiff...")
importexport.isis2std_grayscale(to_tiff=output_file, from_cube=cube_file)
print("done")
return output_file
def convert_16bitgrayscale_to_8bitRGB(self, im):
im = np.copy(np.asarray(im, dtype=np.float32))
im = im / 65535.0
im = im * 255.0
im = np.asarray(np.dstack((im, im, im)), dtype=np.uint8)
return im
def downscale_texture(self, img, max_dimension=16384):
if img.shape[0] > max_dimension or img.shape[1] > max_dimension:
print("Size Before:", img.shape)
ratio = min(float(max_dimension) / float(img.shape[0]), float(max_dimension) / float(img.shape[1]))
resize_to = (int(img.shape[0] * ratio), int(img.shape[1] * ratio))
img = imresize(img, resize_to, interp='bilinear')
print("Size After:", img.shape)
return img
else:
return img
def get_max_texture_size(self):
print(glGetIntegerv(GL_MAX_TEXTURE_SIZE, 0))
def pillow_to_gl_texture(self, image, from16bitTiff=False):
if from16bitTiff:
im = self.convert_16bitgrayscale_to_8bitRGB(image)
im = self.downscale_texture(im, max_dimension=16384)
im = Image.fromarray(im)
ix = im.size[0]
iy = im.size[1]
image = im.tobytes("raw", "RGBX", 0, -1)
else:
ix = image.size[0]
iy = image.size[1]
image = image.tobytes("raw", "RGBX", 0, -1)
return image, ix, iy
def load_texture(self, name, from16bitTiff=False):
if self.__tex_id is not None:
return
print("Loading texture '", name, "...")
# global texture
image = Image.open(name)
image, ix, iy = self.pillow_to_gl_texture(image, from16bitTiff)
# Create Texture
self.__tex_id = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, self.__tex_id ) # 2d texture (x and y size)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
print("Done")
return self.__tex_id
class Model:
def __init__(self, cube_file, label_file):
self.__cube_file = cube_file
self.__label_file = label_file
self.__texture = Texture(cube_file)
self.image_time = info.get_field_value(self.__label_file, "IMAGE_TIME")
self.interframe_delay = float(info.get_field_value(self.__label_file, "INTERFRAME_DELAY")) + 0.001
self.start_time = spice.str2et(info.get_field_value(self.__label_file, "START_TIME")) + 0.06188
self.stop_time = spice.str2et(info.get_field_value(self.__label_file, "STOP_TIME")) + 0.06188
self.mid_time = (self.start_time + self.stop_time) / 2.0
self.num_lines = int(info.get_field_value(self.__label_file, "LINES"))
self.min_lat = float(scripting.getkey(self.__cube_file, "MinimumLatitude", grpname="Mapping"))
self.max_lat = float(scripting.getkey(self.__cube_file, "MaximumLatitude", grpname="Mapping"))
self.min_lon = float(scripting.getkey(self.__cube_file, "MinimumLongitude", grpname="Mapping"))
self.max_lon = float(scripting.getkey(self.__cube_file, "MaximumLongitude", grpname="Mapping"))
self.__model_output = "%s_rendered.tif"%(self.__cube_file[:-4])
self.__program_id = None
def unload_textures(self):
self.__texture.unload()
def get_model_output_filename(self):
return self.__model_output
@staticmethod
def rotation_matrix_to_euler_angles(R):
sy = math.sqrt(R[0, 0] * R[0, 0] + R[1, 0] * R[1, 0])
singular = sy < 1e-6
if not singular:
x = math.atan2(R[2, 1], R[2, 2])
y = math.atan2(-R[2, 0], sy)
z = math.atan2(R[1, 0], R[0, 0])
else:
x = math.atan2(-R[1, 2], R[1, 1])
y = math.atan2(-R[2, 0], sy)
z = 0
return np.array([x, y, z])
@staticmethod
def radians_xyz_to_degrees_xyz(xyz):
return np.array([math.degrees(xyz[0]), math.degrees(xyz[1]), math.degrees(xyz[2])])
def calculate_orientations(self, frame_number=0):
observationStartEt = self.start_time
# https://github.com/USGS-Astrogeology/ISIS3/pull/165
# https://naif.jpl.nasa.gov/pub/naif/JUNO/kernels/ik/juno_junocam_v02.ti
startTimeBias = 0.06188
interFrameDelayBias = 0.001
et = observationStartEt + startTimeBias + (frame_number - 1.0) * (self.interframe_delay + interFrameDelayBias);
jupiter_state, lt = spice.spkpos('JUPITER', et, 'IAU_SUN', 'NONE', 'SUN')
jupiter_state = np.array(jupiter_state)
spacecraft_state, lt = spice.spkpos('JUNO_SPACECRAFT', et, 'IAU_JUPITER', 'NONE', 'JUPITER')
spacecraft_state = np.array(spacecraft_state)
m = spice.pxform("IAU_JUPITER", "J2000", et)
jupiter_rotation = np.array(
((m[0][0], m[0][1], m[0][2], 0.0),
(m[1][0], m[1][1], m[1][2], 0.0),
(m[2][0], m[2][1], m[2][2], 0.0),
(0.0, 0.0, 0.0, 1.0))
)
m = spice.pxform("JUNO_SPACECRAFT", "IAU_JUPITER", et)
spacecraft_orientation = np.array(
((m[0][0], m[0][1], m[0][2], 0.0),
(m[1][0], m[1][1], m[1][2], 0.0),
(m[2][0], m[2][1], m[2][2], 0.0),
(0.0, 0.0, 0.0, 1.0))
)
m = spice.pxform("JUNO_JUNOCAM", "IAU_JUPITER", et)
instrument_orientation = np.array(
((m[0][0], m[0][1], m[0][2], 0.0),
(m[1][0], m[1][1], m[1][2], 0.0),
(m[2][0], m[2][1], m[2][2], 0.0),
(0.0, 0.0, 0.0, 1.0))
)
return spacecraft_orientation, jupiter_state, spacecraft_state, jupiter_rotation, instrument_orientation
def is_framebuffer_ready(self):
return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE
def render(self, frame_number, rotate_x, rotate_y, rotate_z, scale):
spacecraft_orientation, jupiter_state, spacecraft_state, jupiter_rotation, instrument_orientation = self.calculate_orientations(
frame_number=frame_number)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
lighting = False
if lighting is True:
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
light_position = (-jupiter_state[0], -jupiter_state[1], -jupiter_state[2])
glLightfv(GL_LIGHT0, GL_POSITION, light_position, 0)
glShadeModel(GL_SMOOTH)
glLightfv(GL_LIGHT0, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0), 0)
else:
glDisable(GL_LIGHTING)
glScalef(scale, scale, scale)
glRotatef(rotate_x, 1, 0, 0)
glRotatef(rotate_y, 0, 1, 0)
glRotatef(rotate_z, 0, 0, 1)
glMultMatrixf(instrument_orientation)
glTranslatef(-spacecraft_state[0], -spacecraft_state[1], -spacecraft_state[2])
glPushMatrix()
self.draw_image_spherical()
glPopMatrix()
@staticmethod
def normalize_vector(vec):
l = math.sqrt(math.pow(vec[0], 2) + math.pow(vec[1], 2) + math.pow(vec[2], 2))
if l == 0.0:
l = 1.0
return vec[0] / l, vec[1] / l, vec[2] / l
@staticmethod
def calc_surface_normal(v0, v1, v2):
v0 = np.array(v0)
v1 = np.array(v1)
v2 = np.array(v2)
U = v1 - v0
V = v2 - v1
c = np.cross(U, V)
n = Model.normalize_vector(c)
return n
def draw_image_spherical(self, lat_slices=128, lon_slices=128):
if self.__program_id is None:
self.__program_id = glGenLists(1)
glNewList(self.__program_id, GL_COMPILE)
lat_res = (self.max_lat - self.min_lat) / float(lat_slices)
lon_res = (self.max_lon - self.min_lon) / float(lon_slices)
self.__texture.bind()
for y in range(0, int(lat_slices)):
glBegin(GL_TRIANGLES)
for x in range(0, int(lon_slices)):
mx_lat = self.max_lat - (lat_res * y)
mn_lon = self.min_lon + (lon_res * x)
mn_lat = mx_lat - lat_res
mx_lon = mn_lon + lon_res
mx_lat = math.radians(mx_lat)
mn_lat = math.radians(mn_lat)
mx_lon = math.radians(mx_lon)
mn_lon = math.radians(mn_lon)
ul_vector = np.array(spice.srfrec(599, mn_lon, mx_lat))
ll_vector = np.array(spice.srfrec(599, mn_lon, mn_lat))
ur_vector = np.array(spice.srfrec(599, mx_lon, mx_lat))
lr_vector = np.array(spice.srfrec(599, mx_lon, mn_lat))
ul_uv = (x / float(lon_slices), 1.0 - y / float(lat_slices))
ll_uv = (x / float(lon_slices), 1.0 - (y + 1.0) / float(lat_slices))
ur_uv = ((x + 1.0) / float(lon_slices), 1.0 - y / float(lat_slices))
lr_uv = ((x + 1.0) / float(lon_slices), 1.0 - (y + 1.0) / float(lat_slices))
print("Upper Left: ", ul_uv)
print("Lower Left: ", ll_uv)
print("Upper Right: ", ur_uv)
print("Lower Right: ", lr_uv)
norm = self.calc_surface_normal(ul_vector, ll_vector, ur_vector)
glNormal3f(norm[0], norm[1], norm[2])
glTexCoord2f(ul_uv[0], ul_uv[1])
glVertex3f(ul_vector[0], ul_vector[1], ul_vector[2])
glTexCoord2f(ll_uv[0], ll_uv[1])
glVertex3f(ll_vector[0], ll_vector[1], ll_vector[2])
glTexCoord2f(ur_uv[0], ur_uv[1])
glVertex3f(ur_vector[0], ur_vector[1], ur_vector[2])
norm = self.calc_surface_normal(ur_vector, ll_vector, lr_vector)
glNormal3f(norm[0], norm[1], norm[2])
glTexCoord2f(ur_uv[0], ur_uv[1])
glVertex3f(ur_vector[0], ur_vector[1], ur_vector[2])
glTexCoord2f(ll_uv[0], ll_uv[1])
glVertex3f(ll_vector[0], ll_vector[1], ll_vector[2])
glTexCoord2f(lr_uv[0], lr_uv[1])
glVertex3f(lr_vector[0], lr_vector[1], lr_vector[2])
glEnd()
glEndList()
glCallList(self.__program_id)
class RenderEngine:
def __init__(self, cube_file_red, cube_file_green, cube_file_blue, label_file, output_file, output_width, output_height, frame_offset, ortho=False, window_size=(1024, 1024)):
self.red_model = Model(cube_file_red, label_file)
self.green_model = Model(cube_file_green, label_file)
self.blue_model = Model(cube_file_blue, label_file)
self.output_file = output_file
self.output_width = output_width
self.output_height = output_height
self.__ortho = ortho
self.__frame_number = frame_offset
self.__scale = 1.0
self.__fov = 90
self.__rotate_x = 0
self.__rotate_y = 0
self.__rotate_z = 0
self.__process_final_and_exit = False
self.__window_size = window_size
def reshape(self, width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
if self.__ortho:
glOrtho(- (width / 2), (width / 2), height / 2, - (height / 2), 10, 90000000.0)
else:
aspect = float(width) / float(height)
gluPerspective(self.__fov, aspect, 100, 900000.0)
glutPostRedisplay()
def mouse(self, button, state, x, y):
pass
def motion(self, x1, y1):
pass
def keyboard(self, c, x, y):
"""keyboard callback."""
if c in ["q", chr(27)]:
sys.exit(0)
elif c == 'f':
self.__frame_number += 1.0
print(self.__frame_number)
elif c == 'F':
self.__frame_number += 100.0
print(self.__frame_number)
elif c == 'b':
self.__frame_number -= 1.0
print(self.__frame_number)
elif c == 'B':
self.__frame_number -= 100.0
print(self.__frame_number)
elif c == 'o':
self.__scale *= 0.9
elif c == 'i':
self.__scale *= 1.1
elif c == 'k':
self.__fov -= 1.0
self.reshape(self.__window_size[0], self.__window_size[1])
elif c == 'l':
self.__fov += 1.0
self.reshape(self.__window_size[0], self.__window_size[1])
elif c == 's':
self.__rotate_x = 0.0
self.__rotate_y = 0.0
self.__rotate_z = 0.0
elif c == 'w':
self.__rotate_x += 1.0
elif c == 'x':
self.__rotate_x -= 1.0
elif c == 'a':
self.__rotate_y += 1.0
elif c == 'd':
self.__rotate_y -= 1.0
elif c == 'e':
self.__rotate_z += 1.0
elif c == 'r':
self.__rotate_z -= 1.0
elif c == 'p':
self.__process_final_and_exit = True
glutPostRedisplay()
def display_standard(self):
print("Rendering Grayscale frame with red channel...")
self.red_model.render(self.__frame_number, self.__rotate_x, self.__rotate_y, self.__rotate_z, self.__scale)
glFlush()
glutSwapBuffers()
@staticmethod
def create_dummy_image(width, height):
im = np.zeros((width, height, 4), dtype=np.uint8)
im = Image.fromarray(im)
image = im.tobytes("raw", "RGBA", 0, -1)
return image
def display_for_export(self):
self.reshape(self.output_width, self.output_height)
dummy_image = self.create_dummy_image(self.output_width, self.output_height)
fb_name = glGenFramebuffers(1)
glBindFramebuffer(GL_FRAMEBUFFER, fb_name)
fb_tex_id = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, fb_tex_id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.output_width, self.output_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, dummy_image)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fb_tex_id, 0)
glDrawBuffers(1, GL_COLOR_ATTACHMENT0)
print("Rendering Red...")
self.red_model.render(self.__frame_number, self.__rotate_x, self.__rotate_y, self.__rotate_z, self.__scale)
self.red_model.unload_textures()
red_pixels = self.export_frame_buffer(self.red_model.get_model_output_filename())
print("Rendering Green...")
self.green_model.render(self.__frame_number, self.__rotate_x, self.__rotate_y, self.__rotate_z, self.__scale)
self.green_model.unload_textures()
green_pixels = self.export_frame_buffer(self.green_model.get_model_output_filename())
print("Rendering Blue")
self.blue_model.render(self.__frame_number, self.__rotate_x, self.__rotate_y, self.__rotate_z, self.__scale)
self.blue_model.unload_textures()
blue_pixels = self.export_frame_buffer(self.blue_model.get_model_output_filename())
print("Building RGB Composite...")
rgba_buffer = np.zeros(red_pixels.shape, dtype=np.uint8)
rgba_buffer[:, :, 0] = red_pixels[:,:,1]
rgba_buffer[:, :, 1] = green_pixels[:, :, 1]
rgba_buffer[:, :, 2] = blue_pixels[:, :, 1]
rgba_buffer[:, :, 3] = 255
self.save_image(self.output_file, rgba_buffer)
sys.exit(0)
def export_frame_buffer(self, save_copy_to=None):
pixels = glReadPixels(0, 0, self.output_width, self.output_height, GL_RGBA, GL_UNSIGNED_BYTE)
dt = np.dtype(np.uint8)
dt = dt.newbyteorder('>')
pixels = np.frombuffer(pixels, dtype=dt)
pixels = np.flip(np.reshape(pixels, (-1, output_width, 4)), 0)
if save_copy_to is not None:
self.save_image(save_copy_to, pixels)
return pixels
@staticmethod
def save_image(path, data):
im = Image.fromarray(data)
im.save(path)
# data_matrix = data.astype(np.uint16) / 255.0 * 65535.0
# tiff = TIFFimage(data, description='')
# tiff.write_file(path, compression='none')
def display(self):
if self.__process_final_and_exit is True:
self.display_for_export()
else:
self.display_standard()
def __init_glut(self):
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(*self.__window_size)
glutCreateWindow(sys.argv[0])
glutReshapeFunc(self.reshape)
glutDisplayFunc(self.display)
glutKeyboardFunc(self.keyboard)
glutMouseFunc(self.mouse)
glutMotionFunc(self.motion)
def __init_opengl(self):
glEnable(GL_MULTISAMPLE)
glEnable(GL_POLYGON_SMOOTH)
glShadeModel(GL_SMOOTH)
glEnable(GL_TEXTURE_2D)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
glEnable(GL_NORMALIZE)
glClearColor(0.0, 0.0, 0.0, 1.0)
def main(self):
self.__init_glut()
self.__init_opengl()
return glutMainLoop()
def load_kernels(kernelbase, allow_predicted=False):
kernels = [
"%s/juno/kernels/pck/pck00010.tpc"%kernelbase,
"%s/juno/kernels/fk/juno_v12.tf"%kernelbase,
"%s/juno/kernels/ik/juno_junocam_v02.ti"%kernelbase,
"%s/juno/kernels/lsk/naif0012.tls"%kernelbase,
"%s/juno/kernels/sclk/JNO_SCLKSCET.00074.tsc"%kernelbase,
"%s/juno/kernels/tspk/de436s.bsp"%kernelbase,
"%s/juno/kernels/tspk/jup310.bsp"%kernelbase,
"%s/juno/kernels/spk/juno_struct_v04.bsp"%kernelbase
]
kernel_prefix = "spk_rec_" if not allow_predicted else ""
for file in glob.glob("%s/juno/kernels/spk/%s*bsp"%(kernelbase, kernel_prefix)):
kernels.append(file)
kernel_prefix = "juno_sc_rec_" if not allow_predicted else ""
for file in glob.glob("%s/juno/kernels/ck/%s*bc"%(kernelbase, kernel_prefix)):
kernels.append(file)
for kernel in kernels:
spice.furnsh(kernel)
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("-r", "--red", help="Input Projected JunoCam Image for red (cube formatted)", required=True, type=str)
parser.add_argument("-g", "--green", help="Input Projected JunoCam Image for green (cube formatted)", required=True,
type=str)
parser.add_argument("-b", "--blue", help="Input Projected JunoCam Image for blue (cube formatted)", required=True,
type=str)
parser.add_argument("-l", "--label", help="Input JunoCam Label File (PVL formatted)", required=True, type=str)
parser.add_argument("-v", "--verbose", help="Verbose output", action="store_true")
parser.add_argument("-k", "--kernelbase", help="Base directory for spice kernels", required=False, type=str, default=os.environ["ISIS3DATA"])
parser.add_argument("-o", "--output", help="Output file path", required=True, type=str, default=None)
parser.add_argument("-f", "--frameoffset", help="Frame offset", required=False, type=int, default=0)
parser.add_argument("-F", "--fov", help="Field of view (degrees)", required=False, type=int, default=90)
parser.add_argument("-W", "--width", help="Image width in pixels", required=False, type=int, default=2048)
parser.add_argument("-H", "--height", help="Image height in pixels", required=False, type=int, default=2048)
parser.add_argument("-s", "--scale", help="Image height in pixels", required=False, type=float, default=1.0)
parser.add_argument("-p", "--predicted", help="Utilize predicted kernels", action="store_true")
parser.add_argument("-O", "--ortho", help="Use orthographic camera projection", action="store_true")
args = parser.parse_args()
lbl_file = args.label
cube_file_red = args.red
cube_file_green = args.green
cube_file_blue = args.blue
verbose = args.verbose
kernelbase = args.kernelbase
output = args.output
frame_offset = args.frameoffset
output_width = args.width
output_height = args.height
scale = args.scale
allow_predicted = args.predicted
ortho = args.ortho
ratio = min(float(1024) / float(output_width), float(1024) / float(output_height))
window_size = (int(output_width * ratio), int(output_height * ratio))
FOV = args.fov
load_kernels(kernelbase, allow_predicted)
engine = RenderEngine(cube_file_red, cube_file_green, cube_file_blue, lbl_file, output, output_width, output_height, frame_offset, ortho, window_size=window_size)
sys.exit(engine.main())