Ejemplo n.º 1
0
 def ramping(self):
     from time_string import date_time
     info("Ramp start time: %s" % date_time(self.start_time))
     from time import time, sleep
     for (t, T) in zip(self.times, self.temperatures):
         dt = self.start_time + t - time()
         if dt > 0:
             sleep(dt)
             self.VAL = T
         if self.ramping_cancelled: break
     info("Ramp ended")
Ejemplo n.º 2
0
    def run_ramping_once(self):
        """
        runs ramping trajectory defined by self.time_points and self.temperaturs
        """
        from time_string import date_time
        info("Ramp start time: %s" % date_time(self.start_time))
        from time import time, sleep
        from numpy import where, asarray
        if len(self.temperatures) != 0:
            max_set_T = max(self.temperatures)
            min_set_T = min(self.temperatures)
        else:
            min_set_T = nan
            max_set_T = nan
        for (t, T) in zip(self.times, self.temperatures):
            dt = self.start_time + t - time()
            if dt > 0:
                sleep(dt)
                current_setT = self.get_setT()
                debug('t = %r, T = %r,dt = %r' % (t, T, dt))

                self.set_ramp_T(T)
                if T == max_set_T or T == min_set_T:
                    self.set_PIDCOF(
                        (self.P_default, self.I_default, self.D_default))
                else:
                    self.set_PIDCOF((self.P_default, 0.0, 0.0))
                #coeffs = asarray([  4.33863739e-01,  -5.45776351e-02,   3.90549564e-04])
                #limit = poly.polyval(T, coefs)
                # if T > current_setT:
                #     caput('NIH:LIGHTWAVE.IHLM',limit + 0.2)
                #     caput('NIH:LIGHTWAVE.ILLM',-4.0)
                # else:
                #     caput('NIH:LIGHTWAVE.IHLM',+4.0)
                #     caput('NIH:LIGHTWAVE.ILLM',limit - 0.2)
                try:
                    indices = where(
                        self.times >= t + self.oasis_headstart_time)[0][0:1]
                    debug(indices)
                    if len(indices) > 0:
                        idx = indices[0]
                        self.set_set_oasisT(self.oasis_temperatures[idx])
                        debug('time = %r, oasis T = %r' %
                              (t, self.temp_to_oasis(self.temperatures[idx])))
                except:
                    error(traceback.format_exc())
            if self.ramping_cancelled: break

        info("Ramp ended")
        self.set_PIDCOF((self.P_default, self.I_default, self.D_default))
        self.ramping_cancelled = False
        self.ramping = False
    def run_ramping_once(self):
        """
        runs ramping trajectory defined by self.time_points and self.temperatures
        """
        from time_string import date_time
        info("Ramp start time: %s" % date_time(self.start_time))
        from time import time,sleep
        from numpy import where, asarray
        if len(self.temperatures) != 0:
            max_set_T = max(self.temperatures)
            min_set_T = min(self.temperatures)
        else:
            min_set_T = nan
            max_set_T = nan
        for (t,T, grad_T) in zip(self.times,self.temperatures,self.grad_temperatures):
            dt = self.start_time + t - time()
            if dt > 0:
                sleep(dt)
                current_setT = self.get_setT()
                debug('t = %r, T = %r,dt = %r' %(t,T,dt))
                if len(self.temp_points)>0:
                    self.set_ramp_T(T)
                else:
                    info("The TEMP_POINTS list is empty. No temperature to set in the temperature trajectory.")
                # if T == max_set_T or T == min_set_T:
                    # self.set_PIDCOF((self.P_default,self.I_default,self.D_default))
                # else:
                    # (self.P_default,0.0,0.0)
                    # if grad_T > 0:
                        # self.set_PIDCOF((self.proportional_vs_sample_temperature(T,'up'),0.0,0.0))
                    # elif grad_T < 0:
                        # self.set_PIDCOF((self.proportional_vs_sample_temperature(T,'down'),0.0,0.0))
                    # else:
                        # self.set_PIDCOF((self.P_default,0.0,0.0))

                try:
                    indices = where(self.times >= t+self.oasis_headstart_time)[0][0:1]
                    debug('current index in the trajectory = %r' %indices)
                    if len(indices) > 0:
                        idx = indices[0]
                        self.set_set_oasisT(self.oasis_temperatures[idx])
                        debug('time = %r, oasis T = %r' %(t,self.temp_to_oasis(self.temperatures[idx])))
                except:
                    error(traceback.format_exc())
            if self.ramping_cancelled: break

        info("Ramp ended")
        self.set_PIDCOF((self.P_default,self.I_default,self.D_default))
        self.ramping_cancelled = False
        self.ramping = False
Ejemplo n.º 4
0
 def logfile(self):
     from table import table
     from os.path import basename,exists
     from time_string import date_time
     from numpy import concatenate
     if exists(self.log_filename): logfile = table(self.log_filename)
     else:
         logfile = table()
         logfile["date time"] = [date_time(t) for t in self.start_time+self.scan_T]
         logfile["filename"] = [basename(f) for f in self.image_filenames]
         DX,DY = concatenate([self.scan_DXDY.T]*self.repeat_number).T
         logfile["X[mm]"] = DX
         logfile["Y[mm]"] = DY
     logfile.filename = self.log_filename
     return logfile
Ejemplo n.º 5
0
    def append(self, value):
        from time import time
        from os import makedirs
        from os.path import exists, dirname, getmtime

        # A measurement that is a duplicate of the last is probably old.
        self.read_file()
        if len(self.VALUE) > 0 and value == self.VALUE[-1]: return

        t = time()
        self.T = concatenate((self.T, [t]))
        self.VALUE = concatenate((self.VALUE, [value]))

        if not exists(self.filename):
            if not exists(dirname(self.filename)):
                makedirs(dirname(self.filename))
            logfile = file(self.filename, "ab")
            logfile.write("#date time\tvalue[%s]\n" % counter_unit())
        logfile = file(self.filename, "ab")
        logfile.write("%s\t%s\n" % (date_time(t), tostr(value)))
        logfile.close()
        self.timestamp = getmtime(self.filename)
Ejemplo n.º 6
0
    def log(self, *args, **kwargs):
        """Append to logfile
        time: time in seconds since 1970-01-01 00:00:00 UTC
        """
        from time import time
        from time_string import date_time
        from normpath3 import normpath
        from os.path import exists, dirname
        from os import makedirs

        values = args
        if "time" in kwargs: timestamp = kwargs["time"]
        else: timestamp = time()

        with self.lock:  # Allow only one thread at a time inside this function.
            filename = normpath(self.filename)
            if not exists(dirname(filename)): makedirs(dirname(filename))
            if not exists(filename):
                header = "#" + "\t".join(self.columns) + "\n"
            else:
                header = ""
            fields = [date_time(timestamp)] + [str(v) for v in values]
            line = "\t".join(fields) + "\n"
            file(filename, "ab").write(header + line)