예제 #1
0
파일: sunpath.py 프로젝트: sariths/ladybug
    def draw_sunpath(self,
                     hoys=None,
                     origin=None,
                     scale=1, sun_scale=1, annual=True, rem_night=True):
        """Create sunpath geometry. \
        This method should only be used from the + libraries.

        Args:
            hoys: An optional list of hours of the year(default: None).
            origin: Sunpath origin(default: (0, 0, 0)).
            scale: Sunpath scale(default: 1).
            sun_scale: Scale for the sun spheres(default: 1).
            annual: Set to True to draw an annual sunpath.
                Otherwise a daily sunpath is drawn.
            rem_night: Remove suns which are under the horizon(night!).
        Returns:
            base_curves: A collection of curves for base plot.
            analemma_curves: A collection of analemma_curves.
            daily_curves: A collection of daily_curves.
            suns: A list of suns.
        """
        # check and make sure the call is coming from inside a plus library
        assert ladybug.isplus, \
            '"draw_sunpath" method can only be used in the [+] libraries.'
        hoys = hoys or ()
        origin = origin or (0, 0, 0)
        try:
            origin = tuple(origin)
        except TypeError as e:
            # dynamo
            try:
                origin = origin.X, origin.Y, origin.Z
            except AttributeError:
                raise TypeError(str(e))

        scale = scale or 1
        sun_scale = sun_scale or 1
        assert annual or hoys, 'For daily sunpath you need to provide at least one hour.'

        radius = 200 * scale

        # draw base circles and lines
        base_curves = plus.base_curves(origin, radius, self.north_angle)
        # draw analemma
        # calculate date times for analemma curves
        if annual:
            asuns = self._analemma_suns()
            analemma_curves = plus.analemma_curves(asuns, origin, radius)
        else:
            analemma_curves = ()

        # add sun spheres
        if hoys:
            suns = tuple(self.calculate_sun_from_hoy(hour) for hour in hoys)
        else:
            suns = ()

        if rem_night:
            suns = tuple(sun for sun in suns if sun.is_during_day)

        sun_geos = plus.sun_geometry(suns, origin, radius)

        # draw daily sunpath
        if annual:
            dts = (DateTime(m, 21) for m in xrange(1, 13))
        else:
            dts = (sun.datetime for sun in suns)

        dsuns = self._daily_suns(dts)
        daily_curves = plus.daily_curves(dsuns, origin, radius)

        SPGeo = namedtuple(
            'SunpathGeo',
            ('compass_curves',
             'analemma_curves',
             'daily_curves',
             'suns',
             'sun_geos'))

        # return outputs
        return SPGeo(base_curves, analemma_curves, daily_curves, suns, sun_geos)
예제 #2
0
파일: sunpath.py 프로젝트: ocni-dtu/ladybug
    def draw_sunpath(self,
                     hoys=None,
                     origin=None,
                     scale=1,
                     sun_scale=1,
                     annual=True,
                     rem_night=True):
        """Create sunpath geometry. \
        This method should only be used from the + libraries.

        Args:
            hoys: An optional list of hours of the year(default: None).
            origin: Sunpath origin(default: (0, 0, 0)).
            scale: Sunpath scale(default: 1).
            sun_scale: Scale for the sun spheres(default: 1).
            annual: Set to True to draw an annual sunpath.
                Otherwise a daily sunpath is drawn.
            rem_night: Remove suns which are under the horizon(night!).
        Returns:
            base_curves: A collection of curves for base plot.
            analemma_curves: A collection of analemma_curves.
            daily_curves: A collection of daily_curves.
            suns: A list of suns.
        """
        # check and make sure the call is coming from inside a plus library
        assert ladybug.isplus, \
            '"draw_sunpath" method can only be used in the [+] libraries.'
        hoys = hoys or ()
        origin = origin or (0, 0, 0)
        try:
            origin = tuple(origin)
        except TypeError as e:
            # dynamo
            try:
                origin = origin.X, origin.Y, origin.Z
            except AttributeError:
                raise TypeError(str(e))

        scale = scale or 1
        sun_scale = sun_scale or 1
        assert annual or hoys, 'For daily sunpath you need to provide at least one hour.'

        radius = 200 * scale

        # draw base circles and lines
        base_curves = plus.base_curves(origin, radius, self.north_angle)
        # draw analemma
        # calculate date times for analemma curves
        if annual:
            asuns = self._analemma_suns()
            analemma_curves = plus.analemma_curves(asuns, origin, radius)
        else:
            analemma_curves = ()

        # add sun spheres
        if hoys:
            suns = tuple(self.calculate_sun_from_hoy(hour) for hour in hoys)
        else:
            suns = ()

        if rem_night:
            suns = tuple(sun for sun in suns if sun.is_during_day)

        sun_geos = plus.sun_geometry(suns, origin, radius)

        # draw daily sunpath
        if annual:
            dts = (DateTime(m, 21) for m in range(1, 13))
        else:
            dts = (sun.datetime for sun in suns)

        dsuns = self._daily_suns(dts)
        daily_curves = plus.daily_curves(dsuns, origin, radius)

        SPGeo = namedtuple('SunpathGeo', ('compass_curves', 'analemma_curves',
                                          'daily_curves', 'suns', 'sun_geos'))

        # return outputs
        return SPGeo(base_curves, analemma_curves, daily_curves, suns,
                     sun_geos)