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(" *")
Esempio n. 2
0
    #
    dataset_info_dict["Delta_T"] = Delta_T
    #
    dataset_info_dict["Delta_t"] = Delta_t
    #
    dataset_info_dict["delta_t"] = delta_t
    #
    dataset_info_dict["file_name"] = dataset_file_name
    #
    dataset_info_dict["n_frames"] = n_frames
    #
    dataset_info_dict["file_size"] = file_size

    lg.info(" * Chip ID         : '%s'" % (chip_id))
    lg.info(" *")
    lg.info(" * First start time: %s (%f)" % (first_start_time_str, st_s[ 0]))
    lg.info(" * Last  start time: %s (%f)" % (last_start_time_str,  st_s[-1]))
    lg.info(" *")
    lg.info(" * Delta_{T} = %f [s]" % (Delta_T))
    lg.info(" *")
    lg.info(" * Delta_{t} = %f [s]" % (Delta_t))
    lg.info(" *")
    lg.info(" * File size = %d [B]" % (file_size))

    ## The JSON file name.
    json_file_name = "%s_%s.json" % (chip_id, make_time_dir(st_s[0]))
    #
    # Write out the frame information to a JSON file.
    with open(os.path.join(outputpath, json_file_name), "w") as jf:
        json.dump(dataset_info_dict, jf)
    def __init__(self, data_hour, **kwargs):
        """
        Constructor.
        """

        lg.info(" *")
        lg.info(" * Initialising HourPlot object...")
        #print(" * Initialising HourPlot object...")

        # Reset the matplot lib plotting stuff.
        plt.close()

        # Here we create the figure on which we'll be plotting our results.
        # We assign the figure a number, a size (5" x 3"), set the resolution
        # of the image (150 DPI), and set the background and outline to white.

        ## The figure width [inches].
        self.__fig_w = 42.0
        #
        if "fig_width" in kwargs.keys():
            self.__fig_width = kwargs["fig_width"]

        ## The figure height [inches].
        self.__fig_h = 4.2
        #
        if "fig_height" in kwargs.keys():
            self.__fig_h = kwargs["fig_height"]

        ## The histogram.
        self.__plot = plt.figure(101, figsize=(self.__fig_w, self.__fig_h), dpi=150, facecolor='w', edgecolor='w')

        # Then we give a bit of clearance for the axes.
        self.__plot.subplots_adjust(bottom=0.15, left=0.02, right=0.99)

        # This is the subplot on which we'll actually be plotting.
        self.__plot_ax = self.__plot.add_subplot(111)

        # Label your axes:

        ## The x axis label.
        self.__x_label = "$t$ / s"
        #
        if "x_label" in kwargs.keys():
            self.__x_label = kwargs["x_label"]
        #
        plt.xlabel(self.__x_label)

        ## The y axis label.
        self.__y_label = "$y$"
        #
        if "y_label" in kwargs.keys():
            self.__y_label = kwargs["y_label"]
        #
        plt.ylabel(self.__y_label)

        # Plot the number of frames.

        # Should be we use a logarithmic scale for the y axis?
        # Not yet, but we might do later.
        uselogy = False

        ## The hour's start time.
        h_st = data_hour.getStartTime()

        lg.info(" * The hour's start time: %d [s] => '%s' UTC." % (h_st, make_time_dir(h_st)))

        ## The maximum y value.
        y_max = 1.0

        # Loop over the frames found.
        for i, st in enumerate(data_hour.getStartTimes()):

            ## The frame's acquisition time [s].
            acq_time = data_hour.getAcqTimes()[i]

            ## The number of pixels in the frame.
            n_pixels = data_hour.getNumberOfPixels()[i]

            lg.info(" * Found new frame: %s (%f [s], % 7d pixels)." % (time.asctime(time.gmtime(st)), acq_time, n_pixels))

            ## The "normal" frame colour.
            frame_color = "#44aa44"

            ## The x position of the frame's bar (frame - hour's start time).
            x = st - h_st

            lg.info(" *--> Start time from frame: % 15d [s] => '%s' UTC." % (st, make_time_dir(st)))
            lg.info(" *--> %d, %d, %d" % (st, h_st, x))

            ## The y position of the frame's bar.
            y = 0

            ## The width of the bar - the acquition time.
            w = acq_time
            #
            ## The height of the bar - the pixels per second.
            #
            # This means the area of the bar is the total number of pixels
            # in the frame.
            if float(acq_time) > 0.:
                h = float(n_pixels) / float(acq_time)
            else:
                h = 500
                w = 1
                frame_color = "#222288"

            # Check if we have a noisy frame.
            if n_pixels > 30000:
                # Set the frame color to indicate an error (i.e. noise).
                frame_color = "#882222"
            else:
                # If normal, check if we have a new maximum.
                if h > y_max:
                    y_max = h

            lg.info(" *---> (x, y) = (%f, %f)" % (x, y))
            lg.info(" *---> (w, h) = (%f, %f)" % (w, h))

            # Add a rectangle representing the frame to the plot.
            self.__plot_ax.add_patch(Rectangle((x, y), w, h, facecolor=frame_color, edgecolor=frame_color))

        # Round up to the nearest 10.
        y_max = 10 * (np.floor(y_max/10.) + 1)
        #
        if y_max > 0:
            plt.ylim([0.0, y_max])

        # If supplied by the user, set the y axis limits.
        if "y_max" in kwargs.keys():
            y_max = kwargs["y_max"]
            plt.ylim([0.0, y_max])

        # Add gridlines.
        plt.grid(1)

        ## The x axis maximum.
        self.__x_max = 3600.0
        #
        if "x_max" in kwargs.keys():
            self.__x_max = kwargs["x_max"]

        # Set the x axis limits.
        plt.xlim([0, self.__x_max])

        # Set the x axis tickers.
        self.__plot_ax.xaxis.set_ticks(np.arange(0.0, self.__x_max + 100, 100))

        #self.__plot_ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))

        lg.info(" *")
Esempio n. 4
0
    #
    dataset_info_dict["Delta_T"] = Delta_T
    #
    dataset_info_dict["Delta_t"] = Delta_t
    #
    dataset_info_dict["delta_t"] = delta_t
    #
    dataset_info_dict["file_name"] = dataset_file_name
    #
    dataset_info_dict["n_frames"] = n_frames
    #
    dataset_info_dict["file_size"] = file_size

    lg.info(" * Chip ID         : '%s'" % (chip_id))
    lg.info(" *")
    lg.info(" * First start time: %s (%f)" % (first_start_time_str, st_s[0]))
    lg.info(" * Last  start time: %s (%f)" % (last_start_time_str, st_s[-1]))
    lg.info(" *")
    lg.info(" * Delta_{T} = %f [s]" % (Delta_T))
    lg.info(" *")
    lg.info(" * Delta_{t} = %f [s]" % (Delta_t))
    lg.info(" *")
    lg.info(" * File size = %d [B]" % (file_size))

    ## The JSON file name.
    json_file_name = "%s_%s.json" % (chip_id, make_time_dir(st_s[0]))
    #
    # Write out the frame information to a JSON file.
    with open(os.path.join(outputpath, json_file_name), "w") as jf:
        json.dump(dataset_info_dict, jf)