Example #1
0
    def __init__(self,  data,
                        priors):
                            
        # TODO: autoriser l'utilisateur à ne pas faire de Gelman-Rubin                            
 
         # TODO: Revoir les méthodes Temporary et showCorner de AISampler
 
         # TODO: revoir la méthode showPDF

         # TODO: dans le notebook, avant de faire tourner le MCMC, on doit présenter les méthodes liés à la visualisation des data, ...
 
        # TODO: créer une méthode qui ajoute ou retire un point d'observation dans les data.                  

        # TODO: les highly probable initial guess devrait se trouver dans un fichier texte lui-même sauvegardé dans PyAstrOFit/rsc.
        
        """ The constructor of the class """
        # -----------------------------
        # Main part of the constructor
        # -----------------------------
         
        ## Get the data and convert the time of observation in JD                
        self._ob, self._er = get_planet_data(data)
        if self._ob is None and self._er is None:
            try:
                FileHandler.__init__(self,data,addContent=[])
                (self._ob, self._er) = FileHandler.getInfo(self)        
            except:
                raise Exception("Crash during the load of your data. Is the path correct ? --> {}".format(data))

        if len(self._ob.values()[0]) == 0:
            raise Exception("The file '{}' seems to be empty.".format(data))
        self._ob['timePositionJD'] = [Time(self._ob['timePosition'][k],format='iso',scale='utc').jd for k in range(len(self._ob['timePosition']))]
        self._l = len(self._ob['timePositionJD'])                
                   
        self._data = data                 
        self._ndim = 6     
        self._pKey = ['semiMajorAxis','eccentricity','inclinaison', 'longitudeAscendingNode', 'periastron', 'periastronTime']    

        ## Check what contains the attribut priors and initialize the initial state self._theta0
        self._priors, self._theta0 = AISampler.priors_check(self,priors)
        
        ## List class attributs
        self._list = [s for s in dir(self) if s[0] == '_' and s[1] != '_' and s[1:12] != 'FileHandler' and s[1:4] != 'get']   
    def __init__(self, markovchain, data, priors, lnprobability=None, input_parameters=None, outputPath=""):

        """ The constructor of the class """
        ### TODO: les attributs qui ne nécessitent pas d'appel via @property
        ###       devraient être renommé self.attribut au lieu de self._attribut

        # Priors and Input parameters
        self._priors = priors
        self._input_parameters = input_parameters

        if input_parameters is not None:
            self._synthetic = self._input_parameters["synthetic"]
        else:
            self._synthetic = False

        # Markov chain
        if self._synthetic:
            self.markovchain_synthetic = markovchain
            self.markovchain = np.zeros_like(markovchain)
            for j, walker in enumerate(self.markovchain_synthetic):
                self.markovchain[j, :, :] = np.array(
                    [
                        toKepler(
                            parameters,
                            which=self._priors["which"],
                            mass=self._priors["starMass"],
                            referenceTime=self._priors["referenceTime"],
                        )
                        for parameters in walker
                    ]
                )
        else:
            self.markovchain = markovchain
            self.markovchain_synthetic = np.zeros_like(markovchain)

        self._isamples = np.empty([0])
        self._isamples_in_confidence = np.empty([0])
        self._isamples_out_confidence = np.empty([0])
        self._isamples_synthetic = np.empty([0])

        # log-likelihood
        self.lnprobability = lnprobability
        self._ilnprobability = np.empty([0])

        # chi2 and n_orbit
        self._iorbit = None
        self._n_iorbit = 0.0
        self._ichi2_in_confidence = np.empty([0])
        self._n_iorbit_in_confidence = 0.0
        self._ichi2_out_confidence = np.empty([0])
        self._n_iorbit_out_confidence = 0.0

        # Load observations
        self._ob, self._er = get_planet_data(data)
        if self._ob is None and self._er is None:
            try:
                # FileHandler.__init__(self,self._dataFilePath,addContent=[])
                st_temp = fh(data)
                (self._ob, self._er) = st_temp.getInfo()
            except:
                raise Exception("Crash during the load of your data. Is the path correct ? --> {}".format(data))

        if len(self._ob.values()[0]) == 0:
            raise Exception("The file '{}' seems to be empty.".format(data))

        self._nob = len(self._ob["timePosition"])
        self._ob["timePositionJD"] = [
            Time(self._ob["timePosition"][k], format="iso", scale="utc").jd for k in range(self._nob)
        ]

        # Other arguments
        self._outputpath = outputPath
        self._pKey = [
            "semiMajorAxis",
            "eccentricity",
            "inclinaison",
            "longitudeAscendingNode",
            "periastron",
            "periastronTime",
        ]
        self._nwalker, self._walker_length, self._nparameters = self.markovchain.shape
        self._dof = self._nob * 2 - self._nparameters
        self._length = -1
        self._dim = self.markovchain.shape[2]
        self._best = None
        self.valMax = None
        self.confidenceInterval = None