示例#1
0
    def test_overlay_a_lot_of_points_1(self):
        """Customize a chart with group of points."""
        # Load config
        config = load_config("minimal")

        # Customization
        config["limits"]["pressure_kpa"] = 90.5

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90500.0, chart.pressure)

        # Plotting
        chart.plot()

        # Create a lot of points
        num_samples = 50000
        theta = np.linspace(0, 2 * np.pi, num_samples)
        r = np.random.rand(num_samples)
        x, y = 7 * r * np.cos(theta) + 25, 20 * r * np.sin(theta) + 50

        points = {"test_series_1": (x, y)}
        scatter_style = {
            "s": 5,
            "alpha": 0.1,
            "color": "darkorange",
            "marker": "+",
        }

        chart.plot_points_dbt_rh(points, scatter_style=scatter_style)

        # Save to disk
        path_png = TEST_BASEDIR / "chart_overlay_test_lot_of_points_1.png"
        chart.save(path_png)
    def test_custom_psychrochart_2(self):
        """Customize a chart with some additions from a default style."""
        # Load config
        config = load_config("minimal")

        # Customization
        config['limits']['pressure_kpa'] = 90.5
        config['figure']['x_label'] = None
        config['figure']['y_label'] = None
        config['saturation']['linewidth'] = 3
        config['chart_params']['with_constant_dry_temp'] = False
        config['chart_params']['with_constant_humidity'] = False
        config['chart_params']['with_constant_wet_temp'] = False
        config['chart_params']['with_constant_h'] = False

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90.5, chart.p_atm_kpa)

        # Zones:
        zones_conf = {
            "zones":
                [
                    {
                        "zone_type": "xy-points",
                        "style": {"linewidth": 2,
                                  "linestyle": "--",
                                  # "color": [0.831, 0.839, 0.0],
                                  "edgecolor": [0.498, 0.624, 0.8],
                                  "facecolor": [0.498, 0.624, 1.0, 0.3]
                                  },
                        "points_x": [23, 28, 28, 24, 23],
                        "points_y": [1, 3, 4, 4, 2],
                        "label": "Custom"
                    },
                    {
                        "zone_type": "not_recognized_type",
                        "label": "Bad zone"
                    }
                ]
        }
        chart.append_zones(zones_conf)

        # Plotting
        chart.plot()

        points = {'exterior': (31.06, 32.9),
                  'exterior_estimated': (36.7, 25.0),
                  'interior': (29.42, 52.34)}

        points_plot = chart.plot_points_dbt_rh(points)
        print('Points in chart: %s' % points_plot)

        # Legend
        chart.plot_legend(markerscale=1., fontsize=11, labelspacing=1.3)

        # Save to disk
        path_svg = os.path.join(
            basedir, 'chart_overlay_test.svg')
        chart.save(path_svg)
示例#3
0
 def test_default_psychrochart(self):
     """Test the plot custom styling with JSON files/dicts."""
     path_svg_default = os.path.join(basedir,
                                     'test_default_psychrochart.svg')
     chart = PsychroChart()
     chart.save(path_svg_default)
     chart.close_fig()
示例#4
0
    def test_0_pickle_psychrochart(self):
        """Test the plot custom styling with JSON files/dicts."""
        path_svg = os.path.join(basedir, 'test_to_pickle.svg')
        chart = PsychroChart()
        chart.save(path_svg)
        chart.close_fig()

        with open(os.path.join(basedir, 'chart.pickle'), 'wb') as f:
            pickle.dump(chart, f)
    def test_0_pickle_psychrochart(self):
        """Test the plot custom styling with JSON files/dicts."""
        path_svg = TEST_BASEDIR / "test_to_pickle.svg"
        chart = PsychroChart()
        chart.save(path_svg)
        chart.close_fig()

        with open(TEST_BASEDIR / "chart.pickle", "wb") as f:
            pickle.dump(chart, f)
示例#6
0
    def test_overlay_a_lot_of_points_2(self):
        """Customize a chart with two cloud of points."""
        # Load config
        config = load_config("minimal")

        # Customization
        config['limits']['pressure_kpa'] = 90.5

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90.5, chart.p_atm_kpa)

        # Plotting
        chart.plot()

        # Create a lot of points
        num_samples = 100000
        theta = np.linspace(0, 2 * np.pi, num_samples)
        r = np.random.rand(num_samples)
        x, y = 7 * r * np.cos(theta) + 25, 20 * r * np.sin(theta) + 50

        scatter_style_1 = {
            's': 20,
            'alpha': .02,
            'color': 'darkblue',
            'marker': 'o'
        }
        scatter_style_2 = {
            's': 10,
            'alpha': .04,
            'color': 'darkorange',
            'marker': '+'
        }
        x2, y2 = x + 5, y - 20

        points = {
            'test_original': {
                'label': 'Original',
                'style': scatter_style_1,
                'xy': (x, y)
            },
            'test_displaced': {
                'label': 'Displaced',
                'xy': (x2, y2)
            }
        }
        chart.plot_points_dbt_rh(points, scatter_style=scatter_style_2)
        chart.plot_legend(markerscale=1., fontsize=11, labelspacing=1.3)

        # Save to disk
        path_png = os.path.join(basedir,
                                'chart_overlay_test_lot_of_points.png')
        chart.save(path_png)
示例#7
0
def make_psychrochart(svg_image, altitude, pressure_kpa, points, connectors,
                      arrows):
    """Create the PsychroChart SVG file and save it to disk."""
    from psychrochart.agg import PsychroChart
    from psychrochart.util import load_config

    # Load chart style:
    chart_style = load_config(CHART_STYLE_JSON)
    if altitude is not None:
        chart_style['limits']['altitude_m'] = altitude
    elif pressure_kpa is None:
        chart_style['limits']['pressure_kpa'] = pressure_kpa

    # Make chart
    chart = PsychroChart(chart_style, OVERLAY_ZONES_JSON, logger=_LOGGER)

    # Append lines
    t_min, t_opt, t_max = 16, 23, 30
    chart.plot_vertical_dry_bulb_temp_line(t_min, {
        "color": [0.0, 0.125, 0.376],
        "lw": 2,
        "ls": ':'
    },
                                           ' TOO COLD, {:g}°C'.format(t_min),
                                           ha='left',
                                           loc=0.,
                                           fontsize=14)
    chart.plot_vertical_dry_bulb_temp_line(t_opt, {
        "color": [0.475, 0.612, 0.075],
        "lw": 2,
        "ls": ':'
    })
    chart.plot_vertical_dry_bulb_temp_line(t_max, {
        "color": [1.0, 0.0, 0.247],
        "lw": 2,
        "ls": ':'
    },
                                           'TOO HOT, {:g}°C '.format(t_max),
                                           ha='right',
                                           loc=1,
                                           reverse=True,
                                           fontsize=14)

    chart.plot_points_dbt_rh(points, connectors)
    if arrows:
        chart.plot_arrows_dbt_rh(arrows)
    chart.plot_legend(frameon=False,
                      fontsize=8,
                      labelspacing=.8,
                      markerscale=.7)

    chart.save(svg_image, format='svg')
    return True
示例#8
0
    def test_custom_psychrochart_3(self):
        """Customize a chart with some additions from a default style."""
        # Load config
        config = load_config("interior")

        # Chart creation
        chart = PsychroChart(config)

        # Zones:

        # Plotting
        chart.plot()

        arrows = {'exterior': [(31.06, 32.9), (29.06, 31.9)],
                  'exterior_estimated': [(36.7, 25.0), (34.7, 30.0)],
                  'interior': [(29.42, 52.34), (31.42, 57.34)]}

        arrows_plot = chart.plot_arrows_dbt_rh(arrows)
        print('arrows in chart: %s' % arrows_plot)

        # Legend
        chart.plot_legend(markerscale=1., fontsize=11, labelspacing=1.3)

        # Save to disk
        path_svg = os.path.join(
            basedir, 'test_chart_overlay_arrows_1.svg')
        chart.save(path_svg)

        chart.remove_annotations()
        points_arrows = {
            'exterior': {'label': 'Exterior',
                         'style': {
                             'color': [0.855, 0.004, 0.278, 0.8],
                             'marker': 'X', 'markersize': 15},
                         'xy': [(30.06, 34.9), (31.06, 35.9)]},
            'exterior_estimated': {
                'label': 'Estimated (Weather service)',
                'style': {'color': [0.573, 0.106, 0.318, 0.5],
                          'marker': 'x', 'markersize': 10},
                'xy': [(32.7, 27.0), (31.7, 28.0)]},
            'interior': {'label': 'Interior',
                         'style': {
                             'color': [0.592, 0.745, 0.051, 0.9],
                             'marker': 'o', 'markersize': 30},
                         'xy': [(29.92, 50.34), (28.92, 50.34)]}}

        arrows_plot = chart.plot_arrows_dbt_rh(points_arrows)
        print('arrows in chart 2: %s' % arrows_plot)

        # Save to disk
        path_svg = os.path.join(
            basedir, 'test_chart_overlay_arrows_2.svg')
        chart.save(path_svg)
示例#9
0
    def test_overlay_a_lot_of_points_2(self):
        """Customize a chart with two cloud of points."""
        # Load config
        config = load_config("minimal")

        # Customization
        config["limits"]["pressure_kpa"] = 90.5

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90500.0, chart.pressure)

        # Plotting
        chart.plot()

        # Create a lot of points
        num_samples = 100000
        theta = np.linspace(0, 2 * np.pi, num_samples)
        r = np.random.rand(num_samples)
        x, y = 7 * r * np.cos(theta) + 25, 20 * r * np.sin(theta) + 50

        scatter_style_1 = {
            "s": 20,
            "alpha": 0.02,
            "color": "darkblue",
            "marker": "o",
        }
        scatter_style_2 = {
            "s": 10,
            "alpha": 0.04,
            "color": "darkorange",
            "marker": "+",
        }
        x2, y2 = x + 5, y - 20

        points = {
            "test_original": {
                "label": "Original",
                "style": scatter_style_1,
                "xy": (x, y),
            },
            "test_displaced": {
                "label": "Displaced",
                "xy": (x2, y2)
            },
        }
        chart.plot_points_dbt_rh(points, scatter_style=scatter_style_2)
        chart.plot_legend(markerscale=1.0, fontsize=11, labelspacing=1.3)

        # Save to disk
        path_png = TEST_BASEDIR / "chart_overlay_test_lot_of_points.png"
        chart.save(path_png)
示例#10
0
    def test_default_styles_psychrochart(self):
        """Test the plot custom styling with JSON files."""
        path_svg_ashrae = os.path.join(basedir, 'test_ashrae_psychrochart.svg')
        chart = PsychroChart("ashrae")
        chart.plot()
        chart.save(path_svg_ashrae)
        chart.save(path_svg_ashrae.replace('svg', 'png'), transparent=True)
        chart.close_fig()

        path_svg_2 = os.path.join(basedir, 'test_interior_psychrochart.svg')
        chart = PsychroChart("interior")
        chart.plot()
        chart.plot_legend(markerscale=.7,
                          frameon=False,
                          fontsize=10,
                          labelspacing=1.2)
        chart.save(path_svg_2)
        chart.close_fig()

        path_svg_3 = os.path.join(basedir, 'test_minimal_psychrochart.svg')
        chart = PsychroChart("minimal")
        chart.plot()
        chart.plot_legend()
        chart.save(path_svg_3)
        chart.close_fig()
示例#11
0
    def test_default_styles_psychrochart(self):
        """Test the plot custom styling with JSON files."""
        path_svg_ashrae = str(TEST_BASEDIR / "test_ashrae_psychrochart.svg")
        chart = PsychroChart("ashrae")
        chart.plot()
        chart.save(path_svg_ashrae)
        chart.save(path_svg_ashrae.replace("svg", "png"), transparent=True)
        chart.close_fig()

        path_svg_2 = TEST_BASEDIR / "test_interior_psychrochart.svg"
        chart = PsychroChart("interior")
        chart.plot()
        chart.plot_legend(markerscale=0.7,
                          frameon=False,
                          fontsize=10,
                          labelspacing=1.2)
        chart.save(path_svg_2)
        chart.close_fig()

        path_svg_3 = TEST_BASEDIR / "test_minimal_psychrochart.svg"
        chart = PsychroChart("minimal")
        chart.plot()
        chart.plot_legend()
        chart.save(path_svg_3)
        chart.close_fig()
示例#12
0
def _make_chart(path_save=None):
    chart = PsychroChart("minimal")
    # Zones:
    zones_conf = {
        "zones":
            [
                {
                    "zone_type": "dbt-rh",
                    "style": {"edgecolor": [1.0, 0.749, 0.0, 0.8],
                              "facecolor": [1.0, 0.749, 0.0, 0.2],
                              "linewidth": 2,
                              "linestyle": "--"},
                    "points_x": [23, 28],
                    "points_y": [40, 60],
                    "label": "Summer"
                },
                {
                    "zone_type": "dbt-rh",
                    "style": {"edgecolor": [0.498, 0.624, 0.8],
                              "facecolor": [0.498, 0.624, 1.0, 0.2],
                              "linewidth": 2,
                              "linestyle": "--"},
                    "points_x": [18, 23],
                    "points_y": [35, 55],
                    "label": "Winter"
                }
            ]
    }
    chart.append_zones(zones_conf)
    # Plotting
    chart.plot()
    # Vertical lines
    t_min, t_opt, t_max = 16, 23, 30
    chart.plot_vertical_dry_bulb_temp_line(
        t_min, {"color": [0.0, 0.125, 0.376], "lw": 2, "ls": ':'},
        '  TOO COLD ({}°C)'.format(t_min), ha='left', loc=0., fontsize=14)
    chart.plot_vertical_dry_bulb_temp_line(
        t_opt, {"color": [0.475, 0.612, 0.075], "lw": 2, "ls": ':'})
    chart.plot_vertical_dry_bulb_temp_line(
        t_max, {"color": [1.0, 0.0, 0.247], "lw": 2, "ls": ':'},
        'TOO HOT ({}°C)  '.format(t_max), ha='right', loc=1,
        reverse=True, fontsize=14)
    # Save to disk the base chart
    if path_save is not None:
        path_svg = os.path.join(
            basedir, path_save)
        chart.save(path_svg)
    return chart
示例#13
0
    def test_custom_style_psychrochart(self):
        """Test the plot custom styling with dicts."""
        custom_style = {
            "figure": {
                "figsize": [12, 8],
                "base_fontsize": 12,
                "title": None,
                "x_label": None,
                "y_label": None,
                "partial_axis": False
            },
            "limits": {
                "range_temp_c": [15, 25],
                "range_humidity_g_kg": [0, 20],
                "altitude_m": 900,
                "step_temp": .2
            },
            "saturation": {
                "color": [0, .3, 1.],
                "linewidth": 2
            },
            "constant_rh": {
                "color": [0.0, 0.498, 1.0, .7],
                "linewidth": 2.5,
                "linestyle": ":"
            },
            "chart_params": {
                "with_constant_rh": True,
                "constant_rh_curves": [25, 50, 75],
                "constant_rh_labels": [25, 50, 75],
                "with_constant_v": False,
                "with_constant_h": False,
                # "with_constant_wet_temp": False,
                "range_wet_temp": [-10, 30],
                # "constant_wet_temp_labels": [5, 10, 15, 20],
                # "with_constant_dry_temp": False,
                "constant_humid_label_include_limits": False,
                "with_zones": False
            }
        }
        chart = PsychroChart(custom_style)
        chart.plot()
        chart.plot_legend()

        path_png = os.path.join(basedir, 'test_custom_psychrochart.png')
        chart.save(path_png, transparent=True)
        chart.close_fig()
示例#14
0
    def test_custom_psychrochart_4(self):
        """Customize a chart with group of points."""
        # Load config
        config = load_config("minimal")

        # Customization
        config['limits']['pressure_kpa'] = 90.5

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90.5, chart.p_atm_kpa)

        # Plotting
        chart.plot()

        points = {'exterior': (31.06, 32.9),
                  'exterior_estimated': (36.7, 25.0),
                  'interior': (29.42, 52.34)}

        convex_groups_bad = [
            (['exterior', 'interior'],
             {},
             {}
             ),
        ]
        convex_groups_ok = [
            (['exterior', 'exterior_estimated', 'interior'],
             {},
             {}
             ),
        ]

        points_plot = chart.plot_points_dbt_rh(
            points, convex_groups=convex_groups_bad)
        print('Points in chart: %s' % points_plot)

        chart.plot_points_dbt_rh(
            points, convex_groups=convex_groups_ok)

        # Legend
        chart.plot_legend(markerscale=1., fontsize=11, labelspacing=1.3)

        # Save to disk
        path_svg = os.path.join(
            basedir, 'chart_overlay_test_convexhull.svg')
        chart.save(path_svg)
示例#15
0
    def test_overlay_a_lot_of_points_1(self):
        """Customize a chart with group of points."""
        # Load config
        config = load_config("minimal")

        # Customization
        config['limits']['pressure_kpa'] = 90.5

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90.5, chart.p_atm_kpa)

        # Plotting
        chart.plot()

        # Create a lot of points
        num_samples = 50000
        # num_samples = 5000
        theta = np.linspace(0, 2 * np.pi, num_samples)
        r = np.random.rand(num_samples)
        x, y = 7 * r * np.cos(theta) + 25, 20 * r * np.sin(theta) + 50

        points = {'test_series_1': (x, y)}
        scatter_style = {
            's': 5,
            'alpha': .1,
            'color': 'darkorange',
            'marker': '+'
        }

        # chart.plot_points_dbt_rh(points)
        chart.plot_points_dbt_rh(points, scatter_style=scatter_style)

        # Save to disk
        path_png = os.path.join(basedir,
                                'chart_overlay_test_lot_of_points_1.png')
        chart.save(path_png)
示例#16
0
    def test_custom_psychrochart_4(self):
        """Customize a chart with group of points."""
        # Load config
        config = load_config("minimal")

        # Customization
        config["limits"]["pressure_kpa"] = 90.5

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90500.0, chart.pressure)

        # Plotting
        chart.plot()

        points = {
            "exterior": (31.06, 32.9),
            "exterior_estimated": (36.7, 25.0),
            "interior": (29.42, 52.34),
        }

        convex_groups_bad = [
            (["exterior", "interior"], {}, {}),
        ]
        chart.plot_points_dbt_rh(points, convex_groups=convex_groups_bad)
        convex_groups_ok = [
            (["exterior", "exterior_estimated", "interior"], {}, {}),
        ]
        chart.plot_points_dbt_rh(points, convex_groups=convex_groups_ok)

        # Legend
        chart.plot_legend(markerscale=1.0, fontsize=11, labelspacing=1.3)

        # Save to disk
        path_svg = TEST_BASEDIR / "chart_overlay_test_convexhull.svg"
        chart.save(path_svg)
示例#17
0
    def test_custom_psychrochart_2(self):
        """Customize a chart with some additions from a default style."""
        # Load config
        config = load_config("minimal")

        # Customization
        config["limits"]["pressure_kpa"] = 90.5
        config["figure"]["x_label"] = None
        config["figure"]["y_label"] = None
        config["saturation"]["linewidth"] = 3
        config["chart_params"]["with_constant_dry_temp"] = False
        config["chart_params"]["with_constant_humidity"] = False
        config["chart_params"]["with_constant_wet_temp"] = False
        config["chart_params"]["with_constant_h"] = False

        # Chart creation
        chart = PsychroChart(config)
        self.assertEqual(90500.0, chart.pressure)

        # Zones:
        zones_conf = {
            "zones": [
                {
                    "zone_type": "xy-points",
                    "style": {
                        "linewidth": 2,
                        "linestyle": "--",
                        "edgecolor": [0.498, 0.624, 0.8],
                        "facecolor": [0.498, 0.624, 1.0, 0.3],
                    },
                    "points_x": [23, 28, 28, 24, 23],
                    "points_y": [1, 3, 4, 4, 2],
                    "label": "Custom",
                },
                {
                    "zone_type": "not_recognized_type",
                    "label": "Bad zone"
                },
            ]
        }
        chart.append_zones(zones_conf)

        # Plotting
        chart.plot()

        points = {
            "exterior": (31.06, 32.9),
            "exterior_estimated": (36.7, 25.0),
            "interior": (29.42, 52.34),
        }

        convex_groups = [
            (["exterior", "exterior_estimated", "interior"], {}, {}),
        ]
        chart.plot_points_dbt_rh(points, convex_groups=convex_groups)

        # Legend
        chart.plot_legend(markerscale=1.0, fontsize=11, labelspacing=1.3)

        # Save to disk
        path_svg = TEST_BASEDIR / "chart_overlay_test.svg"
        chart.save(path_svg)
示例#18
0
        def _make_chart():
            chart = PsychroChart("minimal")

            # Zones:
            zones_conf = {
                "zones":
                    [
                        {
                            "zone_type": "dbt-rh",
                            "style": {"edgecolor": [1.0, 0.749, 0.0, 0.8],
                                      "facecolor": [1.0, 0.749, 0.0, 0.2],
                                      "linewidth": 2,
                                      "linestyle": "--"},
                            "points_x": [23, 28],
                            "points_y": [40, 60],
                            "label": "Summer"
                        },
                        {
                            "zone_type": "dbt-rh",
                            "style": {"edgecolor": [0.498, 0.624, 0.8],
                                      "facecolor": [0.498, 0.624, 1.0, 0.2],
                                      "linewidth": 2,
                                      "linestyle": "--"},
                            "points_x": [18, 23],
                            "points_y": [35, 55],
                            "label": "Winter"
                        }
                    ]
            }
            chart.append_zones(zones_conf)

            # Plotting
            chart.plot()

            # Vertical lines
            t_min, t_opt, t_max = 16, 23, 30
            chart.plot_vertical_dry_bulb_temp_line(
                t_min, {"color": [0.0, 0.125, 0.376], "lw": 2, "ls": ':'},
                '  TOO COLD ({}°C)'.format(t_min), ha='left',
                loc=0., fontsize=14)
            chart.plot_vertical_dry_bulb_temp_line(
                t_opt, {"color": [0.475, 0.612, 0.075], "lw": 2, "ls": ':'})
            chart.plot_vertical_dry_bulb_temp_line(
                t_max, {"color": [1.0, 0.0, 0.247], "lw": 2, "ls": ':'},
                'TOO HOT ({}°C)  '.format(t_max), ha='right', loc=1,
                reverse=True, fontsize=14)

            points = {'exterior': {'label': 'Exterior',
                                   'style': {
                                       'color': [0.855, 0.004, 0.278, 0.8],
                                       'marker': 'X', 'markersize': 15},
                                   'xy': (31.06, 32.9)},
                      'exterior_estimated': {
                          'label': 'Estimated (Weather service)',
                          'style': {'color': [0.573, 0.106, 0.318, 0.5],
                                    'marker': 'x', 'markersize': 10},
                          'xy': (36.7, 25.0)},
                      'interior': {'label': 'Interior',
                                   'style': {
                                       'color': [0.592, 0.745, 0.051, 0.9],
                                       'marker': 'o', 'markersize': 30},
                                   'xy': (29.42, 52.34)}}
            connectors = [{'start': 'exterior',
                           'end': 'exterior_estimated',
                           'style': {'color': [0.573, 0.106, 0.318, 0.7],
                                     "linewidth": 2, "linestyle": "-."}},
                          {'start': 'exterior',
                           'end': 'interior',
                           'style': {'color': [0.855, 0.145, 0.114, 0.8],
                                     "linewidth": 2, "linestyle": ":"}}]

            points_plot = chart.plot_points_dbt_rh(points, connectors)
            print('Points in chart: %s' % points_plot)

            # Legend
            chart.plot_legend(
                markerscale=.7, frameon=False, fontsize=10, labelspacing=1.2)

            # Save to disk
            path_svg = os.path.join(
                basedir, 'chart_overlay_style_minimal.svg')
            chart.save(path_svg)
示例#19
0
 def test_default_psychrochart(self):
     """Test the plot custom styling with JSON files/dicts."""
     path_svg_default = TEST_BASEDIR / "test_default_psychrochart.svg"
     chart = PsychroChart()
     chart.save(path_svg_default)
     chart.close_fig()
示例#20
0
 def test_imperial_units_psychrochart(self):
     """Test the plot custom styling with JSON files/dicts."""
     path_svg_default = TEST_BASEDIR / "test_ashrae_psychrochart_ip.svg"
     chart = PsychroChart(styles="ashrae_ip", use_unit_system_si=False)
     chart.save(path_svg_default)
     chart.close_fig()
示例#21
0
def _make_chart(path_save=None):
    chart = PsychroChart("minimal")
    # Zones:
    zones_conf = {
        "zones": [
            {
                "zone_type": "dbt-rh",
                "style": {
                    "edgecolor": [1.0, 0.749, 0.0, 0.8],
                    "facecolor": [1.0, 0.749, 0.0, 0.2],
                    "linewidth": 2,
                    "linestyle": "--",
                },
                "points_x": [23, 28],
                "points_y": [40, 60],
                "label": "Summer",
            },
            {
                "zone_type": "dbt-rh",
                "style": {
                    "edgecolor": [0.498, 0.624, 0.8],
                    "facecolor": [0.498, 0.624, 1.0, 0.2],
                    "linewidth": 2,
                    "linestyle": "--",
                },
                "points_x": [18, 23],
                "points_y": [35, 55],
                "label": "Winter",
            },
        ]
    }
    chart.append_zones(zones_conf)
    # Plotting
    chart.plot()
    # Vertical lines
    t_min, t_opt, t_max = 16, 23, 30
    chart.plot_vertical_dry_bulb_temp_line(
        t_min,
        {
            "color": [0.0, 0.125, 0.376],
            "lw": 2,
            "ls": ":"
        },
        f"  TOO COLD ({t_min}°C)",
        ha="left",
        loc=0.0,
        fontsize=14,
    )
    chart.plot_vertical_dry_bulb_temp_line(t_opt, {
        "color": [0.475, 0.612, 0.075],
        "lw": 2,
        "ls": ":"
    })
    chart.plot_vertical_dry_bulb_temp_line(
        t_max,
        {
            "color": [1.0, 0.0, 0.247],
            "lw": 2,
            "ls": ":"
        },
        f"TOO HOT ({t_max}°C)  ",
        ha="right",
        loc=1,
        reverse=True,
        fontsize=14,
    )
    # Save to disk the base chart
    if path_save is not None:
        path_svg = TEST_BASEDIR / path_save
        chart.save(path_svg)
    return chart
示例#22
0
    def test_custom_style_psychrochart_2(self):
        """Test the plot custom styling with dicts."""
        import logging
        from psychrochart.util import f_range

        custom_style = {
            'chart_params': {
                'constant_h_label': None,
                'constant_h_labels': [30, 40, 50, 60, 70, 80],
                'constant_h_step': 5,
                'constant_humid_label': None,
                'constant_humid_label_include_limits': False,
                'constant_humid_label_step': 5,
                'constant_humid_step': 2.5,
                'constant_rh_curves': [20, 40, 50, 60, 80],
                'constant_rh_label': None,
                'constant_rh_labels': [20, 30, 40, 50, 60],
                'constant_rh_labels_loc': 0.5,
                'constant_temp_label': None,
                'constant_temp_label_include_limits': False,
                'constant_temp_label_step': 10,
                'constant_temp_step': 5,
                'constant_v_label': None,
                'constant_v_labels': [0.83, 0.84, 0.85, 0.86, 0.87, 0.88],
                'constant_v_labels_loc': 0.1,
                'constant_v_step': 0.01,
                'constant_wet_temp_label': None,
                'constant_wet_temp_labels': [10, 15, 20, 25],
                'constant_wet_temp_step': 5,
                'range_wet_temp': [10, 30],
                'range_h': [10, 100],
                'range_vol_m3_kg': [0.82, 0.9],
                'with_constant_dry_temp': True,
                'with_constant_h': True,
                'with_constant_humidity': True,
                'with_constant_rh': True,
                'with_constant_v': True,
                'with_constant_wet_temp': True,
                'with_zones': False
            },
            'constant_dry_temp': {
                'color': [0.855, 0.145, 0.114, 0.7],
                'linestyle': ':',
                'linewidth': 0.75
            },
            'constant_h': {
                'color': [0.251, 0.0, 0.502, 0.7],
                'linestyle': '-',
                'linewidth': 2
            },
            'constant_humidity': {
                'color': [0.0, 0.125, 0.376, 0.7],
                'linestyle': ':',
                'linewidth': 0.75
            },
            'constant_rh': {
                'color': [0.0, 0.498, 1.0, 0.7],
                'linestyle': '-.',
                'linewidth': 2
            },
            'constant_v': {
                'color': [0.0, 0.502, 0.337, 0.7],
                'linestyle': '-',
                'linewidth': 1
            },
            'constant_wet_temp': {
                'color': [0.498, 0.875, 1.0, 0.7],
                'linestyle': '-',
                'linewidth': 1
            },
            'figure': {
                'figsize': [16, 9],
                'partial_axis': True,
                'position': [0, 0, 1, 1],
                'title': None,
                'x_axis': {
                    'color': [0.855, 0.145, 0.114],
                    'linestyle': '-',
                    'linewidth': 2
                },
                'x_axis_labels': {
                    'color': [0.855, 0.145, 0.114],
                    'fontsize': 10
                },
                'x_axis_ticks': {
                    'color': [0.855, 0.145, 0.114],
                    'direction': 'in',
                    'pad': -20
                },
                'x_label': None,
                'y_axis': {
                    'color': [0.0, 0.125, 0.376],
                    'linestyle': '-',
                    'linewidth': 2
                },
                'y_axis_labels': {
                    'color': [0.0, 0.125, 0.376],
                    'fontsize': 10
                },
                'y_axis_ticks': {
                    'color': [0.0, 0.125, 0.376],
                    'direction': 'in',
                    'pad': -20
                },
                'y_label': None
            },
            # 'limits': {'range_humidity_g_kg': [2.5, 17.5],
            'limits': {
                'range_humidity_g_kg': [2.5, 20],
                'range_temp_c': [15, 35],
                'step_temp': 0.5,
                'pressure_kpa': 101.42
            },
            'saturation': {
                'color': [0.855, 0.145, 0.114],
                'linestyle': '-',
                'linewidth': 5
            },
            'zones': [{
                'label': 'Summer',
                'points_x': [23, 28],
                'points_y': [40, 60],
                'style': {
                    'edgecolor': [1.0, 0.749, 0.0, 0.8],
                    'facecolor': [1.0, 0.749, 0.0, 0.2],
                    'linestyle': '--',
                    'linewidth': 2
                },
                'zone_type': 'dbt-rh'
            }, {
                'label': 'Winter',
                'points_x': [18, 23],
                'points_y': [35, 55],
                'style': {
                    'edgecolor': [0.498, 0.624, 0.8],
                    'facecolor': [0.498, 0.624, 1.0, 0.2],
                    'linestyle': '--',
                    'linewidth': 2
                },
                'zone_type': 'dbt-rh'
            }]
        }
        chart = PsychroChart(custom_style, logger=logging, verbose=True)
        chart.plot()
        chart.plot_legend()

        path_png = os.path.join(basedir, 'test_custom_psychrochart_2.png')
        chart.save(path_png, transparent=True)
        chart.close_fig()

        for p in f_range(90., 105., 1.):
            print('Trying with P: {} kPa:'.format(p))
            custom_style['limits']['pressure_kpa'] = p
            PsychroChart(custom_style, logger=logging, verbose=True)
示例#23
0
    def test_custom_style_psychrochart_3(self):
        """Test the plot custom styling with dicts, negative temperatures."""
        custom_style = {
            "chart_params": {
                "constant_h_label": None,
                "constant_h_labels": [-25, -15, 0, 10, 15],
                "constant_h_step": 5,
                "constant_humid_label": None,
                "constant_humid_label_include_limits": False,
                "constant_humid_label_step": 1,
                "constant_humid_step": 0.5,
                "constant_rh_curves": [10, 20, 40, 50, 60, 80, 90],
                "constant_rh_label": None,
                "constant_rh_labels": [20, 40, 60],
                "constant_rh_labels_loc": 0.8,
                "constant_temp_label": None,
                "constant_temp_label_include_limits": False,
                "constant_temp_label_step": 5,
                "constant_temp_step": 5,
                "constant_v_label": None,
                "constant_v_labels": [0.74, 0.76, 0.78, 0.8],
                "constant_v_labels_loc": 0.01,
                "constant_v_step": 0.01,
                "constant_wet_temp_label": None,
                "constant_wet_temp_labels": [-15, -10, -5, 0],
                "constant_wet_temp_step": 5,
                "range_wet_temp": [-25, 5],
                "range_h": [-30, 20],
                "range_vol_m3_kg": [0.7, 0.82],
                "with_constant_dry_temp": True,
                "with_constant_h": True,
                "with_constant_humidity": True,
                "with_constant_rh": True,
                "with_constant_v": True,
                "with_constant_wet_temp": True,
                "with_zones": False,
            },
            "constant_dry_temp": {
                "color": [0.855, 0.145, 0.114, 0.7],
                "linestyle": ":",
                "linewidth": 0.75,
            },
            "constant_h": {
                "color": [0.251, 0.0, 0.502, 0.7],
                "linestyle": "-",
                "linewidth": 2,
            },
            "constant_humidity": {
                "color": [0.0, 0.125, 0.376, 0.7],
                "linestyle": ":",
                "linewidth": 0.75,
            },
            "constant_rh": {
                "color": [0.0, 0.498, 1.0, 0.7],
                "linestyle": "-.",
                "linewidth": 2,
            },
            "constant_v": {
                "color": [0.0, 0.502, 0.337, 0.7],
                "linestyle": "-",
                "linewidth": 1,
            },
            "constant_wet_temp": {
                "color": [0.498, 0.875, 1.0, 0.7],
                "linestyle": "-",
                "linewidth": 1,
            },
            "figure": TEST_EXAMPLE_FIG_CONFIG,
            "limits": {
                "range_humidity_g_kg": [0, 3],
                "range_temp_c": [-30, 10],
                "step_temp": 0.5,
                "pressure_kpa": 101.42,
            },
            "saturation": {
                "color": [0.855, 0.145, 0.114],
                "linestyle": "-",
                "linewidth": 5,
            },
            "zones": TEST_EXAMPLE_ZONES,
        }
        chart = PsychroChart(custom_style)
        chart.plot()

        path_png = TEST_BASEDIR / "test_custom_psychrochart_3.png"
        chart.save(path_png, transparent=True)
        chart.close_fig()

        for p in np.arange(90.0, 105.0):
            custom_style["limits"]["pressure_kpa"] = p
            PsychroChart(custom_style)
示例#24
0
        def _make_chart():
            chart = PsychroChart("minimal")

            # Zones:
            zones_conf = {
                "zones": [
                    {
                        "zone_type": "dbt-rh",
                        "style": {
                            "edgecolor": [1.0, 0.749, 0.0, 0.8],
                            "facecolor": [1.0, 0.749, 0.0, 0.2],
                            "linewidth": 2,
                            "linestyle": "--",
                        },
                        "points_x": [23, 28],
                        "points_y": [40, 60],
                        "label": "Summer",
                    },
                    {
                        "zone_type": "dbt-rh",
                        "style": {
                            "edgecolor": [0.498, 0.624, 0.8],
                            "facecolor": [0.498, 0.624, 1.0, 0.2],
                            "linewidth": 2,
                            "linestyle": "--",
                        },
                        "points_x": [18, 23],
                        "points_y": [35, 55],
                        "label": "Winter",
                    },
                ]
            }
            chart.append_zones(zones_conf)

            # Plotting
            chart.plot()

            # Vertical lines
            t_min, t_opt, t_max = 16, 23, 30
            chart.plot_vertical_dry_bulb_temp_line(
                t_min,
                {
                    "color": [0.0, 0.125, 0.376],
                    "lw": 2,
                    "ls": ":"
                },
                f"  TOO COLD ({t_min}°C)",
                ha="left",
                loc=0.0,
                fontsize=14,
            )
            chart.plot_vertical_dry_bulb_temp_line(
                t_opt, {
                    "color": [0.475, 0.612, 0.075],
                    "lw": 2,
                    "ls": ":"
                })
            chart.plot_vertical_dry_bulb_temp_line(
                t_max,
                {
                    "color": [1.0, 0.0, 0.247],
                    "lw": 2,
                    "ls": ":"
                },
                f"TOO HOT ({t_max}°C)  ",
                ha="right",
                loc=1,
                reverse=True,
                fontsize=14,
            )

            points = {
                "exterior": {
                    "label": "Exterior",
                    "style": {
                        "color": [0.855, 0.004, 0.278, 0.8],
                        "marker": "X",
                        "markersize": 15,
                    },
                    "xy": (31.06, 32.9),
                },
                "exterior_estimated": {
                    "label": "Estimated (Weather service)",
                    "style": {
                        "color": [0.573, 0.106, 0.318, 0.5],
                        "marker": "x",
                        "markersize": 10,
                    },
                    "xy": (36.7, 25.0),
                },
                "interior": {
                    "label": "Interior",
                    "style": {
                        "color": [0.592, 0.745, 0.051, 0.9],
                        "marker": "o",
                        "markersize": 30,
                    },
                    "xy": (29.42, 52.34),
                },
            }
            connectors = [
                {
                    "start": "exterior",
                    "end": "exterior_estimated",
                    "style": {
                        "color": [0.573, 0.106, 0.318, 0.7],
                        "linewidth": 2,
                        "linestyle": "-.",
                    },
                },
                {
                    "start": "exterior",
                    "end": "interior",
                    "style": {
                        "color": [0.855, 0.145, 0.114, 0.8],
                        "linewidth": 2,
                        "linestyle": ":",
                    },
                },
            ]
            chart.plot_points_dbt_rh(points, connectors)

            # Legend
            chart.plot_legend(markerscale=0.7,
                              frameon=False,
                              fontsize=10,
                              labelspacing=1.2)

            # Save to disk
            path_svg = TEST_BASEDIR / "chart_overlay_style_minimal.svg"
            chart.save(path_svg)
示例#25
0
    def test_custom_psychrochart_3(self):
        """Customize a chart with some additions from a default style."""
        # Load config
        config = load_config("interior")

        # Chart creation
        chart = PsychroChart(config)

        # Zones:

        # Plotting
        chart.plot()

        arrows = {
            "exterior": [(31.06, 32.9), (29.06, 31.9)],
            "exterior_estimated": [(36.7, 25.0), (34.7, 30.0)],
            "interior": [(29.42, 52.34), (31.42, 57.34)],
        }
        chart.plot_arrows_dbt_rh(arrows)

        # Legend
        chart.plot_legend(markerscale=1.0, fontsize=11, labelspacing=1.3)

        # Save to disk
        path_svg = TEST_BASEDIR / "test_chart_overlay_arrows_1.svg"
        chart.save(path_svg)

        chart.remove_annotations()
        points_arrows = {
            "exterior": {
                "label": "Exterior",
                "style": {
                    "color": [0.855, 0.004, 0.278, 0.8],
                    "marker": "X",
                    "markersize": 15,
                },
                "xy": [(30.06, 34.9), (31.06, 35.9)],
            },
            "exterior_estimated": {
                "label": "Estimated (Weather service)",
                "style": {
                    "color": [0.573, 0.106, 0.318, 0.5],
                    "marker": "x",
                    "markersize": 10,
                },
                "xy": [(32.7, 27.0), (31.7, 28.0)],
            },
            "interior": {
                "label": "Interior",
                "style": {
                    "color": [0.592, 0.745, 0.051, 0.9],
                    "marker": "o",
                    "markersize": 30,
                },
                "xy": [(29.92, 50.34), (28.92, 50.34)],
            },
        }
        chart.plot_arrows_dbt_rh(points_arrows)

        # Save to disk
        path_svg = TEST_BASEDIR / "test_chart_overlay_arrows_2.svg"
        chart.save(path_svg)