model.network ============= .. py:module:: model.network Classes ------- .. autoapisummary:: model.network.Line model.network.Route model.network.VoltageLevel model.network.ChargeType model.network.Station model.network.AssocRouteStation Functions --------- .. autoapisummary:: model.network.check_route_before_insert_or_update Module Contents --------------- .. py:class:: Line Bases: :py:obj:`eflips.model.Base` The Line represents a bus line, which is a collection of :class:`Route` that belong together. This may not include all routes that a bus on this line takes over its service day, since depot and deadhead routes are not included (they can be shared between multiple lines). .. py:attribute:: __tablename__ :value: 'Line' .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the battery type. Auto-incremented. .. py:attribute:: scenario_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the scenario. Foreign key to :attr:`Scenario.id`. .. py:attribute:: scenario :type: sqlalchemy.orm.Mapped[eflips.model.Scenario] The scenario. .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] The name of the line. Usually a number or letter, e.g. "1" or "A" followed by the terminal stations. Example: "1 - Hauptbahnhof <-> Hauptfriedhof" .. py:attribute:: name_short :type: sqlalchemy.orm.Mapped[str] The short name of the line. Usually a number or letter, e.g. "1" or "A". .. py:attribute:: routes :type: sqlalchemy.orm.Mapped[list[Route]] .. py:method:: __repr__() .. py:class:: Route Bases: :py:obj:`eflips.model.Base` A route is a fixed geometry that a bus takes. It is a part of a :class:`Line`. A trip takes place on a route. .. py:attribute:: __tablename__ :value: 'Route' .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the battery type. Auto-incremented. .. py:attribute:: scenario_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the scenario. Foreign key to :attr:`Scenario.id`. .. py:attribute:: scenario :type: sqlalchemy.orm.Mapped[eflips.model.Scenario] The scenario. .. py:attribute:: departure_station_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the departure station. Foreign key to :attr:`Station.id`. .. py:attribute:: departure_station :type: sqlalchemy.orm.Mapped[Station] The departure station. .. py:attribute:: arrival_station_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the arrival station. Foreign key to :attr:`Station.id`. .. py:attribute:: arrival_station :type: sqlalchemy.orm.Mapped[Station] The arrival station. .. py:attribute:: line_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the line. Foreign key to :attr:`Line.id`. May be ``None``. .. py:attribute:: line :type: sqlalchemy.orm.Mapped[Line] The line. .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] The name of the route. Usually a number followed by the terminal station. Example: "1 Hauptbahnhof -> Hauptfriedhof .. py:attribute:: name_short :type: sqlalchemy.orm.Mapped[str] The short name of the route (if available). .. py:attribute:: headsign :type: sqlalchemy.orm.Mapped[str] The headsign of the route (if available). This is whatever is displayed on the bus. .. py:attribute:: distance :type: sqlalchemy.orm.Mapped[float] The length of the route in meters. .. py:attribute:: geom :type: sqlalchemy.orm.Mapped[geoalchemy2.Geometry] The shape of the route as a 3D polyline (X = lon, Y = lat, Z = elevation in meters). If set, the 2D ground length of this shape must be within 50 meters of :attr:`Route.distance` — Z is ignored by the length check, by PostGIS' ``ST_Length(..., true)`` and SpatiaLite's ``GeodesicLength``. Use WGS84 coordinates (EPSG:4326). Z = 0 is acceptable when elevation is unknown; populate it via the ``eflips-ingest`` elevation backfill. .. py:attribute:: trips :type: sqlalchemy.orm.Mapped[List[eflips.model.Trip]] The trips. .. py:attribute:: assoc_route_stations :type: sqlalchemy.orm.Mapped[List[AssocRouteStation]] The associated route stations. This contains metadata about the stops on the route, such as the partial distance. .. py:attribute:: stations :type: sqlalchemy.orm.Mapped[List[Station]] This is a list of all stations on the route. .. py:attribute:: __table_args__ .. py:method:: __repr__() .. py:method:: calculate_length(session, linestring) :staticmethod: Portable function to calculate the length of a linestring in meters. It adapts to whether the database uses PostGIS or SpatiaLite. :param session: An open SQLAlchemy session. :param linestring: A string representation of a linestring in WKT format. :return: The length of the linestring in meters. .. py:function:: check_route_before_insert_or_update(_, __, target) Check the route before flushing it to the database. - Ensure that the distance of the first stop time is 0 - Ensure that the distance of the last stop time is the distance of the route - Ensure that the first and last associated route stations correspond to the departure and arrival stations - If we have stop times, we must ensure that the temporal order of stop times matches the spatial order of the stations. :param target: :return: Nothing. Raises an exception if the route is invalid. .. py:class:: VoltageLevel(*args, **kwds) Bases: :py:obj:`enum.Enum` The voltage level of a charging infrastructure. Used in analysis and simulation to determine grid load. .. py:attribute:: HV High Voltage, e.g. 110kV transmission grid .. py:attribute:: HV_MV Both high and medium voltage .. py:attribute:: MV Medium Voltage, e.g. 10kV distribution grid .. py:attribute:: MV_LV Both medium and low voltage .. py:attribute:: LV Low voltage, e.g. 400V three- phase .. py:class:: ChargeType(*args, **kwds) Bases: :py:obj:`enum.Enum` The type of charging infrastructure. Only vehicle types with opportunity charging can charge at opportunity charging stations. .. py:attribute:: depb Only charge when vehicle is not on a rotation .. py:attribute:: oppb Aka „terminus charging“. While on a rotation, charge in the breaks between trips .. py:attribute:: DEPOT Legacy value for depb .. py:attribute:: OPPORTUNITY Legacy value for oppb .. py:class:: Station Bases: :py:obj:`eflips.model.Base` A Station is a point on the map that a bus can stop at. It is visited on a :class:`Trip`. The station may not mark the exact location of the stop, but rather a point nearby, in case the station is part of a larger complex. .. py:attribute:: __tablename__ :value: 'Station' .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the battery type. Auto-incremented. .. py:attribute:: scenario_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the scenario. Foreign key to :attr:`Scenario.id`. .. py:attribute:: scenario :type: sqlalchemy.orm.Mapped[eflips.model.Scenario] The scenario. .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] The name of the station. Example: "Hauptbahnhof" .. py:attribute:: name_short :type: sqlalchemy.orm.Mapped[str] The short name of the station (if available). .. py:attribute:: geom :type: sqlalchemy.orm.Mapped[geoalchemy2.Geometry] The (optional) 3D location of the station (X = lon, Y = lat, Z = elevation in meters). Use WGS84 coordinates (EPSG:4326). Z = 0 is acceptable when elevation is unknown. .. py:attribute:: is_electrified Whether the station has a charging infrastructure. If yes, then - `amount_charging_places` must be set - `power_per_charger` must be set - `power_total` must be set - `charge_type` must be set - `voltage_level` must be set .. py:attribute:: is_electrifiable Whether the station can be electrified. This is used to determine whether a station can be electrified in the simulation. If the station is electrified, this must be set to true. .. py:attribute:: amount_charging_places The amount of charging poles at the station. If `is_electrified` is true, this must be set. .. py:attribute:: power_per_charger The power per charger in kW. If `is_electrified` is true, this must be set. .. py:attribute:: power_total The total power of the charging infrastructure in kW. If `is_electrified` is true, this must be set. .. py:attribute:: charge_type The type of charging infrastructure. If `is_electrified` is true, this must be set. When running simBA and eflips, this is set to `oppb` for all stations. `depb` only makes sense in standalone simBA runs. .. py:attribute:: voltage_level The voltage level of the charging infrastructure. If `is_electrified` is true, this must be set. .. py:attribute:: charging_point_type_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the charging point type. Foreign key to :attr:`ChargingPointType.id` .. py:attribute:: charging_point_type :type: sqlalchemy.orm.Mapped[eflips.model.ChargingPointType] The charging point type. This is used to represent the different types of charging points installed at stations or areas. It is mainly relevant for TCO calculations. .. py:attribute:: tco_parameters :type: sqlalchemy.orm.Mapped[Dict[str, Any]] The TCO parameters of the charging point stored as a JSON object. This field contains Total Cost of Ownership parameters used for financial analysis and planning of the charging station. The JSON object includes: - useful_life (int): Expected operational lifespan of the charging station in years (e.g., 20) - procurement_cost (float): Initial acquisition cost per station or depot. - cost_escalation (float): Annual cost escalation rate as a decimal between 0 and 1 (e.g., 0.02 represents 2% annual escalation) .. py:attribute:: depot :type: sqlalchemy.orm.Mapped[eflips.model.Depot] The (optional) depot that is associated with this station. Only set if the station has a depot. .. py:attribute:: routes_departing :type: sqlalchemy.orm.Mapped[List[Route]] .. py:attribute:: routes_arriving :type: sqlalchemy.orm.Mapped[List[Route]] .. py:attribute:: stop_times :type: sqlalchemy.orm.Mapped[List[eflips.model.StopTime]] The stop times. .. py:attribute:: trips :type: sqlalchemy.orm.Mapped[List[eflips.model.Trip]] The trips stopping at this station. .. py:attribute:: assoc_route_stations :type: sqlalchemy.orm.Mapped[List[AssocRouteStation]] The associated route stations. This contains metadata about the stops on the route, such as the partial distance. .. py:attribute:: routes :type: sqlalchemy.orm.Mapped[List[Route]] This is a list of all routes that stop at this station. .. py:attribute:: events :type: sqlalchemy.orm.Mapped[List[eflips.model.Event]] The events that take place at this station. Only expected to be filled for charging at electrified stations. .. py:attribute:: __table_args__ .. py:method:: __repr__() .. py:class:: AssocRouteStation Bases: :py:obj:`eflips.model.Base` An association table between :class:`Route` and :class:`Station`. It is used to represent the stops on a route. .. py:attribute:: __tablename__ :value: 'AssocRouteStation' .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the association. Auto-incremented. .. py:attribute:: scenario_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the scenario. Foreign key to :attr:`Scenario.id`. .. py:attribute:: scenario :type: sqlalchemy.orm.Mapped[eflips.model.Scenario] The scenario. .. py:attribute:: route_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the route. Foreign key to :attr:`Route.id`. .. py:attribute:: route :type: sqlalchemy.orm.Mapped[Route] The route. .. py:attribute:: station_id :type: sqlalchemy.orm.Mapped[int] The unique identifier of the station. Foreign key to :attr:`Station.id`. .. py:attribute:: station :type: sqlalchemy.orm.Mapped[Station] The station. .. py:attribute:: location :type: sqlalchemy.orm.Mapped[geoalchemy2.Geometry] An optional precise 3D location of this route's stop at the station (X = lon, Y = lat, Z = elevation in meters). Use WGS84 coordinates (EPSG:4326). Z = 0 is acceptable when elevation is unknown. .. py:attribute:: elapsed_distance :type: sqlalchemy.orm.Mapped[float] The distance in m that the bus has traveled when it reached this stop. .. py:method:: __repr__()