Skip to content
Snippets Groups Projects
Commit 160c1ae0 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Small changes (#81)

* Small updates to get the scripts working.

* Fixed pradius calculations, and made some small changes.

* Removed coord transforms and made body_fix func more generic.

* Updated reproj doc string.

* General refactor to socet scripts and clean up. Simplfied input for both scripts.

* Updated conf to use conda prefix

* Fixed up __getattr__ func

* Corrected attribute error text

* Uploaded notebooks for remote access

* Updated notebooks with complete footprint function

* More or less final notebook

* Forgot to tab this in under the first except block

* Updated version.

* Removed unnecessary notebooks

* Removed previously removed module

* Removed old import

* Updates travis to use environment.yml

* Fixes issue indexing on the hcube
parent 622e8daa
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#!$CONDA_PREFIX/bin/python
# -*- coding: utf-8 -*-
#
# autocnet documentation build configuration file, created by
......@@ -17,7 +17,6 @@ import sys
import os
from unittest.mock import MagicMock
autodoc_mock_imports = ['proj4', 'gdal', 'osr','ogr', 'osgeo', 'osgeo.gdal',
'osgeo.gdalconst']
......
......@@ -73,6 +73,11 @@ class HCube(object):
pixels = (xstart, ystart, xstep, ystep)
if isinstance(key[0], (int, np.integer)):
return self.read_array(band=int(key[0]+1), pixels=pixels)
elif isinstance(key[0], slice):
# Given some slice iterate over the bands and get the bands and pixel space requested
return [self.read_array(i, pixels = pixels) for i in list(range(1, self.nbands + 1))[key[0]]]
else:
arrs = []
for b in key[0]:
......
......@@ -2,13 +2,42 @@ import os
import numpy as np
from .io_gdal import GeoDataset
from .hcube import HCube
try:
from libpysat.derived import crism
from libpysat.derived.utils import get_derived_funcs
libpysat_enabled = True
except:
print('No libpysat module. Unable to attach derived product functions')
libpysat_enabled = False
import gdal
class Crism(GeoDataset, HCube):
"""
An M3 specific reader with the spectral mixin.
An Crism specific reader with the spectral mixin.
"""
def __init__(self, file_name):
GeoDataset.__init__(self, file_name)
HCube.__init__(self)
self.derived_funcs = {}
if libpysat_enabled:
self.derived_funcs = get_derived_funcs(crism)
def __getattr__(self, name):
try:
func = self.derived_funcs[name]
setattr(self, name, func.__get__(self))
return getattr(self, name)
except KeyError as keyerr:
raise AttributeError("'Crism' object has no attribute '{}'".format(name)) from None
@property
def wavelengths(self):
if not hasattr(self, '_wavelengths'):
......
......@@ -269,6 +269,7 @@ class GeoDataset(object):
@property
def footprint(self):
if not hasattr(self, '_footprint'):
# Try to get the footprint from the image
try:
polygon_pvl = find_in_dict(self.metadata, 'Polygon')
start_polygon_byte = find_in_dict(polygon_pvl, 'StartByte')
......@@ -280,9 +281,12 @@ class GeoDataset(object):
# Sloppy unicode to string because GDAL pukes on unicode
stream = str(f.read(num_polygon_bytes))
self._footprint = ogr.CreateGeometryFromWkt(stream)
except:
self._footprint = None
# If the image does not have a footprint, try getting the image from projected
# coordinates
try:
# Get the lat lon corners
lat = [i[0] for i in self.latlon_corners]
......@@ -299,6 +303,7 @@ class GeoDataset(object):
poly.AddGeometry(ring)
poly.FlattenTo2D()
self._footprint = poly
except:
self._footprint = None
......
......@@ -4,11 +4,11 @@ from .io_gdal import GeoDataset
from .hcube import HCube
try:
from libpysat.derived import m3, crism
from libpysat.derived.utils import add_derived_funcs
from libpysat.derived import m3
from libpysat.derived.utils import get_derived_funcs
libpysat_enabled = True
except:
print('No libpysat module. Unable to attached derived product functions')
print('No libpysat module. Unable to attach derived product functions')
libpysat_enabled = False
import gdal
......@@ -23,8 +23,10 @@ class M3(GeoDataset, HCube):
GeoDataset.__init__(self, file_name)
HCube.__init__(self)
self.derived_funcs = {}
if libpysat_enabled:
self.derived_funcs = add_derived_funcs(m3)
self.derived_funcs = get_derived_funcs(m3)
def __getattr__(self, name):
try:
......@@ -33,8 +35,8 @@ class M3(GeoDataset, HCube):
setattr(self, name, func.__get__(self))
return getattr(self, name)
except:
raise AttributeError()
except KeyError as keyerr:
raise AttributeError("'M3' object has no attribute '{}'".format(name)) from None
@property
def wavelengths(self):
......
......@@ -51,6 +51,7 @@ requirements:
- usgscam
- jinja2
test:
imports:
- plio
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment