Exemple #1
0
def test_valid_string():
    """Test the valid_string method."""
    correct_str = '0.5 in. Gypsum Wall'
    incorrect_str = '0.5 in., Gypsum Wall'
    long_str = 'This is an exceptionally long text string that should never be used ' \
        'for the name of anything in EnergyPlus for whatever reason'

    assert valid_string(correct_str) == '0.5in.GypsumWall'
    assert valid_string(incorrect_str) == '0.5in.GypsumWall'
    with pytest.raises(AssertionError):
        valid_string(long_str)
Exemple #2
0
    def __init__(self,
                 name,
                 lower_limit=None,
                 upper_limit=None,
                 numeric_type='Continuous',
                 unit_type='Dimensionless'):
        """Initialize ScheduleTypeLimit.

        Args:
            name: Text string for schedule type name. Must be <= 100 characters.
                Can include spaces but special characters will be stripped out.
            lower_limit: An optional number for the lower limit for values in the
                schedule. If None, there will be no lower limit.
            upper_limit: An optional number for the upper limit for values in the
                schedule. If None, there will be no upper limit.
            numeric_type: Either one of two strings: 'Continuous' or 'Discrete'.
                The latter means that only integers are accepted as schedule values.
                Default: 'Continuous'.
            unit_type: Text for an EnergyPlus unit type, which will be used
                to assign units to the values in the schedule.  Note that this field
                is not used in the actual calculations of EnergyPlus.
                Default: 'Dimensionless'. Choose from the following options:
                'Dimensionless', 'Temperature', 'DeltaTemperature', 'PrecipitationRate',
                'Angle', 'ConvectionCoefficient', 'ActivityLevel', 'Velocity',
                'Capacity', 'Power', 'Availability', 'Percent', 'Control', 'Mode'
        """
        # process the name and limits
        self._name = valid_ep_string(name, 'schedule type name')
        self._lower_limit = float_in_range(lower_limit) if lower_limit is not \
            None else None
        self._upper_limit = float_in_range(upper_limit) if upper_limit is not \
            None else None
        if self._lower_limit is not None and self._upper_limit is not None:
            assert self._lower_limit <= self._upper_limit, 'ScheduleTypeLimit ' \
                'lower_limit must be less than upper_limit. {} > {}.'.format(
                    self._lower_limit, self._upper_limit)

        # process the numeric type
        self._numeric_type = numeric_type.capitalize() or 'Continuous'
        assert self._numeric_type in self.NUMERIC_TYPES, '"{}" is not an acceptable ' \
            'numeric type.  Choose from the following:\n{}'.format(
                numeric_type, self.NUMERIC_TYPES)

        # process the unit type and assign the ladybug data type and unit
        if unit_type is None:
            self._data_type, self._unit = self._default_lb_unit_type[
                'Dimensionless']
            self._unit_type = 'Dimensionless'
        else:
            clean_input = valid_string(unit_type).lower()
            for key in self.UNIT_TYPES:
                if key.lower() == clean_input:
                    unit_type = key
                    break
            else:
                raise ValueError(
                    'unit_type {} is not recognized.\nChoose from the '
                    'following:\n{}'.format(unit_type, self.UNIT_TYPES))
            self._data_type, self._unit = self._default_lb_unit_type[unit_type]
            self._unit_type = unit_type
Exemple #3
0
    def to_file(self, folder, name=None, hoys=None, mkdir=False):
        """Write matrix to a Radiance file.

        This method also writes the wea information to a .wea file.

        Args:
            folder: Target folder.
            name: File name.
            hoys: Optional list of hoys to filter the hours of the wea. If None,
                this object's wea will be used as-is. Note that you may not want
                to use this input if this object's wea is not annual since an
                exception will be raised if a given hoy is not found in the
                wea. (Default: None).
            mkdir: A boolean to note if the directory should be created if doesn't
                exist (default: False).

        Returns:
            Full path to the newly created file.
        """
        name = typing.valid_string(name) if name \
            else '%s.rad' % self.__class__.__name__.lower()
        # write wea file first
        wea_file = self.write_wea(folder, hoys=hoys)
        content = self.to_radiance(wea_file=os.path.split(wea_file)[-1])
        return futil.write_to_file_by_name(folder, name, '!' + content, mkdir)
Exemple #4
0
 def __init__(self, identifier):
     """Initialize base object."""
     self._identifier = valid_string(identifier,
                                     'dragonfly object identifier')
     self._display_name = self._identifier
     self._properties = None
     self._user_data = None
Exemple #5
0
    def to_file(self, folder='.', name=None, mkdir=False):
        """Write ground to a .ground Radiance file.

        Returns:
            Full path to the newly created file.
        """
        content = self.to_radiance() + '\n'
        name = typing.valid_string(name) if name else 'ground.rad'
        return futil.write_to_file_by_name(folder, name, content, mkdir)
Exemple #6
0
 def economizer_type(self, value):
     clean_input = valid_string(value).lower()
     for key in self.ECONOMIZER_TYPES:
         if key.lower() == clean_input:
             value = key
             break
     else:
         raise ValueError(
             'economizer_type {} is not recognized.\nChoose from the '
             'following:\n{}'.format(value, self.ECONOMIZER_TYPES))
     self._economizer_type = value
 def start_day_of_week(self, value):
     clean_input = valid_string(value).lower()
     for key in self.DAYS_OF_THE_WEEK:
         if key.lower() == clean_input:
             value = key
             break
     else:
         raise ValueError(
             'start_day_of_week {} is not recognized.\nChoose from the '
             'following:\n{}'.format(value, self.DAYS_OF_THE_WEEK))
     self._start_day_of_week = value
Exemple #8
0
 def calculation_method(self, value):
     clean_input = valid_string(value).lower()
     for key in self.CALCULATION_METHODS:
         if key.lower() == clean_input:
             value = key
             break
     else:
         raise ValueError(
             'calculation_method {} is not recognized.\nChoose from the '
             'following:\n{}'.format(value, self.CALCULATION_METHODS))
     self._calculation_method = value
Exemple #9
0
 def solar_distribution(self, value):
     clean_input = valid_string(value).lower()
     for key in self.SOLAR_DISTRIBUTIONS:
         if key.lower() == clean_input:
             value = key
             break
     else:
         raise ValueError(
             'solar_distribution {} is not recognized.\nChoose from the '
             'following:\n{}'.format(value, self.SOLAR_DISTRIBUTIONS))
     self._solar_distribution = value
Exemple #10
0
 def economizer_type(self, value):
     clean_input = valid_string(value).lower()
     for key in self.ECONOMIZER_TYPES:
         if key.lower() == clean_input:
             value = key
             break
     else:
         raise ValueError(
             'economizer_type {} is not recognized.\nChoose from the '
             'following:\n{}'.format(value, self.ECONOMIZER_TYPES))
     if value != 'Inferred':
         assert self._has_air_loop, \
             'HVAC system must have an air loop to assign an economizer.'
     self._economizer_type = value
Exemple #11
0
    def to_file(self, folder, name=None, mkdir=False):
        """Write sky hemisphere to a sky_hemisphere.rad Radiance file.
        Args:
            folder: Target folder.
            name: File name.
            mkdir: A boolean to note if the directory should be created if doesn't
                exist (default: False).

        Returns:
            Full path to the newly created file.
        """
        content = self.to_radiance()
        name = typing.valid_string(name) if name else 'skydome.rad'
        return futil.write_to_file_by_name(folder, name, content, mkdir)
    def to_file(self, folder, name=None, mkdir=False):
        """Write sky hemisphere to a sky_hemisphere.rad Radiance file.

        Args:
            folder: Target folder.
            name: File name.
            mkdir: A boolean to note if the directory should be created if doesn't
                exist (default: False).

        Returns:
            Full path to the newly created file.
        """
        content = self.to_radiance()
        name = typing.valid_string(name) if name \
            else '%.3f_%.3f_%d_%d.sky' % (
                self.altitude, self.azimuth,
                self.direct_normal_irradiance, self.diffuse_horizontal_irradiance
        )
        return futil.write_to_file_by_name(folder, name, content, mkdir)
Exemple #13
0
    def __init__(self,
                 identifier,
                 lower_limit=no_limit,
                 upper_limit=no_limit,
                 numeric_type='Continuous',
                 unit_type='Dimensionless'):
        """Initialize ScheduleTypeLimit."""
        # process the identifier and limits
        self._identifier = valid_ep_string(identifier,
                                           'schedule type identifier')
        self._display_name = None
        self._lower_limit = float_in_range(lower_limit) if lower_limit is not \
            None and lower_limit != no_limit else no_limit
        self._upper_limit = float_in_range(upper_limit) if upper_limit is not \
            None and upper_limit != no_limit else no_limit
        if self._lower_limit != no_limit and self._upper_limit != no_limit:
            assert self._lower_limit <= self._upper_limit, 'ScheduleTypeLimit ' \
                'lower_limit must be less than upper_limit. {} > {}.'.format(
                    self._lower_limit, self._upper_limit)

        # process the numeric type
        self._numeric_type = numeric_type.capitalize() or 'Continuous'
        assert self._numeric_type in self.NUMERIC_TYPES, '"{}" is not an acceptable ' \
            'numeric type.  Choose from the following:\n{}'.format(
                numeric_type, self.NUMERIC_TYPES)

        # process the unit type and assign the ladybug data type and unit
        if unit_type is None:
            self._data_type, self._unit = self._default_lb_unit_type[
                'Dimensionless']
            self._unit_type = 'Dimensionless'
        else:
            clean_input = valid_string(unit_type).lower()
            for key in self.UNIT_TYPES:
                if key.lower() == clean_input:
                    unit_type = key
                    break
            else:
                raise ValueError(
                    'unit_type {} is not recognized.\nChoose from the '
                    'following:\n{}'.format(unit_type, self.UNIT_TYPES))
            self._data_type, self._unit = self._default_lb_unit_type[unit_type]
            self._unit_type = unit_type
 def room_identifier(self, n):
     self._room_identifier = typing.valid_string(n)
Exemple #15
0
 def identifier(self, value):
     self._identifier = valid_string(value, 'dragonfly object identifier')