-
Notifications
You must be signed in to change notification settings - Fork 33
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
Allow ALE NaifSpice Mixins to Access SpiceQL service #523
Changes from all commits
8aab709
7e26fb5
0a89f4b
0e4c165
9835056
ee7a562
7311697
6a20a5a
187eb7a
a9f28dc
f493221
e33a638
f4d909d
f79c918
ef1aac2
d1220aa
2d494dc
3e83d34
f99a504
2cefbaf
07532e3
cf388b1
c54a72e
2a6e007
dde7bec
a021b54
07ea9a9
107d1a6
ae3abaa
ad08596
f6bdee8
079ccdd
eb30bb3
59c94a5
af88d37
cadd5bc
bc95db1
ebfefdf
67e65d3
01f6380
a9ef7e3
079392e
f59549a
f165826
90d2913
b0a4113
dee9e37
27ca1e7
4263499
c7c8c29
8c42530
6681941
032a994
e8592fd
b965298
f6f0c61
a914525
0883096
ff34212
d07a6e9
289620d
8dbcfdb
8e58f89
8aed755
c366767
cd46b88
6d74087
8a3f4a3
7946736
bf464ac
b5f9755
68c93d1
27201fc
209d8ea
a661097
6ec7345
021833b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,91 @@ | ||
from ale.base.base import Driver | ||
|
||
spiceql_mission_map = { | ||
"CHANDRAYAAN-1_M3": "m3", | ||
"CHANDRAYAAN-1_MRFFR": "mrffr", | ||
"CASSINI_ISS_NAC": "cassini", | ||
"CASSINI_ISS_WAC": "cassini", | ||
"DAWN_FC2_FILTER_1": "fc2", | ||
"DAWN_FC2_FILTER_2": "fc2", | ||
"DAWN_FC2_FILTER_3": "fc2", | ||
"DAWN_FC2_FILTER_4": "fc2", | ||
"DAWN_FC2_FILTER_5": "fc2", | ||
"DAWN_FC2_FILTER_6": "fc2", | ||
"DAWN_FC2_FILTER_7": "fc2", | ||
"DAWN_FC2_FILTER_8": "fc2", | ||
"GLL_SSI_PLATFORM": "galileo", | ||
"HAYABUSA_AMICA": "amica", | ||
"HAYABUSA_NIRS": "nirs", | ||
"HAYABUSA2_ONC-W2": "", | ||
"JUNO_JUNOCAM": "juno", | ||
"LRO_LROCNACL": "lroc", | ||
"LRO_LROCNACR": "lroc", | ||
"LRO_LROCWAC_UV": "lroc", | ||
"LRO_LROCWAC_VIS": "lroc", | ||
"LRO_MINIRF": "", | ||
"M10_VIDICON_A": "m10_vidicon_a", | ||
"M10_VIDICON_B": "m10_vidicon_b", | ||
"MSGR_MDIS_WAC": "mdis", | ||
"MSGR_MDIS_NAC": "mdis", | ||
"MEX_HRSC_SRC": "src", | ||
"MEX_HRSC_IR": "hrsc", | ||
"MGS_MOC_NA": "mgs", | ||
"MGS_MOC_WA_RED": "mgs", | ||
"MGS_MOC_WA_BLUE": "mgs", | ||
"MRO_MARCI_VIS": "marci", | ||
"MRO_MARCI_UV": "marci", | ||
"MRO_CTX": "ctx", | ||
"MRO_HIRISE": "hirise", | ||
"MRO_CRISM_VNIR": "crism", | ||
"NEAR EARTH ASTEROID RENDEZVOUS": "", | ||
"MSL_MASTCAM_RIGHT": "", | ||
"MSL_MASTCAM_LEFT": "", | ||
"NH_LORRI": "lorri", | ||
"NH_RALPH_LEISA": "leisa", | ||
"NH_MVIC": "mvic_tdi", | ||
"ISIS_NH_RALPH_MVIC_METHANE": "mvic_framing", | ||
"THEMIS_IR": "odyssey", | ||
"THEMIS_VIS": "odyssey", | ||
"ORX_OCAMS_MAPCAM": "", | ||
"ORX_OCAMS_POLYCAM": "", | ||
"ORX_OCAMS_SAMCAM": "", | ||
"LISM_MI-VIS1": "kaguya", | ||
"LISM_MI-VIS2": "kaguya", | ||
"LISM_MI-VIS3": "kaguya", | ||
"LISM_MI-VIS4": "kaguya", | ||
"LISM_MI-VIS5": "kaguya", | ||
"LISM_MI-NIR1": "kaguya", | ||
"LISM_MI-NIR2": "kaguya", | ||
"LISM_MI-NIR3": "kaguya", | ||
"LISM_MI-NIR4": "kaguya", | ||
"LISM_TC1_WDF": "kaguya", | ||
"LISM_TC1_WTF": "kaguya", | ||
"LISM_TC1_SDF": "kaguya", | ||
"LISM_TC1_STF": "kaguya", | ||
"LISM_TC1_WDN": "kaguya", | ||
"LISM_TC1_WTN": "kaguya", | ||
"LISM_TC1_SDN": "kaguya", | ||
"LISM_TC1_STN": "kaguya", | ||
"LISM_TC1_WDH": "kaguya", | ||
"LISM_TC1_WTH": "kaguya", | ||
"LISM_TC1_SDH": "kaguya", | ||
"LISM_TC1_STH": "kaguya", | ||
"LISM_TC1_SSH": "kaguya", | ||
"LO1_HIGH_RESOLUTION_CAMERA": "", | ||
"LO2_HIGH_RESOLUTION_CAMERA": "", | ||
"LO3_HIGH_RESOLUTION_CAMERA": "", | ||
"LO4_HIGH_RESOLUTION_CAMERA": "", | ||
"LO5_HIGH_RESOLUTION_CAMERA": "", | ||
"TGO_CASSIS": "cassis", | ||
"VIKING ORBITER 1": "viking1", | ||
"VIKING ORBITER 2": "viking2", | ||
"VG1_ISSNA": "", | ||
"VG1_ISSWA": "", | ||
"VG2_ISSNA": "", | ||
"VG2_ISSWA": "", | ||
"ULTRAVIOLET/VISIBLE CAMERA": "uvvis", | ||
"Near Infrared Camera": "nir", | ||
"High Resolution Camera": "clementine1", | ||
"Long Wave Infrared Camera": "clementine1", | ||
"Visual and Infrared Spectrometer": "vir", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import pvl | ||
import json | ||
|
||
import tempfile | ||
import os | ||
from multiprocessing.pool import ThreadPool | ||
|
||
import time | ||
import pvl | ||
|
||
class Driver(): | ||
""" | ||
|
@@ -41,6 +44,69 @@ def __init__(self, file, num_ephem=909, num_quats=909, props={}, parsed_label=No | |
if parsed_label: | ||
self._label = parsed_label | ||
|
||
def to_dict(self, properties=None): | ||
def get_property(prop_name): | ||
try: | ||
return getattr(self, prop_name) | ||
except Exception as e: | ||
print(prop_name, e) | ||
return None | ||
|
||
if properties is None: | ||
properties = [] | ||
for attr in dir(self): | ||
if isinstance(getattr(self.__class__, attr, None), property): | ||
properties.append(attr) | ||
|
||
spice_props = ["ikid", | ||
"ephemeris_start_time", | ||
"ephemeris_stop_time", | ||
"spacecraft_id", | ||
"target_id", | ||
"target_frame_id", | ||
"reference_frame", | ||
"sensor_frame_id"] | ||
|
||
# Remove position and orientation properties | ||
ephemeris_props = ["sensor_position", "sun_position", "frame_chain"] | ||
for prop in ephemeris_props or prop in spice_props: | ||
properties.remove(prop) | ||
|
||
if "fikid" in properties: | ||
properties.remove("fikid") | ||
spice_props.append("fikid") | ||
if "sensor_orientation" in properties: | ||
properties.remove("sensor_orientation") | ||
|
||
data = {} | ||
|
||
start = time.time() | ||
with ThreadPool() as pool: | ||
jobs = pool.starmap_async(get_property, [(name,) for name in spice_props]) | ||
jobs = jobs.get() | ||
|
||
for result, property_name in zip(jobs, spice_props): | ||
data[property_name] = result | ||
end = time.time() | ||
print(f"TOTAL SPICE TIME: {end - start}") | ||
|
||
start = time.time() | ||
for prop in properties: | ||
data[prop] = get_property(prop) | ||
end = time.time() | ||
print(f"TOTAL OTHER TIME: {end - start}") | ||
|
||
start = time.time() | ||
with ThreadPool() as pool: | ||
jobs = pool.starmap_async(get_property, [(name,) for name in ephemeris_props]) | ||
jobs = jobs.get() | ||
|
||
for result, property_name in zip(jobs, ephemeris_props): | ||
data[property_name] = result | ||
end = time.time() | ||
print(f"TOTAL EPHEM TIME: {end - start}") | ||
return data | ||
|
||
@property | ||
def image_lines(self): | ||
""" | ||
|
@@ -446,13 +512,19 @@ def projection(self): | |
with tempfile.NamedTemporaryFile() as tmp: | ||
tmp.write(pvl.dumps(self._file)) | ||
|
||
geodata = gdal.Open(tempfile.name) | ||
try: | ||
geodata = gdal.Open(tempfile.name) | ||
except: | ||
geodata = None | ||
else: | ||
# should be a path | ||
if not os.path.exists(self._file): | ||
self._projection = "" | ||
else: | ||
geodata = gdal.Open(self._file) | ||
try: | ||
geodata = gdal.Open(self._file) | ||
except: | ||
geodata = None | ||
|
||
Comment on lines
+524
to
+527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not want an exception if the geodata cannot be loaded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be worth reporting the exception to the user as a warning. When working with pds3 labels I was running into issues where the label was pointing to a data file causing the gdal.Open to fail but the label could be used as valid input for a driver. |
||
|
||
# Try to get the projection, if we are unsuccessful set it | ||
|
@@ -465,35 +537,32 @@ def projection(self): | |
|
||
@property | ||
def geotransform(self): | ||
""" | ||
Return geotransform information generated by osgeo. | ||
|
||
Returns | ||
------- | ||
tuple | ||
Geotransform information | ||
|
||
""" | ||
if not hasattr(self, "_geotransform"): | ||
if not hasattr(self, "_geotransform"): | ||
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0) | ||
try: | ||
from osgeo import gdal | ||
from osgeo import gdal | ||
except: | ||
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0) | ||
return self._geotransform | ||
|
||
geodata = None | ||
if isinstance(self._file, pvl.PVLModule): | ||
# save it to a temp folder | ||
with tempfile.NamedTemporaryFile() as tmp: | ||
tmp.write(pvl.dumps(self._file)) | ||
|
||
geodata = gdal.Open(tempfile.name) | ||
self._geotransform = geodata.GetGeoTransform() | ||
try: | ||
geodata = gdal.Open(tempfile.name) | ||
except: | ||
geodata = None | ||
else: | ||
# should be a path | ||
if not os.path.exists(self._file): | ||
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0) | ||
else: | ||
geodata = gdal.Open(self._file) | ||
self._geotransform = geodata.GetGeoTransform() | ||
|
||
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0) | ||
else: | ||
try: | ||
geodata = gdal.Open(self._file) | ||
except: | ||
geodata = None | ||
|
||
if geodata != None: | ||
self._geotransform = geodata.GetGeoTransform() | ||
return self._geotransform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put this in SpiceQL instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could go in spiceql, the translation has to exist somewhere. I think it's better off in ALE since ALE is using the spiceql interface rather than spiceql conforming to ALE.
Granted all of the keys are from NAIF so 🤷