Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com>
  • Loading branch information
enekomartinmartinez and schlunma committed Feb 27, 2024
1 parent 83cb96b commit 835b81e
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions esmvalcore/preprocessor/_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,9 @@ def calculate_volume(cube: Cube) -> da.core.Array:
if not has_cell_measure:
cube.remove_cell_measure('cell_area')

# Get slices to make area and thickness match with the same number
# of dimensions as the cube
z_slice = tuple(
slice(None) if i in z_dim else None
for i in range(cube.ndim)
)
area_slice = tuple(
slice(None) if i in area_dim else None
for i in range(cube.ndim)
)

# Calculate grid cell volume as area * thickness
grid_volume = area.lazy_data()[area_slice] * thickness[z_slice]
area_arr = iris.util.broadcast_to_shape(area.core_data(), cube.shape, area_dim)

Check notice on line 154 in esmvalcore/preprocessor/_volume.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/preprocessor/_volume.py#L154

line too long (83 > 79 characters) (E501)
thickness_arr = iris.util.broadcast_to_shape(thickness, cube.shape, z_dim)
grid_volume = area_arr * thickness_arr

return grid_volume

Expand Down Expand Up @@ -192,7 +182,7 @@ def _try_adding_calculated_ocean_volume(cube: Cube) -> None:
units='m3',
measure='volume',
)
cube.add_cell_measure(cell_measure, data_dims)
cube.add_cell_measure(cell_measure, np.arange(cube.ndim))


@register_supplementaries(
Expand Down

0 comments on commit 835b81e

Please sign in to comment.