timeseries_scripts/read.py
def read_amprion(filepath, variable_name, url, headers):
    '''Read a file from Amprion into a DataFrame'''
    df = pd.read_csv(
        filepath,
        sep=';',
        header=0,
        index_col='timestamp',
        parse_dates={'timestamp': ['Datum', 'Uhrzeit']},
        date_parser=None,
        dayfirst=True,
        decimal=',',
        thousands=None,
        # Truncate values in 'time' column after 5th character.
        converters={'Uhrzeit': lambda x: x[:5]},
    )

    index1 = df.index[df.index.year <= 2009]
    index1 = index1.tz_localize('Europe/Berlin', ambiguous='infer')

    # In the years after 2009, during the fall dst-transistion, only the
    # summertime hour is reported, the wintertime hour is missing in the data.
    # dst_arr is a boolean array consisting only of "True" entries, telling
    # python to treat the hour from 2:00 to 2:59 as summertime.
    index2 = df.index[df.index.year > 2009]
    dst_arr = np.ones(len(index2), dtype=bool)
    index2 = index2.tz_localize('Europe/Berlin', ambiguous=dst_arr)
    df.index = index1.append(index2)
    df.index = df.index.tz_convert(None)

    tech = variable_name
    colmap = {
        '8:00 Uhr Prognose [MW]': {
            'variable': '{tech}',
            'region': 'DE_amprion',
            'attribute': 'forecast',
            'source': 'Amprion',
            'web': url,
            'unit': 'MW'
        },
        'Online Hochrechnung [MW]': {
            'variable': '{tech}',
            'region': 'DE_amprion',
            'attribute': 'generation',
            'source': 'Amprion',
            '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 Amprion into a DataFrame
Read a file from Amprion into a DataFrame
Read a file from Amprion into a DataFrame
def read_amprion(filepath, variable_name, url, headers):
    df = pd.read_csv(
        filepath,
        sep=';',
        header=0,
        index_col='timestamp',
        parse_dates={'timestamp': ['Datum', 'Uhrzeit']},
        date_parser=None,
        dayfirst=True,
        decimal=',',
        thousands=None,
        converters={'Uhrzeit': lambda x: x[:5]},
    )
    index1 = df.index[df.index.year <= 2009]
    index1 = index1.tz_localize('Europe/Berlin', ambiguous='infer')
    index2 = df.index[df.index.year > 2009]
    dst_arr = np.ones(len(index2), dtype=bool)
    index2 = index2.tz_localize('Europe/Berlin', ambiguous=dst_arr)
    df.index = index1.append(index2)
    df.index = df.index.tz_convert(None)
    tech = variable_name
    colmap = {
        '8:00 Uhr Prognose [MW]': {
            'variable': '{tech}',
            'region': 'DE_amprion',
            'attribute': 'forecast',
            'source': 'Amprion',
            'web': url,
            'unit': 'MW'
        },
        'Online Hochrechnung [MW]': {
            'variable': '{tech}',
            'region': 'DE_amprion',
            'attribute': 'generation',
            'source': 'Amprion',
            '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_amprion ( filepath , variable_name , url , headers ) : df = pd . read_csv ( filepath , sep = ';' , header = 0 , index_col = 'timestamp' , parse_dates = { 'timestamp' : [ 'Datum' , 'Uhrzeit' ] } , date_parser = None , dayfirst = True , decimal = ',' , thousands = None , converters = { 'Uhrzeit' : lambda x : x [ : 5 ] } , ) index1 = df . index [ df . index . year <= 2009 ] index1 = index1 . tz_localize ( 'Europe/Berlin' , ambiguous = 'infer' ) index2 = df . index [ df . index . year > 2009 ] dst_arr = np . ones ( len ( index2 ) , dtype = bool ) index2 = index2 . tz_localize ( 'Europe/Berlin' , ambiguous = dst_arr ) df . index = index1 . append ( index2 ) df . index = df . index . tz_convert ( None ) tech = variable_name colmap = { '8:00 Uhr Prognose [MW]' : { 'variable' : '{tech}' , 'region' : 'DE_amprion' , 'attribute' : 'forecast' , 'source' : 'Amprion' , 'web' : url , 'unit' : 'MW' } , 'Online Hochrechnung [MW]' : { 'variable' : '{tech}' , 'region' : 'DE_amprion' , 'attribute' : 'generation' , 'source' : 'Amprion' , '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 Amprion into a DataFrame
Read a file from Amprion into a DataFrame
'''Read a file from Amprion into a DataFrame''' # Truncate values in 'time' column after 5th character. # In the years after 2009, during the fall dst-transistion, only the # summertime hour is reported, the wintertime hour is missing in the data. # dst_arr is a boolean array consisting only of "True" entries, telling # python to treat the hour from 2:00 to 2:59 as summertime. # Drop any column not in colmap # Create the MultiIndex
filepath
variable_name
url
headers