示例#1
0
def realtime_keogram(image, output, settings_manager):

    # see if a realtime keogram has been created yet
    log.info("starting keogram")
    try:
        filename = settings_manager.get(
            ['user_rt_keo_name'])['user_rt_keo_name']
    except KeyError:
        filename = None
    image = image.resize((500, 500))

    if filename is None or not os.path.exists(filename):
        settings_manager.set(
            {'output': "OutputTaskHandler> Creating new realtime keogram."})
        # work out the start and end times for the keogram based on the setting
        # in the settings file
        end_time = datetime.datetime.utcnow()
        time_span = datetime.timedelta(hours=output.time_range)
        start_time = end_time - time_span

        keo = allskyKeo.new([image], output.angle, start_time, end_time, strip_width=output.strip_width,
                            data_spacing=output.data_spacing, keo_fov_angle=output.fov_angle)

        try:
            keo.save(os.path.expanduser('~') + "/realtime_keogram")
            settings_manager.create('user_rt_keo_name', os.path.expanduser(
                '~') + "/realtime_keogram", persistant=True)
        except ValueError:
            # value already exists - just update it to the new value
	    print("Unexpected error:", sys.exc_info()[0])
            settings_manager.set(
                {'user_rt_keo_name': os.path.expanduser('~') + "/realtime_keogram"})
    else:
        log.info("Opening keogram")
        try:
            keo = allskyKeo.load(filename)
	except IOError: 
	    print("Unexpected error:", sys.exc_info()[0])
	    print(filename)
        except:
            print("Unexpected error:", sys.exc_info()[0])
        settings_manager.set(
            {'output': "OutputTaskHandler> Adding image to realtime keogram."})

        # check that the image (and output settings) is actually compatible with the current
        # keogram - for example if the FOV has changed we don't want the range on the keogram
        # to always be out of date.

        if check_keo_compatibility(keo, image, output):
            keo = keo.roll([image])
            try:
                keo.save(filename)
            except:
                print("Unexpected error:", sys.exc_info()[0])
        else:
            # some of the settings must have changed - time to start a new
            # keogram
            settings_manager.set(
                {'user_rt_keo_name': None, 'output': "OutputTaskHandler> New image is not compatible with existing keogram."})
            return realtime_keogram(image, output, settings_manager)
        log.info("made keogram")

    return allskyPlot.plot([keo], size=(9, 3.7))
示例#2
0
    sys.exit(0)

if not os.path.isdir(sys.argv[1]):
    print "keo_create: \""+sys.argv[1]+"\" is not a directory."
    print""
    print "Usage: keo_create [DIRECTORY]"
    sys.exit(0)
    
# Import the PASKIL modules needed to create keograms
from PASKIL import allskyData, allskyKeo, allskyPlot

# create a dataset object containing all the images of
# the correct type and wavelength in the specified folder
dataset = allskyData.new(sys.argv[1], IMAGE_WAVELENGTH, IMAGE_FILE_TYPES)

# create a keogram from the dataset
keogram = allskyKeo.new(dataset, ANGLE, strip_width=STRIP_WIDTH, 
                        data_spacing=DATA_SPACING, keo_type=KEO_TYPE,
                        keo_fov_angle=KEO_FOV_ANGLE)

# save the keogram object so that it can be opened/edited in future
keo_obj_filename = os.path.normpath(sys.argv[1]+"/keogram_object")
keogram.save(keo_obj_filename)

# plot the keogram and save the plot
keo_plot_filename = os.path.normpath(sys.argv[1]+"/keogram_plot.png")
plotted_keo = allskyPlot.plot([keogram])
plotted_keo.savefig(keo_plot_filename)