<jupyter_start><jupyter_text>Small consumer 2-zone testGenerators use 1980-2017 using 1-system planned capacities<jupyter_code># Suppress minor warnings
import warnings
warnings.filterwarnings('ignore')
import calliope
import models
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Read in National grid planning output (full 1980-2017)From timeseries calculate mean and standard deviation of demand.Change back from negative convention (calliope) to positive demand convention (readable)<jupyter_code># read csv
df = pd.read_csv('outputs_plan_national-grid-full/inputs_resource.csv',
                 usecols=['timesteps', 'resource', 'techs'], index_col='timesteps')
# split demand / wind /solar into 3 separate columns
national_demand_index = pd.to_datetime(df[df['techs'] == 'demand_power'].index)
national_demand = pd.DataFrame(dict(), index=national_demand_index)
national_demand['demand'] = - df[df['techs'] == 'demand_power']['resource']
national_demand['wind'] = df[df['techs'] == 'wind']['resource']
national_demand['solar'] = df[df['techs'] == 'solar']['resource']
del df
national_demand_stats = mean, std = [stat(national_demand.demand) for stat in [np.mean, np.std]]<jupyter_output><empty_output><jupyter_text>Generate a random timeseries (simulated zone 2 demand)form with similar overall mean/stddev to UK wide demand (scaled to 1%), ensure no negative values<jupyter_code># ensure always using the same seed (which we obtained one-off using RNG)
np.random.seed(285183912)

# normal distribution parameters = 1% National Grid mean/std dev.
normal_dist = [stat*0.01 for stat in national_demand_stats]

# Sample from normal distribution
demand_region2 = np.random.normal(*normal_dist, len(national_demand))

# Force positives (very minute chance of this occuring...)
demand_region2[demand_region2 < 0] = 0
demand_region2<jupyter_output><empty_output><jupyter_text>Load secondary zone demand into a DataFrameAllows easy loading into ts_data<jupyter_code>df_region2 = pd.DataFrame({'demand_region2': demand_region2},
                          index=pd.to_datetime(national_demand.index))<jupyter_output><empty_output><jupyter_text>`operational` Calliope 2-zone model (with infinite diesel cap)Note: can shrink operational range to subset, eg. 2017 year only<jupyter_code>date_start, date_end = '1980', '2017'
# Import timeseries data demand / wind (as in 1_region)
ts_data = models.load_time_series_data('2_region', additional_data=df_region2)

# Crop to date range
ts_data = ts_data.loc[date_start:date_end]

display(ts_data.head(6))
# Read in generation capacities
generation_capacities_planned = pd.read_csv('outputs_plan_national-grid-full/results_energy_cap.csv')

# Rename techs
generation_capacities = dict()
for tech, cap in zip(generation_capacities_planned['techs'],
                     generation_capacities_planned['energy_cap']):
    if tech not in ['unmet', 'demand_power']:
        key = f'cap_{tech}_region1'
        generation_capacities[key] = cap

# Insert diesel generators, transmission capacity = max possible region2 demand
generation_capacities['cap_generators_region2'] = max(ts_data['demand_region2'])
generation_capacities['cap_transmission_region1_region2'] = max(ts_data['demand_region2'])

# Display
display(generation_capacities)<jupyter_output><empty_output><jupyter_text>Generation capacities to trial (-0, -2, -4, -6, -8, -10) %<jupyter_code># percentage generation capacity reduction to trial
trial_percents = [0,2,4,6,8,10]
# convert into generation_capacity dict
gen_cap_trials = {p: {tech: cap if 'region2' in tech else cap*(1-p/100)
                      for tech, cap in generation_capacities.items()}
                  for p in trial_percents}
# define each trial model
print('defining models:')
trial_models = {p: models.TwoRegionModel(ts_data, 'operate', fixed_caps=caps)
                for p, caps in gen_cap_trials.items()}

# run each trial model
for p, model in trial_models.items():
    print(f'running model {p}')
    model.run()
# Export all model outputs to CSV (creates directory called 'outputs_operate')
output_folder = 'outputs_operational_two-zone_exp-2'
models.rm_folder(output_folder)
model.to_csv(output_folder)
# Generate HTML plots
for var in ['power', 'cost_var', 'resource']:
    plot_html = model.plot.timeseries(array=var, html_only=True)
    models.save_html(plot_html, f'plots/operate_2_{var}.html', f'{var} plot')
import IPython; IPython.embed()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10971024109710241, 'fraction_numerical': 0.019464720194647202, 'mean_word_length': 5.978395061728395, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '268639', 'license': 'MIT', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1408, 'n_words': 362, 'path': 'experiment 2.ipynb', 'repo_name': 'jfallon1997/renewable_test_PSMs', 'size': '4521'}