def test_segment_text(): """Test the segment_text property.""" legend = Legend(range(10), LegendParameters(segment_count=6)) assert len(legend.segment_text_location) == len(legend.segment_text) == 6 assert legend.segment_text == [ '0.00', '1.80', '3.60', '5.40', '7.20', '9.00' ] for pl in legend.segment_text_location: assert isinstance(pl, Plane) for pt in legend.segment_text_location_2d: assert isinstance(pt, Point2D) seg_num = [0, 1.8, 3.6, 5.4, 7.2, 9] for i, num in enumerate(legend.segment_numbers): assert num == pytest.approx(seg_num[i], rel=1e-3) legend = Legend(range(10), LegendParameters(segment_count=6)) legend.legend_parameters.vertical = False assert len(legend.segment_text_location) == len(legend.segment_text) == 6 assert legend.segment_text == [ '0.00', '1.80', '3.60', '5.40', '7.20', '9.00' ] for pl in legend.segment_text_location: assert isinstance(pl, Plane)
def test_equality(): """Test the equality of legend parameters.""" leg_par = LegendParameters(0, 1000) leg_par_dup = leg_par.duplicate() assert leg_par is not leg_par_dup assert leg_par == leg_par_dup leg_par_dup.segment_count = 3 assert leg_par != leg_par_dup
def legend_parameters(self, value): if value is not None: assert isinstance(value, LegendParameters), \ 'Expected LegendParameters. Got {}.'.format(type(value)) self._legend_parameters = value.duplicate() else: self._legend_parameters = LegendParameters()
def legend_parameters(self, value): if value is not None: assert isinstance(value, LegendParameters) and not \ isinstance(value, LegendParametersCategorized), \ 'Expected LegendParameters. Got {}.'.format(type(value)) self._legend_parameters = value else: self._legend_parameters = LegendParameters()
def test_init_legend_parameters(): """Test the initialization of LegendParameter objects.""" leg_par = LegendParameters(0, 1000) str(leg_par) # Test the LegendParameters representation assert leg_par.min == 0 assert leg_par.max == 1000 assert leg_par.is_segment_count_default is True assert leg_par.is_title_default is True assert leg_par.is_base_plane_default is True assert leg_par.is_segment_height_default is True assert leg_par.is_segment_width_default is True assert leg_par.is_text_height_default is True leg_par_copy = leg_par.duplicate() assert leg_par_copy.min == leg_par.min assert leg_par_copy.max == leg_par.max assert leg_par_copy.segment_count == leg_par.segment_count
def test_segment_text_ordinal_dictionary(self): """Test the segment_text property with ordinal dictionary.""" results = list(range(3000)) ordinal_dict = {300: 'low', 1150: 'desired', 2000: 'too much'} legend = Legend(results, LegendParameters(min=300, max=2000, segment_count=3)) legend.legend_parameters.ordinal_dictionary = ordinal_dict assert len(legend.segment_text_location) == len(legend.segment_text) == 3 assert legend.segment_text == ['low', 'desired', 'too much'] assert len(set(legend.value_colors)) > 100 legend = Legend(results, LegendParameters(min=300, max=2000, segment_count=3)) legend.legend_parameters.ordinal_dictionary = ordinal_dict legend.legend_parameters.continuous_colors = False assert len(legend.segment_text_location) == len(legend.segment_text) == 3 assert legend.segment_text == ['low', 'desired', 'too much'] assert len(set(legend.value_colors)) == 3
def test_init_graphic_con_data_type(self): """Test the initialization of GraphicContainer objects with a DataType.""" mesh2d = Mesh2D.from_grid(num_x=2, num_y=2) mesh3d = Mesh3D.from_mesh2d(mesh2d) data = [-1, 0, 1, 2] graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max, data_type=Temperature()) assert graphic_con.legend_parameters.is_title_default is False assert graphic_con.legend_parameters.title == 'C' legend_par = LegendParameters() legend_par.vertical = False graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max, legend_par, data_type=Temperature()) assert graphic_con.legend_parameters.is_title_default is False assert graphic_con.legend_parameters.title == 'Temperature (C)'
def test_init_legend_with_parameter(): """Test the initialization of Legend with LegendParameter objects.""" legend = Legend([0, 10], LegendParameters(2, 8)) assert len(legend.values) == 2 assert legend.legend_parameters.min == 2 assert legend.legend_parameters.max == 8 assert legend.is_min_default is False assert legend.is_max_default is False
def test_legend_value_colors(): """Test the color_range, value_colors, and segment_colors property.""" legend = Legend(range(5), LegendParameters(segment_count=10)) for i, color in enumerate(legend.color_range): assert color == ColorRange()[i] assert legend.color_range.domain == ColorRange(domain=(0, 4)).domain assert len(legend.values) == 5 assert len(legend.value_colors) == 5 assert legend.value_colors[0] == Colorset.original()[0] assert legend.segment_colors == Colorset.original()
def test_monthlychart_set_min_max_by_index(): """Test the set_minimum_by_index amd set_maximum_by_index methods.""" header = Header(Temperature(), 'C', AnalysisPeriod()) values = [i for i in range(12)] date_t = list(range(1, 13)) data_coll = MonthlyCollection(header, values, date_t) header2 = Header(RelativeHumidity(), '%', AnalysisPeriod()) values2 = [i for i in range(10, 70, 5)] data_coll2 = MonthlyCollection(header2, values2, date_t) l_par = LegendParameters(min=-20, max=40) l_par.decimal_count = 0 month_chart = MonthlyChart([data_coll, data_coll2], legend_parameters=l_par) assert month_chart.y_axis_labels1[0] == '-20' assert month_chart.y_axis_labels1[-1] == '40' month_chart.set_minimum_by_index(0, 1) assert month_chart.y_axis_labels2[0] == '0' month_chart.set_maximum_by_index(100, 1) assert month_chart.y_axis_labels2[-1] == '100'
def test_legend_title(): """Test the title property.""" legend = Legend(range(5)) assert legend.title == '' assert legend.legend_parameters.is_title_default is True assert legend.title_location.o == Point3D(0, 11.25, 0) assert legend.title_location_2d == Point2D(0, 11.25) legend = Legend(range(5), LegendParameters(segment_count=5, title='C')) assert legend.title == 'C' assert legend.legend_parameters.is_title_default is False assert legend.title_location.o == Point3D(0, 5.25, 0) assert legend.title_location_2d == Point2D(0, 5.25)
def test_decimal_count(): """Test the LegendParameter decimal_count property.""" leg_par = LegendParameters() leg_par.decimal_count = 3 assert leg_par.decimal_count == 3 leg_par_copy = leg_par.duplicate() assert leg_par_copy.decimal_count == 3 leg_par.decimal_count = 0 assert leg_par.decimal_count == 0 with pytest.raises(Exception): leg_par = LegendParameters(decimal_count='2') with pytest.raises(Exception): leg_par.decimal_count = '2'
def test_ordinal_dictionary(): """Test the LegendParameter ordinal_dictionary property.""" leg_par = LegendParameters(min=0, max=1) leg_par.ordinal_dictionary = {0: 'False', 1: 'True'} assert leg_par.ordinal_dictionary == {0: 'False', 1: 'True'} leg_par_copy = leg_par.duplicate() assert leg_par_copy.ordinal_dictionary == {0: 'False', 1: 'True'} leg_par.ordinal_dictionary = {0: 'No', 1: 'Yes'} assert leg_par.ordinal_dictionary == {0: 'No', 1: 'Yes'} with pytest.raises(Exception): leg_par = LegendParameters(ordinal_dictionary=['False', 'True']) with pytest.raises(Exception): leg_par.ordinal_dictionary = ['False', 'True']
def test_segment_text_ordinal_dictionary2(self): """Test the segment_text property with another ordinal dictionary.""" results = list(range(-4, 5)) ordinal_dict = PredictedMeanVote().unit_descr legend = Legend(results, LegendParameters(min=-3, max=3, segment_count=7)) legend.legend_parameters.ordinal_dictionary = ordinal_dict assert legend.segment_text == ['Cold', 'Cool', 'Slightly Cool', 'Neutral', 'Slightly Warm', 'Warm', 'Hot'] legend.legend_parameters.min = -2 legend.legend_parameters.max = 2 legend.legend_parameters.segment_count = 5 assert legend.segment_text == ['Cool', 'Slightly Cool', 'Neutral', 'Slightly Warm', 'Warm']
def test_vertical(self): """Test the LegendParameter continuous_legend property.""" leg_par = LegendParameters() leg_par.vertical = False assert leg_par.vertical is False leg_par_copy = leg_par.duplicate() assert leg_par_copy.vertical is False leg_par.vertical = True assert leg_par.vertical is True with pytest.raises(Exception): leg_par = LegendParameters(vertical='yes') with pytest.raises(Exception): leg_par.vertical = 'yes'
def test_continuous_colors(): """Test the LegendParameter continuous_colors property.""" leg_par = LegendParameters() leg_par.continuous_colors = False assert not leg_par.continuous_colors leg_par_copy = leg_par.duplicate() assert not leg_par_copy.continuous_colors leg_par.continuous_colors = True assert leg_par.continuous_colors with pytest.raises(Exception): leg_par = LegendParameters(continuous_colors='yes') with pytest.raises(Exception): leg_par.continuous_colors = 'yes'
def test_font(): """Test the LegendParameter font property.""" leg_par = LegendParameters() leg_par.font = 'Times' assert leg_par.font == 'Times' leg_par_copy = leg_par.duplicate() assert leg_par_copy.font == 'Times' leg_par.font = 'Courier' assert leg_par.font == 'Courier' with pytest.raises(Exception): leg_par = LegendParameters(font=0) with pytest.raises(Exception): leg_par.font = 0
def test_continuous_legend(): """Test the LegendParameter continuous_legend property.""" leg_par = LegendParameters() leg_par.continuous_legend = True assert leg_par.continuous_legend is True leg_par_copy = leg_par.duplicate() assert leg_par_copy.continuous_legend is True leg_par.continuous_legend = False assert leg_par.continuous_legend is False with pytest.raises(Exception): leg_par = LegendParameters(continuous_legend='yes') with pytest.raises(Exception): leg_par.continuous_legend = 'yes'
def test_segment_width(): """Test the LegendParameter segment_width property.""" leg_par = LegendParameters() leg_par.segment_width = 3 assert leg_par.segment_width == 3 assert leg_par.is_segment_width_default is False leg_par_copy = leg_par.duplicate() assert leg_par_copy.segment_width == 3 leg_par.segment_width = 2 assert leg_par.segment_width == 2 with pytest.raises(Exception): leg_par = LegendParameters(segment_width=0) with pytest.raises(Exception): leg_par.segment_width = 0
def test_segment_height(): """Test the LegendParameter segment_height property.""" leg_par = LegendParameters() leg_par.segment_height = 3 assert leg_par.segment_height == 3 assert not leg_par.is_segment_height_default leg_par_copy = leg_par.duplicate() assert leg_par_copy.segment_height == 3 leg_par.segment_height = 2 assert leg_par.segment_height == 2 with pytest.raises(Exception): leg_par = LegendParameters(segment_height=0) with pytest.raises(Exception): leg_par.segment_height = 0
def test_text_height(): """Test the LegendParameter text_height property.""" leg_par = LegendParameters() leg_par.text_height = 0.25 assert leg_par.text_height == 0.25 assert leg_par.is_text_height_default is False leg_par_copy = leg_par.duplicate() assert leg_par_copy.text_height == 0.25 leg_par.text_height = 2 assert leg_par.text_height == 2 with pytest.raises(Exception): leg_par = LegendParameters(text_height=0) with pytest.raises(Exception): leg_par.text_height = 0
def test_segment_mesh_2d(): """Test the segment_mesh_2d property.""" legend = Legend(range(10), LegendParameters(segment_count=6)) assert isinstance(legend.segment_mesh_2d, Mesh2D) assert len(legend.segment_mesh_2d.faces) == 6 assert len(legend.segment_mesh_2d.vertices) == 14 legend.legend_parameters.vertical = False assert len(legend.segment_mesh_2d.faces) == 6 assert len(legend.segment_mesh_2d.vertices) == 14 legend.legend_parameters.continuous_legend = True assert len(legend.segment_mesh_2d.faces) == 5 assert len(legend.segment_mesh_2d.vertices) == 12 legend.legend_parameters.vertical = True assert len(legend.segment_mesh_2d.faces) == 5 assert len(legend.segment_mesh_2d.vertices) == 12
def test_title(): """Test the LegendParameter title property.""" leg_par = LegendParameters(title='m2') assert leg_par.title == 'm2' assert leg_par.is_title_default is False leg_par_copy = leg_par.duplicate() assert leg_par_copy.title == 'm2' leg_par.title = 'm2' assert leg_par.title == 'm2' with pytest.raises(Exception): leg_par = LegendParameters(title=2) with pytest.raises(Exception): leg_par.title = 2
def test_hourlyplot_custom(): """Test the initialization of HourlyPlot with custom properties.""" header = Header(Temperature(), 'C', AnalysisPeriod()) values = list(range(8760)) data_coll = HourlyContinuousCollection(header, values) hour_plot = HourlyPlot(data_coll, LegendParameters(), Point3D(10, 10, 10), 2, 2, 100) assert hour_plot.base_point == Point3D(10, 10, 10) assert hour_plot.x_dim == 2 assert hour_plot.y_dim == 2 assert hour_plot.z_dim == 100 mesh = hour_plot.colored_mesh3d assert isinstance(mesh, Mesh3D) assert len(mesh.faces) == 8760 assert mesh.min == Point3D(10, 10, 10) assert mesh.max == Point3D(2 * 365 + 10, 2 * 24 + 10, 110)
def test_base_plane(): """Test the LegendParameter base_plane property.""" leg_par = LegendParameters( base_plane=Plane(Vector3D(0, 0, 0), Point3D(10, 10, 0))) assert leg_par.base_plane.o == Point3D(10, 10, 0) assert leg_par.is_base_plane_default is False leg_par_copy = leg_par.duplicate() assert leg_par_copy.base_plane.o == Point3D(10, 10, 0) leg_par.base_plane = Plane(Vector3D(0, 0, 0), Point3D(-10, -10, 0)) assert leg_par.base_plane.o == Point3D(-10, -10, 0) with pytest.raises(Exception): leg_par = LegendParameters(base_plane=Point3D(-10, -10, 0)) with pytest.raises(Exception): leg_par.base_plane = Point3D(-10, -10, 0)
def test_colors(): """Test the LegendParameter colors property.""" leg_par = LegendParameters(colors=[Color(0, 0, 0), Color(255, 255, 255)]) assert len(leg_par.colors) == 2 assert leg_par.colors[0] == Color(0, 0, 0) assert leg_par.colors[1] == Color(255, 255, 255) leg_par_copy = leg_par.duplicate() assert len(leg_par_copy.colors) == 2 assert leg_par_copy.colors[0] == Color(0, 0, 0) assert leg_par_copy.colors[1] == Color(255, 255, 255) leg_par.colors = [Color(0, 0, 0), Color(100, 100, 100)] assert leg_par.colors[1] == Color(100, 100, 100) with pytest.raises(Exception): leg_par = LegendParameters(colors=[0, 1]) with pytest.raises(Exception): leg_par.colors = [0, 1]
def test_wind_polygons(): """Test colors for different windrose types.""" # Testing vals dir_vals = [0, 0, 0, 0, 10, 10, 10, 85, 90, 90, 90, 95, 170, 285, 310] spd_vals = [0, 0, 0, 0, 1, 145, 189, 15, 10, 150, 300, 259, 100, 5, 301] # Make into fake data collections a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13) dates = [DateTime(6, 21, i) for i in range(len(dir_vals))] spd_header = Header(Speed(), 'm/s', a_per) dir_header = Header(GenericType('Direction', 'deg'), 'deg', a_per) spd_data = HourlyDiscontinuousCollection(spd_header, spd_vals, dates) dir_data = HourlyDiscontinuousCollection(dir_header, dir_vals, dates) # Bin values to divide into 6 intervals = 10 - 310 = 300 / 6 = 50 m/s # intervals: [1-50, 51-100, 101-150, 151-200, 201-250, 251-300, 301-350] # # [[1], [], [145], [189], [], []], # 0-49, 100-149, 150-199 # [[10, 15], [], [150], [], [], [259, 300]], # 0-49, 150-199,, 250-299 # [[], [100], [], [], [], []], # 100-149 # [[5], [], [], [], [], [301]] # 0-49, 300-349 # Check freq=True, zeros=False w = WindRose(dir_data, spd_data, 4) w.show_freq, w.show_zeros = True, False w.frequency_hours = 2 w.legend_parameters = LegendParameters(segment_count=6) chk_poly_num = sum([3, 3, 1, 2]) assert chk_poly_num == len(w.windrose_lines) # For averaged w.show_freq = False chk_poly_num = 4 w.colored_mesh assert chk_poly_num == len(w.windrose_lines)
def test_windrose_set_legend_parameters(): """Test setting legend params property""" epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw') epw = EPW(epw_path) w = WindRose(epw.wind_direction, epw.wind_speed, 5) # Default assert w._legend_parameters is None assert isinstance(w.legend_parameters, LegendParameters) assert w.legend_parameters.segment_count == pytest.approx(11.0, abs=1e-10) # Check setting wrong input with pytest.raises(AssertionError): w.legend_parameters = 'string' # Check setting w.legend_parameters = LegendParameters(segment_count=16) assert w.legend_parameters.segment_count == pytest.approx(16, abs=1e-10) # Check resetting w.legend_parameters = None assert isinstance(w.legend_parameters, LegendParameters) assert w.legend_parameters.segment_count == pytest.approx(11.0, abs=1e-10)
def test_init_graphic_con_legend_parameters(): """Test the initialization of ResultMesh objects with a LegendParameters.""" mesh2d = Mesh2D.from_grid(num_x=2, num_y=2) mesh3d = Mesh3D.from_mesh2d(mesh2d) data = [-1, 0, 1, 2] legend_par = LegendParameters(base_plane=Plane(o=Point3D(2, 2, 0))) legend_par.vertical = False legend_par.segment_height = 0.25 legend_par.segment_width = 0.5 legend_par.text_height = 0.15 graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max, legend_par) assert graphic_con.legend_parameters.is_base_plane_default is False assert graphic_con.legend_parameters.is_segment_height_default is False assert graphic_con.legend_parameters.is_segment_width_default is False assert graphic_con.legend_parameters.is_text_height_default is False assert graphic_con.legend_parameters.vertical is False assert graphic_con.legend_parameters.base_plane.o == Point3D(2, 2, 0) assert graphic_con.legend_parameters.segment_height == 0.25 assert graphic_con.legend_parameters.segment_width == 0.5 assert graphic_con.legend_parameters.text_height == 0.15
def legend_parameters(self): """Legend parameters for grid based analysis.""" return LegendParameters(0, 3000)