def edges_df(self):
        edges_df = geopandas.GeoDataFrame.from_file(
            self.locator.get_network_layout_edges_shapefile(self.network_type, self.network_name)).to_crs(
            get_geographic_coordinate_system())
        edges_df["_LineWidth"] = 0.1 * edges_df["Pipe_DN"]
        edges_df["length_m"] = edges_df["length_m"].round(1)

        # color the edges based on aggregated pipe heat loss
        P_loss_kPaperm_peak = (self.linear_pressure_loss_Paperm.max() / 1000).round(1) #to kPa/m
        Mass_flow_kgs_peak = self.mass_flow_kgs_pipes.max().round(1) #in kgs
        edges_df["Peak pressure loss [kPa/m]"] = P_loss_kPaperm_peak.values
        edges_df["Peak mass flow rate [kg/s]"] = Mass_flow_kgs_peak.values

        if self.velocity_mps_pipes is not None: #backward compatibility with detailed thermal network (which does not include this output)
            velocity_ms_peak = self.velocity_mps_pipes.max().round(1)  # in kgs
            edges_df["Peak velocity [m/s]"] = velocity_ms_peak.values

        # color the edges based on aggregated pipe heat loss
        if self.thermal_loss_edges_Wperm is not None: #backward compatibility with detailed thermal network (which does not include this output)
            yearly_thermal_loss = (self.thermal_loss_edges_Wperm.max()).round(2)
            edges_df["Peak Thermal losses [W/m]"] = yearly_thermal_loss.values

        # figure out colors
        p_loss_min = edges_df.Pipe_DN.min()
        p = edges_df.Pipe_DN.max()
        scale_p_loss = lambda x: remap(x, p_loss_min, p, 1.0, 1.0)
        min_rgb_mpl = [remap(c, 0.0, 255.0, 0.0, 1.0) for c in get_color_array("white")]
        max_rgb_mpl = [remap(c, 0.0, 255.0, 0.0, 1.0) for c in get_color_array("red")]

        edges_df["_FillColor"] = edges_df.Pipe_DN.apply(
            lambda p_loss: json.dumps(
                [remap(x, 0.0, 1.0, 0.0, 255.0)
                 for x in color_fader_rgb(min_rgb_mpl, max_rgb_mpl, mix=scale_p_loss(p_loss))])).values
        return edges_df
Esempio n. 2
0
    def __init__(self, project, parameters, cache):
        super(ThermalNetworksMapPlotBase,
              self).__init__(project, parameters, cache)
        self.network_args = [self.network_type, self.network_name]

        self.colors = {
            "zone":
            get_color_array("grey_light"),
            "district":
            get_color_array("white"),
            "edges":
            get_color_array("blue")
            if self.network_type == "DC" else get_color_array("red"),
            "building":
            get_color_array("orange"),
            "plant":
            get_color_array("purple")
        }

        self.color_by_type = {
            "NONE": self.colors["edges"],
            "PLANT": self.colors["plant"],
            "CONSUMER": self.colors["building"]
        }

        self.input_files = [
            (self.locator.get_zone_geometry, []),
            (self.locator.get_thermal_demand_csv_file, self.network_args),
            (self.locator.get_thermal_network_edge_list_file,
             self.network_args),
            (self.locator.get_network_thermal_loss_edges_file,
             self.network_args),
            (self.locator.get_thermal_network_node_types_csv_file,
             self.network_args)
        ]
Esempio n. 3
0
import cea.scripts
import cea.schemas
from cea.datamanagement.databases_verification import InputFileValidator
from cea.interfaces.dashboard.api.databases import read_all_databases, DATABASES_SCHEMA_KEYS
from cea.plots.supply_system.a_supply_system_map import get_building_connectivity, newer_network_layout_exists
from cea.plots.variable_naming import get_color_array
from cea.technologies.network_layout.main import layout_network, NetworkLayout
from cea.utilities.schedule_reader import schedule_to_file, get_all_schedule_names, schedule_to_dataframe, \
    read_cea_schedule, save_cea_schedule
from cea.utilities.standardize_coordinates import get_geographic_coordinate_system
from fiona.errors import DriverError

api = Namespace('Inputs', description='Input data for CEA')

COLORS = {
    'surroundings': get_color_array('white'),
    'dh': get_color_array('red'),
    'dc': get_color_array('blue'),
    'disconnected': get_color_array('grey')
}

# List of input databases (db_name, locator/schema_key)
INPUT_DATABASES = [('zone', 'get_zone_geometry'),
                   ('typology', 'get_building_typology'),
                   ('architecture', 'get_building_architecture'),
                   ('internal-loads', 'get_building_internal'),
                   ('indoor-comfort', 'get_building_comfort'),
                   ('air-conditioning-systems',
                    'get_building_air_conditioning'),
                   ('supply-systems', 'get_building_supply'),
                   ('surroundings', 'get_surroundings_geometry')]
from cea.technologies.network_layout.main import layout_network, NetworkLayout
from cea.utilities.standardize_coordinates import get_geographic_coordinate_system
from cea.utilities.dbf import dbf_to_dataframe

__author__ = "Jimeno Fonseca"
__copyright__ = "Copyright 2019, Architecture and Building Systems - ETH Zurich"
__credits__ = ["Jimeno Fonseca"]
__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "Daren Thomas"
__email__ = "*****@*****.**"
__status__ = "Production"

# Colors for the networks in the map
COLORS = {
    'district': get_color_array('white'),
    'dh': get_color_array('red'),
    'dc': get_color_array('blue'),
    'disconnected': get_color_array('grey')
}


class SupplySystemMapPlot(cea.plots.supply_system.SupplySystemPlotBase):
    """Show a pareto curve for a single generation"""
    name = "Supply system map"

    expected_parameters = {
        'system': 'plots-supply-system:system',
        'scenario-name': 'general:scenario-name',
    }
Esempio n. 5
0
    def nodes_df(self):
        nodes_df = geopandas.GeoDataFrame.from_file(
            self.locator.get_network_layout_nodes_shapefile(
                self.network_type,
                self.network_name)).to_crs(get_geographic_coordinate_system())

        P_loss_kPa_peak = (self.pressure_at_nodes_Pa.max() / 1000).round(
            1)  #to kPa
        nodes_df["Peak pressure [kPa]"] = P_loss_kPa_peak.values

        #temperature at all nodes
        temperature_supply = self.temperature_supply_nodes_C.round(1)
        temperature_return = self.temperature_return_nodes_C.round(1)
        index_max = self.buildings_hourly.idxmax(axis=0)
        delta_T = (temperature_supply - temperature_return).round(1)

        #temperature at the plant
        index_max_T_plant = self.buildings_hourly.sum(axis=1).idxmax(axis=0)
        temperature_supply_plant = self.temperature_supply_return_plant_C[
            'temperature_supply_K'] - 273
        temperature_return_plant = self.temperature_supply_return_plant_C[
            'temperature_return_K'] - 273
        T_supply_peak = round(temperature_supply_plant[index_max_T_plant], 1)
        delta_T_peak = round((temperature_supply_plant -
                              temperature_return_plant)[index_max_T_plant], 1)

        #energy generation at the plant
        annual_loads = self.hourly_loads.values
        Q_loss_kWh = self.total_thermal_losses_kWh.values
        Peak_load_MWh = round((annual_loads + Q_loss_kWh).max() / 1000, 1)

        if self.mass_flow_kgs_nodes is not None:  #backward compatibility with detailed thermal network (which does not include this output)
            Mass_flow_kgs_peak = self.mass_flow_kgs_nodes.max().round(1)
            nodes_df["Peak mass flow rate [kg/s]"] = Mass_flow_kgs_peak.values

        peak_demands = self.buildings_hourly.apply(pd.Series.max)
        pumping_peak = self.plant_pumping_requirement_kWh.max().round(1)

        def get_peak_building_demand(row):
            if row["Type"] == "CONSUMER":
                return peak_demands[row["Building"]]
            else:
                return None

        def get_pumping_node(row):
            if row["Type"] == "PLANT":
                return pumping_peak[0]
            else:
                return None

        def get_T_plant_node(row):
            if row["Type"] == "PLANT":
                return T_supply_peak
            else:
                return None

        def get_Peak_plant_node(row):
            if row["Type"] == "PLANT":
                return Peak_load_MWh
            else:
                return None

        def get_DT_plant_node(row):
            if row["Type"] == "PLANT":
                return delta_T_peak
            else:
                return None

        def get_peak_supply_temp(row):
            if row["Building"] in index_max.index.values:
                return temperature_supply[row['Name']][index_max[
                    row["Building"]]]
            else:
                return None

        def get_peak_delta_temp(row):
            if row["Building"] in index_max.index.values:
                return delta_T[row['Name']][index_max[row["Building"]]]
            else:
                return None

        nodes_df["Peak Supply Temperature [C]"] = nodes_df.apply(
            get_peak_supply_temp, axis=1)
        nodes_df["Peak delta Temperature [C]"] = nodes_df.apply(
            get_peak_delta_temp, axis=1)
        nodes_df["Peak Thermal Demand [kW]"] = nodes_df.apply(
            get_peak_building_demand, axis=1)
        nodes_df["Pumping Power [kW]"] = nodes_df.apply(get_pumping_node,
                                                        axis=1)
        nodes_df["Supply Temperature [C]"] = nodes_df.apply(get_T_plant_node,
                                                            axis=1)
        nodes_df["Delta Temperature [C]"] = nodes_df.apply(get_DT_plant_node,
                                                           axis=1)
        nodes_df["Peak Thermal Generation [MW]"] = nodes_df.apply(
            get_Peak_plant_node, axis=1)

        nodes_df["_Radius"] = self.get_radius(nodes_df)

        # Figure out the colors (based on the average supply temperatures)
        P_loss_min = nodes_df["Peak Thermal Demand [kW]"].min()
        P_loss_max = nodes_df["Peak Thermal Demand [kW]"].max()
        scale_p_loss = lambda x: remap(x, P_loss_min, P_loss_max, 0.0, 1.0)

        # matplotlib works on RGB in ranges [0.0, 1.0] - scale the input colors to that, transform and then scale back
        # to web versions ([0, 255])
        min_rgb_mpl = [
            remap(c, 0.0, 255.0, 0.0, 1.0) for c in get_color_array("white")
        ]
        max_rgb_mpl = [
            remap(c, 0.0, 255.0, 0.0, 1.0) for c in get_color_array("red")
        ]

        nodes_df["Peak Thermal Demand [kW]"] = nodes_df[
            "Peak Thermal Demand [kW]"].fillna(0.0)
        nodes_df["_FillColor"] = json.dumps(get_color_array("black"))
        nodes_df["_FillColor"] = nodes_df["Peak Thermal Demand [kW]"].apply(
            lambda p_loss: json.dumps([
                remap(x, 0.0, 1.0, 0.0, 255.0) for x in color_fader_rgb(
                    min_rgb_mpl, max_rgb_mpl, mix=scale_p_loss(p_loss))
            ])).values

        return nodes_df