Пример #1
0
def plot(name, data):
    filename = os.path.join(CSV_DIR, "{name}_{type}.csv".format(name=name, type=get_datapoint_type()))

    headers = list(data.keys())
    amount_of_rows = max(map(len, data.values()))

    rows = [None] * amount_of_rows
    for rownr in range(amount_of_rows):
        rows[rownr] = {daynr: get_datapoint(data, daynr, rownr) for daynr in headers}

    csvfp = csv.DictWriter(open(filename, "w"), fieldnames=headers)
    csvfp.writeheader()
    csvfp.writerows(rows)



if __name__ == '__main__':
    type = get_datapoint_type()

    if type == DAS:
        aggregator = aggregate_das
    elif type == GAP:
        aggregator = aggregate_gap
    elif type == CTIME:
        aggregator = aggregate_ctime
    else:
        assert False, "Not possible :)"

    analyse(chain(*relational.BROTHERS.items()), aggregator=aggregator, plotter=plot, plot_threaded=True)
Пример #2
0
            median, stderr = bootstrapped[day]
        except KeyError:
            # This bird didn't have this day
            yield ""
        else:
            yield "{median}±{stderr}".format(**locals())

def plot(*veugel_tuples):
    all_veugels = list(itertools.chain(*veugel_tuples))

    # Determine all available days
    all_days = set()
    for (name, bootstrapped) in all_veugels:
        for daynr in bootstrapped.keys():
            all_days.add(daynr)
    all_days = list(sorted(all_days))

    # Open CSV file
    filename = os.path.join(CSV_DIR, "bootstrapped.csv")
    file = open(filename, "w")

    csvfp = csv.writer(file)
    csvfp.writerow(["name"] + all_days)

    for name, bootstrapped in all_veugels:
        csvfp.writerow([name] + list(get_row(bootstrapped, all_days)))


if __name__ == '__main__':
    analyse(relational.BROTHERS.items(), aggregator=aggregate, plotter=plot, plot_threaded=False)
Пример #3
0
    # peaks: een dictionary van bucket (int) -> count (int)
    # buckets: een dictionary van bucket (int) -> count(int)

    # Return an ordered dict of buckets, and their peaks
    return buckets, peaks


def aggregate(veugel):
    # @LINDA: Kies je dagen die je wil berekenen in de onderstaande constructie!
    days = veugel.days # FILTER DUS HIER

    aggregated = [(day.daynr, day_aggregate(day.rows["duration_of_state"])) for day in days]
    aggregated = OrderedDict(aggregated)

    # HACK: als we hier een enkel item teruggeven gaat analyse() over de zeik :<. We geven
    # dus een lijst met een enkel item terug, wat vervolgens weer goed gaat in plot().
    return [aggregated]

def plot(aggregated):
    pyplot.figure()

    for day, (buckets, peaks) in aggregated.items():
        print(day)
        pyplot.plot(list(buckets.keys()), list(buckets.values()))
        pyplot.plot(list(peaks.keys()), list(peaks.values()), 'x')

    pyplot.show()

if __name__ == "__main__":
    analyse([list(BROTHERS.keys())[0]], aggregator=aggregate, plotter=plot, plot_threaded=True)
Пример #4
0
        #print(sorted(Counter(choose_day(iso.days, daynr).rows["duration_of_state"]).items()))
        #print(sorted(Counter(choose_day(self.days, daynr).rows["duration_of_state"]).items()))
        iso_das = choose_day(iso.days, daynr).rows["duration_of_state"]
        self_das = choose_day(self.days, daynr).rows["duration_of_state"]
        yield stats.ks_2samp(iso_das, self_das)


def _aggregate(iso, self):
    yield iso.name
    yield self.name

    yield get_hist_data(iso)
    yield get_hist_data(self)

    yield list(get_ks(iso, self))


def aggregate(iso, self):
    return list(_aggregate(iso, self))


def plot(iso_name, self_name, iso_hist, self_hist, ks):

    print("{} <-> {}".format(iso_name, self_name))
    for day, res in zip(BUCKETS, ks):
        print("{}: {}".format(day, res))


if __name__ == '__main__':
    analyse(list(relational.BROTHERS.items())[:1], plot, aggregate, plot_threaded=True)
Пример #5
0
from veugel import relational
from veugel.analyse import analyse

def plot_avg_das(means):
    pyplot.plot(list(means.keys()), list(means.values()), marker='x')

def plot(iso_name, iso_avgs, self_name, self_avgs):
    pyplot.figure()
    pyplot.gca().set_color_cycle(['red', 'blue'])

    plot_avg_das(iso_avgs)
    plot_avg_das(self_avgs)

    pyplot.ylabel('Mean DAS')
    pyplot.xlabel('DPH')
    pyplot.ylim(0, 150)
    pyplot.legend([iso_name, self_name], loc=0)

    pyplot.savefig("das_{iso_name}_{self_name}.png".format(**locals()), bbox_inches='tight')

def get_das_mapping(veugel):
    return OrderedDict((day.daynr, day.get_das_mean()) for day in veugel.days)

def aggregate(iso, self):
    return [iso.name, get_das_mapping(iso), self.name, get_das_mapping(self)]

if __name__ == '__main__':
    analyse(relational.BROTHERS.items(), plot, aggregate, plot_threaded=True)