def run(self): """Runs the script""" # Convert the units to the desired ones for meas in zip(*[iter(self.measurements)] * 2): unit = (self.config["relaxation_time"].get("Relax", {}).get( "UnitConversion", None)) if unit: self.data = convert_to_EngUnits(self.data, meas[1], unit) # Plot all Measurements together for x, y in zip(*[iter(self.measurements)] * 2): self.Plots.append( holoplot("Relax", self.data, self.config["relaxation_time"], x, y)) # Add the individual plots self.allPlots = self.Plots[0] self.individual = self.Plots[0] for plot in self.Plots[1:]: self.allPlots *= plot self.individual += plot self.PlotDict["All"] = self.allPlots + self.individual # Reconfig the plots to be sure self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config.get("Relaxation time", {}).get("Layout", {})) return self.PlotDict
def run(self): """Runs the script""" # Convert the units to the desired ones for meas in self.measurements: unit = self.config[self.analysisname].get(meas, {}).get("UnitConversion", None) if unit: self.data = convert_to_EngUnits(self.data, meas, unit) # Scale data first for plots_data in self.to_plot: try: self.data["All"][plots_data[1]] = self.data["All"][plots_data[1]] * float(plots_data[2]) * float(plots_data[3]) # Take the y axis and multipy area and scaling for meas in self.data['keys']: self.data[meas]["data"][plots_data[1]] = self.data[meas]["data"][plots_data[1]] * float(plots_data[2]) * float(plots_data[3]) # Take the y axis and multipy area and scaling except: pass # Plot all Measurements self.PlotDict["All"] = None for plots_data in self.to_plot: try: # If key is not there error happens if self.PlotDict["All"]: self.PlotDict["All"] += Simple2DPlot(self.data, self.config, plots_data[1], plots_data[0], self.analysisname) else: self.PlotDict["All"] = Simple2DPlot(self.data, self.config, plots_data[1], plots_data[0], self.analysisname) except: self.log.warning("Key '{}' not found in data. Skipping.".format(plots_data[1])) # Do CCE self.do_CCE() # Reconfig the plots to be sure self.PlotDict["All"] = config_layout(self.PlotDict["All"], **self.config.get(self.analysisname, {}).get("Layout", {})) return self.PlotDict
def dospecialPlots(data, config, analysisType, plotType, measurements, **plotConfigs): """ Can plot all plots from the specialPlots library and returns It looks in all data files and plots it, if specified in the config! Returns a Holoviews plot object configured with the standard configs It does not allow additional configs for the holoview :param data: Dictionary with the data frames :param config: The configs dict :param analysisType: The analysis type in which should be looked :param plotType: The type of plot as str :param plotConfigs: The parameters for the special plot, not the holoviews framework!!! :param measurements: A list of all possible measurements :return: Holoviews plot object with all plots """ # Plot all Histograms Plots = None log.info("Plotting special plot: {}".format(plotType)) for meas in measurements: # if plotType in config[analysisType].get(meas, {}).get( "AdditionalPlots", "") and plotType in config[analysisType].get( "DoSpecialPlots", []): if Plots: Plots += eval( "{plotType}({dfs},{measurement},{configs}, {analysisType}, **{plotConfigs})" .format( plotType="{}".format(plotType), dfs="data", measurement="meas", configs="config", analysisType="analysisType", plotConfigs="plotConfigs", )) else: Plots = eval( "{plotType}({dfs},{measurement},{configs}, {analysisType}, **{plotConfigs})" .format( plotType="{}".format(plotType), dfs="data", measurement="meas", configs="config", analysisType="analysisType", plotConfigs="plotConfigs", )) if Plots: try: Plots = config_layout(Plots, **config[analysisType].get("Layout", {})) except: pass else: log.warning( "No plots could be generated for {} Plot. No data had a flag for plotting this type of plot" .format(plotType)) return Plots
def run(self): """Runs the script""" # Convert the units to the desired ones for meas in self.measurements: unit = (self.config[self.analysisname].get(meas, {}).get( "UnitConversion", None)) if unit: self.data = convert_to_EngUnits(self.data, meas, unit) # Plot all Measurements self.basePlots = plot_all_measurements( self.data, self.config, self.measurements[0], self.analysisname, do_not_plot=[self.measurements[0]], ) self.PlotDict["All"] = self.basePlots # Plot all special Plots: # Histogram Plot self.Histogram = dospecialPlots( self.data, self.config, self.analysisname, "concatHistogram", self.measurements, **self.config[self.analysisname].get( "AuxOptions", {}).get("concatHistogram", {})) if self.Histogram: self.PlotDict["Histogram"] = self.Histogram self.PlotDict["All"] = self.PlotDict["All"] + self.Histogram # Whiskers Plot self.WhiskerPlots = dospecialPlots(self.data, self.config, self.analysisname, "BoxWhisker", self.measurements) if self.WhiskerPlots: self.PlotDict["Whiskers"] = self.WhiskerPlots self.PlotDict["All"] = self.PlotDict["All"] + self.WhiskerPlots # Violin Plot self.Violin = dospecialPlots(self.data, self.config, self.analysisname, "Violin", self.measurements) if self.Violin: self.PlotDict["Violin"] = self.Violin self.PlotDict["All"] = self.PlotDict["All"] + self.Violin # Reconfig the plots to be sure self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config.get(self.analysisname, {}).get("Layout", {})) return self.PlotDict
def run(self): """Runs the script""" # Plot all Measurements self.basePlots = plot_all_measurements(self.data, self.config, self.xaxis, self.name, do_not_plot = self.donts) self.PlotDict["BasePlots"] = self.basePlots self.PlotDict["All"] = self.basePlots # Histogram Plot self.Histogram = dospecialPlots(self.data, self.config, self.name, "concatHistogram", self.measurements, **self.config[self.name].get("AuxOptions", {}).get("concatHistogram", {})) if self.Histogram: self.PlotDict["Histogram"] = self.Histogram self.PlotDict["All"] = self.PlotDict["All"] + self.Histogram # Whiskers Plot self.WhiskerPlots = dospecialPlots(self.data, self.config, self.name, "BoxWhisker", self.measurements) if self.WhiskerPlots: self.PlotDict["Whiskers"] = self.WhiskerPlots self.PlotDict["All"] = self.PlotDict["All"] + self.WhiskerPlots # Violin Plot self.Violin = dospecialPlots(self.data, self.config,self.name, "Violin", self.measurements) if self.Violin: self.PlotDict["Violin"] = self.Violin self.PlotDict["All"] += self.Violin # singleHist Plot self.singleHist = dospecialPlots(self.data, self.config, self.name, "Histogram", self.measurements, **self.config[self.name].get("AuxOptions", {}).get("singleHistogram", {})) if self.singleHist: self.PlotDict["singleHistogram"] = self.singleHist self.PlotDict["All"] = self.PlotDict["All"] + self.singleHist # Reconfig the plots to be sure self.PlotDict["All"] = config_layout(self.PlotDict["All"], **self.config[self.name].get("Layout", {})) return self.PlotDict
def run(self): """Runs the script""" # Add the measurement to the list # Plot all IV measurements # (data, config, xaxis_measurement, analysis_name, do_not_plot=(), plot_only=(), keys=None, **kwargs) IVplot = None IVSubplot = None self.PlotDict["All"] = None for file in self.data["keys"]: if "IV" in file: for meas in self.measurements: self.config[self.analysisName][meas + "IV"] = self.config[ self.analysisName]["current"] tempplot = plot( self.data, self.config, self.xaxis, self.analysisName, plot_only=(meas, ), keys=(file, ), do_not_plot=self.donts, PlotLabel=meas, ) tempplot = customize_plot(tempplot, "current", self.config[self.analysisName]) if IVplot: IVplot *= tempplot else: IVplot = tempplot if IVSubplot: IVSubplot += tempplot else: IVSubplot = tempplot IVplot = customize_plot(IVplot, "current", self.config[self.analysisName]) # Plot all CV measurements # (data, config, xaxis_measurement, analysis_name, do_not_plot=(), plot_only=(), keys=None, **kwargs) CVplot = None for file in self.data["keys"]: if "CV" in file: for meas in self.measurements: self.config[self.analysisName][meas + "CV"] = self.config[ self.analysisName]["capacitance"] tempplot = plot( self.data, self.config, self.xaxis, self.analysisName, plot_only=(meas, ), keys=(file, ), do_not_plot=self.donts, PlotLabel=meas + "CV", ) if CVplot: CVplot *= tempplot else: CVplot = tempplot CVplot = customize_plot(CVplot, "capacitance", self.config[self.analysisName]) # Add full depletion point to 1/c^2 curve c2plot = None for file in self.data["keys"]: if "1C2" in file: for meas in self.measurements: self.config[self.analysisName][meas + "1c2"] = self.config[ self.analysisName]["1C2"] tempplot = plot( self.data, self.config, self.xaxis, self.analysisName, plot_only=(meas, ), keys=(file, ), do_not_plot=self.donts, PlotLabel=meas + "1c2", ) if c2plot: c2plot *= tempplot else: c2plot = tempplot c2plot = customize_plot(c2plot, "1C2", self.config[self.analysisName]) if IVplot: self.PlotDict["All"] = IVplot self.PlotDict["All"] += IVSubplot if CVplot and self.PlotDict["All"]: self.PlotDict["All"] += CVplot + c2plot elif CVplot and not self.PlotDict["All"]: self.PlotDict["All"] = CVplot + c2plot # Reconfig the plots to be sure self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config[self.analysisName].get("Layout", {})) return self.PlotDict
def run(self): """Runs the script""" # Add the 1/c^2 data to the dataframes for df in self.data["keys"]: if "CV" in self.data[df]["data"]: self.data[df]["data"].insert( 3, "1C2", 1 / self.data[df]["data"]["CV"].pow(2)) self.data[df]["units"].append("arb. units") self.data[df]["measurements"].append("1C2") elif "capacitance" in self.data[df]["data"]: self.data[df]["data"].insert( 3, "1C2", 1 / self.data[df]["data"]["capacitance"].pow(2)) self.data[df]["units"].append("arb. units") self.data[df]["measurements"].append("1C2") # Add the measurement to the list # Plot all Measurements self.basePlots = plot_all_measurements(self.data, self.config, self.xaxis, self.analysisName, do_not_plot=self.donts) #self.basePlots = applyPlotOptions(self.basePlots, {'Curve': {'color': "hv.Cycle('PiYG')"}}) self.PlotDict["BasePlots"] = self.basePlots self.PlotDict["All"] = self.basePlots # Add full depletion point to 1/c^2 curve if self.config[self.analysisName].get("1C2", {}).get( "DoFullDepletionCalculation", False): try: if self.basePlots.Overlay.CV_CURVES_hyphen_minus_Full_depletion.children: c2plot = self.basePlots.Overlay.CV_CURVES_hyphen_minus_Full_depletion.opts( clone=True) else: c2plot = self.basePlots.Curve.CV_CURVES_hyphen_minus_Full_depletion.opts( clone=True) fdestimation = self.find_full_depletion( c2plot, self.data, self.config, PlotLabel="Full depletion estimation") self.PlotDict["All"] += fdestimation self.PlotDict["BasePlots"] += fdestimation except Exception as err: self.log.warning( "No full depletion calculation possible... Error: {}". format(err)) # Whiskers Plot self.WhiskerPlots = dospecialPlots(self.data, self.config, self.analysisName, "BoxWhisker", self.measurements) if self.WhiskerPlots: self.PlotDict["Whiskers"] = self.WhiskerPlots self.PlotDict["All"] = self.PlotDict["All"] + self.WhiskerPlots # Histogram Plot self.HistogramPlots = dospecialPlots(self.data, self.config, self.analysisName, "Histogram", self.measurements) if self.HistogramPlots: self.PlotDict["Histogram"] = self.HistogramPlots self.PlotDict["All"] = self.PlotDict["All"] + self.HistogramPlots # Reconfig the plots to be sure self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config[self.analysisName].get("Layout", {})) return self.PlotDict
def run(self): """Runs the script""" # Convert the units to the desired ones self.original_data = deepcopy(self.data) # Is needed for grading for meas in self.measurements: unit = (self.config[self.analysisName].get(meas, {}).get( "UnitConversion", None)) if unit: self.data = convert_to_EngUnits(self.data, meas, unit) # Add the 1/c^2 data to the dataframes for df in self.data["keys"]: if "CV" in self.data[df]["data"]: self.data[df]["data"].insert( 3, "1C2", 1 / self.data[df]["data"]["CV"].pow(2)) self.data[df]["units"].append("arb. units") self.data[df]["measurements"].append("1C2") elif "capacitance" in self.data[df]["data"]: self.data[df]["data"].insert( 3, "1C2", 1 / self.data[df]["data"]["capacitance"].pow(2)) self.data[df]["units"].append("arb. units") self.data[df]["measurements"].append("1C2") # Add the measurement to the list # Plot all Measurements self.basePlots = plot_all_measurements( self.data, self.config, self.xaxis, self.analysisName, do_not_plot=self.donts, ) # self.basePlots = applyPlotOptions(self.basePlots, {'Curve': {'color': "hv.Cycle('PiYG')"}}) self.PlotDict["BasePlots"] = self.basePlots self.PlotDict["All"] = self.basePlots # Add full depletion point to 1/c^2 curve if (self.config[self.analysisName].get("1C2", {}).get( "DoFullDepletionCalculation", False)): try: if (self.basePlots.Overlay. CV_CURVES_hyphen_minus_Full_depletion.children): c2plot = self.basePlots.Overlay.CV_CURVES_hyphen_minus_Full_depletion.opts( clone=True) else: c2plot = self.basePlots.Curve.CV_CURVES_hyphen_minus_Full_depletion.opts( clone=True) fdestimation = self.find_full_depletion( c2plot, self.data, self.config, PlotLabel="Full depletion estimation", ) self.PlotDict["All"] += fdestimation self.PlotDict["BasePlots"] += fdestimation except Exception as err: self.log.warning( "No full depletion calculation possible... Error: {}". format(err)) # Whiskers Plot self.WhiskerPlots = dospecialPlots(self.data, self.config, self.analysisName, "BoxWhisker", self.measurements) if self.WhiskerPlots: self.PlotDict["Whiskers"] = self.WhiskerPlots self.PlotDict["All"] = self.PlotDict["All"] + self.WhiskerPlots # Histogram Plot self.HistogramPlots = dospecialPlots(self.data, self.config, self.analysisName, "Histogram", self.measurements) if self.HistogramPlots: self.PlotDict["Histogram"] = self.HistogramPlots self.PlotDict["All"] = self.PlotDict["All"] + self.HistogramPlots # Reconfig the plots to be sure self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config[self.analysisName].get("Layout", {})) self.PlotDict["data"] = self.data # Grade the sensor try: self.grade_Sensor() except: self.log.critical( "Some error happend while evaluating grade of sensor. This can happen!", exc_info=True) return self.PlotDict
def run(self): """Runs the script""" # Add the measurement to the list # Plot all IV measurements # (data, config, xaxis_measurement, analysis_name, do_not_plot=(), plot_only=(), keys=None, **kwargs) IVplot = None self.PlotDict["All"] = None for file in self.data["keys"]: if "IV" in file: for meas in self.measurements: self.config[self.analysisName][meas + "IV"] = self.config[ self.analysisName]["current"] tempplot = plot( self.data, self.config, self.xaxis, self.analysisName, plot_only=(meas, ), keys=(file, ), do_not_plot=self.donts, PlotLabel=meas + "IV", ) if IVplot: IVplot *= tempplot else: IVplot = tempplot IVplot = customize_plot(IVplot, "current", self.config[self.analysisName]) # Plot all CV measurements # (data, config, xaxis_measurement, analysis_name, do_not_plot=(), plot_only=(), keys=None, **kwargs) CVplot = None for file in self.data["keys"]: if "CV" in file: for meas in self.measurements: self.config[self.analysisName][meas + "CV"] = self.config[ self.analysisName]["capacitance"] tempplot = plot( self.data, self.config, self.xaxis, self.analysisName, plot_only=(meas, ), keys=(file, ), do_not_plot=self.donts, PlotLabel=meas + "CV", ) if CVplot: CVplot *= tempplot else: CVplot = tempplot CVplot = customize_plot(CVplot, "capacitance", self.config[self.analysisName]) # Add full depletion point to 1/c^2 curve c2plot = None for file in self.data["keys"]: if "1C2" in file: for meas in self.measurements: self.config[self.analysisName][meas + "1c2"] = self.config[ self.analysisName]["1C2"] tempplot = plot( self.data, self.config, self.xaxis, self.analysisName, plot_only=(meas, ), keys=(file, ), do_not_plot=self.donts, PlotLabel=meas + "1c2", ) if c2plot: c2plot *= tempplot else: c2plot = tempplot c2plot = customize_plot(c2plot, "1C2", self.config[self.analysisName]) # if self.config[self.analysisName].get("1C2", {}).get("DoFullDepletionCalculation", False): # try: # if self.basePlots.Overlay.CV_CURVES_hyphen_minus_Full_depletion.children: # c2plot = self.basePlots.Overlay.CV_CURVES_hyphen_minus_Full_depletion.opts(clone = True) ## else: c2plot = self.basePlots.Curve.CV_CURVES_hyphen_minus_Full_depletion.opts(clone = True) # fdestimation = self.find_full_depletion(c2plot, self.data, self.config, PlotLabel="Full depletion estimation") # self.PlotDict["All"] += fdestimation # self.PlotDict["BasePlots"] += fdestimation # except Exception as err: # self.log.warning("No full depletion calculation possible... Error: {}".format(err)) # Reconfig the plots to be sure # self.PlotDict["All"] = config_layout(self.PlotDict["All"], **self.config[self.analysisName].get("Layout", {})) self.PlotDict["All"] = IVplot + CVplot + c2plot # Reconfig the plots to be sure self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config[self.analysisName].get("Layout", {})) return self.PlotDict
def run(self): """Runs the script""" from forge.tools import plainPlot # some elusive error in debugger it works while running it does not, but only here # Do some grouping and sanatizing groupedcountries = self.data["All"].groupby( self.data["All"]["Country/Region"]) # Data grouped by country self.countries = list(groupedcountries.groups) self.PlotDict["All"] = None prekeys = self.data["keys"] for items in self.config["COVID19"]["Countries"]: countryName = list(items.keys())[0] inhabitants = list(items.values())[0] countrycasegrouped = groupedcountries.get_group( countryName).groupby( "Name") # Grouped for death, confirmed, recovered seldata = { } # a dict containing all data from one country grouped by death, confirmed, recovered for i, key in enumerate( prekeys): # The three groups: death, confirmed, recovered rawdata = countrycasegrouped.get_group(key).sum( ) # Some countries have region information (I combine them to a single one) seldata[self.keys_basenames[i]] = rawdata[ self.measurements].reindex(self.measurements) # Now do the anlysis growth = {} relgrowth = {} for key, dat in seldata.items(): growth[key] = dat.diff() # Calculate the relative growth gr = growth[key].reindex(self.measurements) absc = dat.reindex(self.measurements) relgrowth[key] = gr.shift( periods=-1, fill_value=np.nan).divide( absc.replace(0, np.nan)).shift( periods=1, fill_value=np.nan ) * self.config["COVID19"]["GrowingRateMulti"] # Replace the data in the data structure newkeys = [ "Accumulated", "Growth", "RelativeGrowth*{}".format( self.config["COVID19"]["GrowingRateMulti"]) ] self.data["keys"] = newkeys self.data["columns"] = self.keys_basenames units = ["#" for i in self.keys_basenames] for key, dat in zip(newkeys, [seldata, growth, relgrowth]): self.data[key] = { "analysed": False, "plots": False, "header": "" } self.data[key]["measurements"] = self.keys_basenames self.data[key]["units"] = units #self.data[key]["units"][-2] = "%" # The last one is percent dat["Date"] = pd.to_datetime(pd.Series(self.measurements, name="Date", index=pd.Index( self.measurements)), infer_datetime_format=True) dat["Date"] = dat["Date"].dt.to_period('d') dat["Name"] = pd.Series([key for i in self.measurements], name="Name", index=pd.Index(self.measurements)) self.data[key]["measurements"].append("Date") self.data[key]["units"].append("") self.data[key]["data"] = pd.DataFrame(dat) # Start plotting # All individual donts = ["Date"] individual = plot_all_measurements( self.data, self.config, "Date", "COVID19", keys=[ "Accumulated", "Growth", "RelativeGrowth*{}".format( self.config["COVID19"]["GrowingRateMulti"]) ], do_not_plot=donts, PlotLabel="{}".format(countryName)) if self.Plots: self.Plots += individual else: self.Plots = individual self.relgrowth_all_countries(countryName) if self.config["COVID19"]["Normalize"] == True: self.accumulated_all_countries_normalizes( countryName, inhabitants) elif self.config["COVID19"]["Normalize"] == False: self.accumulated_all_countries(countryName) # Cases vs growth if not self.GrowthvsCases: self.GrowthvsCases = plainPlot( "Curve", self.data["Accumulated"]["data"]["confirmed"], self.data["Growth"]["data"]["confirmed"], label=countryName, ylabel="New Cases", **self.config['COVID19']['General'], **self.config['COVID19']['GvC']["PlotOptions"]) else: self.GrowthvsCases *= plainPlot( "Curve", self.data["Accumulated"]["data"]["confirmed"], self.data["Growth"]["data"]["confirmed"], label=countryName, ylabel="New Cases", **self.config['COVID19']['General'], **self.config['COVID19']['GvC']["PlotOptions"]) # Death vs growth if not self.DeathvsCases: self.DeathvsCases = plainPlot( "Curve", self.data["Accumulated"]["data"]["confirmed"], self.data["Accumulated"]["data"]["deaths"], label=countryName, ylabel="Total Deaths", **self.config['COVID19']['General'], **self.config['COVID19']['GvC']["PlotOptions"]) else: self.DeathvsCases *= plainPlot( "Curve", self.data["Accumulated"]["data"]["confirmed"], self.data["Accumulated"]["data"]["deaths"], label=countryName, ylabel="Total Deaths", **self.config['COVID19']['General'], **self.config['COVID19']['GvC']["PlotOptions"]) # Relabel the plots self.GrowthvsCases = relabelPlot( self.GrowthvsCases.opts(xlim=(1, None), ylim=(1, None)), "New Cases vs. Total Cases") self.DeathvsCases = relabelPlot( self.DeathvsCases.opts(xlim=(1, None), ylim=(1, None)), "Total Death vs. Total Cases") if not self.config["COVID19"]["Normalize"]: self.cases = relabelPlot(self.cases, "Confirmed Cases not normalized") self.recovered = relabelPlot(self.recovered, "Recovered Cases not normalized") self.deaths = relabelPlot(self.deaths, "Deaths not normalized") self.casesrelgrowth = relabelPlot(self.casesrelgrowth, "Confirmed Cases relative growth") self.recoveredrelgrowth = relabelPlot( self.recoveredrelgrowth, "Recovered Cases relative growth") self.deathsrelgrowth = relabelPlot(self.deathsrelgrowth, "Deaths relative growth") if self.config["COVID19"]["Normalize"]: self.casesNorm = relabelPlot(self.casesNorm, "Confirmed Cases normalized") self.recoveredNorm = relabelPlot(self.recoveredNorm, "Recovered Cases normalized") self.deathsNorm = relabelPlot(self.deathsNorm, "Deaths normalized") # Define Plotting order self.plottingOrder = [ self.GrowthvsCases, self.DeathvsCases, self.casesNorm, self.recoveredNorm, self.deathsNorm, self.casesrelgrowth, self.recoveredrelgrowth, self.deathsrelgrowth, self.cases, self.recovered, self.deaths, self.Plots ] for plot in self.plottingOrder: if plot: if self.PlotDict["All"]: self.PlotDict["All"] += plot else: self.PlotDict["All"] = plot # Reconfig the plots to be sure self.PlotDict["All"].opts(opts.Bars(stacked=True)) self.PlotDict["All"] = config_layout( self.PlotDict["All"], **self.config.get(self.analysisname, {}).get("Layout", {})) return self.PlotDict