def unit_conversion(self):

        # function called when 'CONVERT' button is pressed
        if self.unit1 is None or self.unit2 is None:  # when no units are chosen, dialog box will appear
            # close button for the dialog box
            close = MDFlatButton(text="Close", on_release=self.dialog_close)
            self.dialog = MDDialog(title="Unit Error",
                                   text="Select units",
                                   size_hint=(0.7, 1),
                                   buttons=[close])
            self.dialog.open()

        else:
            try:
                # conversion from one unit to the other
                value = float(
                    self.root.window.get_screen('conversion').ids.unity.text)
                # conversion function from the functions module
                conversion_result = round(
                    functions.conversion(self.unit1, self.unit2, value), 3)
                self.root.window.get_screen(
                    'conversion'
                ).ids.convert.text = f'{str(conversion_result)} {self.unit2}'

            except Exception:
                # when the input value is invalid(not a number) dialog box will appear
                close = MDFlatButton(text="Close",
                                     on_release=self.dialog_close)
                self.dialog = MDDialog(title="Value Error",
                                       text="Invalid Input",
                                       size_hint=(0.7, 1),
                                       buttons=[close])
                self.dialog.open()
 def DiscreteAzimuth(self):
     # Calculate Azimuth angles for the discretization of time.
     AZ = []
     NX = np.size(self.X, 0)
     for i in range(self.NightDisc):
         self.obs.date = self.NightBeg + (i + 0.5) * self.Interval
         [Azi, Alt] = conversion(self.obs, self.X[:, 0], self.X[:, 1])
         AZ.append(Azi)
     return AZ
 def DiscreteZenithAngle(self):
     # Calculate zenith angles for the discretization of time.
     ZA = []
     NX = np.size(self.X, 0)
     for i in range(self.NightDisc):
         self.obs.date = self.NightBeg + (i + 0.5) * self.Interval
         [Azi, Alt] = conversion(self.obs, self.X[:, 0], self.X[:, 1])
         ZA.append(np.pi / 2 - np.array(Alt))
     return ZA
    def __init__(self, X, observer, ND, T):
        # This is the inicialization function. It recieves an array X of points in (DEC,RA) coordinates (a two column numpy array),
        # an observer instance of the ephem library, the number of intervals ND for the discretization of the night, and the times
        # since the last visit in the array T with same length as X.

        print datetime.datetime.now()
        self.NightDisc = ND  # Number of intervals for discretization of the night.

        # ACS parameters---------
        self.q_0 = 1  # Parameter for step choosing in ACS
        self.chi = 0.1  # Parameter for pheromone wasting in ACS
        self.rho = 0.1  # Parameter for pheromone updating in ACS
        self.NormObsQ = 1
        self.NormTimeQ = 1
        self.m = 10  # Number of ants per iteration.
        # ------------------------

        # Compute Night parameters
        self.obs = observer  # Observer instance of pyephem.
        sun = ephem.Sun()
        sun.compute(observer)
        self.NightEnd = observer.next_rising(sun)
        observer.date = self.NightEnd
        sun.compute(observer)
        self.NightBeg = observer.previous_setting(sun)
        observer.date = self.NightBeg
        self.NightLength = self.NightEnd - self.NightBeg
        self.Interval = self.NightLength / ND
        print self.NightLength
        # ----------------------

        self.X = X  # DEC-RA of discretization of the sky.
        self.Fact = self.DiscreteFactibles()
        self.TotalFact = sum(self.Fact)
        self.TotalFact = self.TotalFact != 0
        self.X = self.X[self.TotalFact, :]
        self.Fact = self.DiscreteFactibles()
        self.X_obs = []
        for i in range(self.NightDisc):
            self.obs.date = self.NightBeg + (i + 0.5) * self.Interval
            self.X_obs.append(
                np.transpose(
                    np.array(conversion(
                        self.obs, self.X[:, 0],
                        self.X[:, 1]))))  # [AZ,ALT] of X for the observer.
        self.NX = np.size(self.X, 0)
        self.T = T[self.TotalFact]  # Time since last visit for X.
        #self.T = T # Time since last visit for X.
        self.Ph_ObsQ = self.init_Pheromone(
        )  # Pheromone for quality of the observations (little zenith angle).
        self.Ph_TimeQ = self.init_Pheromone(
        )  # Pheromone for correct distance in time between obs of the same point.
        self.Ph_ObsQBeg = self.Ph_ObsQ[1, :]
        self.Ph_TimeQBeg = self.Ph_TimeQ[1, :]
        self.Dist = self.DiscreteDistances()  # Distances between points
        self.ZenAn = [np.pi / 2 - i[:, 1] for i in self.X_obs]
        self.AzAn = [i[:, 0] for i in self.X_obs]
        #self.ZenAn = self.DiscreteZenithAngle()
        #self.AzAn = self.DiscreteAzimuth()
        [self.Times, self.MAA] = self.MoonPosition()
        self.Epsilon = 0.5
        if np.size(X, 0) == 3072:
            self.ObservationTime = 4 * 30. / (24 * 3600)
        elif np.size(X, 0) == 768:
            self.ObservationTime = 16 * 30. / (24 * 3600)
        else:
            self.ObservationTime = 30. / (24 * 3600)
        print self.ObservationTime

        # Best (in Pareto's sense) solutions
        self.BPS = []
        # This list stores the solutions. The solutions are also lists with the form [path,ObsQ,TimeQ].
        # ---------------------------------

        self.m = np.size(self.Fact[0][self.Fact[0] != 0])
        self.IterationNumber = -1
        self.ParetoHistorial = []

        print('Construccion Completa\n')
        print datetime.datetime.now()