Example #1
0
def main():
    """Do the search for correlations between lightning strikes and events"""
    start = datetime.date(2011, 9, 10)
    stop = datetime.date(2011, 9, 10)
    station_ids = get_stations.get_station_ids(start)

    #  This should be in the for loop and start should be date.
    #  But for better performance, it is not yet..
    stations = get_stations.get_station_positions(station_ids, start)

    for date in date_generator.daterange(start, stop):
        lgt_file = knmi_lightning.data_file(date)
        his_file = hisparc_data.data_file(date)

        discharges = knmi_lightning.discharges(lgt_file)
        for discharge in discharges:
            matches = []
            close_station_ids = get_stations.find_close_stations(discharge, stations)
            for station_id in close_station_ids:
                events = hisparc_data.events_table(his_file, station_id)
                matched_events = hisparc_data.events_in_range(events, discharge['timestamp'])
                matches.append([station_id, matched_events['ext_timestamp']])
            if len(close_station_ids) > 0:
                print "Discharge:", discharge
                print "Close stations: ", close_station_ids
                print "Matching events: ", matches

        lgt_file.close()
        his_file.close()
Example #2
0
def main():
    start = datetime.date(2011, 1, 1)
    stop = datetime.date(2011, 1, 10)
    for date in date_generator.daterange(start, stop):
        source_file = hisparc_data.data_file(date)
        if not source_file:
            continue
        target_file = get_target_file(date)
        for events in source_file.walkNodes('/', 'Table'):
            if not events.name == 'events':
                continue
            target_table = target_file.createTable(
                    os.path.split(events._v_pathname)[0], 'events',
                    EventTimestamps, createparents=True)
            event_id = events.col('event_id')
            ext_timestamps = events.col('ext_timestamp')
            timestamps = events.col('timestamp')
            nanoseconds = events.col('nanoseconds')
            rows_data = zip(event_id, ext_timestamps, timestamps, nanoseconds)
            for row_data in rows_data:
                row = target_table.row
                row['event_id'] = row_data[0]
                row['ext_timestamp'] = row_data[1]
                row['timestamp'] = row_data[2]
                row['nanoseconds'] = row_data[3]
                row.append()
            target_table.flush()
            clean_events_table(target_file, target_table)
        source_file.close()
        target_file.close()
Example #3
0
def data_to_csv():
    for year in range(2004, 2013):
        print year
        with open(LGT_PATH + 'robert_cc_%d.tsv' % year, 'w') as output:
            csvwriter = csv.writer(output, delimiter='\t')
            csvwriter.writerow(['timestamp', 'nanoseconds', 'latitude',
                                'longitude', 'current'])

            for d in daterange(date(year, 1, 1), date(year + 1, 1, 1)):
                try:
                    data = data_file(d)
                    for discharge in discharges(data, type=1):
                        csvwriter.writerow(discharge)
                except:
                    continue
                else:
                    data.close()