def __init__(self, start_time_s, end_time_s):
        """ Constructor. """

        lg.info(" *")
        lg.info(" * Initialising DataDay object...")

        ## The start time of the day [s].
        self.__st_s = start_time_s

        lg.info(" *--> Start time is % 15d [s] => '%s' UTC." % (self.__st_s, make_time_dir(self.__st_s)))

        ## The Python time object representing the day start time.
        self.__st = time.gmtime(self.__st_s)

        ## The Pixelman time string of the start time.
        self.__st_str = getPixelmanTimeString(self.__st_s)[2]

        ## The end time of the day [s].
        self.__et_s = end_time_s

        ## The Python time object representing the month end time.
        self.__et = time.gmtime(self.__et_s)

        ## The Pixelman time string of the end time.
        self.__et_str = getPixelmanTimeString(self.__et_s)[2]

        ## The duration of the day [s].
        self.__Delta_s = self.__et_s - self.__st_s + 1

        ## The number of non-full hour seconds in the day (error checking).
        self.__remainder_seconds = int(self.__Delta_s % (60 * 60))

        ## The number of hours in the day [hours].
        self.__n_hours = int((self.__Delta_s - self.__remainder_seconds) / (60 * 60))
        #
        if self.__remainder_seconds != 0:
            raise IOError("* Error! Day has %d remainder seconds." % (self.__remainder_seconds))

        ## Dictionary of the number of frames recorded in each day.
        self.__frames_in_an_hour = {}
        #
        ## Dictionary of the hours in the day.
        self.__hours = {}
        #
        for hour in range(self.__n_hours):

            self.__frames_in_an_hour[hour] = 0

            self.__hours[hour] = DataHour(self.__st_s + (hour*60*60), self.__st_s + ((hour+1)*60*60) - 1)

        ## The number of frames found in that day.
        self.__num_frames = 0

        # Update the user.
        lg.info(" * Start time is %s (%d)" % (self.__st_str, self.__st_s))
        lg.info(" * End   time is %s (%d)" % (self.__et_str, self.__et_s))
        lg.info(" * Number of hours in the day = %d" % (self.__n_hours))
        lg.info(" *")
示例#2
0
    def __init__(self, start_time_s, end_time_s):
        """ Constructor. """

        lg.info(" *")
        lg.info(" * Initialising DataDay object...")

        ## The start time of the day [s].
        self.__st_s = start_time_s

        ## The Python time object representing the day start time.
        self.__st = time.gmtime(self.__st_s)

        ## The Pixelman time string of the start time.
        self.__st_str = getPixelmanTimeString(self.__st_s)[2]

        ## The end time of the day [s].
        self.__et_s = end_time_s

        ## The Python time object representing the month end time.
        self.__et = time.gmtime(self.__et_s)

        ## The Pixelman time string of the end time.
        self.__et_str = getPixelmanTimeString(self.__et_s)[2]

        ## The duration of the day [s].
        self.__Delta_s = self.__et_s - self.__st_s + 1

        ## The number of non-full hour seconds in the day (error checking).
        self.__remainder_seconds = int(self.__Delta_s % (60 * 60))

        ## The number of hours in the day [hours].
        self.__n_hours = int((self.__Delta_s - self.__remainder_seconds) / (60 * 60))
        #
        if self.__remainder_seconds != 0:
            raise IOError("* Error! Day has %d remainder seconds." % (self.__remainder_seconds))

        ## Dictionary of the number of frames recorded in each day.
        self.__frames_in_an_hour = {}
        #
        ## Dictionary of the hours in the day.
        self.__hours = {}
        #
        for hour in range(self.__n_hours):

            self.__frames_in_an_hour[hour] = 0

            self.__hours[hour] = DataHour(self.__st_s + (hour*60*60), self.__st_s + ((hour+1)*60*60) - 1)

        ## The number of frames found in that day.
        self.__num_frames = 0

        # Update the user.
        lg.info(" * Start time is %s (%d)" % (self.__st_str, self.__st_s))
        lg.info(" * End   time is %s (%d)" % (self.__et_str, self.__et_s))
        lg.info(" * Number of hours in the day = %d" % (self.__n_hours))
        lg.info(" *")
示例#3
0
    def __init__(self, start_time_s, end_time_s):
        """ Constructor. """

        lg.info(" *")
        lg.info(" * Initialising DataHour object...")

        ## The start time of the hour [s].
        self.__st_s = start_time_s

        ## The Python time object representing the hour's start time.
        self.__st = time.gmtime(self.__st_s)

        ## The Pixelman time string of the start time.
        self.__st_str = getPixelmanTimeString(self.__st_s)[2]

        ## The end time of the hour [s].
        self.__et_s = end_time_s

        ## The Python time object representing the hour's end time.
        self.__et = time.gmtime(self.__et_s)

        ## The Pixelman time string of the end time.
        self.__et_str = getPixelmanTimeString(self.__et_s)[2]

        ## The duration of the hour [s].
        self.__Delta_s = self.__et_s - self.__st_s + 1

        ## The number of non-minute hour seconds in the hour (error checking).
        self.__remainder_seconds = int(self.__Delta_s % 60)

        ## The number of minutes in the day [hours].
        self.__n_minutes = int((self.__Delta_s - self.__remainder_seconds) / 60)
        #
        if self.__remainder_seconds != 0:
            raise IOError("* Error! Hour has %d remainder seconds." % (self.__remainder_seconds))

        ## List of frame start times.
        self.__f_sts = []

        ## A list of frame acquisition times.
        self.__f_ats = []

        ## A list of the number of pixels in each frame.
        self.__f_nps = []

        ## The number of frames found in that hour.
        self.__num_frames = 0

        # Update the user.
        lg.info(" * Start time is %s (%d)" % (self.__st_str, self.__st_s))
        lg.info(" * End   time is %s (%d)" % (self.__et_str, self.__et_s))
        lg.info(" * Number of minutes in the hour = %d" % (self.__n_minutes))
        lg.info(" *")
示例#4
0
    def __init__(self, start_time_s, end_time_s):
        """ Constructor. """

        lg.info(" * Initialising DataMonth object...")

        ## The start time of the month [s].
        self.__st_s = start_time_s

        ## The Python time object representing the month start time.
        self.__st = time.gmtime(self.__st_s)

        ## The Pixelman time string of the start time.
        self.__st_str = getPixelmanTimeString(self.__st_s)[2]

        ## The end time of the month [s].
        self.__et_s = end_time_s

        ## The Python time object representing the month end time.
        self.__et = time.gmtime(self.__et_s)

        ## The Pixelman time string of the end time.
        self.__et_str = getPixelmanTimeString(self.__et_s)[2]

        ## The duration of the month [s].
        self.__Delta_s = self.__et_s - self.__st_s + 1

        ## The number of non-full day seconds in the month (error checking).
        self.__remainder_seconds = self.__Delta_s % (60 * 60 * 24)

        ## The number of days in the month [days].
        self.__n_days = (self.__Delta_s - self.__remainder_seconds) / (60 * 60 * 24)
        #
        if self.__remainder_seconds != 0:
            raise IOError("* Error! Month has %d remainder seconds." % (self.__remainder_seconds))

        ## Dictionary of the number of frames recorded in each day.
        self.__frames_in_a_day = {}
        #
        #
        for day in range(1, self.__n_days + 1):
            self.__frames_in_a_day[day] = 0

        ## The number of frames found in that month.
        self.__num_frames = 0

        # Update the user.
        lg.info(" * Start time is %s (%d)" % (self.__st_str, self.__st_s))
        lg.info(" * End   time is %s (%d)" % (self.__et_str, self.__et_s))
        lg.info(" * Number of days in the month = %d" % (self.__n_days))
        lg.info(" *")
    def test_0_00_mm_dataset(self):

        # Load the 0.00 mm dataset JSON.

        ## The frame properties JSON file.
        ff = open("data/sr/0-00_mm/frames.json", "r")
        #
        ## The frame properties JSON object.
        fd = json.load(ff)
        #
        ff.close()

        # Check the number of frames.
        self.assertEqual(len(fd), 600)

        # Check the start time of the first frame.
        start_time = sorted([st["start_time"] for st in fd])[0]
        #
        st, sub, start_time_str = getPixelmanTimeString(start_time)
        lg.info(" * 0.00 mm: '%s'" % (start_time_str))
        lg.info(" *")
        #
        self.assertEqual(start_time_str, "Tue Jul 30 09:55:15.000000 2013")
示例#6
0
    def __init__(self, **kwargs):
        """
        Constructor.
        """
        lg.debug(" Instantiating a Frame object.")

        # Geospatial information
        #------------------------

        if "lat" not in kwargs.keys():
            raise IOError("FRAME_NO_LAT")

        ## The frame latitude [deg.].
        self.__lat = kwargs["lat"]

        if "lon" not in kwargs.keys():
            raise IOError("FRAME_NO_LON")

        ## The frame longitude [deg.].
        self.__lon = kwargs["lon"]

        if "alt" not in kwargs.keys():
            raise IOError("FRAME_NO_ALT")

        ## The frame altitude [m].
        self.__alt = kwargs["alt"]

        ## The roll angle of the lab. frame [deg.].
        self.__roll = 0.0
        if "roll" in kwargs.keys():
            # TODO: validate the value.
            self.__roll = kwargs["roll"]

        ## The pitch angle of the lab. frame [deg.].
        self.__pitch = 0.0
        if "pitch" in kwargs.keys():
            # TODO: validate the value.
            self.__pitch = kwargs["pitch"]

        ## The yaw angle of the lab. frame [deg.].
        self.__yaw = 0.0
        if "yaw" in kwargs.keys():
            # TODO: validate the value.
            self.__yaw = kwargs["yaw"]

        ## The Omega_x of the lab frame [deg. s^{-1}].
        self.__omegax = 0.0
        if "omegax" in kwargs.keys():
            self.__omegax = kwargs["omegax"]

        ## The Omega_y of the lab frame [deg. s^{-1}].
        self.__omegay = 0.0
        if "omegay" in kwargs.keys():
            self.__omegay = kwargs["omegay"]

        ## The Omega_z of the lab frame [deg. s^{-1}].
        self.__omegaz = 0.0
        if "omegaz" in kwargs.keys():
            self.__omegaz = kwargs["omegaz"]

        # For the detector.

        if "chipid" not in kwargs.keys():
            raise IOError("FRAME_NO_CHIPID")

        ## The chip ID.
        self.__chipid = kwargs["chipid"]

        if "biasvoltage" not in kwargs.keys():
            raise IOError("FRAME_NO_HV")

        ## The bias voltage (HV) [V].
        self.__hv = kwargs["biasvoltage"]

        if "ikrum" not in kwargs.keys():
            raise IOError("FRAME_NO IKRUM")

        ## The detector I_Krum value.
        self.__ikrum = kwargs["ikrum"]

        ## The detector x position [mm].
        self.__det_x = 0.0
        if "detx" in kwargs.keys():
            self.__det_x = kwargs["detx"]

        ## The detector y position [mm].
        self.__det_y = 0.0
        if "dety" in kwargs.keys():
            self.__det_y = kwargs["dety"]

        ## The detector z position [mm].
        self.__det_z = 0.0
        if "detz" in kwargs.keys():
            self.__det_z = kwargs["detz"]

        ## The detector Euler angle a [deg.].
        self.__det_euler_a = 0.0
        if "deteulera" in kwargs.keys():
            self.__det_euler_a = kwargs["deteulera"]

        ## The detector Euler angle b [deg.].
        self.__det_euler_b = 0.0
        if "deteulerb" in kwargs.keys():
            self.__det_euler_b = kwargs["deteulerb"]

        ## The detector Euler angle c [deg.].
        self.__det_euler_c = 0.0
        if "deteulerc" in kwargs.keys():
            self.__det_euler_c = kwargs["deteulerc"]

        # Temporal information
        #----------------------

        if "starttime" not in kwargs.keys() or "acqtime" not in kwargs.keys():
            raise IOError("BAD_FRAME_TIME_INFO")

        ## The start time [s].
        self.__starttime = kwargs["starttime"]

        ## The acquisition time [s].
        self.__acqtime = kwargs["acqtime"]

        self.__starttimesec, self.__starttimesubsec, sts = \
            getPixelmanTimeString(self.__starttime)
        lg.debug(" Frame found with start time: '%s'." % (sts))

        ## The end time [s].
        self.__endtime = self.__starttime + self.__acqtime

        self.__endtimesec, self.__endtimesubsec, ets = \
            getPixelmanTimeString(self.__endtime)

        # Payload information
        #--------------------

        ## The frame width.
        self.__width = 256

        if "width" in kwargs.keys():
            self.__width = kwargs["width"]

        ## The frame height.
        self.__height = 256

        if "height" in kwargs.keys():
            self.__height = kwargs["height"]

        if "format" not in kwargs.keys():
            raise IOError("FRAME_NO_FORMAT")

        ## The payload format.
        self.__format = kwargs["format"]

        ## The map of the pixels.
        self.__pixelmap = {}

        if "pixelmap" in kwargs.keys():
            self.__pixelmap = kwargs["pixelmap"]

        ## The pixel mask map.
        self.__pixel_mask_map = {}

        if "pixelmask" in kwargs.keys():
            self.__pixel_mask_map = kwargs["pixelmask"]

        ## Is the data from a Monte Carlo simulation?
        self.__isMC = False
        if "ismc" in kwargs.keys():
            self.__ismc = kwargs["ismc"]

        if "skipclustering" in kwargs.keys():
            if kwargs["skipclustering"]:
                #print("SKIPPING THE CLUSTERING!")
                self.__n_klusters = -1
                return None

        # Do the clustering.

        ## The frame's cluster finder.
        self.__kf = KlusterFinder(self.getPixelMap(), self.getWidth(),
                                  self.getHeight(), self.isMC(),
                                  self.__pixel_mask_map)

        self.__n_klusters = self.__kf.getNumberOfKlusters()
示例#7
0
        #acq_time = float(dataset_chain.Acq_time)

        #lg.info(" * Frame % 15d: %s (%f), %f [s]" % (fn, start_time_str, st, acq_time))

    ## The acquisition time for the frame (from the last frame).
    delta_t = dataset_chain.Acq_time

    # Close the ROOT file.
    f.Close()

    # Sort the list of start times.
    st_s = sorted(st_s)

    # Get the first frame's start time information.
    first_start_time_s, first_start_time_subsec, first_start_time_str = getPixelmanTimeString(st_s[0])

    # Get the last frame's start time information.
    last_start_time_s, last_start_time_subsec, last_start_time_str = getPixelmanTimeString(st_s[-1])

    ## The total length of time covered by the dataset [s].
    Delta_T = st_s[-1] - st_s[0]

    ## The average time between frames [s].
    Delta_t = Delta_T / (len(st_s) - 1)

    ## The file size [B].
    file_size = os.path.getsize(datapath)

    # Create the dataset information JSON.
    dataset_info_dict = {}
示例#8
0
    def processDscFile(self):
        """ Process the detector settings file (.dsc). """

        # The DSC file.
        f = open(self.__dscfilename, "r")

        ## The lines of the DSC file.
        ls = f.readlines()

        # Close the DSC file.
        f.close()

        lg.debug("")

        # The frame width and height.
        whvals = ls[2].strip().split(" ")

        try:
            self.__fWidth = int(whvals[2].split("=")[1])
        except TypeError:
            raise IOError("BAD_WIDTH")

        if self.__fWidth < 256 or self.__fWidth > 1024:
            raise IOError("BAD_WIDTH")

        try:
            self.__fHeight = int(whvals[3].split("=")[1])
        except TypeError:
            raise IOError("BAD_HEIGHT")

        if self.__fHeight < 256 or self.__fHeight > 1024:
            raise IOError("BAD_HEIGHT")

        lg.debug(" * Frame dimensions: %d [pix.] x %d [pix.]." %
                 (self.__fWidth, self.__fHeight))

        # Loop over the lines of the DSC file.
        for i, l in enumerate(ls):
            #print("%5d: %s" % (i, l.strip()))

            # Acquisition mode.
            if DSC_ACQ_MODE_STRING in l:
                try:
                    self.__acqMode = int(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_ACQ_MODE")
                lg.debug(" * Acquisition mode is '%s'." %
                         (ACQ_MODES[self.__acqMode]))

            elif DSC_ACQ_TIME_STRING in l:
                try:
                    self.__acqTime = float(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_ACQ_TIME")
                lg.debug(" * Acquisition time is '%f' [%s]." %
                         (self.__acqTime, ACQ_TIME_UNITS_SHORT))

            elif DSC_CHIPID_STRING in l:

                chipid = ls[i + 2].strip()
                if not isChipIdValid(chipid):
                    raise IOError("Invalid chip ID in the DSC file.")
                self.__chipid = chipid
                lg.debug(" * Chip ID is '%s'." % (self.__chipid))

            elif DSC_DACS_STRING in l:

                # Break down the DAC string.
                self.__dacs = [int(x) for x in ls[i + 2].strip().split(" ")]

                self.__IKrum = self.__dacs[0]
                self.__Disc = self.__dacs[1]
                self.__Preamp = self.__dacs[2]
                self.__BuffAnalogA = self.__dacs[3]
                self.__BuffAnalogB = self.__dacs[4]
                self.__Hist = self.__dacs[5]
                self.__THL = self.__dacs[6]
                self.__THLCoarse = self.__dacs[7]
                self.__Vcas = self.__dacs[8]
                self.__FBK = self.__dacs[9]
                self.__GND = self.__dacs[10]
                self.__THS = self.__dacs[11]
                self.__BiasLVDS = self.__dacs[12]
                self.__RefLVDS = self.__dacs[13]

                lg.debug(" * DAC values:")
                lg.debug(" * --> IKrum           = %4d" % (self.__IKrum))
                lg.debug(" * --> Disc            = %4d" % (self.__Disc))
                lg.debug(" * --> Preamp          = %4d" % (self.__Preamp))
                lg.debug(" * --> BuffAnalogA     = %4d" % (self.__BuffAnalogA))
                lg.debug(" * --> BuffAnalogB     = %4d" % (self.__BuffAnalogB))
                lg.debug(" * --> Hist            = %4d" % (self.__Hist))
                lg.debug(" * --> THL             = %4d" % (self.__THL))
                lg.debug(" * --> THLCoarse       = %4d" % (self.__THLCoarse))
                lg.debug(" * --> Vcas            = %4d" % (self.__Vcas))
                lg.debug(" * --> FBK             = %4d" % (self.__FBK))
                lg.debug(" * --> GND             = %4d" % (self.__GND))
                lg.debug(" * --> THS             = %4d" % (self.__THS))
                lg.debug(" * --> BiasLVDS        = %4d" % (self.__BiasLVDS))
                lg.debug(" * --> RefLVDS         = %4d" % (self.__RefLVDS))

            elif DSC_FIRMWARE_STRING in l:
                self.__firmwarev = ls[i + 2].strip()

            # Note - needs 'lower()' because of a 2.1.1/2.2.2 mismatch...
            elif DSC_BIAS_VOLTAGE_STRING.lower() in l.lower():
                try:
                    hv = float(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_HV_VALUE")

                if hv < 0.0 or hv > 100.0:
                    raise IOError("BAD_HV_VALUE")

                self.__hv = hv
                lg.debug(" * Bias voltage (HV) is %f [V]." % (self.__hv))

            elif DSC_HW_TIMER_STRING in l:
                try:
                    self.__hwTimerMode = int(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_HW_TIMER_MODE")
                lg.debug(" * Hardware time mode is '%s'." %
                         (HW_TIME_MODES[self.__hwTimerMode]))

            elif DSC_INTERFACE_STRING in l:
                self.__interface = ls[i + 2].strip()
                lg.debug(" * Interface is '%s'." % (self.__interface))

            elif DSC_MPX_CLOCK_STRING in l:
                try:
                    mpxClock = float(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_MPX_CLOCK")
                self.__mpxClock = mpxClock
                lg.debug(" * Medipix clock is %f [MHz]." % (self.__mpxClock))

            elif DSC_MPX_TYPE_STRING in l:
                try:
                    mpxType = int(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_MPX_TYPE")
                if mpxType not in [1, 2, 3]:
                    raise IOError("BAD_MPX_TYPE")
                self.__mpxType = mpxType
                lg.debug(" * Detector type is '%s'." %
                         (MPX_TYPES_LONG[self.__mpxType]))

            elif DSC_PIXELMAN_VERSION_STRING in l:
                self.__pixelmanv = ls[i + 2].strip()
                lg.debug(" * Pixelman version is '%s'." % (self.__pixelmanv))

            elif DSC_POLARITY_STRING in l:
                try:
                    pol = int(ls[i + 2].strip())
                except ValueError:
                    raise IOError("BAD_POLARITY")
                if pol not in [0, 1]:
                    raise IOError("BAD_POLARITY")
                self.__polarity = pol
                lg.debug(" * Polarity is '%s'." %
                         (POLARITIES[self.__polarity]))

            elif DSC_START_TIME_STRING in l:

                try:
                    ## The full start time.
                    st = float(ls[i + 2].strip())

                    self.__startTime = st

                except:
                    raise IOError("BAD_START_TIME")

                sec, sub, sts = getPixelmanTimeString(st)

                self.__startTimeS = sts

                lg.debug(" * Start time is %20.6f [s]." % (self.__startTime))
                lg.debug(" *--> Converted to string: '%s'." % (sts))

                # Check if the start time matches the supplied string.
                #if self.__startTimeS is not None and sts != self.__startTimeS:
                #    lg.debug(" * A mismatch between the start times.")
                #    raise IOError("START_TIME_MISMATCH")

            #elif DSC_START_TIME_S_STRING in l:
            #
            #    # Set the start time string from the DSC file.
            #    self.__startTimeS = ls[i+2].strip()
            #
            #    lg.debug(" * Start time (string) is '%s'." % (self.__startTimeS))
            #
            #    #if self.__startTime is not None:
            #    #    sec, sub, sts = getPixelmanTimeString(self.__startTime)
            #    #    #if self.__startTimeS != sts:
            #    #    #    raise IOError("START_TIME_MISMATCH")

            elif DSC_TPX_CLOCK_STRING.lower() in l.lower():

                if "byte[1]" in ls[i + 1].strip():

                    val = int(ls[i + 2].strip())

                    if val not in [0, 1, 2, 3]:
                        raise ("BAD_TPX_CLOCK_MODE")

                    self.__tpxClock = TPX_CLOCK_VALS[val]
                    lg.debug(" * Timepix clock = %f [MHz]." %
                             (self.__tpxClock))

                elif "double[1]" in ls[i + 1].strip():
                    self.__tpxClock = float(ls[i + 2].strip())
                else:
                    raise IOError("BAD_TPX_CLOCK")

            elif DSC_NAME_SN_STRING in l:
                self.__nameAndSN = ls[i + 2].strip()
                lg.debug(" * Name and serial no. = '%s'." % (self.__nameAndSN))

        lg.debug("")
示例#9
0
    def __init__(self, **kwargs):
        """
        Constructor.
        """
        lg.debug(" Instantiating a Frame object.")

        # Geospatial information
        #------------------------

        if "lat" not in kwargs.keys():
            raise IOError("FRAME_NO_LAT")

        ## The frame latitude [deg.].
        self.__lat = kwargs["lat"]

        if "lon" not in kwargs.keys():
            raise IOError("FRAME_NO_LON")

        ## The frame longitude [deg.].
        self.__lon = kwargs["lon"]

        if "alt" not in kwargs.keys():
            raise IOError("FRAME_NO_ALT")

        ## The frame altitude [m].
        self.__alt = kwargs["alt"]

        ## The roll angle of the lab. frame [deg.].
        self.__roll = 0.0
        if "roll" in kwargs.keys():
            # TODO: validate the value.
            self.__roll = kwargs["roll"]

        ## The pitch angle of the lab. frame [deg.].
        self.__pitch = 0.0
        if "pitch" in kwargs.keys():
            # TODO: validate the value.
            self.__pitch = kwargs["pitch"]

        ## The yaw angle of the lab. frame [deg.].
        self.__yaw = 0.0
        if "yaw" in kwargs.keys():
            # TODO: validate the value.
            self.__yaw = kwargs["yaw"]

        ## The Omega_x of the lab frame [deg. s^{-1}].
        self.__omegax = 0.0
        if "omegax" in kwargs.keys():
            self.__omegax = kwargs["omegax"]

        ## The Omega_y of the lab frame [deg. s^{-1}].
        self.__omegay = 0.0
        if "omegay" in kwargs.keys():
            self.__omegay = kwargs["omegay"]

        ## The Omega_z of the lab frame [deg. s^{-1}].
        self.__omegaz = 0.0
        if "omegaz" in kwargs.keys():
            self.__omegaz = kwargs["omegaz"]

        # For the detector.

        if "chipid" not in kwargs.keys():
            raise IOError("FRAME_NO_CHIPID")

        ## The chip ID.
        self.__chipid = kwargs["chipid"]

        if "biasvoltage" not in kwargs.keys():
            raise IOError("FRAME_NO_HV")

        ## The bias voltage (HV) [V].
        self.__hv = kwargs["biasvoltage"]

        if "ikrum" not in kwargs.keys():
            raise IOError("FRAME_NO IKRUM")

        ## The detector I_Krum value.
        self.__ikrum = kwargs["ikrum"]

        ## The detector x position [mm].
        self.__det_x = 0.0
        if "detx" in kwargs.keys():
            self.__det_x = kwargs["detx"]

        ## The detector y position [mm].
        self.__det_y = 0.0
        if "dety" in kwargs.keys():
            self.__det_y = kwargs["dety"]

        ## The detector z position [mm].
        self.__det_z = 0.0
        if "detz" in kwargs.keys():
            self.__det_z = kwargs["detz"]

        ## The detector Euler angle a [deg.].
        self.__det_euler_a = 0.0
        if "deteulera" in kwargs.keys():
            self.__det_euler_a = kwargs["deteulera"]

        ## The detector Euler angle b [deg.].
        self.__det_euler_b = 0.0
        if "deteulerb" in kwargs.keys():
            self.__det_euler_b = kwargs["deteulerb"]

        ## The detector Euler angle c [deg.].
        self.__det_euler_c = 0.0
        if "deteulerc" in kwargs.keys():
            self.__det_euler_c = kwargs["deteulerc"]


        # Temporal information
        #----------------------

        if "starttime" not in kwargs.keys() or "acqtime" not in kwargs.keys():
            raise IOError("BAD_FRAME_TIME_INFO")

        ## The start time [s].
        self.__starttime = kwargs["starttime"]

        ## The acquisition time [s].
        self.__acqtime = kwargs["acqtime"]

        self.__starttimesec, self.__starttimesubsec, sts = \
            getPixelmanTimeString(self.__starttime)
        lg.debug(" Frame found with start time: '%s'." % (sts))

        ## The end time [s].
        self.__endtime = self.__starttime + self.__acqtime

        self.__endtimesec, self.__endtimesubsec, ets = \
            getPixelmanTimeString(self.__endtime)


        # Payload information
        #--------------------

        ## The frame width.
        self.__width = 256

        if "width" in kwargs.keys():
            self.__width = kwargs["width"]

        ## The frame height.
        self.__height = 256

        if "height" in kwargs.keys():
            self.__height = kwargs["height"]

        if "format" not in kwargs.keys():
            raise IOError("FRAME_NO_FORMAT")

        ## The payload format.
        self.__format = kwargs["format"]

        ## The map of the pixels.
        self.__pixelmap = {}

        if "pixelmap" in kwargs.keys():
            self.__pixelmap = kwargs["pixelmap"]

        ## The pixel mask map.
        self.__pixel_mask_map = {}

        if "pixelmask" in kwargs.keys():
            self.__pixel_mask_map = kwargs["pixelmask"]

        ## Is the data from a Monte Carlo simulation?
        self.__isMC = False
        if "ismc" in kwargs.keys():
            self.__ismc = kwargs["ismc"]

        if "skipclustering" in kwargs.keys():
            if kwargs["skipclustering"]:
                #print("SKIPPING THE CLUSTERING!")
                self.__n_klusters = -1
                return None

        # Do the clustering.

        ## The frame's cluster finder.
        self.__kf = KlusterFinder(self.getPixelMap(), self.getWidth(), self.getHeight(), self.isMC(), self.__pixel_mask_map)

        self.__n_klusters = self.__kf.getNumberOfKlusters()
示例#10
0
        #acq_time = float(dataset_chain.Acq_time)

        #lg.info(" * Frame % 15d: %s (%f), %f [s]" % (fn, start_time_str, st, acq_time))

    ## The acquisition time for the frame (from the last frame).
    delta_t = dataset_chain.Acq_time

    # Close the ROOT file.
    f.Close()

    # Sort the list of start times.
    st_s = sorted(st_s)

    # Get the first frame's start time information.
    first_start_time_s, first_start_time_subsec, first_start_time_str = getPixelmanTimeString(
        st_s[0])

    # Get the last frame's start time information.
    last_start_time_s, last_start_time_subsec, last_start_time_str = getPixelmanTimeString(
        st_s[-1])

    ## The total length of time covered by the dataset [s].
    Delta_T = st_s[-1] - st_s[0]

    ## The average time between frames [s].
    Delta_t = Delta_T / (len(st_s) - 1)

    ## The file size [B].
    file_size = os.path.getsize(datapath)

    # Create the dataset information JSON.
示例#11
0
    def processDscFile(self):
        """ Process the detector settings file (.dsc). """

        # The DSC file.
        f = open(self.__dscfilename, "r")

        ## The lines of the DSC file.
        ls = f.readlines()

        # Close the DSC file.
        f.close()

        lg.debug("")

        # The frame width and height.
        whvals = ls[2].strip().split(" ")

        try:
            self.__fWidth = int(whvals[2].split("=")[1])
        except TypeError:
            raise IOError("BAD_WIDTH")

        if self.__fWidth < 256 or self.__fWidth > 1024:
            raise IOError("BAD_WIDTH")

        try:
            self.__fHeight = int(whvals[3].split("=")[1])
        except TypeError:
            raise IOError("BAD_HEIGHT")

        if self.__fHeight < 256 or self.__fHeight > 1024:
            raise IOError("BAD_HEIGHT")

        lg.debug(" * Frame dimensions: %d [pix.] x %d [pix.]." % (self.__fWidth, self.__fHeight))

        # Loop over the lines of the DSC file.
        for i, l in enumerate(ls):
            #print("%5d: %s" % (i, l.strip()))

            # Acquisition mode.
            if DSC_ACQ_MODE_STRING in l:
                try:
                    self.__acqMode = int(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_ACQ_MODE")
                lg.debug(" * Acquisition mode is '%s'." % (ACQ_MODES[self.__acqMode]))

            elif DSC_ACQ_TIME_STRING in l:
                try:
                    self.__acqTime = float(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_ACQ_TIME")
                lg.debug(" * Acquisition time is '%f' [%s]." % (self.__acqTime, ACQ_TIME_UNITS_SHORT))

            elif DSC_CHIPID_STRING in l:

                chipid = ls[i+2].strip()
                if not isChipIdValid(chipid):
                    raise IOError("Invalid chip ID in the DSC file.")
                self.__chipid = chipid
                lg.debug(" * Chip ID is '%s'." % (self.__chipid))

            elif DSC_DACS_STRING in l:

                # Break down the DAC string.
                self.__dacs = [int(x) for x in ls[i+2].strip().split(" ")]

                self.__IKrum       = self.__dacs[0]
                self.__Disc        = self.__dacs[1]
                self.__Preamp      = self.__dacs[2]
                self.__BuffAnalogA = self.__dacs[3]
                self.__BuffAnalogB = self.__dacs[4]
                self.__Hist        = self.__dacs[5]
                self.__THL         = self.__dacs[6]
                self.__THLCoarse   = self.__dacs[7]
                self.__Vcas        = self.__dacs[8]
                self.__FBK         = self.__dacs[9]
                self.__GND         = self.__dacs[10]
                self.__THS         = self.__dacs[11]
                self.__BiasLVDS    = self.__dacs[12]
                self.__RefLVDS     = self.__dacs[13]

                lg.debug(" * DAC values:")
                lg.debug(" * --> IKrum           = %4d" % (self.__IKrum))
                lg.debug(" * --> Disc            = %4d" % (self.__Disc))
                lg.debug(" * --> Preamp          = %4d" % (self.__Preamp))
                lg.debug(" * --> BuffAnalogA     = %4d" % (self.__BuffAnalogA))
                lg.debug(" * --> BuffAnalogB     = %4d" % (self.__BuffAnalogB))
                lg.debug(" * --> Hist            = %4d" % (self.__Hist))
                lg.debug(" * --> THL             = %4d" % (self.__THL))
                lg.debug(" * --> THLCoarse       = %4d" % (self.__THLCoarse))
                lg.debug(" * --> Vcas            = %4d" % (self.__Vcas))
                lg.debug(" * --> FBK             = %4d" % (self.__FBK))
                lg.debug(" * --> GND             = %4d" % (self.__GND))
                lg.debug(" * --> THS             = %4d" % (self.__THS))
                lg.debug(" * --> BiasLVDS        = %4d" % (self.__BiasLVDS))
                lg.debug(" * --> RefLVDS         = %4d" % (self.__RefLVDS))

            elif DSC_FIRMWARE_STRING in l:
                self.__firmwarev = ls[i+2].strip()

            # Note - needs 'lower()' because of a 2.1.1/2.2.2 mismatch...
            elif DSC_BIAS_VOLTAGE_STRING.lower() in l.lower():
                try:
                    hv = float(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_HV_VALUE")

                if hv < 0.0 or hv > 100.0:
                    raise IOError("BAD_HV_VALUE")

                self.__hv = hv
                lg.debug(" * Bias voltage (HV) is %f [V]." % (self.__hv))

            elif DSC_HW_TIMER_STRING in l:
                try:
                    self.__hwTimerMode = int(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_HW_TIMER_MODE")
                lg.debug(" * Hardware time mode is '%s'." % (HW_TIME_MODES[self.__hwTimerMode]))

            elif DSC_INTERFACE_STRING in l:
                self.__interface = ls[i+2].strip()
                lg.debug(" * Interface is '%s'." % (self.__interface))

            elif DSC_MPX_CLOCK_STRING in l:
                try:
                    mpxClock = float(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_MPX_CLOCK")
                self.__mpxClock = mpxClock
                lg.debug(" * Medipix clock is %f [MHz]." % (self.__mpxClock))

            elif DSC_MPX_TYPE_STRING in l:
                try:
                    mpxType = int(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_MPX_TYPE")
                if mpxType not in [1,2,3]:
                    raise IOError("BAD_MPX_TYPE")
                self.__mpxType = mpxType
                lg.debug(" * Detector type is '%s'." % (MPX_TYPES_LONG[self.__mpxType]))

            elif DSC_PIXELMAN_VERSION_STRING in l:
                self.__pixelmanv = ls[i+2].strip()
                lg.debug(" * Pixelman version is '%s'." % (self.__pixelmanv))

            elif DSC_POLARITY_STRING in l:
                try:
                    pol = int(ls[i+2].strip())
                except ValueError:
                    raise IOError("BAD_POLARITY")
                if pol not in [0,1]:
                    raise IOError("BAD_POLARITY")
                self.__polarity = pol
                lg.debug(" * Polarity is '%s'." % (POLARITIES[self.__polarity]))

            elif DSC_START_TIME_STRING in l:

                try:
                    ## The full start time.
                    st = float(ls[i+2].strip())

                    self.__startTime = st

                except:
                    raise IOError("BAD_START_TIME")

                sec, sub, sts = getPixelmanTimeString(st)

                self.__startTimeS = sts

                lg.debug(" * Start time is %20.6f [s]." % (self.__startTime))
                lg.debug(" *--> Converted to string: '%s'." % (sts))

                # Check if the start time matches the supplied string.
                #if self.__startTimeS is not None and sts != self.__startTimeS:
                #    lg.debug(" * A mismatch between the start times.")
                #    raise IOError("START_TIME_MISMATCH")

            #elif DSC_START_TIME_S_STRING in l:
            #
            #    # Set the start time string from the DSC file.
            #    self.__startTimeS = ls[i+2].strip()
            #
            #    lg.debug(" * Start time (string) is '%s'." % (self.__startTimeS))
            #
            #    #if self.__startTime is not None:
            #    #    sec, sub, sts = getPixelmanTimeString(self.__startTime)
            #    #    #if self.__startTimeS != sts:
            #    #    #    raise IOError("START_TIME_MISMATCH")

            elif DSC_TPX_CLOCK_STRING.lower() in l.lower():

                if "byte[1]" in ls[i+1].strip():

                    val = int(ls[i+2].strip())

                    if val not in [0,1,2,3]:
                        raise("BAD_TPX_CLOCK_MODE")

                    self.__tpxClock = TPX_CLOCK_VALS[val]
                    lg.debug(" * Timepix clock = %f [MHz]." % (self.__tpxClock))

                elif "double[1]" in ls[i+1].strip():
                    self.__tpxClock = float(ls[i+2].strip())
                else:
                    raise IOError("BAD_TPX_CLOCK")

            elif DSC_NAME_SN_STRING in l:
                self.__nameAndSN = ls[i+2].strip()
                lg.debug(" * Name and serial no. = '%s'." % (self.__nameAndSN))

        lg.debug("")
示例#12
0
def make_profile_page(jds):

    """
    Make a dataset profile page.

    @param [in] jds Dictionary of JSON data for the datasets.
    """

    ## The string to return for the page.
    s = '''<!DOCTYPE html>
<html>
<head>
  <!-- <link rel="stylesheet" type="text/css" href="main.css"> -->
  <style>
{{CSS}}
  </style>
</head>
<div id="container">

  <!-- Main Content -->
  <div id="main">
    <table>
      <tr>
        <th>Run ID</th>
        <!-- <th>Chip ID</th> -->
        <th>Frames</th>
        <th>Size [B]</th>
        <th>Start time</th>
        <th>&Delta; <em>T</em> [s]</th>
        <th>&Delta; <em>t</em> [s]</th>
        <th>&delta; <em>t</em> [s]</th>
        <th>File name</th>
      </tr>
      {{TABLE_ROWS}}
    </table>
  </div>

  <!-- Footer -->
  <div id="footer">&copy; CERN@school 2015</div>

</div>
</html>
'''

    ## The table contents (generated from the JSON information).
    t = ""

    # Loop over the datasets.
    for run_id in sorted(jds.keys()):

        ## The dataset JSON information.
        jd = jds[run_id]

        # The start time second, sub-second, and Pixelman timestamp.
        st_s, st_sub, st_str = getPixelmanTimeString(jd["start_time_s"])

        ## The total length of the run.
        Delta_T = jd["Delta_T"]

        ## The number of days in the run.
        days = int(Delta_T/(24*60*60))

        ## The (remainder) hours in the run.
        hours = int((Delta_T%(24*60*60))/(60*60))

        ## The (remainder) minutes in the run.
        mins = int((Delta_T%(60*60))/60)

        #check_s = days*(24*60*60) + hours*(60*60) + mins*(60)
        #print check_s, Delta_T

        ## String representing the run length.
        Delta_T_str = "%3d days, %3d hours, %2d mins." % (days, hours, mins)

        # Add the dataset information to the table.
        t += '''
      <tr>
        <td>%s</td>
        <!-- <td>%s</td> -->
        <td class="number">%d</td>
        <td class="number">%d</td>
        <td>%s</td>
        <td>%s</td>
        <td class="number">%.2f</td>
        <td class="number">%.4f</td>
        <td>%s</td>
      </tr>
''' % \
            (run_id, jd["chip_id"], jd["n_frames"], jd["file_size"], st_str, Delta_T_str, jd["Delta_t"], jd["delta_t"], jd["file_name"])

    # Add the table contents.
    s = s.replace('{{TABLE_ROWS}}', t)

    # Add the CSS inline to the web page.
    s = s.replace('{{CSS}}', make_css())

    return s