Skip to content

Commit

Permalink
Code formatting (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Oct 22, 2020
1 parent cc348d2 commit fd5a33c
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 197 deletions.
12 changes: 5 additions & 7 deletions dask_geomodeling/geometry/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from math import ceil, floor, log, sqrt
from collections import defaultdict
from functools import partial
import warnings

from scipy import ndimage
import numpy as np
Expand Down Expand Up @@ -148,7 +147,7 @@ class AggregateRaster(GeometryBlock):
auto_pixel_size (boolean): Determines whether the pixel size is adjusted
automatically when ``"max_pixels"`` is exceeded. Default False.
Returns:
Returns:
GeometryBlock with aggregation results in an added column
The global raster-limit setting can be adapted as follows:
Expand Down Expand Up @@ -361,7 +360,7 @@ def process(geom_data, raster_data, process_kwargs):
agg_srs = process_kwargs["agg_srs"]

agg_geometries = utils.geoseries_transform(
features["geometry"], req_srs, agg_srs,
features["geometry"], req_srs, agg_srs
)

statistic = process_kwargs["statistic"]
Expand All @@ -381,7 +380,7 @@ def process(geom_data, raster_data, process_kwargs):
threshold_name = process_kwargs.get("threshold_name")
if threshold_name:
# get the threshold, appending NaN for unlabeled pixels
threshold_values = np.empty((len(features) + 1, ), dtype="f4")
threshold_values = np.empty((len(features) + 1,), dtype="f4")
threshold_values[:-1] = features[threshold_name].values
threshold_values[-1] = np.nan
else:
Expand Down Expand Up @@ -437,9 +436,7 @@ def process(geom_data, raster_data, process_kwargs):
# select features that actually have data
# (min, max, median, and percentile cannot handle it otherwise)
active_labels = labels[active]
select_and_active = list(
set(np.unique(active_labels)) & set(select)
)
select_and_active = list(set(np.unique(active_labels)) & set(select))

if not select_and_active:
continue
Expand Down Expand Up @@ -486,6 +483,7 @@ class AggregateRasterAboveThreshold(AggregateRaster):
Returns:
GeometryBlock with aggregation results in an added column
"""

def __init__(
self,
source,
Expand Down
10 changes: 5 additions & 5 deletions dask_geomodeling/geometry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ def __xor__(self, other):
class GetSeriesBlock(SeriesBlock):
"""
Obtain a single feature property column from a GeometryBlock.
Provide a GeometryBlock with one or more columns. One of these columns can
Provide a GeometryBlock with one or more columns. One of these columns can
be read from this source into a SeriesBlock. This SeriesBlock can be used
to run for example classifications.
Args:
source (GeometryBlock): GeometryBlock with the column you want to load
source (GeometryBlock): GeometryBlock with the column you want to load
into the SeriesBlock.
name (str): Name of the column to load into the SeriesBlock.
Returns:
Returns:
SeriesBlock containing the single property column
"""
Expand Down Expand Up @@ -240,7 +240,7 @@ def process(data, name):
class SetSeriesBlock(GeometryBlock):
"""
Add one or multiple property columns (SeriesBlocks) to a GeometryBlock.
Provide the GeometryBlock that you want to add more properties to. Then
provide the SeriesBlock(s) which you want to add to the GeometryBlock. The
values of the SeriesBlock will be added to the features in the
Expand Down
24 changes: 12 additions & 12 deletions dask_geomodeling/geometry/constructive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
class Buffer(BaseSingle):
"""
Buffer ('expand') geometries with a given value.
A GeometryBlock and a buffer distance are provided. Each feature in the
GeometryBlock is buffered with the distance provided, resulting in updated
geometries.
A GeometryBlock and a buffer distance are provided. Each feature in the
GeometryBlock is buffered with the distance provided, resulting in updated
geometries.
Args:
source (GeometryBlock): The source GeometryBlock whose geometry will be
source (GeometryBlock): The source GeometryBlock whose geometry will be
updated.
distance (float): The distance used to buffer all features. The distance
distance (float): The distance used to buffer all features. The distance
is measured in the unit of the given projection (e.g. m, °).
projection (str): The projection used in the operation provided in the
format: ``"EPSG:28992"``.
resolution (integer, optional): The resolution of the buffer provided as
the number of points used to represent a quarter of a circle. The
resolution (integer, optional): The resolution of the buffer provided as
the number of points used to represent a quarter of a circle. The
default value is ``16``.
Returns:
Expand Down Expand Up @@ -94,15 +94,15 @@ def process(data, kwargs):
class Simplify(BaseSingle):
"""
Simplify geometries, mainly to make them computationally more efficient.
Provide a GeometryBlock and a tolerance value to simplify the geometries.
Provide a GeometryBlock and a tolerance value to simplify the geometries.
As a result all features in the GeometryBlock are simplified.
Args:
source (GeometryBlock): Source of the geometries to be simplified.
tolerance (float): The tolerance used in the simplification. If no
tolerance (float): The tolerance used in the simplification. If no
tolerance is given the ``"min_size"`` request parameter is used.
preserve_topology (boolean, optional): Determines whether the topology
preserve_topology (boolean, optional): Determines whether the topology
should be preserved in the operation. Defaults to ``True``.
Returns:
Expand Down
25 changes: 13 additions & 12 deletions dask_geomodeling/geometry/field_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def process(data, value_column, bin_columns, labels, right):
# Check in which bin every value is. because bins may be different for
# each value, searchsorted is not an option. We assume that bins are
# sorted in increasing order. Checking that would be costly.
with np.errstate(invalid='ignore'): # comparison to NaN is OK here
with np.errstate(invalid="ignore"): # comparison to NaN is OK here
if right:
indices = np.sum(values[:, np.newaxis] > bins, axis=1)
else:
Expand Down Expand Up @@ -249,13 +249,13 @@ def process(source, other):


class Add(BaseFieldOperation):
"""
"""
Element-wise addition of SeriesBlock or number to another SeriesBlock.
Args:
source (SeriesBlock): First addition term
other (SeriesBlock or number): Second addition term
Returns:
SeriesBlock
"""
Expand Down Expand Up @@ -298,7 +298,7 @@ class Multiply(BaseFieldOperation):


class Divide(BaseFieldOperation):
"""
"""
Element-wise division of SeriesBlock or number with another SeriesBlock.
Note that if you want to divide a constant value by a SeriesBlock (like
Expand Down Expand Up @@ -348,6 +348,7 @@ class Power(BaseFieldOperation):
Returns:
SeriesBlock
"""

def __init__(self, source, other):
# the float(other) will raise a TypeError if necessary
super().__init__(source, float(other))
Expand Down Expand Up @@ -395,7 +396,7 @@ class Equal(BaseFieldOperation):

class NotEqual(BaseFieldOperation):
"""
Determine whether a SeriesBlock and a second SeriesBlock or a constant
Determine whether a SeriesBlock and a second SeriesBlock or a constant
value are not equal.
Note that 'no data' does not equal 'no data'.
Expand Down Expand Up @@ -447,7 +448,7 @@ class Less(BaseFieldOperation):
"""
Determine for each value in a SeriesBlock whether it is less than a
comparison value from a SeriesBlock or constant.
Args:
source (SeriesBlock): First comparison term
other (SeriesBlock or number): Second comparison term
Expand All @@ -463,7 +464,7 @@ class LessEqual(BaseFieldOperation):
"""
Determine for each value in a SeriesBlock whether it is less than or equal
to a comparison value from a SeriesBlock or constant.
Args:
source (SeriesBlock): First comparison term
other (SeriesBlock or number): Second comparison term
Expand Down Expand Up @@ -494,7 +495,7 @@ class And(BaseLogicOperation):
Args:
source (SeriesBlock): First boolean term
other (SeriesBlock): Second boolean term
Returns:
SeriesBlock with boolean values
"""
Expand Down Expand Up @@ -544,7 +545,7 @@ class Invert(BaseSingleSeries):
Args:
source (SeriesBlock): SeriesBlock with boolean values.
Returns:
SeriesBlock with boolean values
"""
Expand All @@ -570,7 +571,7 @@ class Where(BaseSingleSeries):
other (SeriesBlock or constant): The value that should be used as a
replacement for the source SeriesBlock where the conditional
SeriesBlock is False.
Returns:
SeriesBlock with updated values where condition is False.
"""
Expand Down Expand Up @@ -642,11 +643,11 @@ class Round(BaseSingleSeries):
source (SeriesBlock): SeriesBlock with float data that is rounded to the
provided number of decimals.
decimals (int, optional): number of decimal places to round to
(default: 0). If decimals is negative, it specifies the number of
(default: 0). If decimals is negative, it specifies the number of
positions to the left of the decimal point.
Returns:
SeriesBlock with rounded values.
SeriesBlock with rounded values.
"""

def __init__(self, source, decimals=0):
Expand Down
6 changes: 3 additions & 3 deletions dask_geomodeling/geometry/geom_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Area(SeriesBlock):
Provide a GeometryBlock and a projection. Returns the area of each
individual geometry in the input block, in that projection.
Args:
source (GeometryBlock): Source GeometryBlock which contains the features.
projection (str): Projection in which to compute the area
(i.e. ``"epsg:28992"``).
Returns:
Returns:
SeriesBlock with only the computed area
"""

Expand Down
2 changes: 1 addition & 1 deletion dask_geomodeling/geometry/set_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Difference(BaseSingle):
"""
Calculate the geometric difference of two GeometryBlocks.
All geometries in the source GeometryBlock will be adapted by geometries
with the same index from the second GeometryBlock. The difference operation
removes any overlap between the geometries from the first geometry.
Expand Down
24 changes: 8 additions & 16 deletions dask_geomodeling/geometry/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def process(data, process_kwargs):
for col in fields.keys():
series = features[col]
if series.dtype == object or (
str(series.dtype) == "category"
and series.cat.categories.dtype == object
str(series.dtype) == "category"
and series.cat.categories.dtype == object
):
features[col] = series.map(_to_json)

Expand All @@ -155,9 +155,7 @@ def process(data, process_kwargs):

# GeoJSON needs reprojection to EPSG:4326
if driver == "GeoJSON" and projection.upper() != "EPSG:4326":
features = utils.geodataframe_transform(
features, projection, "EPSG:4326"
)
features = utils.geodataframe_transform(features, projection, "EPSG:4326")

# generate the file
features.to_file(os.path.join(path, filename), driver=driver)
Expand All @@ -179,7 +177,7 @@ def merge_files(path, target, remove_source=False):
raise IOError("Target '{}' already exists".format(target))

target_base, ext = os.path.splitext(target)
source_paths = glob.glob(os.path.join(path, '*' + ext))
source_paths = glob.glob(os.path.join(path, "*" + ext))
if len(source_paths) == 0:
raise IOError(
"No source files found with matching extension '{}'".format(ext)
Expand All @@ -189,10 +187,8 @@ def merge_files(path, target, remove_source=False):
# files (e.g. shapefiles have multiple files)
source_base = os.path.splitext(source_paths[0])[0]
move_or_copy = shutil.move if remove_source else shutil.copy
for file_path in glob.glob(source_base + '.*'):
move_or_copy(
file_path, target_base + os.path.splitext(file_path)[1]
)
for file_path in glob.glob(source_base + ".*"):
move_or_copy(file_path, target_base + os.path.splitext(file_path)[1])
return

with utils.fiona_env():
Expand Down Expand Up @@ -225,9 +221,7 @@ def DryRunTempDir(*args, **kwargs):
yield "/tmp/dummy"


def to_file(
source, url, fields=None, tile_size=None, dry_run=False, **request
):
def to_file(source, url, fields=None, tile_size=None, dry_run=False, **request):
"""Utility function to export data from a GeometryBlock to a file on disk.
You need to specify the target file path as well as the extent geometry
Expand Down Expand Up @@ -270,9 +264,7 @@ def to_file(

TmpDir = DryRunTempDir if dry_run else tempfile.TemporaryDirectory
with TmpDir(dir=config.get("temporary_directory", None)) as tmpdir:
sink = GeometryFileSink(
source, tmpdir, extension=extension, fields=fields
)
sink = GeometryFileSink(source, tmpdir, extension=extension, fields=fields)

# wrap the sink in a GeometryTiler
if tile_size is not None:
Expand Down

0 comments on commit fd5a33c

Please sign in to comment.