mrtommyb / ktransit

A simple exoplanet transit modeling tool in python
GNU General Public License v3.0
52 stars 20 forks source link

Code cleanup suggestion #13

Closed jasonleehodges closed 6 years ago

jasonleehodges commented 6 years ago

Curious why in the below code you are setting the default of the parameters to None and then checking for None before assigning properties to the self object? Why not just set the defaults within the method definition? For example instead of setting time=None, just set def add_data(self, time=np.arange(0,10,0.0188),...) and then in the body of the method set self.time = time. If the user doesn't put in a time value it will default as expected, otherwise self.time will be set to whatever the user entered for time.

def add_data(self, time=None, itime=None,
        ntt=None, tobs=None, omc=None,
        datatype=None):
        """
        Add data after all the planets are added!!
        """
        if time is None:
            self.time = np.arange(0,10,0.0188)
        else:
            self.time = time
        npt = len(self.time)
        nmax = 1500000

        if itime is None:
            default_cadence = 1625.3 / 86400.
            self.itime = np.zeros(npt) + default_cadence
        else:
            self.itime = itime

        if ntt is None:
            self.ntt = np.zeros(self.nplanets)
        else:
            self.ntt = ntt

        if tobs is None:
            self.tobs = np.empty([self.nplanets,nmax])
        else:
            self.tobs = tobs

        if omc is None:
            self.omc = np.empty([self.nplanets,nmax])
        else:
            self.omc = omc

        if datatype is None:
            self.datatype = np.zeros(npt)
        else:
            self.datatype = datatype
mrtommyb commented 6 years ago

That's a good question. I'm not sure why I did it that way, it looks weird.