Skip to content

Commit

Permalink
refactor: use >3.9 hint syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Oct 21, 2024
1 parent 6fafd4c commit 429d917
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
38 changes: 19 additions & 19 deletions geetools/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,9 @@ def byBands(
regions: ee.featurecollection,
reducer: str = "mean",
scale: int = 10000,
bands: Optional[List] = None,
bands: list = [],
regionId: str = "system:index",
labels: Optional[List] = None,
labels: list = [],
) -> ee.Dictionary:
"""Compute a reducer for each band of the image in each region.
Expand Down Expand Up @@ -1474,10 +1474,10 @@ def byBands(
features = features.map(lambda i: ee.Algorithms.If(isString(i), i, ee.Number(i).format()))

# get the bands to be used in the reducer
eeBands = ee.List(bands) if bands else self._obj.bandNames()
eeBands = ee.List(bands) if len(bands) else self._obj.bandNames()

# retrieve the label to use for each bands if provided
eeLabels = ee.List(labels) if labels else eeBands
eeLabels = ee.List(labels) if len(labels) else eeBands

# by default for 1 band image, the reducers are renaming the output band. To ensure it keeps
# the original band name we add setOutputs that is ignored for multi band images.
Expand All @@ -1501,9 +1501,9 @@ def byRegions(
regions: ee.featurecollection,
reducer: str = "mean",
scale: int = 10000,
bands: Optional[List] = None,
bands: list = [],
regionId: str = "system:index",
labels: Optional[List] = None,
labels: list = [],
) -> ee.Dictionary:
"""Compute a reducer in each region of the image for eah band.
Expand Down Expand Up @@ -1551,10 +1551,10 @@ def byRegions(
features = features.map(lambda i: ee.Algorithms.If(isString(i), i, ee.Number(i).format()))

# get the bands to be used in the reducer
bands = ee.List(bands) if bands else self._obj.bandNames()
bands = ee.List(bands) if len(bands) else self._obj.bandNames()

# retrieve the label to use for each bands if provided
labels = ee.List(labels) if labels else bands
labels = ee.List(labels) if len(labels) else bands

# by default for 1 band image, the reducers are renaming the output band. To ensure it keeps
# the original band name we add setOutputs that is ignored for multi band images.
Expand All @@ -1581,11 +1581,11 @@ def plot_by_regions(
regions: ee.FeatureCollection,
reducer: str = "mean",
scale: int = 10000,
bands: Optional[List] = None,
bands: list = [],
regionId: str = "system:index",
labels: Optional[List] = None,
labels: list = [],
colors: list = [],
ax: Optional[Axes] = None,
ax: Axes | None = None,
):
"""Plot the reduced values for each region.
Expand Down Expand Up @@ -1637,8 +1637,8 @@ def plot_by_regions(
features = features.getInfo()

# extract the labels from the parameters
eeBands = ee.List(bands) if bands else self._obj.bandNames()
labels = labels if labels else eeBands.getInfo()
eeBands = ee.List(bands) if len(bands) else self._obj.bandNames()
labels = labels if len(labels) else eeBands.getInfo()

# reorder the data according to the labels id set by the user
data = {b: {f: data[b][f] for f in features} for b in labels}
Expand All @@ -1651,11 +1651,11 @@ def plot_by_bands(
regions: ee.FeatureCollection,
reducer: str = "mean",
scale: int = 10000,
bands: Optional[List] = None,
bands: list = [],
regionId: str = "system:index",
labels: Optional[List] = None,
labels: list = [],
colors: list = [],
ax: Optional[Axes] = None,
ax: Axes | None = None,
):
"""Plot the reduced values for each bands.
Expand Down Expand Up @@ -1708,8 +1708,8 @@ def plot_by_bands(
features = features.getInfo()

# extract the labels from the parameters
eeBands = ee.List(bands) if bands else self._obj.bandNames()
labels = labels if labels else eeBands.getInfo()
eeBands = ee.List(bands) if len(bands) else self._obj.bandNames()
labels = labels if len(labels) else eeBands.getInfo()

# reorder the data according to the labels id set by the user
data = {f: {b: data[f][b] for b in labels} for f in features}
Expand All @@ -1720,7 +1720,7 @@ def plot_hist(
self,
ax: Axes,
bins: int = 30,
region: Optional[ee.Geometry] = None,
region: ee.Geometry | None = None,
bands: list = [],
labels: list = [],
colors: list = [],
Expand Down
5 changes: 3 additions & 2 deletions geetools/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utils methods for file and asset manipulation in the context of batch processing."""
from __future__ import annotations

import re
from typing import Optional

import numpy as np
from anyascii import anyascii
Expand Down Expand Up @@ -70,7 +71,7 @@ def plot_data(
data: dict,
label_name: str,
colors: list = [],
ax: Optional[Axes] = None,
ax: Axes | None = None,
**kwargs,
) -> Axes:
"""Plotting mechanism used in all the plotting functions.
Expand Down

0 comments on commit 429d917

Please sign in to comment.