timeseries_scripts/read.py
def read_transnetbw(filepath, variable_name, url, headers):
    '''Read a file from TransnetBW into a DataFrame'''
    df = pd.read_csv(
        filepath,
        sep=';',
        header=0,
        index_col='timestamp',
        parse_dates={'timestamp': ['Datum bis', 'Uhrzeit bis']},
        date_parser=None,
        dayfirst=True,
        decimal=',',
        thousands=None,
        converters=None,
    )

    # DST-transistion is conducted 2 hours too late in the data
    # (hour 4:00-5:00 is repeated instead of 2:00-3:00)
    if df.index[0].date().month == 10:
        df.index = pd.DatetimeIndex(start=df.index[0],
                                    end=df.index[-1],
                                    freq='15min',
                                    tz=pytz.timezone('Europe/Berlin'))
    else:
        df.index = df.index.tz_localize('Europe/Berlin')
    df.index = df.index.tz_convert(None)

    # The 2nd column represents the start and the 4th the end of the respective
    # period. The former has some errors, so we use the latter to construct the
    # index and shift the data back by 1 period.
    df = df.shift(periods=-1, freq='15min', axis='index')

    tech = variable_name
    colmap = {
        'Prognose (MW)': {
            'variable': '{tech}',
            'region': 'DE_transnetbw',
            'attribute': 'forecast',
            'source': 'TransnetBW',
            'web': url,
            'unit': 'MW'
        },
        'Ist-Wert (MW)': {
            'variable': '{tech}',
            'region': 'DE_transnetbw',
            'attribute': 'generation',
            'source': 'TransnetBW',
            'web': url,
            'unit': 'MW'
        }
    }

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

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

    return df
Read a file from TransnetBW into a DataFrame
Read a file from TransnetBW into a DataFrame
Read a file from TransnetBW into a DataFrame
def read_transnetbw(filepath, variable_name, url, headers):
    df = pd.read_csv(
        filepath,
        sep=';',
        header=0,
        index_col='timestamp',
        parse_dates={'timestamp': ['Datum bis', 'Uhrzeit bis']},
        date_parser=None,
        dayfirst=True,
        decimal=',',
        thousands=None,
        converters=None,
    )
    if df.index[0].date().month == 10:
        df.index = pd.DatetimeIndex(start=df.index[0],
                                    end=df.index[-1],
                                    freq='15min',
                                    tz=pytz.timezone('Europe/Berlin'))
    else:
        df.index = df.index.tz_localize('Europe/Berlin')
    df.index = df.index.tz_convert(None)
    df = df.shift(periods=-1, freq='15min', axis='index')
    tech = variable_name
    colmap = {
        'Prognose (MW)': {
            'variable': '{tech}',
            'region': 'DE_transnetbw',
            'attribute': 'forecast',
            'source': 'TransnetBW',
            'web': url,
            'unit': 'MW'
        },
        'Ist-Wert (MW)': {
            'variable': '{tech}',
            'region': 'DE_transnetbw',
            'attribute': 'generation',
            'source': 'TransnetBW',
            'web': url,
            'unit': 'MW'
        }
    }
    df = df[list(colmap.keys())]
    tuples = [tuple(colmap[col][level].format(tech=tech) for level in headers)
              for col in df.columns]
    df.columns = pd.MultiIndex.from_tuples(tuples, names=headers)
    return df
def read_transnetbw ( filepath , variable_name , url , headers ) : df = pd . read_csv ( filepath , sep = ';' , header = 0 , index_col = 'timestamp' , parse_dates = { 'timestamp' : [ 'Datum bis' , 'Uhrzeit bis' ] } , date_parser = None , dayfirst = True , decimal = ',' , thousands = None , converters = None , ) if df . index [ 0 ] . date ( ) . month == 10 : df . index = pd . DatetimeIndex ( start = df . index [ 0 ] , end = df . index [ - 1 ] , freq = '15min' , tz = pytz . timezone ( 'Europe/Berlin' ) ) else : df . index = df . index . tz_localize ( 'Europe/Berlin' ) df . index = df . index . tz_convert ( None ) df = df . shift ( periods = - 1 , freq = '15min' , axis = 'index' ) tech = variable_name colmap = { 'Prognose (MW)' : { 'variable' : '{tech}' , 'region' : 'DE_transnetbw' , 'attribute' : 'forecast' , 'source' : 'TransnetBW' , 'web' : url , 'unit' : 'MW' } , 'Ist-Wert (MW)' : { 'variable' : '{tech}' , 'region' : 'DE_transnetbw' , 'attribute' : 'generation' , 'source' : 'TransnetBW' , 'web' : url , 'unit' : 'MW' } } df = df [ list ( colmap . keys ( ) ) ] tuples = [ tuple ( colmap [ col ] [ level ] . format ( tech = tech ) for level in headers ) for col in df . columns ] df . columns = pd . MultiIndex . from_tuples ( tuples , names = headers ) return df
Read a file from TransnetBW into a DataFrame
Read a file from TransnetBW into a DataFrame
'''Read a file from TransnetBW into a DataFrame''' # DST-transistion is conducted 2 hours too late in the data # (hour 4:00-5:00 is repeated instead of 2:00-3:00) # The 2nd column represents the start and the 4th the end of the respective # period. The former has some errors, so we use the latter to construct the # index and shift the data back by 1 period. # Drop any column not in colmap # Create the MultiIndex
filepath
variable_name
url
headers