Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize column integral calculation #350

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions driver/pace/driver/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from datetime import datetime, timedelta
from typing import List, Optional, Union

from sympy import ShapeError

import pace.driver
import pace.dsl
import pace.stencils
Expand Down Expand Up @@ -174,13 +172,14 @@ def _compute_column_integral(
q_in: tracer mixing ratio
delp: pressure thickness of atmospheric layer
"""
if len(q_in.shape) < 3:
assert ShapeError(f"{name} does not have vertical levels.")
assert len(q_in.dims) > 2
if q_in.dims[2] != pace.util.Z_DIM:
raise NotImplementedError(
"this function assumes the z-dimension is the third dimension"
)
k_slice = slice(q_in.origin[2], q_in.origin[2] + q_in.extent[2])
column_integral = pace.util.Quantity(
sum(
q_in.data[:, :, k] * delp.data[:, :, k]
for k in range(q_in.metadata.extent[2])
),
q_in.np.sum(q_in.data[:, :, k_slice] * delp.data[:, :, k_slice], axis=2),
dims=("x", "y"),
origin=q_in.metadata.origin[0:2],
extent=(q_in.metadata.extent[0], q_in.metadata.extent[1]),
Expand Down