Skip to content

Commit

Permalink
Fix flake8 style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
scottwittenburg committed Aug 6, 2018
1 parent 373bbaf commit d7c0a05
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 110 deletions.
5 changes: 4 additions & 1 deletion gaia/gaia_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

from sqlalchemy import create_engine, MetaData, Table, text
from geoalchemy2 import Geometry
Expand All @@ -11,6 +13,7 @@
from osgeo import osr

from gaia import GaiaException
from gaia.filters import filter_postgis
from gaia.geo.gdal_functions import gdal_reproject
from gaia.util import sqlengines

Expand Down
4 changes: 2 additions & 2 deletions gaia/geo/gdal_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import rasterio
import rasterio.features
from gaia import GaiaException
from gaia.util import get_uri_extension, UnsupportedFormatException
try:
import gdalnumeric
except ImportError:
Expand All @@ -36,6 +37,7 @@
import osr
from PIL import Image, ImageDraw
from osgeo.gdal_array import BandReadAsArray, BandWriteArray
import numpy as np
from numpy.ma.core import MaskedConstant

logger = logging.getLogger('gaia.geo.gdal_functions')
Expand All @@ -56,8 +58,6 @@
'Float64': 1.7976931348623158E+308
}



# Map of file extensions to driver name
driver_lookup = {
'tif': 'GTiff',
Expand Down
23 changes: 13 additions & 10 deletions gaia/io/gaia_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)
from future.utils import with_metaclass

from gaia.gaia_data import GaiaDataObject
Expand All @@ -12,19 +14,20 @@
)


"""
This is the metaclass for any type deriving from GaiaReader, providing
us with a registry of possible readers, which we can use to look for an
appropriate subtype at runtime, based on constructor args.
"""
class GaiaReaderFactoryMetaclass(type):
"""
This is the metaclass for any type deriving from GaiaReader, providing
us with a registry of possible readers, which we can use to look for an
appropriate subtype at runtime, based on constructor args.
"""
_registry = {}

"""
Make sure we include every GaiaReader subtype in our registry.
"""
def __new__(cls, clsname, bases, dct):
classtoreturn = super(GaiaReaderFactoryMetaclass, cls).__new__(cls, clsname, bases, dct)
classtoreturn = super(GaiaReaderFactoryMetaclass,
cls).__new__(cls, clsname, bases, dct)
GaiaReaderFactoryMetaclass._registry[clsname] = classtoreturn
return classtoreturn

Expand Down Expand Up @@ -74,10 +77,10 @@ def __call__(cls, *args, **kwargs):
return instance


"""
Abstract base class, root of the reader class hierarchy.
"""
class GaiaReader(with_metaclass(GaiaReaderFactoryMetaclass, object)):
"""
Abstract base class, root of the reader class hierarchy.
"""
def __init__(self, *args, **kwargs):
pass

Expand Down
18 changes: 11 additions & 7 deletions gaia/io/gdal_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

import os

Expand Down Expand Up @@ -27,10 +29,10 @@
import gaia.types as types


"""
A specific subclass for reading GDAL files
"""
class GaiaGDALReader(GaiaReader):
"""
A specific subclass for reading GDAL files
"""
def __init__(self, *args, **kwargs):
super(GaiaGDALReader, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -77,8 +79,10 @@ def read(self, format=formats.RASTER, epsg=None, as_numpy_array=False,
self.old_nodata = old_nodata
self.new_nodata = new_nodata

# FIXME: if we got "as_numpy_array=True", should we return different data object type?
return GDALDataObject(reader=self, dataFormat=self.format, epsg=self.epsg)
# FIXME: if we got "as_numpy_array=True", should we return different
# data object type?
o = GDALDataObject(reader=self, dataFormat=self.format, epsg=self.epsg)
return o

def load_metadata(self, dataObject):
self.__read_internal(dataObject)
Expand All @@ -98,7 +102,7 @@ def __read_internal(self, dataObject):
dataObject.set_data(gdal.Open(self.uri))

if self.epsg and dataObject.get_epsg() != self.epsg:
dataObject.reproject(epsg)
dataObject.reproject(self.epsg)

dataObject.set_metadata({})
dataObject.datatype = types.RASTER
Expand Down
16 changes: 9 additions & 7 deletions gaia/io/geojson_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

import re
import geopandas
Expand All @@ -17,10 +19,10 @@
import gaia.types as types


"""
Another specific subclass for reading GeoJSON
"""
class GaiaGeoJSONReader(GaiaReader):
"""
Another specific subclass for reading GeoJSON
"""
epsgRegex = re.compile('epsg:([\d]+)')

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -48,7 +50,7 @@ def load_data(self, dataObject):
self.__read_internal(dataObject)

def __read_internal(self, dataObject):
### FIXME: need to handle format
# FIXME: need to handle format
# if not self.format:
# self.format = self.default_output

Expand All @@ -62,11 +64,11 @@ def __read_internal(self, dataObject):

data = geopandas.read_file(self.uri)

### FIXME: still need to handle filtering
# FIXME: still need to handle filtering
# if self.filters:
# self.filter_data()

### FIXME: skipped the transformation step for now
# FIXME: skipped the transformation step for now
# return self.transform_data(format, epsg)

# do the actual reading and set both data and metadata
Expand Down
4 changes: 3 additions & 1 deletion gaia/io/postgis_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

from gaia.gaia_data import PostgisDataObject
from gaia.io.readers import GaiaReader
Expand Down
6 changes: 3 additions & 3 deletions gaia/io/readers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from gaia.io.gaia_reader import *
from gaia.io.geojson_reader import *
from gaia.io.gdal_reader import *
from gaia.io.gaia_reader import GaiaReader
from gaia.io.geojson_reader import GaiaGeoJSONReader
from gaia.io.gdal_reader import GaiaGDALReader
16 changes: 8 additions & 8 deletions gaia/preprocess/gdal_processes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

from gaia import GaiaException
from gaia.gaia_data import GDALDataObject
Expand All @@ -8,19 +10,17 @@
from gaia.geo.gdal_functions import gdal_clip


"""
Rely on the base validate method for the bulk of the work, just make
sure the inputs are gdal-compatible.
"""
def validate_gdal(v):
"""
Rely on the base validate method for the bulk of the work, just make
sure the inputs are gdal-compatible.
"""
def validator(inputs=[], args=[]):
# FIXME: we should check we have a specific gdal type input also
return v(inputs, args)
return validator

"""
Do a gdal crop
"""

@register_process('crop')
@validate_subset
@validate_gdal
Expand Down
25 changes: 12 additions & 13 deletions gaia/preprocess/pandas_processes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

from gaia.validators import *
import gaia.validators as validators
from gaia.process_registry import register_process
from gaia import GaiaException
from gaia.gaia_data import GaiaDataObject
Expand All @@ -10,29 +12,26 @@
from geopandas import GeoSeries


"""
Since the base validate method we import does most of the work in a fairly
generic way, this function only needs to add a little bit to that: make sure
the inputs contain geopandas dataframe. Additionally, all the processes
defined in this module can re-use the same validate method.
"""
def validate_pandas(v):
"""
Since the base validate method we import does most of the work in a fairly
generic way, this function only needs to add a little bit to that: make
sure the inputs contain geopandas dataframe. Additionally, all the
processes defined in this module can re-use the same validate method.
"""
def validator(inputs=[], args={}):
# First should check if input is compatible w/ pandas computation
if type(inputs[0].get_data()) is not GeoDataFrame:
raise GaiaException('pandas processes need data objects containing a GeoDataFrame')
raise GaiaException('pandas process requires a GeoDataFrame')

# Otherwise call up the chain to let parent do common validation
return v(inputs, args)

return validator


"""
Crop in pandas
"""
@register_process('crop')
@validate_within
@validators.validate_within
@validate_pandas
def crop_pandas(inputs=[], args={}):
"""
Expand Down
36 changes: 18 additions & 18 deletions gaia/process_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

from gaia import GaiaException

Expand All @@ -18,34 +20,32 @@
__process_registry = {}


"""
Return a list of registry entries that implement the process.
"""
def find_processes(processName):
"""
Return a list of registry entries that implement the named process.
"""
if processName in __process_registry:
return __process_registry[processName]
return None


"""
Process registration decorator
"""
def register_process(processName):
"""
Return a process registration decorator
"""
def processRegistrationDecorator(computeMethod):
if not processName in __process_registry:
if processName not in __process_registry:
__process_registry[processName] = []
__process_registry[processName].append(computeMethod)
return computeMethod
return processRegistrationDecorator


"""
Display a list of the processes in the registry, for debugging or informational
purposes.
"""
def list_processes(processName=None):
processes = []

"""
Display a list of the processes in the registry, for debugging or
informational purposes.
"""
def display_processes(name, plist):
print('%s processes:' % name)
for item in plist:
Expand All @@ -61,10 +61,10 @@ def display_processes(name, plist):
display_processes(pName, __process_registry[pName])


"""
Just looks up a process that can do the job and asks it to 'compute'
"""
def compute(processName, inputs, args):
"""
Just looks up a process that can do the job and asks it to 'compute'
"""
processes = find_processes(processName)

if not processes:
Expand All @@ -76,7 +76,7 @@ def compute(processName, inputs, args):
# just return the first one.
try:
return p(inputs, args)
except GaiaException as inst:
except GaiaException:
pass

raise GaiaException('No registered processes were able to validate inputs')
4 changes: 3 additions & 1 deletion gaia/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
from builtins import (bytes, str, open, super, range, zip, round, input, int, pow, object)
from builtins import (
bytes, str, open, super, range, zip, round, input, int, pow, object
)

from gaia import GaiaException

Expand Down

0 comments on commit d7c0a05

Please sign in to comment.