Exemple #1
0
def test_segment_shaded_length(shade_collections):
    """Test that calculation of shaded length is correct"""
    illum_col, shaded_col = shade_collections
    seg_1 = PVSegment(illum_collection=illum_col)
    assert seg_1.shaded_length == 0
    seg_2 = PVSegment(shaded_collection=shaded_col)
    assert seg_2.shaded_length == 1
Exemple #2
0
def test_pvsegment_setter(shade_collections):
    """Test that pv segment collection updates correctly"""
    illum_col, shaded_col = shade_collections
    seg = PVSegment()
    assert seg.length == 0
    seg.illum_collection = illum_col
    assert seg.length == 1
    seg.shaded_collection = shaded_col
    assert seg.length == 2
Exemple #3
0
    def at(self, idx):
        """Generate a PV segment geometry for the desired index.

        Parameters
        ----------
        idx : int
            Index to use to generate PV segment geometry

        Returns
        -------
        segment : :py:class:`~pvfactors.geometry.base.PVSegment`
        """
        # Create illum collection
        illum_surface = self.illum.at(idx, shaded=False)
        list_illum_surfaces = [] if illum_surface.is_empty \
            else [illum_surface]
        illum_collection = ShadeCollection(
            list_surfaces=list_illum_surfaces, shaded=False,
            param_names=None)
        # Create shaded collection
        shaded_surface = self.shaded.at(idx, shaded=True)
        list_shaded_surfaces = [] if shaded_surface.is_empty \
            else [shaded_surface]
        shaded_collection = ShadeCollection(
            list_surfaces=list_shaded_surfaces, shaded=True,
            param_names=None)
        # Create PV segment
        segment = PVSegment(illum_collection=illum_collection,
                            shaded_collection=shaded_collection,
                            index=self.index)
        return segment
Exemple #4
0
    def as_flat(cls,
                x_min_max=None,
                shaded=False,
                y_ground=Y_GROUND,
                surface_params=[]):
        """Build a horizontal flat ground surface, made of 1 PV segment.

        Parameters
        ----------
        x_min_max : tuple, optional
            List of minimum and maximum x coordinates for the flat surface [m]
            (Default = None)
        shaded : bool, optional
            Shaded status of the created PV surfaces (Default = False)
        y_ground : float, optional
            Location of flat ground on y axis in [m] (Default = Y_GROUND)
        surface_params : list of str, optional
            Names of the surface parameters, eg reflectivity, total incident
            irradiance, temperature, etc. (Default = [])
        """
        # Get ground boundaries
        if x_min_max is None:
            x_min, x_max = MIN_X_GROUND, MAX_X_GROUND
        else:
            x_min, x_max = x_min_max
        # Create PV segment for flat ground
        coords = [(x_min, y_ground), (x_max, y_ground)]
        seg = PVSegment.from_linestring_coords(coords,
                                               shaded=shaded,
                                               normal_vector=[0., 1.],
                                               surface_params=surface_params)
        return cls(list_segments=[seg], original_linestring=LineString(coords))
Exemple #5
0
def test_pvsegment_deleter(shade_collections):
    """Test that elements of pv segment collection get deleted
    correctly"""
    seg = PVSegment(*shade_collections)
    assert seg.length == 2
    del seg.shaded_collection
    assert seg.length == 1
    del seg.illum_collection
    assert seg.length == 0
Exemple #6
0
def test_cast_shadow_segment():
    """Test shadow casting on PVSegment"""
    seg = PVSegment.from_linestring_coords([(0, 0), (2, 0)],
                                           shaded=False,
                                           index=0)
    shadow = LineString([(0.5, 0), (1.5, 0)])
    seg.cast_shadow(shadow)

    assert seg.length == 2
    assert seg.shaded_length == 1
    assert seg.index == 0
Exemple #7
0
    def from_lists_surfaces(
            cls, list_shaded_surfaces, list_illum_surfaces, x_min_max=None,
            y_ground=Y_GROUND, param_names=None):
        """Create ground from lists of shaded and illuminated PV surfaces.

        Parameters
        ----------
        list_shaded_surfaces : \
        list of :py:class:`~pvfactors.geometry.base.PVSurface`
            List of shaded ground PV surfaces
        list_illum_surfaces : \
        list of :py:class:`~pvfactors.geometry.base.PVSurface`
            List of illuminated ground PV surfaces
        x_min_max : tuple, optional
            List of minimum and maximum x coordinates for the flat surface [m]
            (Default = None)
        y_ground : float, optional
            Location of flat ground on y axis in [m] (Default = Y_GROUND)
        param_names : list of str, optional
            Names of the surface parameters, eg reflectivity, total incident
            irradiance, temperature, etc. (Default = [])

        Returns
        -------
        PVGround object
        """
        param_names = param_names or []
        # Get ground boundaries
        if x_min_max is None:
            x_min, x_max = MIN_X_GROUND, MAX_X_GROUND
        else:
            x_min, x_max = x_min_max
        full_extent_coords = [(x_min, y_ground), (x_max, y_ground)]

        # Create the shade collections
        shaded_collection = ShadeCollection(
            list_surfaces=list_shaded_surfaces, shaded=True,
            param_names=param_names)
        illum_collection = ShadeCollection(
            list_surfaces=list_illum_surfaces, shaded=False,
            param_names=param_names)

        # Create the ground segment
        segment = PVSegment(illum_collection=illum_collection,
                            shaded_collection=shaded_collection)

        return cls(list_segments=[segment],
                   original_linestring=LineString(full_extent_coords))
Exemple #8
0
    def at(self, idx):
        """Generate a PV segment geometry for the desired index.

        Parameters
        ----------
        idx : int
            Index to use to generate PV segment geometry

        Returns
        -------
        segment : :py:class:`~pvfactors.geometry.base.PVSegment`
        """
        # Create illum collection
        illum_collection = self.illum.at(idx)
        # Create shaded collection
        shaded_collection = self.shaded.at(idx)
        # Create PV segment
        segment = PVSegment(illum_collection=illum_collection,
                            shaded_collection=shaded_collection,
                            index=self.index)
        return segment
Exemple #9
0
def test_cast_shadow_segment_precision_error():
    """Test shadow casting on PVSegment when using inexact projection.
    In shapely, need to use ``buffer`` method for the intersection to be
    calculated correctly
    """
    coords = [(0, 0), (3, 2)]
    seg = PVSegment.from_linestring_coords(coords, shaded=False, index=0)
    # Project point on line
    pt = Point(0, 2)
    line = seg.illum_collection.list_surfaces[0]  # LineString(coords)
    vector = [1, -1]
    proj = projection(pt, vector, line)
    # Use result of projection to create shadow
    shadow = LineString([Point(0, 0), proj])
    seg.cast_shadow(shadow)

    np.testing.assert_almost_equal(seg.length, 3.60555127546)
    np.testing.assert_almost_equal(seg.shaded_collection.length, 1.44222051019)
    assert len(seg.shaded_collection.list_surfaces) == 1
    assert len(seg.illum_collection.list_surfaces) == 1
    np.testing.assert_almost_equal(
        seg.shaded_collection.list_surfaces[0].length, 1.44222051019)
    np.testing.assert_almost_equal(
        seg.illum_collection.list_surfaces[0].length, 2.1633307652783933)
Exemple #10
0
def pvsegments(shade_collections):
    seg_1 = PVSegment(illum_collection=shade_collections[0])
    seg_2 = PVSegment(shaded_collection=shade_collections[1])
    yield seg_1, seg_2
Exemple #11
0
    def from_ordered_shadow_and_cut_pt_coords(cls,
                                              x_min_max=None,
                                              y_ground=Y_GROUND,
                                              ordered_shadow_coords=[],
                                              cut_point_coords=[],
                                              param_names=[],
                                              shaded_params={},
                                              illum_params={}):
        """Build a horizontal flat ground surface, made of 1 PVSegment with
        shaded areas and "cut points" (reference points used in view factor
        calculations)

        Parameters
        ----------
        x_min_max : tuple, optional
            List of minimum and maximum x coordinates for the flat surface [m]
            (Default = None)
        y_ground : float, optional
            Location of flat ground on y axis in [m] (Default = Y_GROUND)
        ordered_shadow_coords : list, optional
            List of shadow coordinates, ordered from left to right.
            Shape = (# of shadows, 2 {# of points}, 2 {for xy coords})
            (Default = [])
        cut_point_coords : list, optional
            List of cut point coordinates, ordered from left to right.
            Shape = (# of cut points, 2 {# of points}, 2 {for xy coords})
            (Default = [])
        param_names : list of str, optional
            Names of the surface parameters, eg reflectivity, total incident
            irradiance, temperature, etc. (Default = [])
        shaded_params : dict, optional
            Dictionary of parameter values for shaded surfaces
            (Default = {})
        illum_params : dict, optional
            Dictionary of parameter values for illuminated surfaces
            (Default = {})

        Returns
        -------
        PVGround object
            PV ground with shadows, illuminated ground, and cut points
        """
        # Get ground boundaries
        if x_min_max is None:
            x_min, x_max = MIN_X_GROUND, MAX_X_GROUND
        else:
            x_min, x_max = x_min_max
        full_extent_coords = [(x_min, y_ground), (x_max, y_ground)]

        # Create the list of illuminated and shaded PV surfaces
        list_shaded_surfaces = []
        list_illum_surfaces = []
        recurse_on_cut_points(list_shaded_surfaces, list_illum_surfaces,
                              ordered_shadow_coords, cut_point_coords, x_min,
                              x_max, y_ground, param_names, shaded_params,
                              illum_params)
        # Create the shade collections
        shaded_collection = ShadeCollection(list_surfaces=list_shaded_surfaces,
                                            shaded=True,
                                            param_names=param_names)
        illum_collection = ShadeCollection(list_surfaces=list_illum_surfaces,
                                           shaded=False,
                                           param_names=param_names)

        # Create the ground segment
        segment = PVSegment(illum_collection=illum_collection,
                            shaded_collection=shaded_collection)

        return cls(list_segments=[segment],
                   original_linestring=LineString(full_extent_coords))