timeseries_scripts/read.py
def read_elia(filepath, variable_name, url, headers):
    '''Read a file from Elia into a DataFrame'''
    df = pd.read_excel(
        io=filepath,
        header=None,
        skiprows=4,
        index_col=0,
        parse_cols=None
    )

    colmap = {
        'Day-Ahead forecast [MW]': {
            'region': 'BE',
            'variable': variable,
            'attribute': 'forecast',
            'source': 'Elia',
            'web': url,
            'unit': 'MW'
        },
        'Corrected Upscaled Measurement [MW]': {
            'region': 'BE',
            'variable': variable,
            'attribute': 'generation',
            'source': 'Elia',
            'web': url,
            'unit': 'MW'
        },
        'Monitored Capacity [MWp]': {
            'region': 'BE',
            'variable': variable,
            'attribute': 'capacity',
            'source': 'Elia',
            'web': url,
            'unit': 'MW'
        }
    }

    # Drop any column not in colmap
    df = df[list(colmap.keys())]

    df.index = pd.to_datetime(df.index.rename('timestamp'))

    df.index = df.index.tz_localize('Europe/Brussels', ambiguous='infer')
    df.index = df.index.tz_convert(None)

    # Create the MultiIndex
    tuples = [tuple(colmap[col][level] for level in headers)
              for col in df.columns]
    df.columns = pd.MultiIndex.from_tuples(tuples, names=headers)

    return df
Read a file from Elia into a DataFrame
Read a file from Elia into a DataFrame
Read a file from Elia into a DataFrame
def read_elia(filepath, variable_name, url, headers):
    df = pd.read_excel(
        io=filepath,
        header=None,
        skiprows=4,
        index_col=0,
        parse_cols=None
    )
    colmap = {
        'Day-Ahead forecast [MW]': {
            'region': 'BE',
            'variable': variable,
            'attribute': 'forecast',
            'source': 'Elia',
            'web': url,
            'unit': 'MW'
        },
        'Corrected Upscaled Measurement [MW]': {
            'region': 'BE',
            'variable': variable,
            'attribute': 'generation',
            'source': 'Elia',
            'web': url,
            'unit': 'MW'
        },
        'Monitored Capacity [MWp]': {
            'region': 'BE',
            'variable': variable,
            'attribute': 'capacity',
            'source': 'Elia',
            'web': url,
            'unit': 'MW'
        }
    }
    df = df[list(colmap.keys())]
    df.index = pd.to_datetime(df.index.rename('timestamp'))
    df.index = df.index.tz_localize('Europe/Brussels', ambiguous='infer')
    df.index = df.index.tz_convert(None)
    tuples = [tuple(colmap[col][level] for level in headers)
              for col in df.columns]
    df.columns = pd.MultiIndex.from_tuples(tuples, names=headers)
    return df
def read_elia ( filepath , variable_name , url , headers ) : df = pd . read_excel ( io = filepath , header = None , skiprows = 4 , index_col = 0 , parse_cols = None ) colmap = { 'Day-Ahead forecast [MW]' : { 'region' : 'BE' , 'variable' : variable , 'attribute' : 'forecast' , 'source' : 'Elia' , 'web' : url , 'unit' : 'MW' } , 'Corrected Upscaled Measurement [MW]' : { 'region' : 'BE' , 'variable' : variable , 'attribute' : 'generation' , 'source' : 'Elia' , 'web' : url , 'unit' : 'MW' } , 'Monitored Capacity [MWp]' : { 'region' : 'BE' , 'variable' : variable , 'attribute' : 'capacity' , 'source' : 'Elia' , 'web' : url , 'unit' : 'MW' } } df = df [ list ( colmap . keys ( ) ) ] df . index = pd . to_datetime ( df . index . rename ( 'timestamp' ) ) df . index = df . index . tz_localize ( 'Europe/Brussels' , ambiguous = 'infer' ) df . index = df . index . tz_convert ( None ) tuples = [ tuple ( colmap [ col ] [ level ] for level in headers ) for col in df . columns ] df . columns = pd . MultiIndex . from_tuples ( tuples , names = headers ) return df
Read a file from Elia into a DataFrame
Read a file from Elia into a DataFrame
'''Read a file from Elia into a DataFrame''' # Drop any column not in colmap # Create the MultiIndex
filepath
variable_name
url
headers