import utils import glob from datetime import datetime, timedelta CSV_DIRECTORY = "input/csv/" OUTPUT_DIRECTORY = "output/aggregated" DATE = "20190124" MINIMUM_WIDTH = 1 start = datetime(2018, 10, 2) end = datetime(2018, 10, 3) #end day+1!! SHOWER = "Draconids2018" STATION = "BEHUMA" spectrograms = [] for result in utils.perdelta(start, end, timedelta(minutes=5)): spectrograms.append("RAD_BEDOUR_"+datetime.strftime(result,"%Y%m%d_%H%M")+"_"+STATION+"_SYS001.png") aggregated_identifications = {} csv_files = glob.glob(CSV_DIRECTORY+"*.csv") for spectrogram in spectrograms: dt = datetime.strptime(spectrogram[11:24], "%Y%m%d_%H%M") print("{}".format(dt)) #Step 1: read detection file detection_files = {} for csv_file in csv_files: tmp = utils.read_detection_file_per_spectrogram(csv_file,spectrogram) if tmp is not None: detection_files[csv_file] = tmp #Step 2: run meteor identification algorithm threshold_image = utils.calculate_threshold_image(detection_files)
if header: writer.writeheader() writer.writerows(results) def calculate_distance(image1, image2): """Calculate the distance between two images (intersection / union)""" intersection = np.sum(image1 & image2) union = np.sum(image1 | image2) fraction = float(intersection) / float(union) return fraction # generate list of all spectrogram names spectrograms = [] for result in utils.perdelta(START, END, timedelta(minutes=5)): spectrograms.append("RAD_BEDOUR_" + datetime.strftime(result, "%Y%m%d_%H%M") + "_" + STATION + "_SYS001") csv_files = glob.glob(CSV_DIRECTORY + "*.csv") write_output([], header=True) #write only the header for spectrogram in spectrograms: output = [] # load reference classifications spectrogram = spectrogram dt = datetime.strptime(spectrogram[11:24], "%Y%m%d_%H%M") print "Loading reference classification " + str(dt) reference_classification = utils.read_detection_file_per_spectrogram( REFERENCE_FILE, spectrogram + ".wav", swap_topbottom=True) if reference_classification is None:
import matplotlib.patches as patches from PIL import Image import utils plt.ioff() # Turn interactive plotting off PNG_DIRECTORY = "input/png/" CSV_DIRECTORY = "input/csv/" OUTPUT_DIRECTORY = "output/" MASKSIZE = (595, 864) start = datetime(2016, 8, 19) end = datetime(2016, 8, 20) station = "BEHUMA" spectrograms = [] for result in utils.perdelta(start, end, timedelta(minutes=5)): spectrograms.append("RAD_BEDOUR_"+datetime.strftime(result,"%Y%m%d_%H%M")+"_"+station+"_SYS001.png") csv_files = glob.glob(CSV_DIRECTORY+"*.csv") date_time, identifications, volunteers = [], [], [] for spectrogram in spectrograms: dt = datetime.strptime(spectrogram[11:24], "%Y%m%d_%H%M") #Step 1: read detection file detection_files = {} for csv_file in csv_files: tmp = utils.read_detection_file_per_spectrogram(csv_file,spectrogram) if tmp is not None: detection_files[csv_file] = tmp #Step 2: run meteor identification algorithm threshold_image = utils.calculate_threshold_image(detection_files) #Step 3: select regions that are above identification threshold
plt.yticks(size=12) plt.ylim([0,1.2*max(binned.counts)]) plt.xlim([binned.index.min(), binned.index.max()]) plt.grid(axis='x') ax1.xaxis.set_major_formatter(plt.NullFormatter()) ax1.fill_between(binned.index, 0, binned.counts, alpha=.3, color='blue') ax1.spines["top"].set_visible(False) ax1.spines["right"].set_visible(False) # Plot radiant altitude if show_radiant_altitude: JDs = map(utils.toJD,rad_pos.keys()) pos = np.deg2rad(rad_pos.values()).tolist() retrieve = interpolate.interp1d(JDs, pos, axis=0) ax1b = ax1.twinx() for utc in utils.perdelta(min(dt), max(dt), timedelta(minutes=60)): RA, Dec = retrieve(utils.toJD(utc)) equ_coord = sidereal.RADec(RA,Dec) h = equ_coord.hourAngle(utc,lon) horiz_coord = equ_coord.altAz(h,lat) ax1b.set_ylabel('Radiant elevation [$\degree$]',size=14,style='italic',color='green') ax1b.scatter(utc,np.rad2deg(horiz_coord.alt),marker='.',color='green') ax1.autoscale(True,axis='x',tight=True) ax2 = plt.subplot(2, 1, 2) ax2.spines["top"].set_visible(False) ax2.spines["right"].set_visible(False) col_list = [ utils.color_gradient(val) for val in binned.percentage_completed] plt.bar(binned.index, height=binned.percentage_completed, width=1/24., color = col_list, ec='black') locs, labels = plt.xticks() plt.setp(labels, rotation=45)
plt.yticks(size=12) plt.ylim([0, 1.2 * max(binned.counts)]) plt.xlim([binned.index.min(), binned.index.max()]) plt.grid(axis='x') ax1.xaxis.set_major_formatter(plt.NullFormatter()) ax1.fill_between(binned.index, 0, binned.counts, alpha=.3, color='blue') ax1.spines["top"].set_visible(False) ax1.spines["right"].set_visible(False) # Plot radiant altitude if show_radiant_altitude: JDs = map(utils.toJD, rad_pos.keys()) pos = np.deg2rad(rad_pos.values()).tolist() retrieve = interpolate.interp1d(JDs, pos, axis=0) ax1b = ax1.twinx() for utc in utils.perdelta(min(dt), max(dt), timedelta(minutes=60)): RA, Dec = retrieve(utils.toJD(utc)) equ_coord = sidereal.RADec(RA, Dec) h = equ_coord.hourAngle(utc, lon) horiz_coord = equ_coord.altAz(h, lat) ax1b.set_ylabel('Radiant elevation [$\degree$]', size=14, style='italic', color='green') ax1b.scatter(utc, np.rad2deg(horiz_coord.alt), marker='.', color='green') ax1.autoscale(True, axis='x', tight=True) ax2 = plt.subplot(2, 1, 2)
fieldnames = ['spectrogram', 'outlier_threshold', 'cost'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) if header: writer.writeheader() writer.writerows(results) def calculate_distance(image1, image2): """Calculate the distance between two images (intersection / union)""" intersection = np.sum(image1 & image2) union = np.sum(image1 | image2) fraction = float(intersection) / float(union) return fraction # generate list of all spectrogram names spectrograms = [] for result in utils.perdelta(START, END, timedelta(minutes=5)): spectrograms.append("RAD_BEDOUR_"+datetime.strftime(result,"%Y%m%d_%H%M")+"_"+STATION+"_SYS001") csv_files = glob.glob(CSV_DIRECTORY+"*.csv") write_output([], header=True) #write only the header for spectrogram in spectrograms: output = [] # load reference classifications spectrogram = spectrogram dt = datetime.strptime(spectrogram[11:24], "%Y%m%d_%H%M") print "Loading reference classification "+str(dt) reference_classification = utils.read_detection_file_per_spectrogram(REFERENCE_FILE,spectrogram+".wav", swap_topbottom=True) if reference_classification is None: continue print("--- %s seconds ---" % (time.time() - start_time))