Skip to content

Commit

Permalink
Code documentation cleanup (#631)
Browse files Browse the repository at this point in the history
* cleanup some codedoc

* precommit
  • Loading branch information
nllong authored Apr 22, 2024
1 parent 35e675f commit 5aeba32
Show file tree
Hide file tree
Showing 34 changed files with 115 additions and 167 deletions.
9 changes: 3 additions & 6 deletions geojson_modelica_translator/geojson/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@


class Schemas:
"""
Class to hold the various schemas
"""
"""Class to hold the various schemas"""

def __init__(self):
"""Load in the schemas"""
Expand All @@ -31,15 +29,14 @@ def __init__(self):
self.schemas[s] = json.load(f)

def retrieve(self, name):
"""name of the schema to retrieve"""
"""Name of the schema to retrieve"""
if self.schemas.get(name):
return self.schemas[name]
else:
raise NameError(f"Schema for {name} does not exist")

def validate(self, name, instance):
"""
Validate an instance against a loaded schema
"""Validate an instance against a loaded schema
:param name: str, name of the schema to validate against
:param instance: dict, instance to validate
Expand Down
9 changes: 4 additions & 5 deletions geojson_modelica_translator/geojson/urbanopt_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class GeoJsonValidationError(Exception):

# TODO: Inherit from GeoJSON Feature class, move to its own file
class UrbanOptLoad:
"""
An UrbanOptLoad is a container for holding Building-related data in a dictionary. This object
"""An UrbanOptLoad is a container for holding Building-related data in a dictionary. This object
does not do much work on the GeoJSON definition of the data at the moment, rather it creates
an isolation layer between the GeoJSON data and the GMT.
"""
Expand All @@ -36,13 +35,13 @@ def __str__(self):


class UrbanOptGeoJson:
"""
Root class for parsing an URBANopt GeoJSON file. This class simply reads and parses
"""Root class for parsing an URBANopt GeoJSON file. This class simply reads and parses
URBANopt GeoJSON files.
"""

def __init__(self, filename, building_ids=None):
"""
"""Initialize the UrbanOptGeoJson object by reading the GeoJSON file
:param filename: str, path to the GeoJSON file to parse
:param building_ids: list[str | int] | None, optional, list of GeoJSON building
IDs to parse from the file. If None or an empty list, parse all buildings.
Expand Down
4 changes: 1 addition & 3 deletions geojson_modelica_translator/geojson_modelica_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def simulate(self):


class GeoJsonModelicaTranslator:
"""
Main class for using the GeoJSON to Modelica Translator.
"""
"""Main class for using the GeoJSON to Modelica Translator."""

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

class DiagramNode:
def __init__(self, context_id, model_name, model_type):
"""
"""DiagramNode represents a node in the diagram graph
:param context_id: str, used for "grouping" nodes, e.g., this would be
either the coupling id or the model id (depending on where the icon is declared)
:param model_name: str
Expand Down Expand Up @@ -58,7 +59,8 @@ def __hash__(self):
return hash((self.context_id, self.model_name, self.model_type))

def add_connection(self, this_port, other_node, other_port):
"""
"""Add a connection to the diagram
:param this_port: str, name or dotted path of port for this node (should not start with '.' though)
:param other_node: DiagramNode, other node connecting to
:param other_port: str, name or dotted path of port for other node (should not start with '.' though)
Expand Down Expand Up @@ -440,12 +442,12 @@ class DiagramIcon(ABC):
@property
@abstractmethod
def height(self):
"""fraction of a diagram grid cell height (1 is full height, 0.5 is half, etc)"""
"""Fraction of a diagram grid cell height (1 is full height, 0.5 is half, etc)"""

@property
@abstractmethod
def width(self):
"""fraction of a diagram grid cell width (1 is full width, 0.5 is half, etc)"""
"""Fraction of a diagram grid cell width (1 is full width, 0.5 is half, etc)"""

@staticmethod
def get_icon(icon_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def render_template(template_name, template_params):


class District:
"""
Class for modeling entire district energy systems
"""
"""Class for modeling entire district energy systems"""

def __init__(self, root_dir, project_name, system_parameters, coupling_graph):
self._scaffold = Scaffold(root_dir, project_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __init__(self, system_parameters, geojson_load_id):
self._model_filename = f"CoolingIndirect_{self._geojson_load_id}"

def to_modelica(self, scaffold):
"""
Create indirect cooling models based on the data in the buildings and geojsons
"""Create indirect cooling models based on the data in the buildings and geojsons
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@


class EnergyTransferBase(ModelBase):
"""
Base class of the energy transfer connectors.
"""
"""Base class of the energy transfer connectors."""

simple_gmt_type = "ets"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def __init__(self, system_parameters):
self.id = "etsColWatStub_" + simple_uuid()

def to_modelica(self, scaffold):
"""
Create cooling water stub models
"""Create cooling water stub models
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def __init__(self, system_parameters):
self.id = "etsHotWatStub_" + simple_uuid()

def to_modelica(self, scaffold):
"""
Create indirect cooling models based on the data in the buildings and geojsons
"""Create indirect cooling models based on the data in the buildings and geojsons
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __init__(self, system_parameters, geojson_load_id):
self._model_filename = f"HeatingIndirect_{self._geojson_load_id}"

def to_modelica(self, scaffold):
"""
Create indirect heating models based on the data in the buildings and geojsons
"""Create indirect heating models based on the data in the buildings and geojsons
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@


class LoadBase(ModelBase):
"""
Base class of the load connectors.
"""
"""Base class of the load connectors."""

simple_gmt_type = "load"

def __init__(self, system_parameters, geojson_load):
"""
Base class for load connectors.
"""Base class for load connectors.
:param system_parameters: SystemParameter object, the entire system parameter file which will be used to
generate this load.
Expand Down Expand Up @@ -102,8 +99,7 @@ def __init__(self, system_parameters, geojson_load):
}

def add_building(self, urbanopt_building, mapper=None):
"""
Add building to the load to be translated. This is simply a helper method.
"""Add building to the load to be translated. This is simply a helper method.
:param urbanopt_building: an urbanopt_building (also known as a geojson_load)
:param mapper: placeholder object for mapping between urbanopt_building and load_connector building.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def __init__(self, system_parameters, geojson_load):
self.id = "SpawnLoad_" + simple_uuid()

def to_modelica(self, scaffold, keep_original_models=False):
"""
Create spawn models based on the data in the buildings and geojsons
"""Create spawn models based on the data in the buildings and geojsons
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down Expand Up @@ -226,8 +225,7 @@ def to_modelica(self, scaffold, keep_original_models=False):
self.post_process(scaffold, keep_original_models=keep_original_models)

def post_process(self, scaffold, keep_original_models=False):
"""
Cleanup the export of Spawn files into a format suitable for the district-based analysis. This includes
"""Cleanup the export of Spawn files into a format suitable for the district-based analysis. This includes
the following:
* Add a Loads project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def lookup_building_type(self, building_type):
raise Exception(f"Building type of {building_type} not defined in GeoJSON to TEASER mappings")

def to_modelica(self, scaffold, keep_original_models=False):
"""
Save the TEASER representation of a sinlge building to the filesystem. The path will
"""Save the TEASER representation of a sinlge building to the filesystem. The path will
be scaffold.loads_path.files_dir.
:param scaffold: Scaffold object, contains all the paths of the project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def __init__(self, system_parameters, geojson_load):
self.id = "TimeSerLoa_" + simple_uuid()

def to_modelica(self, scaffold):
"""
Create timeSeries models based on the data in the buildings and geojsons
"""Create timeSeries models based on the data in the buildings and geojsons
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down Expand Up @@ -158,8 +157,7 @@ def to_modelica(self, scaffold):
self.post_process(scaffold)

def post_process(self, scaffold):
"""
Cleanup the export of time series files into a format suitable for the district-based analysis. This includes
"""Cleanup the export of time series files into a format suitable for the district-based analysis. This includes
the following:
* Add a Loads project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def __init__(self, system_parameters, geojson_load):
# self.required_mo_files.append(os.path.join(self.template_dir, 'getPeakMassFlowRate.mo'))

def to_modelica(self, scaffold):
"""
Create TimeSeries models based on the data in the building and geojson
"""Create TimeSeries models based on the data in the building and geojson
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down Expand Up @@ -118,8 +117,7 @@ def to_modelica(self, scaffold):
self.post_process(scaffold)

def post_process(self, scaffold):
"""
Cleanup the export of TimeSeries files into a format suitable for the district-based analysis. This includes
"""Cleanup the export of TimeSeries files into a format suitable for the district-based analysis. This includes
the following:
* Add a Loads project
* Add a project level project
Expand Down
9 changes: 3 additions & 6 deletions geojson_modelica_translator/model_connectors/model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class ModelBase:
model_name: Union[str, None] = None

def __init__(self, system_parameters, template_dir):
"""
Base initializer
"""Base initializer
:param system_parameters: SystemParameters object
"""
Expand Down Expand Up @@ -62,8 +61,7 @@ def __init__(self, system_parameters, template_dir):
}

def ft2_to_m2(self, area_in_ft2: float) -> float:
"""
Converts square feet to square meters
"""Converts square feet to square meters
:param area_in_ft2: Area in square feet to be converted to square meters
"""
Expand Down Expand Up @@ -96,8 +94,7 @@ def copy_required_mo_files(self, dest_folder, within=None):
return result

def run_template(self, template, save_file_name, do_not_add_to_list=False, **kwargs):
"""
Helper method to create the file from Jinja2's templating framework.
"""Helper method to create the file from Jinja2's templating framework.
:param template: object, Jinja template from the `template_env.get_template()` command.
:param save_file_name: string, fully qualified path to save the rendered template to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def __init__(self, system_parameters):
self.id = "disNet_" + simple_uuid()

def to_modelica(self, scaffold):
"""
"""Convert the Network2Pipe to Modelica code
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# no model to generate, its fully implemented in the Modelica Buildings library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ def __init__(self, system_parameters):
self.id = "MyNetworkAmbientWaterStub"

def to_modelica(self, scaffold):
"""
"""Convert the NetworkAmbientWaterStub to Modelica code
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model to generate, it's fully implemented in the coupling

def get_modelica_type(self, scaffold):
"""
"""Get the Modelica type of the NetworkAmbientWaterStub
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model, so there's no type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@


class NetworkBase(ModelBase):
"""
Base class of the network connectors.
"""
"""Base class of the network connectors."""

simple_gmt_type = "network"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, system_parameters):
self.id = "MyNetworkChilledWaterStub"

def to_modelica(self, scaffold):
"""
"""Convert the NetworkChilledWaterStub to Modelica code
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model to generate, its fully implemented in the coupling currently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def __init__(self, system_parameters):
self.id = "MyNetworkDistributionPump"

def to_modelica(self, scaffold):
"""
"""Convert the NetworkDistributionPump to Modelica code
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model to generate, its fully implemented in the coupling currently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def __init__(self, system_parameters):
self.id = "MyNetworkHeatedWaterStub"

def to_modelica(self, scaffold):
"""
"""Convert the NetworkHeatedWaterStub to Modelica code
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model to generate, its fully implemented in the coupling currently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self, system_parameters):
self.required_mo_files.append(os.path.join(self.template_dir, "GroundTemperatureResponse.mo"))

def to_modelica(self, scaffold):
"""
Create timeSeries models based on the data in the buildings and geojsons
"""Convert the Borefield to Modelica code
Create timeSeries models based on the data in the buildings and GeoJSONs
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
3 changes: 1 addition & 2 deletions geojson_modelica_translator/model_connectors/plants/chp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def __init__(self, system_parameters):
self.required_mo_files.append(Path(self.template_dir) / "ValveParameters.mo")

def to_modelica(self, scaffold):
"""
Create timeSeries models based on the data in the buildings and geojsons
"""Create time series models based on the data in the buildings and GeoJSONs
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def __init__(self, system_parameters):
self.required_mo_files.append(os.path.join(self.template_dir, "ChillerStage.mo"))

def to_modelica(self, scaffold):
"""
Create timeSeries models based on the data in the buildings and geojsons
"""Create time series models based on the data in the buildings and GeoJSONs
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
Expand Down
Loading

0 comments on commit 5aeba32

Please sign in to comment.