Skip to content

Commit 5ca8fe5

Browse files
authored
Merge pull request #48 from earthdaily/dev
v0.0.9
2 parents 01ee6c5 + 5a6593a commit 5ca8fe5

File tree

5 files changed

+56
-28
lines changed

5 files changed

+56
-28
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.0.9] - 2024-02-29
8+
9+
### Fixed
10+
11+
- `_typer` has a better args management.
12+
- `available_indices` returns only indices that can be computed.
13+
714
## [0.0.8] - 2024-02-28
815

916
### Added
@@ -24,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2431

2532
### Fixed
2633

27-
- `to_wkt`for GeometryManager.
34+
- `to_wkt` for GeometryManager.
2835

2936
### Added
3037

earthdaily/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from . import earthdatastore, datasets
22
from .accessor import EarthDailyAccessorDataArray, EarthDailyAccessorDataset
3+
import warnings
34

4-
__version__ = "0.0.8"
5+
# to hide warnings from rioxarray or nano seconds conversion
6+
warnings.filterwarnings("ignore")
7+
8+
__version__ = "0.0.9"

earthdaily/accessor/__init__.py

+38-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,29 @@ def force(*args, **kwargs):
2828
idx = 1
2929
for key, val in func.__annotations__.items():
3030
is_kwargs = key in kwargs.keys()
31-
if val not in _SUPPORTED_DTYPE or kwargs.get(key, None) is None and is_kwargs or len(args)==1:
31+
if not is_kwargs and idx >= len(args):
3232
continue
33-
if raise_mistype and (val != type(kwargs.get(key)) if is_kwargs else val != type(args[idx])):
33+
input_value = kwargs.get(key, None) if is_kwargs else args[idx]
34+
if type(input_value) == val:
35+
continue
36+
if raise_mistype and (
37+
val != type(kwargs.get(key))
38+
if is_kwargs
39+
else val != type(args[idx])
40+
):
3441
if is_kwargs:
3542
expected = f"{type(kwargs[key]).__name__} ({kwargs[key]})"
3643
else:
3744
expected = f"{type(args[idx]).__name__} ({args[idx]})"
3845

3946
raise MisType(
40-
f"{key} expected a {val.__name__}, not a {expected}."
41-
)
47+
f"{key} expected a {val.__name__}, not a {expected}."
48+
)
4249
if is_kwargs:
4350
kwargs[key] = val(kwargs[key]) if val != list else [kwargs[key]]
44-
else:
51+
elif len(args) >= idx:
4552
_args[idx] = val(args[idx]) if val != list else [args[idx]]
46-
idx+=1
53+
idx += 1
4754
args = tuple(_args)
4855
return func(*args, **kwargs)
4956

@@ -116,24 +123,32 @@ def _lee_filter(img, window_size: int):
116123
img_output = xr.where(np.isnan(binary_nan), img_, img_output)
117124
return img_output
118125

126+
119127
@xr.register_dataarray_accessor("ed")
120128
class EarthDailyAccessorDataArray:
121129
def __init__(self, xarray_obj):
122130
self._obj = xarray_obj
123-
131+
124132
def _max_time_wrap(self, wish=5):
125-
return np.min((wish,self._obj['time'].size))
133+
return np.min((wish, self._obj["time"].size))
126134

127135
@_typer()
128136
def plot_band(self, cmap="Greys", col="time", col_wrap=5, **kwargs):
129-
return self._obj.plot.imshow(cmap=cmap, col=col, col_wrap=self._max_time_wrap(col_wrap), **kwargs)
137+
return self._obj.plot.imshow(
138+
cmap=cmap, col=col, col_wrap=self._max_time_wrap(col_wrap), **kwargs
139+
)
130140

131141
@_typer()
132142
def plot_index(
133143
self, cmap="RdYlGn", vmin=-1, vmax=1, col="time", col_wrap=5, **kwargs
134144
):
135145
return self._obj.plot.imshow(
136-
vmin=vmin, vmax=vmax, cmap=cmap, col=col, col_wrap=self._max_time_wrap(col_wrap), **kwargs
146+
vmin=vmin,
147+
vmax=vmax,
148+
cmap=cmap,
149+
col=col,
150+
col_wrap=self._max_time_wrap(col_wrap),
151+
**kwargs,
137152
)
138153

139154

@@ -143,9 +158,8 @@ def __init__(self, xarray_obj):
143158
self._obj = xarray_obj
144159

145160
def _max_time_wrap(self, wish=5):
146-
return np.min((wish,self._obj['time'].size))
147-
148-
161+
return np.min((wish, self._obj["time"].size))
162+
149163
@_typer()
150164
def plot_rgb(
151165
self,
@@ -173,7 +187,12 @@ def plot_index(
173187
self, index, cmap="RdYlGn", vmin=-1, vmax=1, col="time", col_wrap=5, **kwargs
174188
):
175189
return self._obj[index].plot.imshow(
176-
vmin=vmin, vmax=vmax, cmap=cmap, col=col, col_wrap=self._max_time_wrap(col_wrap), **kwargs
190+
vmin=vmin,
191+
vmax=vmax,
192+
cmap=cmap,
193+
col=col,
194+
col_wrap=self._max_time_wrap(col_wrap),
195+
**kwargs,
177196
)
178197

179198
@_typer()
@@ -235,20 +254,23 @@ def _auto_mapper(self):
235254
params[_BAND_MAPPING[v]] = self._obj[v]
236255
return params
237256

238-
def available_index(self, details=False):
257+
def available_indices(self, details=False):
239258
mapper = list(self._auto_mapper().keys())
240259
indices = spyndex.indices
241260
available_indices = []
242261
for k, v in indices.items():
243262
needed_bands = v.bands
263+
missing_bands = False
244264
for needed_band in needed_bands:
245265
if needed_band not in mapper:
266+
missing_bands = True
246267
break
268+
if missing_bands is False:
247269
available_indices.append(spyndex.indices[k] if details else k)
248270
return available_indices
249271

250272
@_typer()
251-
def add_index(self, index: list, **kwargs):
273+
def add_indices(self, index: list, **kwargs):
252274
"""
253275
Uses spyndex to compute and add index.
254276

examples/field_evolution.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
# Plots cube with SCL with at least 50% of clear data
4545
# ----------------------------------------------------
4646
pivot_cube = pivot_cube.load()
47-
pivot_cube.to_array(dim="band").plot.imshow(
48-
vmin=0, vmax=0.4, col="time", col_wrap=3
49-
)
47+
pivot_cube.ed.plot_rgb(col_wrap=3)
5048

5149
plt.title("Clear cover percent with SCL")
5250
plt.title("Pivot evolution with SCL masks")

examples/multisensors_cube.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
)
4444

4545
# Add the NDVI
46-
datacube = datacube.ed.add_index('NDVI')
46+
datacube = datacube.ed.add_indices(['NDVI'])
4747

4848
# Load in memory
4949
datacube = datacube.load()
@@ -52,18 +52,15 @@
5252
# See the evolution in RGB
5353
# -------------------------------------------
5454

55-
datacube[["red", "green", "blue"]].to_array(dim="band").plot.imshow(
56-
col="time", col_wrap=3, vmax=0.2
57-
)
55+
datacube.ed.plot_rgb(col_wrap=3)
5856
plt.show()
5957

58+
6059
##############################################################################
6160
# See the NDVI evolution
6261
# -------------------------------------------
6362

64-
datacube["NDVI"].plot.imshow(
65-
col="time", col_wrap=3, vmin=0, vmax=0.8, cmap="RdYlGn"
66-
)
63+
datacube["NDVI"].ed.plot_index(col_wrap=3, vmin=0, vmax=0.8, cmap="Greens")
6764
plt.show()
6865

6966
##############################################################################

0 commit comments

Comments
 (0)