def test_categorized_to_from_dict(): """Test the LegendParametersCategorized to/from dict methods.""" leg_colors = [Color(0, 0, 255), Color(0, 255, 0), Color(255, 0, 0)] leg_par = LegendParametersCategorized([300, 2000], leg_colors) leg_par_dict = leg_par.to_dict() new_leg_par = LegendParametersCategorized.from_dict(leg_par_dict) assert new_leg_par.to_dict() == leg_par_dict
def test_color_range_to_from_dict(): """Test the to/from dict methods.""" color_range = ColorRange( [Color(0, 100, 0), Color(100, 200, 100)], [0, 1000]) color_range_dict = color_range.to_dict() new_color = ColorRange.from_dict(color_range_dict) assert new_color.to_dict() == color_range_dict
def test_init_legend_parameters_categorized(): """Test the initialization of LegendParametersCategorized objects.""" leg_colors = [Color(0, 0, 255), Color(0, 255, 0), Color(255, 0, 0)] leg_par = LegendParametersCategorized([300, 2000], leg_colors) leg_par.decimal_count = 0 str(leg_par) # Test the LegendParametersCategorized representation hash(leg_par) assert leg_par.domain == (300, 2000) assert leg_par.colors == tuple(leg_colors) assert leg_par.category_names == ('<300', '300 - 2000', '>2000') assert leg_par.min == 300 assert leg_par.max == 2000 assert leg_par.is_segment_count_default assert leg_par.is_title_default assert leg_par.is_base_plane_default assert leg_par.is_segment_height_default assert leg_par.is_segment_width_default assert leg_par.is_text_height_default leg_par_copy = leg_par.duplicate() assert leg_par_copy.domain == leg_par.domain assert leg_par_copy.colors == leg_par.colors assert leg_par_copy.category_names == leg_par.category_names assert leg_par_copy == leg_par leg_par_copy.segment_height = 0.5 assert leg_par_copy != leg_par
def test_init_color_range(): """Test the initialization of color range objects.""" color_range = ColorRange( [Color(75, 107, 169), Color(245, 239, 103), Color(234, 38, 0)]) str(color_range) # Test the color representation assert len(color_range) == 3 assert isinstance(color_range.colors, tuple) assert isinstance(color_range.domain, tuple) assert color_range[0] == Color(75, 107, 169)
def test_categorized_category_names(): """Test the LegendParametersCategorized category_names property.""" data = [100, 300, 500, 1000, 2000, 3000] leg_colors = [Color(0, 0, 255), Color(0, 255, 0), Color(255, 0, 0)] legend_par = LegendParametersCategorized([300, 2000], leg_colors) cat_names = ['low', 'desired', 'too much'] legend_par.category_names = cat_names legend = Legend(data, legend_par) assert legend_par.category_names == tuple(cat_names) assert legend.segment_text == tuple(cat_names) with pytest.raises(AssertionError): legend_par.category_names = [ 'low', 'desired', 'too much', 'not a category' ]
def test_color_range_from_dict(): """Test the from_dict method.""" sample_dict = { 'colors': [{ 'r': '0', 'g': '0', 'b': '0' }, { 'r': '0', 'g': '255', 'b': '100' }] } color_range = ColorRange.from_dict(sample_dict) assert isinstance(color_range, ColorRange) assert color_range[0] == Color(0, 0, 0) assert color_range[1] == Color(0, 255, 100)
def get_default_color(face_type: face_types) -> Color: """Get the default color based of face type. Use these colors to generate visualizations that are familiar for Ladybug Tools users. User can overwrite these colors as needed. This method converts decimal RGBA to integer RGBA values. """ color = _COLORSET.get(face_type, [1, 1, 1, 1]) return Color(*(v * 255 for v in color))
def test_color_range_continuous(): """Test color range objects with continuous colors.""" color_range = ColorRange( [Color(0, 100, 0), Color(100, 200, 100)], [0, 1000]) assert color_range.color(-100) == Color(0, 100, 0) assert color_range.color(0) == Color(0, 100, 0) assert color_range.color(500) == Color(50, 150, 50) assert color_range.color(250) == Color(25, 125, 25) assert color_range.color(1000) == Color(100, 200, 100) assert color_range.color(1100) == Color(100, 200, 100)
def test_init_color(): """Test the initialization of color objects.""" color = Color(255, 0, 100) str(color) # Test the color representation assert color.r == 255 assert color.g == 0 assert color.b == 100 color.r = 100 assert color.r == 100 assert len(color) == 3 assert color == Color(100, 0, 100) assert color != Color(100, 0, 0) assert color == color.duplicate() for c in color: assert isinstance(c, int)
def test_default_colors(): """Test default colors for the model objects.""" file_path = r'tests/assets/revit_model/model.hbjson' model = Model.from_hbjson(file_path, load_grids=SensorGridOptions.Mesh) assert model.get_default_color('Aperture') == Color(63, 179, 255, 127) assert model.get_default_color('Door') == Color(159, 149, 99, 255) assert model.get_default_color('Shade') == Color(119, 74, 189, 255) assert model.get_default_color('Wall') == Color(229, 179, 59, 255) assert model.get_default_color('Floor') == Color(255, 127, 127, 255) assert model.get_default_color('RoofCeiling') == Color(127, 19, 19, 255) assert model.get_default_color('AirBoundary') == Color(255, 255, 199, 255) assert model.get_default_color('Grid') == Color(235, 63, 102, 255)
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_color_range_discontinuous(): """Test color range objects with discontinuous colors.""" color_range = ColorRange(continuous_colors=False) color_range.domain = [100, 2000] color_range.colors = [ Color(75, 107, 169), Color(245, 239, 103), Color(234, 38, 0) ] assert color_range.color(99) == Color(75, 107, 169) assert color_range.color(100) == Color(245, 239, 103) assert color_range.color(2000) == Color(245, 239, 103) assert color_range.color(2001) == Color(234, 38, 0)
def test_init_color_invalid(): """Test the initialization of invalid color objects.""" with pytest.raises(Exception): Color(256, 0, 100) with pytest.raises(Exception): Color(-1, 0, 100) with pytest.raises(Exception): Color(0, 256, 100) with pytest.raises(Exception): Color(0, -1, 100) with pytest.raises(Exception): Color(0, 0, 256) with pytest.raises(Exception): Color(0, 0, -1)
def gray(): """Get a .NET gray color object. Useful when you need a placeholder color.""" return Color(90, 90, 90, 255)
def color(self, value: Color): self._color = value if value else Color(204, 204, 204, 255)
def test_categorized_colors(): """Test the LegendParametersCategorized colors property.""" data = [100, 300, 500, 1000, 2000, 3000] leg_colors = [Color(0, 0, 255), Color(0, 255, 0), Color(255, 0, 0)] legend_par = LegendParametersCategorized([300, 2000], leg_colors) legend = Legend(data, legend_par) assert legend.segment_colors == tuple(leg_colors) assert legend.value_colors == \ (Color(0, 0, 255), Color(0, 255, 0), Color(0, 255, 0), Color(0, 255, 0), Color(0, 255, 0), Color(255, 0, 0)) legend.legend_parameters.continuous_colors = True assert legend.value_colors == \ (Color(0, 0, 255), Color(0, 0, 255), Color(0, 60, 195), Color(0, 210, 45), Color(255, 0, 0), Color(255, 0, 0))
shade_mesh = join_geometry_to_mesh(context_) # mesh the context points = [from_point3d(center_pt3d)] view_vecs = [from_vector3d(pt) for pt in view_vecs] int_matrix, angles = intersect_mesh_rays(shade_mesh, points, view_vecs) context_pattern = [val == 0 for val in int_matrix[0]] apply_mask_to_sky(sky_pattern, context_pattern) # get the weights for each patch to be used in view factor calculation weights = view_sphere.dome_radial_patch_weights(az_count, alt_count) if direction is not None: weights = [ wgt * abs(math.cos(ang)) * 2 for wgt, ang in zip(weights, dir_angles) ] # create meshes for the masks and compute any necessary view factors gray, black = Color(230, 230, 230), Color(0, 0, 0) context_view, orient_view, strategy_view = 0, 0, 0 if context_pattern is not None: context_mask = mask_mesh_from_pattern(sky_mask, context_pattern, black) context_view = sum(wgt for wgt, is_viz in zip(weights, context_pattern) if is_viz) if orient_pattern is not None: orient_mask = mask_mesh_from_pattern(sky_mask, orient_pattern, black) orient_view = sum(wgt for wgt, is_viz in zip(weights, orient_pattern) if is_viz) if strategy_pattern is not None: strategy_mask = mask_mesh_from_pattern(sky_mask, strategy_pattern, black) strategy_view = sum(wgt for wgt, is_viz in zip(weights, strategy_pattern) if is_viz) sky_mask = mask_mesh_from_pattern(sky_mask, sky_pattern, gray) sky_view = sum(wgt for wgt, is_viz in zip(weights, sky_pattern) if is_viz)
def test_to_from_dict(): """Test the to/from dict methods.""" color = Color(255, 0, 100) color_dict = color.to_dict() new_color = Color.from_dict(color_dict) assert new_color.to_dict() == color_dict
def black(): """Get a .NET black color object. Useful for things like default text.""" return Color(0, 0, 0, 255) return Color.Black