Exemple #1
0
def collect_and_plot(files):
    TS = []
    location = []
    for f in files:
        temperatures = [
            section[1] for section in parse.parse_file(f)[1:-1]
            if section[1]['Plant'] == ['tmp']
        ]
        for t in temperatures:
            if t['Step'][0] != '0000-00-00.01:00:00':
                print 'Not hourly readings of temperature. Abort.'
                break
            start_time = datetime.datetime.strptime(t['Start'][0],
                                                    "%Y-%m-%d.%H:%M:%S")
            dates = pd.date_range(start=start_time,
                                  periods=len(t['Value']),
                                  freq='H')
            data = [float(value.rsplit('/')[0]) for value in t['Value']]
            TS.append(pd.Series(data=data, index=dates))
            if location and t['Installation'][0] != location:
                print 'Location changed during reading of gs2 files. Probably some bad grouping of gs2 files.'
            location = t['Installation'][0]
    if TS:
        all_series = pd.concat(TS).sort_index()
        all_series_no_duplicates = all_series.groupby(level=0).first()
        all_series_no_duplicates.dump('temp_data.pickle')
        sg.utils.plot_time_series([all_series_no_duplicates], ['b-'],
                                  [location])
    else:
        print 'No temperature data.'
Exemple #2
0
def _collect_and_plot(files):
    TS = []
    location = []
    for f in files:
        temperatures = [ section[1] for section in parse.parse_file(f)[1:-1] if section[1]['Plant'] == ['tmp'] ]
        for t in temperatures:
            if t['Step'][0] != '0000-00-00.01:00:00':
                print 'Not hourly readings of temperature. Abort.'
                break
            dates = ts.date_array(start_date=ts.Date('H', t['Start'][0]), length=len(t['Value']))
            data = [ float(value.rsplit('/')[0]) for value in t['Value'] ]
            TS.append(ts.TimeSeries(data=data, dates=dates))
            if location and t['Installation'][0] != location:
                print 'Location changed during reading of gs2 files. Probably some bad grouping of gs2 files.'
            location = t['Installation'][0]
    if TS:
        path = '/Users/tidemann/Documents/NTNU/devel/data/eklima/Telemark/'
        for file in os.listdir(path):
            try:
                series = xml.parse(path + file)
                sg.utils.plot_time_series([ts.concatenate((TS)), series], ['b-','r-'], [location, file])
            except:
                print file, 'had no data.'
    else:
        print 'No temperature data.'
def collect_and_plot(files):
    TS = []
    location = []
    for f in files:
        temperatures = [ section[1] for section in parse.parse_file(f)[1:-1] if section[1]['Plant'] == ['tmp'] ]
        for t in temperatures:
            if t['Step'][0] != '0000-00-00.01:00:00':
                print 'Not hourly readings of temperature. Abort.'
                break
            start_time = datetime.datetime.strptime(t['Start'][0], "%Y-%m-%d.%H:%M:%S")
            dates = pd.date_range(start=start_time, periods=len(t['Value']), 
                                    freq='H')
            data = [ float(value.rsplit('/')[0]) for value in t['Value'] ]
            TS.append(pd.Series(data=data, index=dates))
            if location and t['Installation'][0] != location:
                print 'Location changed during reading of gs2 files. Probably some bad grouping of gs2 files.'
            location = t['Installation'][0]
    if TS:
        all_series = pd.concat(TS).sort_index()
        all_series_no_duplicates = all_series.groupby(level=0).first()
        all_series_no_duplicates.dump('temp_data.pickle')
        sg.utils.plot_time_series([all_series_no_duplicates], ['b-'], [location])
    else:
        print 'No temperature data.'