Skip to content

Commit

Permalink
Simplify _fname class
Browse files Browse the repository at this point in the history
  • Loading branch information
AlainKadar committed Jun 17, 2024
1 parent 00f7592 commit ec0f9e8
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions StructuralGT/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def effectice_resistance(self):
Flag representing whether the compute method has been called.
"""

def __init__(self, weight_type=None):
def __init__(self, node_weight=None, edge_weight=None):
self._called_compute = False
self.weight_type = weight_type
self.node_weight = node_weight
self.edge_weight = edge_weight

def __getattribute__(self, attr):
"""Compute methods set a flag to indicate that quantities have been
Expand Down Expand Up @@ -310,25 +311,33 @@ class _fname():
The spatial dimensions of the associated Network object.
"""

def __init__(self, name, domain=_domain(None)):
def __init__(self, name, domain=_domain(None), _2d=False):
if not os.path.exists(name):
raise ValueError('File does not exist.')
self.name = name
self.domain = domain
self._2d=_2d

if self._2d:
self.num='0000'
else:
base_name = os.path.splitext(os.path.split(self.name)[1])[0]
if len(base_name)<4:
raise ValueError('For 3D networks, filenames must end in 4 digits, indicating the depth of the slice.')
self.num = base_name[-4::]

if not self.num.isnumeric():
raise ValueError('For 3D networks, filenames must end in 4 digits, indicating the depth of the slice.')

@property
def isinrange(self):
"""bool: Returns true iff the filename is numeric and within the
spatial dimensions of the associated :class:`_domain` object.
"""
if not self.isimg: return False
base_name = os.path.splitext(os.path.split(self.name)[1])[0]
if len(base_name)<4:
raise ValueError('For 3D networks, filenames must end in 4 digits, indicating the depth of the slice.')
self.num = base_name[-4::]

if not self.num.isnumeric():
raise ValueError('For 3D networks, filenames must end in 4 digits, indicating the depth of the slice.')
if self._2d:
return True
else:
return (int(self.num) > self.domain.domain[0]
and int(self.num) < self.domain.domain[1])
Expand Down

0 comments on commit ec0f9e8

Please sign in to comment.