plt.close (fig) #do seeing x all correlations for index, days in enumerate ([days0, days1]): bigMatrix = makeBigMatrix (correlations) for p in ambient.parameterBasenames [1:]: otherDays = ambient.Days (os.path.join (args.indir, p + ".orig"), args.start_date, args.stop_date, allSeeingDays) #for each day in the seeing correlations tuple, compute the pc seeing vs a non-seeing sensor for row, day in enumerate (days): otherDay = otherDays.getDay (day) pc = (0,(0,0,0)) if otherDay: f0, f1 = [d.periodFilter (args.start_minutes * 60, args.stop_minutes * 60, args.past_midnight) for d in (day, otherDay)] m0, m1 = day.matchMeasurements (otherDay, f0, f1) pc = (ambient.pearsonFromMeasurements (m0, m1, args.min_points), (len (day.measurements), len (otherDay.measurements), len (m0))) bigMatrix [row].append (pc) #strip out nonsense correlations strippedMatrix = [t for t in bigMatrix if t[-1][0] <= 1.0] scatterPC ([t [0] for t in strippedMatrix], [t [-1][0] for t in strippedMatrix], os.path.join (args.outdir, "{}x{}.{}.png".format (p, ambient.parameterBasenames [0], index)), "{} vs {} ({})".format (ambient.parameterBasenames [0], p, index), "rank", "pearson's correlation coefficient", Axis.y) utils.dumpList(os.path.join (args.outdir, "{}xAll.{}.corr".format(ambient.parameterBasenames[0], index)), bigMatrix, lambda out, r: out.write("{} {:%m/%d/%y} {:%m/%d/%y} {:.5f} {:.5f} ({:d},{:d},{:d}) {:.5f} ({:d},{:d},{:d}) {:.5f} ({:d},{:d},{:d}) {:.5f} ({:d},{:d},{:d}) {:.5f} ({:d},{:d},{:d}) {:.5f} ({:d},{:d},{:d}) {:.5f} ({:d},{:d},{:d})\n".format
def plotSites (basename, correlations): assert (args.best_plots <= args.best_count) #load in days for every non seeing sensor for both sites in "sites" #sites [i][j] is sensor j Days for site i #set the goodness of each day to intersect the goodness for the #corresponding day in seeing sites = [] for i in range (2): sites.append ([]) for p in ambient.parameterBasenames [1:]: sites [-1].append (ambient.Days (os.path.join (args.indirs [i].path, p + ".orig"), args.start_date, args.stop_date)) sites [-1][-1].setGoodness (allSeeing [i]) row = 0 for correlation in correlations: if row >= args.best_plots: break if correlation [2] >= 1.0: continue pdfPages = PdfPages (os.path.join (args.outdir, "{}.{}.pdf".format (basename, row))) numPlotted = 0 fig = None def checkPage (last=False): nonlocal pdfPages nonlocal numPlotted nonlocal fig numPlotted += 1 if numPlotted >= 4 or last: numPlotted = 0 fig.subplots_adjust (wspace=0.5, hspace=0.3) pdfPages.savefig (fig) plt.close (fig) if not last: fig = plt.figure () else: fig = None fig = plt.figure () if correlation [1]: # Upper Left: Seeing for both sites ax = fig.add_subplot (2, 2, numPlotted + 1) ax.set_xlabel ("Time") setSeeingY (ax) ax.set_title ("{:%m/%d/%y},{:%m/%d/%y} pc={:0.3f}".format (correlation [0].datetime, correlation [1].datetime, correlation [2])) plotDay (correlation [0], ax, 'red', 'none', 'none', 'o') plotDay (correlation [1], ax, 'blue', 'none', 'none', 'v') checkPage () assert (len (ambient.parameterBasenames) == len (ambient.parameterLimits)) for i in range (1, len (ambient.parameterBasenames)): p = ambient.parameterBasenames [i] limits = ambient.parameterLimits [i] otherDays0 = sites [0][i -1] otherDays1 = sites [1][i -1] otherDay0 = otherDays0.getDay (correlation [0]) otherDay1 = otherDays1.getDay (correlation [0]) ax = fig.add_subplot (2, 2, numPlotted + 1) ax.set_ylabel ("{}".format (p)) ax.set_ylim (*limits) ax.set_xlabel ("Time") if otherDay0 and otherDay1: f0, f1 = [d.goodPeriodFilter () for d in (otherDay0, otherDay1)] m0, m1 = otherDay0.matchMeasurements (otherDay1, f0, f1) pc = ambient.pearsonFromMeasurements (m0, m1, args.min_points) if (pc <= 1): ax.set_title ("pc={:0.3f}".format (pc)) plotDay (otherDay0, ax, 'red', 'none', 'none', 'o') plotDay (otherDay1, ax, 'blue', 'none', 'none', 'v') checkPage (i == len (ambient.parameterBasenames) - 1) pdfPages.close () row += 1