Skip to content

Commit

Permalink
Update parameters.py
Browse files Browse the repository at this point in the history
avoid the massive switch in _fetch_address by keeping each FilePath parameter in its own def
  • Loading branch information
Dobson committed Mar 1, 2024
1 parent 65f541c commit 3d3e0fa
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions swmmanywhere/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,42 @@ def _generate_property(self,
getattr(self, location),
property_name)

def _generate_project(self):
return self._generate_path(self.project_name)

def _generate_national(self):
return self._generate_property('national', 'project')

def _generate_national_building(self):
return self._generate_property('building.parquet',
'national')
def _generate_bbox(self):
return self._generate_property(f'bbox_{self.bbox_number}',
'project')
def _generate_model(self):
return self._generate_property(f'model_{self.model_number}',
'bbox')
def _generate_subcatchments(self):
return self._generate_property(f'subcatchments.{self.extension}',
'model')
def _generate_download(self):
return self._generate_property('download',
'bbox')
def _generate_river(self):
return self._generate_property('river.json',
'download')
def _generate_street(self):
return self._generate_property('street.json',
'download')
def _generate_elevation(self):
return self._generate_property('elevation.tif', 'download')
def _generate_building(self):
return self._generate_property(f'building.{self.extension}',
'download')
def _generate_precipitation(self):
return self._generate_property(f'precipitation.{self.extension}',
'download')

def _fetch_address(self, name):
"""Fetch the address.
Expand All @@ -248,39 +284,8 @@ def _fetch_address(self, name):
Returns:
Path: Path to the folder/file.
"""
if name == 'project':
return self._generate_path(self.project_name)
elif name == 'national':
return self._generate_property('national', 'project')
elif name == 'national_building':
return self._generate_property('building.parquet',
'national')
elif name == 'bbox':
return self._generate_property(f'bbox_{self.bbox_number}',
'project')
elif name == 'model':
return self._generate_property(f'model_{self.model_number}',
'bbox')
elif name == 'subcatchments':
return self._generate_property(f'subcatchments.{self.extension}',
'model')
elif name == 'download':
return self._generate_property('download',
'bbox')
elif name == 'river':
return self._generate_property('river.json',
'download')
elif name == 'street':
return self._generate_property('street.json',
'download')
elif name == 'elevation':
return self._generate_property('elevation.tif', 'download')
elif name == 'building':
return self._generate_property(f'building.{self.extension}',
'download')
elif name == 'precipitation':
return self._generate_property(f'precipitation.{self.extension}',
'download')
else:
raise AttributeError(f"Attribute {name} not found")

try:
return getattr(self, f"_generate_{name}")()
except AttributeError:
raise AttributeError(
f"Generate path for '{name}' failed. Attribute not found.")

0 comments on commit 3d3e0fa

Please sign in to comment.