示例#1
0
def main():
    client = EntsoePandasClient(api_key=api_key)
    (start, end) = get_start_end()

    response = client.query_crossborder_flows(country_code_from,
                                              country_code_to,
                                              start=start,
                                              end=end)
    response_revert_country_flow = client.query_crossborder_flows(
        country_code_to, country_code_from, start=start, end=end)
    # normalize
    result = response.to_frame() - response_revert_country_flow.to_frame()
    result.columns = ['value']
    if len(result):
        print(result.to_markdown())
        result.to_sql(db_table, db, if_exists='append')
示例#2
0
class EntsoeClient:
    def __init__(self, token):
        self.client = EntsoePandasClient(api_key=token)

    def get_unavailability_production(self, country_code, start_date,
                                      end_date):
        """
        Get unavailability of production units (whatever that is)
        :param country_code: iso code of country
        :param start_date: epoch time of start in ms
        :param end_date: epoch time of end in ms
        :return: pandas dataframe with the requested data
        """
        start_date = pd.Timestamp(start_date, unit="ms", tz="CET")
        end_date = pd.Timestamp(end_date, unit="ms", tz="CET")

        return self.client.query_unavailability_of_production_units(
            country_code.upper(), start=start_date, end=end_date)

    def get_cross_border_flow(self, country_from, country_to, start_date,
                              end_date):
        start_date = pd.Timestamp(start_date, unit="ms", tz="CET")
        end_date = pd.Timestamp(end_date, unit="ms", tz="CET")

        return self.client.query_crossborder_flows(
            country_code_from=country_from.upper(),
            country_code_to=country_to.upper(),
            start=start_date,
            end=end_date)

    def get_forecasted_transfer(self, country_from, country_to, start_date,
                                end_date):
        """
        Net capacity transfer for the day ahead between the 2 countries
        :param country_from:
        :param country_to:
        :param start_date:
        :param end_date:
        :return:
        """
        start_date = pd.Timestamp(start_date, unit="ms", tz="CET")
        end_date = pd.Timestamp(end_date, unit="ms", tz="CET")
        return self.client.query_net_transfer_capacity_dayahead(
            country_code_from=country_from.upper(),
            country_code_to=country_to.upper(),
            start=start_date,
            end=end_date)
    country_code, start=start, end=end, psr_type=None)
df_wind_and_solar_forecast.to_csv('data_base/df_wind_and_solar_forecast.csv')

df_generation = client.query_generation(country_code,
                                        start=start,
                                        end=end,
                                        psr_type=None)
df_generation.to_csv('data_base/df_generation.csv')

df_installed_generation_capacity = client.query_installed_generation_capacity(
    country_code, start=start, end=end, psr_type=None)
df_installed_generation_capacity.to_csv(
    'data_base/df_installed_generation_capacity.csv')

df_crossborder_flows = client.query_crossborder_flows('DE',
                                                      'DK',
                                                      start=start,
                                                      end=end)
df_crossborder_flows.to_csv('data_base/df_crossborder_flows.csv')

# df_imbalance_prices = client.query_imbalance_prices(country_code, start=start,end=end, psr_type=None)
# df_imbalance_prices.to_csv('data_base/df_imbalance_prices.csv')

# BadRequest:
# df_unavailability_of_generation_units = client.query_unavailability_of_generation_units(country_code, start=start,end=end, docstatus=None)

# BadRequest:
# df_withdrawn_unavailability_of_generation_units = client.query_withdrawn_unavailability_of_generation_units('DE', start=start,end=end)

# ts.to_csv('outfile.csv')
#"""
                                           start=start,
                                           end=end,
                                           psr_type=None)
 ts.to_csv(path + country_code + '-solar+PV_d-1.csv')
 client.query_generation(country_code,
                         start=start,
                         end=end,
                         psr_type=None)
 ts.to_csv(path + country_code + '-generacion_d.csv')
 ts = client.query_installed_generation_capacity(country_code,
                                                 start=start,
                                                 end=end,
                                                 psr_type=None)
 ts.to_csv(path + country_code + '-capacidad_instalada.csv')
 ts = client.query_crossborder_flows(antiguo_country_code,
                                     country_code,
                                     start=start,
                                     end=end)
 ts.to_csv(path + country_code + '-flujo_fronterizo.csv')
 ts = client.query_imbalance_prices(country_code,
                                    start=start,
                                    end=end,
                                    psr_type=None)
 ts.to_csv(path + country_code + '-desequilibrio_precios.csv')
 ts = client.query_unavailability_of_generation_units(country_code,
                                                      start=start,
                                                      end=end,
                                                      docstatus=None)
 ts.to_csv(path + country_code + '-incapacidad_unidades_generacion.csv')
 ts = client.query_withdrawn_unavailability_of_generation_units(
     country_code, start=start, end=end)
 ts.to_csv(path + country_code +
neighbour_emission_factors = []
for neighbour in neighbour_production:
    neighbour_emissions_df = pd.DataFrame(index=neighbour.index, columns=neighbour.keys())

    for power_type in neighbour:

        neighbour_emissions_df[power_type] = neighbour[power_type]
        neighbour_emissions_df.loc[:,power_type] *= emission_production_matrix.loc[data_source, power_type]

    neighbour_emission_factors.append(neighbour_emissions_df.sum(axis=1).divide(neighbour.sum(axis=1)))


import_cross_border_flows = [] # if the flows are power and not energy, change the resampling from sum to mean
for country in neighbour_countries:
    # resampling to the hour with mean because quarter hourly values are given in MW not MWh
    import_cross_border_flows.append(client.query_crossborder_flows(country, country_code, start=start_time, end=end_time).resample("H").mean())



#Initialization of tatal factor with total summation of emmissions of domestic production
total_emission_factor = domestic_emissions_df.sum(axis=1)
# print("Gelb")
# print(total_emission_factor)
# print("hier_gopfer")
# print(import_cross_border_flows[0])
# print("am gopfsten")
# print(neighbour_emission_factors[0])
# print("hier_gopf")
# print(import_cross_border_flows[0]*neighbour_emission_factors[0])
# print("hier werden die nefs geprinted:")
# print(neighbour_emission_factors)