Ejemplo n.º 1
0
def create_variable_weather(
        weather_data: WeatherData,
        original_epw_file: str,
        columns: List[str] = ['drybulb'],
        variation: Optional[Tuple[float, float,
                                  float]] = None) -> Optional[str]:
    """Create a new weather file using Ornstein-Uhlenbeck process.

    Args:
        weather_data (opyplus.WeatherData): Opyplus object with the weather for the simulation.
        original_epw_file (str): Path to the original EPW file.
        columns (list, optional): List of columns to be affected. Defaults to ['drybulb'].
        variation (tuple, optional): Tuple with the sigma, mean and tau for OU process. Defaults to None.

    Returns:
        str: Name of the file created in the same location as the original one.

    """

    if variation is None:
        return None
    else:
        # Get dataframe with weather series
        df = weather_data.get_weather_series()

        sigma = variation[0]  # Standard deviation.
        mu = variation[1]  # Mean.
        tau = variation[2]  # Time constant.

        T = 1.  # Total time.
        # All the columns are going to have the same num of rows since they are
        # in the same dataframe
        n = len(df[columns[0]])
        dt = T / n
        # t = np.linspace(0., T, n)  # Vector of times.

        sigma_bis = sigma * np.sqrt(2. / tau)
        sqrtdt = np.sqrt(dt)

        x = np.zeros(n)

        # Create noise
        for i in range(n - 1):
            x[i + 1] = x[i] + dt * (-(x[i] - mu) / tau) + \
                sigma_bis * sqrtdt * np.random.randn()

        for column in columns:
            # Add noise
            df[column] += x

        # Save new weather data
        weather_data.set_weather_series(df)
        filename = original_epw_file.split('.epw')[0]
        filename += '_Random_%s_%s_%s.epw' % (str(sigma), str(mu), str(tau))
        weather_data.to_epw(filename)
        return filename
Ejemplo n.º 2
0
    def test_weather_series(self):
        # create weather data
        weather_data0 = WeatherData.load(Resources.Epw.san_fransisco_tmy3)

        # create new epw
        epw1 = weather_data0.save()
        weather_data1 = WeatherData.load(io.StringIO(epw1))

        # check
        assert_frame_equal(weather_data0.get_weather_series(),
                           weather_data1.get_weather_series())
Ejemplo n.º 3
0
    def __init__(
            self,
            idf_path: str,
            weather_path: str,
            env_name: str,
            max_ep_store: int,
            extra_config: Dict[str, Any]):

        self._idf_path = idf_path
        self._weather_path = weather_path
        # DDY path is deducible using weather_path (only change .epw by .ddy)
        self._ddy_path = self._weather_path.split('.epw')[0] + '.ddy'
        self.experiment_path = self.set_experiment_working_dir(env_name)
        self.episode_path = None
        self.max_ep_store = max_ep_store

        self.config = extra_config

        # Opyplus objects
        self._idd = Idd(os.path.join(os.environ['EPLUS_PATH'], 'Energy+.idd'))
        self.building = Epm.from_idf(
            self._idf_path,
            idd_or_version=self._idd,
            check_length=False)
        self.ddy_model = Epm.from_idf(
            self._ddy_path,
            idd_or_version=self._idd,
            check_length=False)
        self.weather_data = WeatherData.from_epw(self._weather_path)
Ejemplo n.º 4
0
    def get_in_weather_data(self):
        """
        Get simulation input WeatherData (epw).

        Returns
        -------
        WeatherData
        """
        return WeatherData.load(self.get_resource_path(ResourcesRefs.epw))
Ejemplo n.º 5
0
    def test_datetime_index(self):
        with open(Resources.Epw.san_fransisco_tmy3) as f:
            sf_content = f.read()

        # create weather data and create datetime instants
        wd = WeatherData.load(io.StringIO(sf_content))
        wd.create_datetime_instants(start_year=2013)

        # generate epws with and without datetimes
        with_datetimes = wd.to_epw()
        without_datetimes = wd.to_epw(use_datetimes=False)

        # check coherence with initial

        # without datetimes
        sf_diff, other_diff = compare_sf(sf_content, without_datetimes)
        self.assertEqual(sf_diff, other_diff)

        # with datetimes
        sf_diff, other_diff = compare_sf(sf_content,
                                         with_datetimes,
                                         datetimes_where_used=True)
        self.assertEqual(sf_diff, other_diff)
Ejemplo n.º 6
0
    def from_inputs(cls,
                    base_dir_path,
                    epm_or_buffer_or_path,
                    weather_data_or_buffer_or_path,
                    simulation_name=None):
        """
        Create a simulation from input data: Epm (idf) and WeatherData (epw).

        Parameters
        ----------
        base_dir_path: str
        epm_or_buffer_or_path: Epm or str or typing.StringIO
        weather_data_or_buffer_or_path: WeatherData or str or typing.StringIO
        simulation_name: str

        Returns
        -------
        Simulation
        """
        # create dir if needed
        dir_path = base_dir_path if simulation_name is None else os.path.join(
            base_dir_path, simulation_name)
        if not os.path.isdir(dir_path):
            os.mkdir(dir_path)

        # check empty
        if len(os.listdir(dir_path)) > 0:
            logger.warning(
                f"called Simulation.from_input on a simulation directory that is not empty ({dir_path})"
            )

        # epm
        epm_path_was_given = False
        if isinstance(epm_or_buffer_or_path, Epm):
            epm = epm_or_buffer_or_path
        else:
            if isinstance(epm_or_buffer_or_path,
                          str) and os.path.isfile(epm_or_buffer_or_path):
                epm_path_was_given = True
            epm = Epm.load(
                epm_or_buffer_or_path
            )  # we load epm (even if we will copy input file) to read e+ version

        # weather data
        weather_data, weather_data_path_was_given = None, False
        if isinstance(weather_data_or_buffer_or_path, WeatherData):
            weather_data = weather_data_or_buffer_or_path
        elif isinstance(
                weather_data_or_buffer_or_path,
                str) and os.path.isfile(weather_data_or_buffer_or_path):
            weather_data_path_was_given = True
        else:
            weather_data = WeatherData.load(weather_data_or_buffer_or_path)

        # find eplus version
        eplus_version = _get_eplus_version(epm)

        # store simulation inputs
        # idf
        simulation_epm_path = get_opyplus_path(dir_path, ResourcesRefs.idf)
        if epm_path_was_given:
            shutil.copy2(epm_or_buffer_or_path, simulation_epm_path)
        else:
            epm.save(simulation_epm_path)
        # epw
        simulation_weather_data_path = get_opyplus_path(
            dir_path, ResourcesRefs.epw)
        if weather_data_path_was_given:
            shutil.copy2(weather_data_or_buffer_or_path,
                         simulation_weather_data_path)
        else:
            weather_data.save(simulation_weather_data_path)

        # store info
        info = Info(EMPTY, eplus_version)
        info.to_json(get_opyplus_path(dir_path, ResourcesRefs.info))

        # create and return simulation
        return cls(base_dir_path, simulation_name=simulation_name)
Ejemplo n.º 7
0
def weather_data(weather_path):
    return WeatherData.from_epw(weather_path)