def bundleDictFromDisk(resultDb, runName, metricDataPath): """Load metric data from disk and import them into metricBundles. Args: resultDb(dict): A ResultDb object. runName(str): The name of the opsim database that the metrics stored in resultDb was evaluated on. metricDataPath(str): The path to the directory where the metric data (.npz files) is stored. Returns: bundleDict(dict): A dictionary of metricBundles reconstructed from data stored on disk, the keys designate metric names. """ bundleDict = {} displayInfo = resultDb.getMetricDisplayInfo() for item in displayInfo: metricName = item['metricName'] metricFileName = item['metricDataFile'] metricId = item['metricId'] newbundle = metricBundles.createEmptyMetricBundle() newbundle.read(os.path.join(metricDataPath, metricFileName)) newbundle.setRunName(runName) bundleDict[metricId, metricName] = newbundle return bundleDict
def readMetricData(self, metricName, metricMetadata, slicerName): # Get the names of the individual files for all runs. # Dictionary, keyed by run name. filenames = self.getFileNames(metricName, metricMetadata, slicerName) mname = self._buildSummaryName(metricName, metricMetadata, slicerName, None) bundleDict = {} for r in filenames: bundleDict[r] = mb.createEmptyMetricBundle() bundleDict[r].read(filenames[r]) return bundleDict, mname
def getJson(self, metric): """ Return the JSON string containing the data for a particular metric. """ if len(metric) > 1: return None metric = metric[0] filename = metric['metricDataFile'] if filename.upper() == 'NULL': return None datafile = os.path.join(self.outDir, filename) # Read data back into a bundle. mB = metricBundles.createEmptyMetricBundle() mB.read(datafile) io = mB.outputJSON() if io is None: return None return io.getvalue()
def getJson(self, metric): """ Return the JSON string containing the data for a particular metric. """ if len(metric) > 1: return None metric = metric[0] filename = metric['metricDataFile'] if filename.upper() == 'NULL': return None datafile = os.path.join(self.outDir, filename) # Read data back into a bundle. mB = metricBundles.createEmptyMetricBundle() mB.read(datafile) io = mB.outputJSON() if io is None: return None return io.getvalue()
def go(dirIn='', metric='properMotion', dirOut='testReplot', \ plotDict = {}, units=''): """Replots a particular metric""" # on my system the defailt path is long - set it here. if len(dirIn) < 1: dirIn = 'metricEvals/astro_lsst_01_1004_nside64_griz_n365_r21p0_lims' if len(dirOut) < 1: dirOut = os.getcwd() if not os.access(dirOut, os.R_OK): os.mkdir(dirOut) if not os.access(dirIn, os.R_OK): print "replotAstromMetrics.go FATAL - cannot read inpath %s" \ % (dirIn) return # find .npz files for this metric LEval = glob.glob('%s/*%s*.npz' % (dirIn, metric)) if len(LEval) < 1: print "replotAstromMetrics.go FATAL - no %s .npz present in %s" \ & (metric, dirIn) return pathEval = LEval[0][:] print pathEval # close pre-existing figures plt.close("all") # now load this up mb = metricBundles.createEmptyMetricBundle() mb.read(pathEval) # set the plot dicts appropriately #for sArg in plotDict.keys(): # mb.plotDict[sArg] = plotDict[sArg] #print mb.plotDict mb.setPlotDict(plotDict) # set the units if len(mb.metric.units) < 1: mb.metric.units = units[:] DFigs = mb.plot(savefig=False) # now save the figures somewhere we can control sFigStem = pathEval.split('/')[-1].split('.')[0] # construct the filenames for sKey in ['SkyMap', 'Histogram']: if not sKey in DFigs.keys(): continue sOut = '%s/%s_%s.png' % (dirOut, sFigStem, sKey) thisFig = plt.figure(DFigs[sKey]) if os.access(sOut, os.R_OK): os.remove(sOut) thisFig.savefig(sOut)
def go(dirIn='', metric='properMotion', dirOut='testReplot', \ plotDict = {}, units=''): """Replots a particular metric""" # on my system the defailt path is long - set it here. if len(dirIn) < 1: dirIn = 'metricEvals/astro_lsst_01_1004_nside64_griz_n365_r21p0_lims' if len(dirOut) < 1: dirOut = os.getcwd() if not os.access(dirOut, os.R_OK): os.mkdir(dirOut) if not os.access(dirIn, os.R_OK): print "replotAstromMetrics.go FATAL - cannot read inpath %s" \ % (dirIn) return # find .npz files for this metric LEval = glob.glob('%s/*%s*.npz' % (dirIn, metric)) if len(LEval) < 1: print "replotAstromMetrics.go FATAL - no %s .npz present in %s" \ & (metric, dirIn) return pathEval = LEval[0][:] print pathEval # close pre-existing figures plt.close("all") # now load this up mb = metricBundles.createEmptyMetricBundle() mb.read(pathEval) # set the plot dicts appropriately #for sArg in plotDict.keys(): # mb.plotDict[sArg] = plotDict[sArg] #print mb.plotDict mb.setPlotDict(plotDict) # set the units if len(mb.metric.units) < 1: mb.metric.units = units[:] DFigs = mb.plot(savefig=False) # now save the figures somewhere we can control sFigStem = pathEval.split('/')[-1].split('.')[0] # construct the filenames for sKey in ['SkyMap', 'Histogram']: if not sKey in DFigs.keys(): continue sOut = '%s/%s_%s.png' % (dirOut, sFigStem, sKey) thisFig = plt.figure(DFigs[sKey]) if os.access(sOut, os.R_OK): os.remove(sOut) thisFig.savefig(sOut)