Skip to content

Commit

Permalink
add code back in but change logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Courtney Peverley committed Feb 14, 2024
1 parent 1f59dd1 commit 180965c
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions scripts/var_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ class VarCompatObj:
# produces the correct reverse transformation
>>> VarCompatObj("var_stdname", "real", "kind_phys", "m", ['vertical_layer_dimension'], "var1_lname", False,\
"var_stdname", "real", "kind_phys", "m", ['vertical_layer_dimension'], "var2_lname", True, \
_DOCTEST_RUNENV).reverse_transform("var1_lname", "var2_lname", 'k', 'nk-k+1')
_DOCTEST_RUNENV).reverse_transform("var1_lname", "var2_lname", ('k',), ('nk-k+1',))
'var1_lname(nk-k+1) = var2_lname(k)'
# Test that a 2-D var with unit conversion m->km works
Expand Down Expand Up @@ -939,6 +939,23 @@ def __init__(self, var1_stdname, var1_type, var1_kind, var1_units,
self.has_vert_transforms = True
# end if
# end if
if self.__compat:
# Check dimensions
##XXgoldyXX: For now, we always have to create a dimension
## transform because we do not know if the vertical
## dimension is flipped.
if var1_dims or var2_dims:
_, vdim_ind = find_vertical_dimension(var1_dims)
if (var1_dims != var2_dims):
self.__dim_transforms = self._get_dim_transforms(var1_dims,
var2_dims)
self.__compat = self.__dim_transforms is not None
# end if
# end if
if not self.__compat:
incompat_reason.append('dimensions')
# end if
# end if
self.__incompat_reason = " and ".join([x for x in incompat_reason if x])

def forward_transform(self, lvar_lname, rvar_lname, rvar_indices, lvar_indices,
Expand All @@ -962,11 +979,11 @@ def forward_transform(self, lvar_lname, rvar_lname, rvar_indices, lvar_indices,
"vertical_interface_dimension").
"""
# Dimension transform (Indices handled externally)
if isinstance(rvar_indices, str):
rvar_indices = (rvar_indices,)
# if isinstance(rvar_indices, str):
# rvar_indices = (rvar_indices,)
# end if
if isinstance(lvar_indices, str):
lvar_indices = (lvar_indices,)
# if isinstance(lvar_indices, str):
# lvar_indices = (lvar_indices,)
# end if
rhs_term = f"{rvar_lname}({','.join(rvar_indices)})"
lhs_term = f"{lvar_lname}({','.join(lvar_indices)})"
Expand Down Expand Up @@ -1008,11 +1025,11 @@ def reverse_transform(self, lvar_lname, rvar_lname, rvar_indices, lvar_indices,
"vertical_interface_dimension").
"""
# Dimension transforms (Indices handled externally)
if isinstance(lvar_indices, str):
lvar_indices = (lvar_indices,)
# if isinstance(lvar_indices, str):
# lvar_indices = (lvar_indices,)
# end if
if isinstance(rvar_indices, str):
rvar_indices = (rvar_indices,)
# if isinstance(rvar_indices, str):
# rvar_indices = (rvar_indices,)
# end if
lhs_term = f"{lvar_lname}({','.join(lvar_indices)})"
rhs_term = f"{rvar_lname}({','.join(rvar_indices)})"
Expand Down

0 comments on commit 180965c

Please sign in to comment.