Exemplo n.º 1
0
    def update_plot(self):
        '''
        update the plot parameters to select the user's
        preferences. also writes these to disk.
        '''
        # map the ui elements to the corresponding
        # parameter names in the plot params list
        add_plot_params(self)

        # load things up in the R side
        python_to_R.load_vars_for_plot(self.img_params_path)

        # update relevant variables (on the R side)
        # with new values -- we also write the updated
        # params out to disk here
        python_to_R.update_plot_params(self.current_param_vals,
                                      write_them_out=True,
                                      outpath="%s.params" % self.img_params_path)
        print("out path for params: %s" % "%s.params" % self.img_params_path)

        # now re-generate the plot data on the R side of
        # things
        #python_to_R.regenerate_plot_data(title=self.title)
        python_to_R.regenerate_plot_data()


        # finally, actually make the plot and spit it to disk in pdf and png formats
        self.png_path = self.current_param_vals["fp_outpath"]
        python_to_R.generate_forest_plot(self.png_path)
        
        python_to_R.write_out_plot_data("%s" % self.img_params_path)
Exemplo n.º 2
0
    def save_image_as(self, params_path, title, plot_type="forest", unscaled_image=None, fmt="png"):
        
        if fmt not in ["pdf","png"]:
            raise Exception("Invalid fmt, needs to be either pdf or png!")
        
        print("unscaled_image: %s" % str(unscaled_image))
        #if not unscaled_image:
        # note that the params object will, by convention,
        # have the (generic) name 'plot.data' -- after this
        # call, this object will be in the namespace
        ##if plot_type not in ["funnel", "histogram", "scatterplot", "forest__phylo"]:
        ##    python_to_R.load_in_R("%s.plotdata" % params_path)
        ##    print("Loaded: %s" % "%s.plotdata" % params_path)
        if plot_type in ["forest", "regression"]:
            python_to_R.load_in_R("%s.plotdata" % params_path)
            print("Loaded: %s" % "%s.plotdata" % params_path)
        elif plot_type == "forest plot of coefficients":
            python_to_R.load_in_R("%s.coef_fp_data" % params_path)
            print("Loaded: %s" % "%s.coef_fp_data" % params_path)

        suffix = unicode("."+fmt)
        default_filename = {"forest":"forest_plot",
                            "forest__phylo":"forest_plot",
                            "regression":"regression",
                            "funnel":"funnel_plot",
                            "histogram":"histogram",
                            "scatterplot":"scatterplot",
                            "forest plot of coefficients":"forest_plot_of_coefficients"}[plot_type] + suffix
        
                        
        default_path = os.path.join(get_user_desktop_path(), default_filename)
        print("default_path for graphic: %s" % default_path)
        default_path = QString(default_path)
        default_path
        
        dfilter = fmt + " files (*." + fmt +")"
        print("filter: %s" % dfilter)

        # where to save the graphic?
        file_path = unicode(QFileDialog.getSaveFileName(self, 
                                                        "OpenMEE -- save plot as",
                                                        default_path,))
                                                        #filter=QString(dfilter)))

        # now we re-generate it, unless they canceled, of course
        if file_path != "":
            if file_path[-4:] != suffix:
                file_path += suffix

            if plot_type == "forest":
                if self._is_side_by_side_fp(title):
                    python_to_R.generate_forest_plot(file_path, side_by_side=True)
                else:
                    python_to_R.generate_forest_plot(file_path)
            elif plot_type == "forest__phylo":
                python_to_R.regenerate_phylo_forest_plot(file_path)
            elif plot_type == "regression":
                python_to_R.generate_reg_plot(file_path)
            elif plot_type == "funnel":
                python_to_R.regenerate_funnel_plot(params_path, file_path)
            elif plot_type in ["histogram","scatterplot"]:
                python_to_R.regenerate_exploratory_plot(params_path, file_path, plot_type=plot_type)
            elif plot_type == "forest plot of coefficients":
                python_to_R.regenerate_forest_plot_of_coefficients(file_path, params_path, fmt)
            else:
                print "sorry -- I don't know how to draw %s plots!" % plot_type
#        else: # case where we just have the png and can't regenerate the pdf from plot data
#            print("Can't regenerate pdf")
#            default_path = '.'.join([title.replace(' ','_'),"png"])
#            file_path = unicode(QFileDialog.getSaveFileName(self, "OpenMeta[Analyst] -- save plot as", QString(default_path)))
#            unscaled_image.save(QString(file_path),"PNG")

            self.statusbar.showMessage("Saved image to %s" % file_path, 10000)