-
Notifications
You must be signed in to change notification settings - Fork 279
/
merge_concat.py
61 lines (44 loc) · 1.85 KB
/
merge_concat.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
# Copyright Iris contributors
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Benchmarks relating to :meth:`iris.cube.CubeList.merge` and ``concatenate``."""
import numpy as np
from iris.cube import CubeList
from . import TrackAddedMemoryAllocation
from .generate_data.stock import realistic_4d_w_everything
class Merge:
# TODO: Improve coverage.
cube_list: CubeList
def setup(self):
source_cube = realistic_4d_w_everything()
# Merge does not yet fully support cell measures and ancillary variables.
for cm in source_cube.cell_measures():
source_cube.remove_cell_measure(cm)
for av in source_cube.ancillary_variables():
source_cube.remove_ancillary_variable(av)
second_cube = source_cube.copy()
scalar_coord = second_cube.coords(dimensions=[])[0]
scalar_coord.points = scalar_coord.points + 1
self.cube_list = CubeList([source_cube, second_cube])
def time_merge(self):
_ = self.cube_list.merge_cube()
@TrackAddedMemoryAllocation.decorator_repeating()
def track_mem_merge(self):
_ = self.cube_list.merge_cube()
class Concatenate:
# TODO: Improve coverage.
cube_list: CubeList
def setup(self):
source_cube = realistic_4d_w_everything()
second_cube = source_cube.copy()
first_dim_coord = second_cube.coord(dimensions=0, dim_coords=True)
first_dim_coord.points = (
first_dim_coord.points + np.ptp(first_dim_coord.points) + 1
)
self.cube_list = CubeList([source_cube, second_cube])
def time_concatenate(self):
_ = self.cube_list.concatenate_cube()
@TrackAddedMemoryAllocation.decorator_repeating()
def track_mem_merge(self):
_ = self.cube_list.concatenate_cube()