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

Allow ALE NaifSpice Mixins to Access SpiceQL service #523

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
8aab709
Initial spiceql integration
AustinSanders Jun 2, 2022
7e26fb5
Reverted change to UTC start time
AustinSanders Jun 2, 2022
0a89f4b
Fixed erronious spiceql calls
acpaquette Sep 28, 2022
0e4c165
Moved kernel accessing methods into there own file
acpaquette Mar 9, 2023
9835056
Added initial ability to access SpiceQL service
acpaquette Mar 9, 2023
ee7a562
General drive import and spacing cleanup
acpaquette Mar 9, 2023
7311697
Adds spiceql call warpper to kernel access function set
acpaquette Mar 14, 2023
6a20a5a
Line space changes and removed commented line
acpaquette Mar 14, 2023
187eb7a
Updates tranformation and data_naif with spiceql_calls
acpaquette Mar 14, 2023
a9f28dc
Fixes other instances of the from_spice call
acpaquette Mar 14, 2023
f493221
Updates MroCtxIsisLabelNaifSpice Driver to fully use spiceql
acpaquette Mar 14, 2023
e33a638
Allow for no kernels to be passed in NaifSpice drivers
acpaquette Mar 14, 2023
f4d909d
Addressed mro_ctx_load test
acpaquette Mar 27, 2023
f79c918
Move write_metakernel_from_cube to kernel_access
acpaquette May 12, 2023
ef1aac2
Added module for access spiceql
acpaquette May 12, 2023
d1220aa
Updated NaifSpice and from_spice to use async functions
acpaquette May 12, 2023
2d494dc
Updated mro tests
acpaquette May 12, 2023
3e83d34
some minor speed improvements
Kelvinrr Jul 13, 2023
f99a504
added some more parallelization
Jul 21, 2023
2cefbaf
Updates to all drivers for spiceql
acpaquette Sep 29, 2023
07532e3
Missed changes to transformation.py
acpaquette Sep 29, 2023
cf388b1
More Kaguya debugging
acpaquette Sep 29, 2023
c54a72e
More debugging
acpaquette Sep 29, 2023
2a6e007
More debugging
acpaquette Sep 29, 2023
dde7bec
Various fixes to drivers and transformation
acpaquette Sep 29, 2023
a021b54
More debugging
acpaquette Sep 29, 2023
07ea9a9
More driver fixes
acpaquette Oct 2, 2023
107d1a6
Removed debugging prints
acpaquette Oct 2, 2023
ae3abaa
Got all load tests passing
acpaquette Oct 2, 2023
ad08596
Fixed parallel property aquisition in to_dict
acpaquette Nov 7, 2023
f6bdee8
Removed all spice calls from new dawn driver
acpaquette Nov 7, 2023
079ccdd
Only remove sensor_orietation if it exists
acpaquette Nov 13, 2023
eb30bb3
Added new spiceql config keys
acpaquette Dec 8, 2023
59c94a5
Ensured try excepts around gdal reads
acpaquette Dec 8, 2023
af88d37
Fixed kernel access calls and pixel2focal properties
acpaquette Dec 8, 2023
cadd5bc
Added missing dict_merge import in kernel_access
acpaquette Dec 8, 2023
bc95db1
Change av arg to expect an empty list instead of None
acpaquette Dec 8, 2023
ebfefdf
Fixed import in isis_formatter
acpaquette Dec 8, 2023
67e65d3
Changed how driver loading is reported in load/loads
acpaquette Dec 8, 2023
01f6380
Added time dependent and constant rotation flag to generate_rotations
acpaquette Dec 8, 2023
a9ef7e3
Updated MRO drivers and tests
acpaquette Dec 9, 2023
079392e
Updated env var tests to not mess with other tests
acpaquette Dec 9, 2023
f59549a
Updated mixin tests
acpaquette Dec 9, 2023
f165826
Updated cassini drivers and tests
acpaquette Dec 9, 2023
90d2913
Updated cassis tests
acpaquette Dec 9, 2023
b0a4113
Updated hayabusa drivers and tests
acpaquette Dec 9, 2023
dee9e37
Updated juno drivers and tests
acpaquette Dec 9, 2023
27ca1e7
Updated lunar orbiter drivers and tests
acpaquette Dec 9, 2023
4263499
Updated clementine tests
acpaquette Dec 9, 2023
c7c8c29
Updated chandrayaan tests
acpaquette Dec 9, 2023
8c42530
Updated dawn tests
acpaquette Dec 9, 2023
6681941
Updated galileo tests
acpaquette Dec 9, 2023
032a994
Updated kaguya drivers and tests
acpaquette Dec 9, 2023
e8592fd
Updated lro drivers and tests
acpaquette Dec 9, 2023
b965298
Updated messenger drivers and tests
acpaquette Dec 9, 2023
f6f0c61
Updated mex drivers and tests
acpaquette Dec 9, 2023
a914525
Updated MGS drivers and tests
acpaquette Dec 9, 2023
0883096
Updated msl drivers and tests
acpaquette Dec 9, 2023
ff34212
Updated new horizons tests
acpaquette Dec 9, 2023
d07a6e9
Updated orex drivers and tests
acpaquette Dec 9, 2023
289620d
Updated themis tests
acpaquette Dec 9, 2023
8dbcfdb
Updated viking drivers and tests
acpaquette Dec 9, 2023
8e58f89
Fixed up last chandrayaan isd
acpaquette Dec 11, 2023
8aed755
Moved kernel_access tests to test_kernel_access
acpaquette Dec 11, 2023
c366767
Minor fixes after rebase
acpaquette Dec 11, 2023
cd46b88
Added pyspiceql to env file
acpaquette Dec 11, 2023
6d74087
Change env pyspiceql entry to spiceql entry
acpaquette Dec 11, 2023
8a3f4a3
Merge spiceql onto dev
acpaquette Jun 12, 2024
7946736
Fixed missed merge conflict
acpaquette Jun 12, 2024
bf464ac
Removed util tests that are part of kernel access
acpaquette Jun 12, 2024
b5f9755
Fixed dawn tests
acpaquette Jun 12, 2024
68c93d1
Merge branch 'main' into spiceql
Kelvinrr Jun 13, 2024
27201fc
Update ndarray value type
chkim-usgs Oct 24, 2024
209d8ea
Fix typo
chkim-usgs Oct 24, 2024
a661097
Another ndarray fix
chkim-usgs Oct 24, 2024
6ec7345
Merge pull request #3 from chkim-usgs/ndarray-fix
acpaquette Oct 25, 2024
021833b
Merge branch 'main' into spiceql
chkim-usgs Oct 29, 2024
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
2 changes: 2 additions & 0 deletions ale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import warnings
from pkg_resources import get_distribution, DistributionNotFound

warnings.filterwarnings("ignore")


try:
_dist = get_distribution('ale')
Expand Down
90 changes: 90 additions & 0 deletions ale/base/__init__.py
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",
Comment on lines +3 to +7
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 🤷

"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",
}
115 changes: 92 additions & 23 deletions ale/base/base.py
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():
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want an exception if the geodata cannot be loaded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Loading
Loading