-
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
added projection code #524
Changes from 4 commits
e3f4239
825c4d0
bffeba5
84927ff
ee320c0
2f4dfe6
ad24b22
441ad96
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,6 +1,9 @@ | ||
import pvl | ||
import json | ||
|
||
import tempfile | ||
import os | ||
|
||
class Driver(): | ||
""" | ||
Base class for all Drivers. | ||
|
@@ -323,3 +326,60 @@ def center_ephemeris_time(self): | |
@property | ||
def short_mission_name(self): | ||
return self.__module__.split('.')[-1].split('_')[0] | ||
|
||
@property | ||
def projection(self): | ||
if not hasattr(self, "_projection"): | ||
try: | ||
from osgeo import gdal | ||
except: | ||
self._projection = None | ||
return self._projection | ||
|
||
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._projection = geodata.GetSpatialRef() | ||
else: | ||
# should be a path | ||
if not os.path.exists(self._file): | ||
self._projection = None | ||
else: | ||
geodata = gdal.Open(self._file) | ||
self._projection = geodata.GetSpatialRef() | ||
|
||
# is None if not projected | ||
if self._projection: | ||
self._projection = self._projection.ExportToProj4() | ||
|
||
return self._projection | ||
|
||
|
||
@property | ||
def geotransform(self): | ||
if not hasattr(self, "_geotransform"): | ||
try: | ||
from osgeo import gdal | ||
except: | ||
self._geotransform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0) | ||
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. Im preeeetty sure this is the identity, probably good as a default. 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. Yes that should identity for GDAL. https://github.com/OSGeo/gdal/blob/c642af0722d43bb337aaf86293129dbed576e534/alg/gdaltransformer.cpp#L1847 But just a warning, this is not same order for all packages. |
||
return self._geotransform | ||
|
||
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() | ||
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() | ||
|
||
return self._geotransform |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ dependencies: | |
- cmake>=3.15 | ||
- pytest | ||
- eigen | ||
- gdal | ||
- jupyter | ||
- nlohmann_json | ||
- numpy | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,9 @@ requirements: | |
- scipy >=1.4.0 | ||
- spiceypy >=4.0.1 | ||
- pyyaml | ||
|
||
run_contrained: | ||
- gdal | ||
Comment on lines
+34
to
+35
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. will only install if it can do so without conflicts. important to co-install with ISIS. |
||
|
||
test: | ||
imports: | ||
- ale | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,25 @@ Object = IsisCube | |
Source = isis | ||
End_Group | ||
|
||
Group = Mapping | ||
ProjectionName = Sinusoidal | ||
CenterLongitude = 148.36859083039 | ||
TargetName = MARS | ||
Comment on lines
+72
to
+75
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. just kinda shoved a projection into an MRO image for testing, I imagine the same to what a real image is like. |
||
EquatorialRadius = 3396190.0 <meters> | ||
PolarRadius = 3376200.0 <meters> | ||
LatitudeType = Planetocentric | ||
LongitudeDirection = PositiveEast | ||
LongitudeDomain = 360 | ||
MinimumLatitude = 63.636322793577 | ||
MaximumLatitude = 87.296295823424 | ||
MinimumLongitude = 139.6658284858 | ||
MaximumLongitude = 157.07135317498 | ||
UpperLeftCornerX = -219771.1526456 <meters> | ||
UpperLeftCornerY = 5175537.8728989 <meters> | ||
PixelResolution = 1455.4380969907 <meters/pixel> | ||
Scale = 40.726361118253 <pixels/degree> | ||
End_Group | ||
|
||
Group = AlphaCube | ||
AlphaSamples = 5000 | ||
AlphaLines = 24576 | ||
|
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.
Localized the import to keep the optional gdal stuff in one location without complicating things by adding some gdal module or something.