Skip to content

Commit

Permalink
Refactor _parse_dim_type() to static method
Browse files Browse the repository at this point in the history
  • Loading branch information
xhgchen committed Jul 24, 2023
1 parent 781bfe7 commit ec31001
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions transport_analysis/viscosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def __init__(

# args
self.temp_avg = temp_avg
self.dim_type = dim_type
self._parse_dim_type()
self.dim_type = dim_type.lower()
self._dim, self.dim_fac = self._parse_dim_type(self.dim_type)
# self.fft = fft # consider whether fft is possible later

# local
Expand Down Expand Up @@ -112,7 +112,8 @@ def _prepare(self):
)
# self.results.timeseries not set here

def _parse_dim_type(self):
@staticmethod
def _parse_dim_type(dim_str):
r"""Sets up the desired dimensionality of the calculation."""
keys = {
"x": [0],
Expand All @@ -124,17 +125,15 @@ def _parse_dim_type(self):
"xyz": [0, 1, 2],
}

self.dim_type = self.dim_type.lower()

try:
self._dim = keys[self.dim_type]
_dim = keys[dim_str]
except KeyError:
raise ValueError(
"invalid dim_type: {} specified, please specify one of xyz, "
"xy, xz, yz, x, y, z".format(self.dim_type)
"xy, xz, yz, x, y, z".format(dim_str)
)

self.dim_fac = len(self._dim)
return _dim, len(_dim)

def _single_frame(self):
"""
Expand Down

0 comments on commit ec31001

Please sign in to comment.