How to use the phoebe.utils.utils.traverse function in phoebe

To help you get started, we’ve selected a few phoebe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phoebe-project / phoebe2 / phoebe / backend / fitting.py View on Github external
def lnprob(pars,ids,system):
        #-- evaluate the system, get the results and return a probability
        had = []
        #-- walk through all the parameterSets available:
        walk = utils.traverse(system,list_types=(universe.BodyBag,universe.Body,list,tuple),dict_types=(dict,))
        for parset in system.walk():
            #-- for each parameterSet, walk to all the parameters
            for qual in parset:
                #-- extract those which need to be fitted
                if parset.get_adjust(qual) and parset.has_prior(qual):
                    #-- ask a unique ID and update the value of the parameter
                    myid = parset.get_parameter(qual).get_unique_label()
                    if myid in had: continue
                    index = ids.index(myid)
                    parset[qual] = pars[index]
                    had.append(myid)
        system.reset()
        system.clear_synthetic()
        system.compute(params=params,mpi=mpi)
        logp, chi2, N = system.get_logp()
        return logp
github phoebe-project / phoebe2 / phoebe / frontend / gui / phoebe_gui.py View on Github external
"""
        #~ print "*** update_system"
        self.dataview_refs = [] # will hold all refs in all dataviews
        self.dataview_treeitems = []
        self.dataview_treeitemnames = []
        
        strucnames, strucnchild, strucsel, strucps = self.get_system_structure(struclabel=self.jsmessenger.sysitems_flat, strucsel=self.jsmessenger.sysitems_sel_flat)
        self.system_names = list(utils.traverse(strucnames))
        self.system_ps = list(utils.traverse(strucps))

        self.jsmessenger.sysitems = strucnames
        self.jsmessenger.sysitems_flat = list(utils.traverse(strucnames))
        self.jsmessenger.sysitems_ps = strucps
        self.jsmessenger.sysitems_nchild = strucnchild
        self.jsmessenger.sysitems_sel = strucsel
        self.jsmessenger.sysitems_sel_flat = list(utils.traverse(strucsel))
        
        self.mp_sysSelWebView.page().mainFrame().evaluateJavaScript("PHOEBE.reset('select','from_messenger','None','%s','%s','%s')" % (self.font.family(),self.palette.color(QPalette.Window).name(),self.palette.color(QPalette.Highlight).name()))
        self.mp_sysEditWebView.page().mainFrame().evaluateJavaScript("PHOEBE.reset('edit','from_messenger','None','%s','%s','%s')" % (self.font.family(),self.palette.color(QPalette.Window).name(),self.palette.color(QPalette.Highlight).name()))

        self.on_sysSel_selectionChanged(skip_collapse=True)
github phoebe-project / phoebe2 / phoebe / wd / wd.py View on Github external
def walk(self):
        walk = utils.traverse(self.params,list_types=(list,tuple),dict_types=(dict,))
        for parset in walk:
            yield parset
github phoebe-project / phoebe2 / phoebe / frontend / gui / phoebe_gui.py View on Github external
def get_system_structure(self, struclabel=None, strucsel=None):
        """
        get the hierarchical structure of the system while maintaining the selected items
        this gets passed on to the html system views
        """
        curr_struclabel = list(utils.traverse(struclabel)) #flattened lists of the incoming values before updating
        curr_strucsel = list(utils.traverse(strucsel))
        
        if self.bundle.get_system() is not None:
            strucnames, strucnchild, strucsel, strucps = self.bundle_get_system_structure(self.bundle, return_type=['label','nchild','mask','ps'],old_mask=(curr_struclabel, curr_strucsel))
        else:
            strucnames, strucnchild, strucsel, strucps = [[]],[[]],[[]],[[]]
            
        return strucnames, strucnchild, strucsel, strucps
github phoebe-project / phoebe2 / phoebe / frontend / gui / phoebe_gui.py View on Github external
def update_system(self):
        """
        this should be called whenever a change to the system structure is detected or possible
        this will recreate the html system views (maintaining previous selection)
        """
        #~ print "*** update_system"
        self.dataview_refs = [] # will hold all refs in all dataviews
        self.dataview_treeitems = []
        self.dataview_treeitemnames = []
        
        strucnames, strucnchild, strucsel, strucps = self.get_system_structure(struclabel=self.jsmessenger.sysitems_flat, strucsel=self.jsmessenger.sysitems_sel_flat)
        self.system_names = list(utils.traverse(strucnames))
        self.system_ps = list(utils.traverse(strucps))

        self.jsmessenger.sysitems = strucnames
        self.jsmessenger.sysitems_flat = list(utils.traverse(strucnames))
        self.jsmessenger.sysitems_ps = strucps
        self.jsmessenger.sysitems_nchild = strucnchild
        self.jsmessenger.sysitems_sel = strucsel
        self.jsmessenger.sysitems_sel_flat = list(utils.traverse(strucsel))
        
        self.mp_sysSelWebView.page().mainFrame().evaluateJavaScript("PHOEBE.reset('select','from_messenger','None','%s','%s','%s')" % (self.font.family(),self.palette.color(QPalette.Window).name(),self.palette.color(QPalette.Highlight).name()))
        self.mp_sysEditWebView.page().mainFrame().evaluateJavaScript("PHOEBE.reset('edit','from_messenger','None','%s','%s','%s')" % (self.font.family(),self.palette.color(QPalette.Window).name(),self.palette.color(QPalette.Highlight).name()))

        self.on_sysSel_selectionChanged(skip_collapse=True)
github phoebe-project / phoebe2 / phoebe / frontend / gui / phoebe_gui.py View on Github external
def get_system_structure(self, struclabel=None, strucsel=None):
        """
        get the hierarchical structure of the system while maintaining the selected items
        this gets passed on to the html system views
        """
        curr_struclabel = list(utils.traverse(struclabel)) #flattened lists of the incoming values before updating
        curr_strucsel = list(utils.traverse(strucsel))
        
        if self.bundle.get_system() is not None:
            strucnames, strucnchild, strucsel, strucps = self.bundle_get_system_structure(self.bundle, return_type=['label','nchild','mask','ps'],old_mask=(curr_struclabel, curr_strucsel))
        else:
            strucnames, strucnchild, strucsel, strucps = [[]],[[]],[[]],[[]]
            
        return strucnames, strucnchild, strucsel, strucps
github phoebe-project / phoebe2 / phoebe / frontend / gui / phoebe_gui.py View on Github external
def on_sysSel_selectionChanged(self,skip_collapse=False):
        """
        this function is called when the selection in the html view is changed
        this then sends the selected objects to the left panel treeviews and rebuilds them
        
        if skip_collapse is False, the treeviews will intelligently be hidden or shown
        if skip_collapse is True, no changes will be made to visibility (data will still be refreshed)
        """
        # flatten all parametersets for comparison
        ps_all = list(utils.traverse(self.jsmessenger.sysitems_ps))
        # apply mask to get selected parametersets
        ps_sel = [ps_all[i] for i in range(len(ps_all)) if self.jsmessenger.sysitems_sel_flat[i]]
        
        # now split into orbits and components
        sel_orbits = [s for s in ps_sel if s.context=='orbit']
        sel_comps = [s for s in ps_sel if s.context != 'orbit']
        #~ sel_meshes = [self.bundle.get_mesh(s.get_value('label')) for s in sel_comps] # this is kind of ugly
        sel_meshes = [self.bundle.get_object(s['label']).params['mesh'] for s in sel_comps] # still ugly

        # Collapse unused tree views
        if len(sel_comps) == 0:
            if not skip_collapse:
                self.lp_compPushButton.setChecked(False)
            self.lp_compTreeView.clear() #if not, the cleared first column might still be populated
            self.lp_meshTreeView.clear()
        else: