/
dimensioncoordinate.py
882 lines (737 loc) · 28.7 KB
/
dimensioncoordinate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
import cfdm
from numpy import empty as numpy_empty
from numpy import result_type as numpy_result_type
from . import Bounds, mixin
from .data.data import Data
from .decorators import (
_deprecated_kwarg_check,
_inplace_enabled,
_inplace_enabled_define_and_cleanup,
)
from .functions import _DEPRECATION_ERROR_ATTRIBUTE, _DEPRECATION_ERROR_KWARGS
from .timeduration import TimeDuration
from .units import Units
class DimensionCoordinate(
mixin.Coordinate, mixin.PropertiesDataBounds, cfdm.DimensionCoordinate
):
"""A dimension coordinate construct of the CF data model.
A dimension coordinate construct provides information which locate
the cells of the domain and which depend on a subset of the domain
axis constructs. The dimension coordinate construct is able to
unambiguously describe cell locations because a domain axis can be
associated with at most one dimension coordinate construct, whose
data array values must all be non-missing and strictly
monotonically increasing or decreasing. They must also all be of
the same numeric data type. If cell bounds are provided, then each
cell must have exactly two vertices. CF-netCDF coordinate
variables and numeric scalar coordinate variables correspond to
dimension coordinate constructs.
The dimension coordinate construct consists of a data array of the
coordinate values which spans a subset of the domain axis
constructs, an optional array of cell bounds recording the extents
of each cell (stored in a `Bounds` object), and properties to
describe the coordinates. An array of cell bounds spans the same
domain axes as its coordinate array, with the addition of an extra
dimension whose size is that of the number of vertices of each
cell. This extra dimension does not correspond to a domain axis
construct since it does not relate to an independent axis of the
domain. Note that, for climatological time axes, the bounds are
interpreted in a special way indicated by the cell method
constructs.
**NetCDF interface**
{{netcdf variable}}
"""
def __new__(cls, *args, **kwargs):
"""Store component classes."""
instance = super().__new__(cls)
instance._Bounds = Bounds
return instance
def __repr__(self):
"""Called by the `repr` built-in function.
x.__repr__() <==> repr(x)
"""
return super().__repr__().replace("<", "<CF ", 1)
def _centre(self, period):
"""It assumed, but not checked, that the period has been set.
.. seealso:: `roll`
"""
if self.direction():
mx = self.data[-1]
else:
mx = self.data[0]
return ((mx // period) * period).squeeze()
def _infer_direction(self):
"""Return True if a coordinate is increasing, otherwise return
False.
A dimension coordinate construct is considered to be increasing if
its data array values are increasing in index space, or if it has
no data nor bounds.
If the direction can not be inferred from the data not bounds then
the coordinate's units are used.
The direction is inferred from the coordinate's data array values
or its from coordinates. It is not taken directly from its
`cf.Data` object.
:Returns:
`bool`
Whether or not the coordinate is increasing.
**Examples**
>>> c.array
array([ 0 30 60])
>>> c._get_direction()
True
>>> c.array
array([15])
>>> c.bounds.array
array([ 30 0])
>>> c._get_direction()
False
"""
data = self.get_data(None, _fill_value=False)
if data is not None:
# Infer the direction from the data
if data._size > 1:
data = data[0:2].array
return bool(
data.item(
0,
)
< data.item(
1,
)
)
# Still here?
data = self.get_bounds_data(None, _fill_value=False)
if data is not None:
# Infer the direction from the bounds
b = data[(0,) * (data.ndim - 1)].array
return bool(
b.item(
0,
)
< b.item(
1,
)
)
# Still here? Then infer the direction from the units.
return not self.Units.ispressure
# ----------------------------------------------------------------
# Attributes
# ----------------------------------------------------------------
# @property
# def cellsize(self):
# '''The cell sizes.
#
# :Returns:
#
# `Data`
# The size for each cell.
#
# **Examples**
#
# >>> print(c.bounds)
# <CF Bounds: latitude(3, 2) degrees_north>
# >>> print(c.bounds.array)
# [[-90. -87.]
# [-87. -80.]
# [-80. -67.]]
# >>> print(d.cellsize)
# <CF Data(3): [3.0, 7.0, 13.0] degrees_north>
# >>> print(d.cellsize.array)
# [ 3. 7. 13.]
# >>> print(c.sin().cellsize.array)
# [ 0.00137047 0.01382178 0.0643029 ]
#
# >>> del(c.bounds)
# >>> c.cellsize
# AttributeError: Can't get cell sizes when coordinates have no bounds
#
# '''
# cells = self.get_bounds_data(None)
# if cells is None:
# raise AttributeError(
# "Can't get cell sizes when coordinates have no bounds")
#
# if self.direction():
# cells = cells[:, 1] - cells[:, 0]
# else:
# cells = cells[:, 0] - cells[:, 1]
#
# cells.squeeze(1, inplace=True)
#
# return cells
@property
def decreasing(self):
"""True if the dimension coordinate is decreasing, otherwise
False.
A dimension coordinate is increasing if its coordinate values are
increasing in index space.
The direction is inferred from one of, in order of precedence:
* The data array
* The bounds data array
* The `units` CF property
:Returns:
`bool`
Whether or not the coordinate is decreasing.
**Examples**
>>> c.decreasing
False
>>> c.flip().increasing
True
"""
return not self.direction()
@property
def increasing(self):
"""`True` for dimension coordinate constructs, `False`
otherwise.
A dimension coordinate is increasing if its coordinate values are
increasing in index space.
The direction is inferred from one of, in order of precedence:
* The data array
* The bounds data array
* The `units` CF property
:Returns:
`bool`
Whether or not the coordinate is increasing.
**Examples**
>>> c.decreasing
False
>>> c.flip().increasing
True
"""
return self.direction()
# @property
# def lower_bounds(self):
# '''The lower dimension coordinate bounds in a `cf.Data` object.
#
# .. seealso:: `bounds`, `upper_bounds`
#
# **Examples**
#
# >>> print(c.bounds.array)
# [[ 5 3]
# [ 3 1]
# [ 1 -1]]
# >>> c.lower_bounds
# <CF Data(3): [3, 1, -1]>
# >>> print(c.lower_bounds.array)
# [ 3 1 -1]
#
# '''
# data = self.get_bounds_data(None)
# if data is None:
# raise ValueError(
# "Can't get lower bounds when there are no bounds")
#
# if self.direction():
# i = 0
# else:
# i = 1
#
# out = data[..., i]
# out.squeeze(1, inplace=True)
# return out
#
# @property
# def upper_bounds(self):
# '''The upper dimension coordinate bounds in a `cf.Data` object.
#
# .. seealso:: `bounds`, `lower_bounds`
#
# **Examples**
#
# >>> print(c.bounds.array)
# [[ 5 3]
# [ 3 1]
# [ 1 -1]]
# >>> c.upper_bounds
# <CF Data(3): [5, 3, 1]>
# >>> print(c.upper_bounds.array)
# [5 3 1]
#
# '''
# data = self.get_bounds_data(None)
# if data is None:
# raise ValueError(
# "Can't get upper bounds when there are no bounds")
#
# if self.direction():
# i = 1
# else:
# i = 0
#
# return data[..., i].squeeze(1)
def direction(self):
"""Return True if the dimension coordinate values are
increasing, otherwise return False.
Dimension coordinates values are increasing if its coordinate
values are increasing in index space.
The direction is inferred from one of, in order of precedence:
* The data array
* The bounds data array
* The `units` CF property
:Returns:
`bool`
Whether or not the coordinate is increasing.
**Examples**
>>> c.array
array([ 0 30 60])
>>> c.direction()
True
>>> c.bounds.array
array([ 30 0])
>>> c.direction()
False
"""
_direction = self._custom.get("direction")
if _direction is not None:
return _direction
_direction = self._infer_direction()
self._custom["direction"] = _direction
return _direction
def create_bounds(
self, bound=None, cellsize=None, flt=0.5, max=None, min=None
):
"""Create cell bounds.
:Parameters:
bound: optional
If set to a value larger (smaller) than the largest
(smallest) coordinate value then bounds are created which
include this value and for which each coordinate is in the
centre of its bounds.
cellsize: optional
Define the exact size of each cell that is
created. Created cells are allowed to overlap do not have
to be contigious. The *cellsize* parameter may be one of:
* A data-like scalar (see below) that defines the cell size,
either in the same units as the coordinates or in the
units provided. Note that in this case, the position of
each coordinate within the its cell is controlled by the
*flt* parameter.
*Parameter example:*
To specify cellsizes of 10, in the same units as the
coordinates: ``cellsize=10``.
*Parameter example:*
To specify cellsizes of 1 day: ``cellsize=cf.Data(1,
'day')`` (see `cf.Data` for details).
*Parameter example:*
For coordinates ``1, 2, 10``, setting ``cellsize=1``
will result in bounds of ``(0.5, 1.5), (1.5, 2.5),
(9.5, 10.5)``.
*Parameter example:*
For coordinates ``1, 2, 10`` kilometres, setting
``cellsize=cf.Data(5000, 'm')`` will result in bounds
of ``(-1.5, 3.5), (-0.5, 4.5), (7.5, 12.5)`` (see
`cf.Data` for details).
*Parameter example:*
For decreasing coordinates ``2, 0, -12`` setting,
``cellsize=2`` will result in bounds of ``(3, 1),
(1, -1), (-11, -13)``.
* A `cf.TimeDuration` defining the cell size. Only
applicable to reference time coordinates. It is possible
to "anchor" the cell bounds via the `cf.TimeDuration`
parameters. For example, to specify cell size of one
calendar month, starting and ending on the 15th day:
``cellsize=cf.M(day=15)`` (see `cf.M` for details). Note
that the *flt* parameter is ignored in this case.
*Parameter example:*
For coordinates ``1984-12-01 12:00, 1984-12-02
12:00, 2000-04-15 12:00`` setting,
``cellsize=cf.D()`` will result in bounds of
``(1984-12-01, 1984-12-02), (1984-12-02,
1984-12-03), (2000-05-15, 2000-04-16)`` (see `cf.D`
for details).
*Parameter example:*
For coordinates ``1984-12-01, 1984-12-02,
2000-04-15`` setting, ``cellsize=cf.D()`` will
result in bounds of ``(1984-12-01, 1984-12-02),
(1984-12-02, 1984-12-03), (2000-05-15, 2000-04-16)``
(see `cf.D` for details).
*Parameter example:*
For coordinates ``1984-12-01, 1984-12-02,
2000-04-15`` setting, ``cellsize=cf.D(hour=12)``
will result in bounds of ``(1984-11:30 12:00,
1984-12-01 12:00), (1984-12-01 12:00, 1984-12-02
12:00), (2000-05-14 12:00, 2000-04-15 12:00)`` (see
`cf.D` for details).
*Parameter example:*
For coordinates ``1984-12-16 12:00, 1985-01-16
12:00`` setting, ``cellsize=cf.M()`` will result in
bounds of ``(1984-12-01, 1985-01-01), (1985-01-01,
1985-02-01)`` (see `cf.M` for details).
*Parameter example:*
For coordinates ``1984-12-01 12:00, 1985-01-01
12:00`` setting, ``cellsize=cf.M()`` will result in
bounds of ``(1984-12-01, 1985-01-01), (1985-01-01,
1985-02-01)`` (see `cf.M` for details).
*Parameter example:*
For coordinates ``1984-12-01 12:00, 1985-01-01
12:00`` setting, ``cellsize=cf.M(day=20)`` will
result in bounds of ``(1984-11-20, 1984-12-20),
(1984-12-20, 1985-01-20)`` (see `cf.M` for details).
*Parameter example:*
For coordinates ``1984-03-01, 1984-06-01`` setting,
``cellsize=cf.Y()`` will result in bounds of
``(1984-01-01, 1985-01-01), (1984-01-01,
1985-01-01)`` (see `cf.Y` for details). Note that in
this case each cell has the same bounds. This
because ``cf.Y()`` is equivalent to ``cf.Y(month=1,
day=1)`` and the closest 1st January to both
coordinates is 1st January 1984.
{+data-like-scalar} TODO
flt: `float`, optional
When creating cells with sizes specified by the *cellsize*
parameter, define the fraction of the each cell which is
less its coordinate value. By default *flt* is 0.5, so that
each cell has its coordinate at it's centre. Ignored if
*cellsize* is not set.
*Parameter example:*
For coordinates ``1, 2, 10``, setting ``cellsize=1,
flt=0.5`` will result in bounds of ``(0.5, 1.5), (1.5,
2.5), (9.5, 10.5)``.
*Parameter example:*
For coordinates ``1, 2, 10``, setting ``cellsize=1,
flt=0.25`` will result in bounds of ``(0.75, 1.75),
(1.75, 2.75), (9.75, 10.75)``.
*Parameter example:*
For decreasing coordinates ``2, 0, -12``, setting
``cellsize=6, flt=0.9`` will result in bounds of
``(2.6, -3.4), (0.6, -5.4), (-11.4, -17.4)``.
max: optional
Limit the created bounds to be no more than this number.
*Parameter example:*
To ensure that all latitude bounds are at most 90:
``max=90``.
min: optional
Limit the created bounds to be no less than this number.
*Parameter example:*
To ensure that all latitude bounds are at least -90:
``min=-90``.
:Returns:
`Bounds`
The newly-created coordinate cell bounds object.
**Examples**
>>> c.create_bounds()
>>> c.create_bounds(bound=-9000.0)
"""
array = self.array
size = array.size
if cellsize is not None:
if bound:
raise ValueError(
"bound parameter can't be True when setting the "
"cellsize parameter"
)
if not isinstance(cellsize, TimeDuration):
# ----------------------------------------------------
# Create bounds based on cell sizes defined by a
# data-like object
#
# E.g. cellsize=10
# cellsize=cf.Data(1, 'day')
# ----------------------------------------------------
cellsize = Data.asdata(abs(cellsize))
if cellsize.Units:
err_msg = (
"Can't create bounds because the bound units "
f"({cellsize.Units}) are not compatible with "
f"the coordinate units ({self.Units})."
)
if self.Units.isreftime:
if not cellsize.Units.istime:
raise ValueError(err_msg)
cellsize.Units = Units(self.Units._utime.units)
else:
if not cellsize.Units.equivalent(self.Units):
raise ValueError(err_msg)
cellsize.Units = self.Units
cellsize = cellsize.datum()
cellsize0 = cellsize * flt
cellsize1 = cellsize * (1 - flt)
if not self.direction():
cellsize0, cellsize1 = -cellsize1, -cellsize0
bounds = numpy_empty((size, 2), dtype=array.dtype)
bounds[:, 0] = array - cellsize0
bounds[:, 1] = array + cellsize1
else:
# ----------------------------------------------------
# Create bounds based on cell sizes defined by a
# TimeDuration object
#
# E.g. cellsize=cf.s()
# cellsize=cf.m()
# cellsize=cf.h()
# cellsize=cf.D()
# cellsize=cf.M()
# cellsize=cf.Y()
# cellsize=cf.D(hour=12)
# cellsize=cf.M(day=16)
# cellsize=cf.M(2)
# cellsize=cf.M(2, day=15, hour=12)
# ----------------------------------------------------
if not self.Units.isreftime:
raise ValueError(
"Can't create reference time bounds for "
f"non-reference time coordinates: {self.Units!r}"
)
bounds = numpy_empty((size, 2), dtype=object)
cellsize_bounds = cellsize.bounds
direction = bool(self.direction())
for c, b in zip(self.datetime_array, bounds):
b[...] = cellsize_bounds(c, direction=direction)
else:
if bound is None:
# ----------------------------------------------------
# Creat Voronoi bounds
# ----------------------------------------------------
if size < 2:
raise ValueError(
"Can't create bounds for Voronoi cells from one value"
)
bounds_1d = [
array.item(
0,
)
* 1.5
- array.item(
1,
)
* 0.5
]
bounds_1d.extend((array[0:-1] + array[1:]) * 0.5)
bounds_1d.append(
array.item(
-1,
)
* 1.5
- array.item(
-2,
)
* 0.5
)
dtype = type(bounds_1d[0])
if max is not None:
if self.direction():
bounds_1d[-1] = max
else:
bounds_1d[0] = max
if min is not None:
if self.direction():
bounds_1d[0] = min
else:
bounds_1d[-1] = min
else:
# ----------------------------------------------------
# Create
# ----------------------------------------------------
direction = self.direction()
if not direction and size > 1:
array = array[::-1]
bounds_1d = [bound]
if bound <= array.item(
0,
):
for i in range(size):
bound = (
2.0
* array.item(
i,
)
- bound
)
bounds_1d.append(bound)
elif bound >= array.item(
-1,
):
for i in range(size - 1, -1, -1):
bound = (
2.0
* array.item(
i,
)
- bound
)
bounds_1d.append(bound)
bounds_1d = bounds_1d[::-1]
else:
raise ValueError("bad bound value")
dtype = type(bounds_1d[-1])
if not direction:
bounds_1d = bounds_1d[::-1]
bounds = numpy_empty((size, 2), dtype=dtype)
bounds[:, 0] = bounds_1d[:-1]
bounds[:, 1] = bounds_1d[1:]
# Create coordinate bounds object
bounds = Bounds(data=Data(bounds, units=self.Units), copy=False)
return bounds
@_deprecated_kwarg_check("i")
@_inplace_enabled(default=False)
def flip(self, axes=None, inplace=False, i=False):
"""Flips the dimension coordinate, that is reverses its
direction."""
d = _inplace_enabled_define_and_cleanup(self)
super(DimensionCoordinate, d).flip(axes=axes, inplace=True)
direction = d._custom.get("direction")
if direction is not None:
d._custom["direction"] = not direction
return d
def get_bounds(self, default=ValueError(), **kwargs):
"""Return the bounds.
.. versionadded:: 3.0.0
.. seealso:: `bounds`, `create_bounds', `get_data`,
`del_bounds`, `has_bounds`, `set_bounds`
:Parameters:
default: optional
Return the value of the *default* parameter if bounds
have not been set.
{{default Exception}}
:Returns:
`Bounds`
The bounds.
**Examples**
>>> b = Bounds(data=cfdm.Data(range(10).reshape(5, 2)))
>>> c.set_bounds(b)
>>> c.has_bounds()
True
>>> c.get_bounds()
<Bounds: (5, 2) >
>>> b = c.del_bounds()
>>> b
<Bounds: (5, 2) >
>>> c.has_bounds()
False
>>> print(c.get_bounds(None))
None
>>> print(c.del_bounds(None))
None
"""
if kwargs:
_DEPRECATION_ERROR_KWARGS(
self,
"get_bounds",
kwargs,
"Bounds creation now uses the 'create_bounds' and "
"'set_bounds' methods.",
) # pragma: no cover
return super().get_bounds(default=default)
# def autoperiod(self, verbose=False):
# '''TODO Set dimensions to be cyclic.
#
# TODO A dimension is set to be cyclic if it has a unique longitude (or
# grid longitude) dimension coordinate construct with bounds and the
# first and last bounds values differ by 360 degrees (or an
# equivalent amount in other units).
#
# .. versionadded:: 3.0.0
#
# .. seealso:: `isperiodic`, `period`
#
# :Parameters:
#
# TODO
#
# :Returns:
#
# `bool`
#
# **Examples**
#
# >>> f.autocyclic()
#
# '''
# if not self.Units.islongitude:
# if verbose:
# print(0)
# if (self.get_property('standard_name', None) not in
# ('longitude', 'grid_longitude')):
# if verbose:
# print(1)
# return False
#
# bounds = self.get_bounds(None)
# if bounds is None:
# if verbose:
# print(2)
# return False
#
# bounds_data = bounds.get_data(None)
# if bounds_data is None:
# if verbose:
# print(3)
# return False
#
# bounds = bounds_data.array
#
# period = Data(360.0, units='degrees')
#
# period.Units = bounds_data.Units
#
# if abs(bounds[-1, -1] - bounds[0, 0]) != period.array:
# if verbose:
# print(4)
# return False
#
# self.period(period)
#
# return True
@_deprecated_kwarg_check("i")
@_inplace_enabled(default=False)
def roll(self, axis, shift, inplace=False, i=False):
"""Rolls the dimension coordinate along a cyclic axis."""
c = _inplace_enabled_define_and_cleanup(self)
size = c.size
if size <= 1:
return c
shift %= size
if not shift:
# Null roll
return c
# period = self._custom.get('period')
period = c.period()
if period is None:
raise ValueError(
f"Can't roll {self.__class__.__name__} when no period has "
"been set"
)
direction = c.direction()
centre = c._centre(period)
if axis not in [0, -1]:
raise ValueError(
f"Can't roll axis {axis} when there is only one axis"
)
super(DimensionCoordinate, c).roll(axis, shift, inplace=True)
c.dtype = numpy_result_type(c.dtype, period.dtype)
b = c.get_bounds(None)
bounds_data = c.get_bounds_data(None, _fill_value=False)
if bounds_data is not None:
b.dtype = numpy_result_type(bounds_data.dtype, period.dtype)
bounds_data = b.get_data(None, _fill_value=False)
if direction:
# Increasing
c[:shift] -= period
if bounds_data is not None:
b[:shift] -= period
if c.data[0] <= centre - period:
c += period
if bounds_data is not None:
b += period
else:
# Decreasing
c[:shift] += period
if bounds_data is not None:
b[:shift] += period
if c.data[0] >= centre + period:
c -= period
if bounds_data is not None:
b -= period
c._custom["direction"] = direction
return c
# ----------------------------------------------------------------
# Deprecated attributes and methods
# ----------------------------------------------------------------
@property
def role(self):
"""Deprecated at version 3.0.0, use `construct_type` attribute
instead."""
_DEPRECATION_ERROR_ATTRIBUTE(
self, "role", "Use attribute 'construct_type' instead"
) # pragma: no cover