Skip to content

Commit

Permalink
updating load and renewable generation with new numpy random generator
Browse files Browse the repository at this point in the history
  • Loading branch information
marota committed Mar 24, 2022
1 parent 3860769 commit 89ffd68
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
14 changes: 7 additions & 7 deletions chronix2grid/generation/consumption/consumption_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def compute_residential(locations, Pmax, temperature_noise, params, weekly_patte
nb_sec_per_day = 24. * 60. * 60.
nb_sec_per_year = (365. * nb_sec_per_day)
year_pattern = 2. * np.pi / nb_sec_per_year
#seasonal_pattern = 1.5 / 7. * np.cos(year_pattern * (t + start_min - 45 * nb_sec_per_day)) # min of the load is 15 of February so 45 days after beginning of year
seasonal_pattern = 1.5 / 7. * np.cos(year_pattern * (t - start_min - 30 * nb_sec_per_day))
seasonal_pattern = 1.5 / 7. * np.cos(year_pattern * (t + start_min - 45 * nb_sec_per_day)) # min of the load is 15 of February so 45 days after beginning of year
#seasonal_pattern = 1.5 / 7. * np.cos(year_pattern * (t - start_min - 30 * nb_sec_per_day)) #older version to be removed
seasonal_pattern += 5.5 / 7.

# Get weekly pattern
Expand Down Expand Up @@ -142,11 +142,11 @@ def create_csv(prng, dict_, path, forecasted=False, reordering=True, noise=None,

df_reactive_power = 0.7 * df
if noise is not None:
#df *= prng.lognormal(mean=0.0,sigma=noise, size=df.shape)
df *= np.random.lognormal(mean=0.0, sigma=noise, size=df.shape)
#df_reactive_power *= prng.lognormal(mean=0.0, sigma=noise, size=df.shape)
df_reactive_power *= np.random.lognormal(mean=0.0, sigma=noise,
size=df.shape)
df *= prng.lognormal(mean=0.0,sigma=noise, size=df.shape)
#df *= np.random.lognormal(mean=0.0, sigma=noise, size=df.shape) #older version to be removed
df_reactive_power *= prng.lognormal(mean=0.0, sigma=noise, size=df.shape)
#df_reactive_power *= np.random.lognormal(mean=0.0, sigma=noise,
# size=df.shape) #older version to be removed

if write_results:
file_extension = '_forecasted' if forecasted else ''
Expand Down
4 changes: 2 additions & 2 deletions chronix2grid/generation/consumption/generate_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main(scenario_destination_path, seed, params, loads_charac, load_weekly_patt

# Set random seed of scenario
prng = default_rng(seed)
np.random.seed(seed)
#np.random.seed(seed) #older version - to be removed

# Define reference datetime indices
datetime_index = pd.date_range(
Expand All @@ -57,7 +57,7 @@ def main(scenario_destination_path, seed, params, loads_charac, load_weekly_patt
y_plus = int(y // dy_corr + 1)
add_dim = max(y_plus, add_dim)
add_dim = max(x_plus, add_dim)
add_dim=0
#add_dim=0 #to get back to when this parameter did not exist - to be removed

# Generate GLOBAL temperature noise
print('Computing global auto-correlated spatio-temporal noise for thermosensible demand...') ## temperature is simply to reflect the fact that loads is correlated spatially, and so is the real "temperature". It is not the real temperature.
Expand Down
4 changes: 2 additions & 2 deletions chronix2grid/generation/generation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def generate_coarse_noise(prng, params, data_type, add_dim):
Nt_comp = int(T // dt_corr + 1) + add_dim

# Generate gaussian noise input·
output = np.random.normal(0, 1, (Nx_comp, Ny_comp, Nt_comp))
#output = prng.normal(0, 1, (Nx_comp, Ny_comp, Nt_comp))
#output = np.random.normal(0, 1, (Nx_comp, Ny_comp, Nt_comp))
output = prng.normal(0, 1, (Nx_comp, Ny_comp, Nt_comp))

return output

Expand Down
6 changes: 1 addition & 5 deletions chronix2grid/generation/renewable/generate_solar_wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main(scenario_destination_path, seed, params, prods_charac, solar_pattern, w
"""

prng = default_rng(seed)
np.random.seed(seed)
#np.random.seed(seed) #olver version - to be removed
smoothdist = params['smoothdist']

# Define datetime indices
Expand Down Expand Up @@ -81,10 +81,6 @@ def main(scenario_destination_path, seed, params, prods_charac, solar_pattern, w
add_dim = max(y_plus, add_dim)
add_dim = max(x_plus, add_dim)

##########
#Getting back to old model
add_dim=0
##########
solar_noise = utils.generate_coarse_noise(prng, params, 'solar', add_dim=add_dim)
long_scale_wind_noise = utils.generate_coarse_noise(prng, params, 'long_wind', add_dim=add_dim)
medium_scale_wind_noise = utils.generate_coarse_noise(prng, params, 'medium_wind', add_dim=add_dim)
Expand Down
16 changes: 8 additions & 8 deletions chronix2grid/generation/renewable/solar_wind_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def compute_wind_series(prng, locations, Pmax, long_noise, medium_noise, short_n
signal = (0.7 + 0.3 * seasonal_pattern) * (0.3 + std_medium_wind_noise * medium_scale_signal + std_long_wind_noise * long_scale_signal)
signal += std_short_wind_noise * short_scale_signal
signal = 1e-1 * np.exp(4 * signal)
# signal += prng.uniform(0, SMOOTHDIST/Pmax, signal.shape)
#signal += prng.uniform(0, smoothdist, signal.shape)
signal += np.random.uniform(0, smoothdist, signal.shape)
#signal += prng.uniform(0, SMOOTHDIST/Pmax, signal.shape)
signal += prng.uniform(0, smoothdist, signal.shape)
#signal += np.random.uniform(0, smoothdist, signal.shape) #older version - to be removed

# signal *= 0.95
signal[signal < 0.] = 0.
Expand Down Expand Up @@ -80,14 +80,14 @@ def compute_solar_series(prng, locations, Pmax, solar_noise, params, solar_patte
mean_solar_pattern = 0.75

signal = solar_pattern * (mean_solar_pattern + std_solar_noise * final_noise)
# signal += prng.uniform(0, smoothdist/Pmax, signal.shape)
signal += np.random.uniform(0, smoothdist / Pmax, signal.shape)
#signal += prng.uniform(0, smoothdist/Pmax, signal.shape) #to be revised: since smmothdist/PMax is very small, the added noise compared to the previous sinal was unsignificant
#signal += np.random.uniform(0, smoothdist / Pmax, signal.shape) #older version - to be removed
# signal[signal > 1] = 1
signal[signal < 0.] = 0.
signal = smooth(signal)
solar_series = Pmax * signal
# solar_series[np.isclose(solar_series, 0.)] = 0
#solar_series[solar_series > 0.95 * Pmax] = 0.95 * Pmax
solar_series[solar_series > 0.95 * Pmax] = 0.95 * Pmax
return solar_series

def compute_solar_pattern(params, solar_pattern):
Expand Down Expand Up @@ -178,8 +178,8 @@ def create_csv(prng, dict_, path, reordering=True, noise=None, shift=False,
new_ordering = [x for _ ,x in sorted(zip(value ,list(df)))]
df = df[new_ordering]
if noise is not None:
#df *= ( 1 +noise * prng.normal(0, 1, df.shape))
df *= (1 + noise * np.random.normal(0, 1, df.shape))
df *= ( 1 +noise * prng.normal(0, 1, df.shape))
#df *= (1 + noise * np.random.normal(0, 1, df.shape)) #older version - to be removed
if shift:
df = df.shift(-1)
df = df.fillna(0)
Expand Down

0 comments on commit 89ffd68

Please sign in to comment.