Пример #1
0
## input data
file_profiles      = join(mypath, 'load_profiles_DK.csv')
file_spot_prices   = join(mypath, 'elspotprices.csv')

## output files for results
file_normed_assets       = join(mypath, 'normed_assets.json')
file_scaling_assets      = join(mypath, 'scaling_assets.json')
file_vol_matching_assets = join(mypath, 'vol_matching_assets.json')
file_timegrid            = join(mypath, 'timegrid.json')
file_prices              = join(mypath, 'prices.json')


###############################################   create helpers 
print('create timegrid and nodes')
timegrid = Timegrid(start = Start, end = End, freq = freq, main_time_unit= 'h')
to_json(timegrid, file_timegrid)
node_green = Node('green sources', commodity= 'power', unit = Unit('MWh', 'MW',  1.))
node_grey  = Node('grey sources', commodity= 'power', unit = Unit('MWh', 'MW',  1.))
node_load  = Node('client', commodity= 'power', unit = Unit('MWh', 'MW',  1.))

###############################################   import data
print('import load profiles and prices')
df_profiles = pd.read_csv(file_profiles)
df_profiles.index = pd.to_datetime(df_profiles['HourUTC'], format='%Y-%m-%dT%H')
df_profiles.sort_index(inplace = True)
# filter for only DK1 price area and time grid
df_profiles = df_profiles.loc[df_profiles['PriceArea'] == 'DK1', ['OnshoreWindPower', 'OffshoreWindPower', 'SolarPower', 'TotalLoad']]
df_profiles = df_profiles.loc[Start:End]
# omit last
df_profiles = df_profiles.iloc[:-1]
# import prices
Пример #2
0
    def test_serialize_portfolio(self):
        """ Unit test serialize portfolio
        """

        node1 = eao.assets.Node('node_1')
        node2 = eao.assets.Node('node_2')
        timegrid = eao.assets.Timegrid(dt.date(2021, 1, 1),
                                       dt.date(2021, 2, 1),
                                       freq='d')
        a1 = eao.assets.SimpleContract(name='SC_1',
                                       price='rand_price_1',
                                       nodes=node1,
                                       min_cap=-20.,
                                       max_cap=20.,
                                       start=dt.date(2021, 1, 10),
                                       end=dt.date(2021, 1, 20))
        #a1.set_timegrid(timegrid)
        a2 = eao.assets.SimpleContract(name='SC_2',
                                       price='rand_price_1',
                                       nodes=node1,
                                       min_cap=-5.,
                                       max_cap=10.,
                                       extra_costs=1.)
        #a2.set_timegrid(timegrid)
        a3 = eao.assets.SimpleContract(name='SC_3',
                                       price='rand_price_2',
                                       nodes=node2,
                                       min_cap=-10.,
                                       max_cap=10.,
                                       extra_costs=1.,
                                       start=dt.date(2021, 1, 10),
                                       end=dt.date(2021, 1, 25))
        a4 = eao.assets.Transport(name='Tr',
                                  costs_const=1.,
                                  nodes=[node1, node2],
                                  min_cap=0.,
                                  max_cap=1.)
        a5 = eao.assets.Storage('storage', nodes = node1, \
             start=dt.date(2021,1,1), end=dt.date(2021,2,1),size=10, \
             cap_in=1.0/24.0, cap_out=1.0/24.0, start_level=5, end_level=5)

        #a3.set_timegrid(timegrid)
        prices = {
            'rand_price_1': np.ones(timegrid.T) * 1.,
            'rand_price_2': np.ones(timegrid.T) * 10.,
            'rand_price_3': np.random.randn(timegrid.T) * 10.
        }

        portf = eao.portfolio.Portfolio([a1, a2, a3, a4, a5])
        portf.set_timegrid(timegrid)

        mys = json.dumps(portf,
                         indent=4,
                         default=eao.serialization.json_serialize_objects)
        aa = json.loads(mys,
                        object_hook=eao.serialization.json_deserialize_objects)

        # file activity
        myf = 'test_portf.json'

        to_json(portf, myf)
        x = load_from_json(file_name=myf)
        xx = load_from_json(mys)

        run_from_json(file_name_in=myf,
                      prices=prices,
                      file_name_out='test_results.xlsx')
        run_from_json(file_name_in = myf, prices = prices, file_name_out = 'test_results.csv',\
                          format_out='csv', csv_ger= True)
        res = run_from_json(file_name_in=myf, prices=prices)

        # array
        mys = json.dumps(prices, indent=4, default=json_serialize_objects)
        pp = json.loads(mys, object_hook=json_deserialize_objects)
        check = True
        for pr in prices:
            check = check and all(prices[pr] == pp[pr])

        return check
Пример #3
0
file_profiles = join(mypath, 'load_profiles_DK.csv')
file_spot_prices = join(mypath, 'elspotprices.csv')

## output files for results
file_normed_assets = join(mypath, 'normed_assets.json')
file_scaling_assets = join(mypath, 'scaling_assets.json')
file_vol_matching_assets = join(mypath, 'vol_matching_assets.json')
file_timegrid = join(mypath, 'timegrid.json')
file_prices = join(mypath, 'prices.json')

file_results = join(mypath, 'loop_results')

###############################################   create helpers
print('create timegrid and nodes')
timegrid = Timegrid(start=Start, end=End, freq=freq, main_time_unit='h')
to_json(timegrid, file_timegrid)
node_green = Node('green sources',
                  commodity='power',
                  unit=Unit('MWh', 'MW', 1.))
node_grey = Node('grey sources', commodity='power', unit=Unit('MWh', 'MW', 1.))
node_load = Node('client', commodity='power', unit=Unit('MWh', 'MW', 1.))

###############################################   import data
print('import load profiles and prices')
df_profiles = pd.read_csv(file_profiles)
df_profiles.index = pd.to_datetime(df_profiles['HourUTC'],
                                   format='%Y-%m-%dT%H')
df_profiles.sort_index(inplace=True)
# filter for only DK1 price area and time grid
df_profiles = df_profiles.loc[
    df_profiles['PriceArea'] == 'DK1',