Skip to content

Commit

Permalink
Fix issues in difference_map.py (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnikaLau authored Aug 2, 2023
1 parent 16df140 commit 6bd4c3a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions difference_map/difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import xarray as xr
from matplotlib.lines import Line2D


def is_size_one_dim(dim, data):
return data.sizes[dim] == 1


if __name__ == "__main__":

####################
Expand Down Expand Up @@ -129,18 +134,21 @@
var["zname"] in data1[var["name"]].dims
and data1[var["name"]].sizes[var["zname"]] > 1
):
values["data1"] = (
values["data1"]
.isel({var["zname"]: var["height"]})
.squeeze(dim=var["zname"])
.values
)
values["data2"] = (
values["data2"]
.isel({var["zname"]: var["height"]})
.squeeze(dim=var["zname"])
.values
)
values["data1"] = values["data1"].isel({var["zname"]: var["height"]})
dims_to_drop = [
dim
for dim in values["data1"].dims
if is_size_one_dim(dim, values["data1"]) and dim != "time"
]
values["data1"] = (values["data1"].squeeze(dim=dims_to_drop, drop=True)).values

values["data2"] = values["data2"].isel({var["zname"]: var["height"]})
dims_to_drop = [
dim
for dim in values["data2"].dims
if is_size_one_dim(dim, values["data2"]) and dim != "time"
]
values["data2"] = (values["data2"].squeeze(dim=dims_to_drop, drop=True)).values
else:
print(
"Warning: The variable "
Expand Down Expand Up @@ -171,8 +179,8 @@
)
data_com["clon"].attrs["bounds"] = "clon_bnds"
data_com["clat"].attrs["bounds"] = "clat_bnds"
data_com["clon"].attrs["units"] = "radian"
data_com["clat"].attrs["units"] = "radian"
data_com["clon"].attrs["units"] = data1["clon"].attrs["units"]
data_com["clat"].attrs["units"] = data1["clat"].attrs["units"]
data_com.var_diff.encoding["coordinates"] = "clat clon"

#############
Expand Down

0 comments on commit 6bd4c3a

Please sign in to comment.