def get_imagefilters(filter_list):
    image_filters = []
    for filters_item in filter_list:
        if type(filters_item) == str:
            image_filters.append(filters.get_filter(filters_item))
        if type(filters_item) == list:
            filter_name = filters_item[0]

            params = filters_item[1:]
            args = []
            kwargs = {}
            if len(params) == 1 and type(params[0]) == list:
                # ["filtername", ["value1", "value2"]]
                args = params[0]
            elif len(params) == 1 and type(params[0]) == dict:
                # ["filtername", {param1: "value1", "param2": "value2"}]
                kwargs = params[0]
            else:
                # ["filtername", "value1", "value2"]
                args = params

            _image_filter = filters.get_filter(filter_name)
            image_filters.append(
                lambda frame: _image_filter(frame, *args, **kwargs)
            )
    return image_filters
Exemple #2
0
def parse_filter(fltr):
    ret = {
        'klass': None,
        'params': {},
    }

    ret['klass'] = get_filter(fltr.get('filter', 'dummy'))
    ret['params'] = fltr.get('params', {})

    return ret
def get_imagefilters(filter_list):
    image_filters = []
    for filters_item in filter_list:
        if type(filters_item) == str:
            image_filters.append(filters.get_filter(filters_item))
        if type(filters_item) == list:
            filter_name = filters_item[0]

            params = filters_item[1:]
            _args = []
            _kwargs = {}
            if len(params) == 1 and type(params[0]) == list:
                # ["filtername", ["value1", "value2"]]
                _args = params[0]
            elif len(params) == 1 and type(params[0]) == dict:
                # ["filtername", {param1: "value1", "param2": "value2"}]
                _kwargs = params[0]
            else:
                # ["filtername", "value1", "value2"]
                _args = params

            _image_filter = filters.get_filter(filter_name)
            if not _image_filter:
                continue

            def filter_with_parameters(_image_filter=_image_filter,
                                       _args=_args,
                                       _kwargs=_kwargs,
                                       *args,
                                       **kwargs):
                # Using default parameters is neccessary to work with
                # a copy of _image_filter, _args and _kwargs instead of
                # a reference
                args = list(args)
                for arg in _args:
                    args.append(arg)
                for key in _kwargs:
                    if not key in kwargs:
                        kwargs[key] = _kwargs[key]
                return _image_filter(*args, **kwargs)

            image_filters.append(filter_with_parameters)
    return image_filters
Exemple #4
0
    def filter_mod(self):

        if issubclass_(self.filter, Filter):
            filter = self.filter(self.mean_dens, self.delta_c, self.lnk, self._lnP_0,
                                 **self.filter_params)
        elif isinstance(self.filter, basestring):
            filter = get_filter(self.filter, rho_mean=self.mean_dens,
                              delta_c=self.delta_c, lnk=self.lnk, lnp=self._lnP_0,
                              **self.filter_params)

        return filter
Exemple #5
0
    def filter_mod(self):

        if issubclass_(self.filter, Filter):
            filter = self.filter(self.mean_dens, self.delta_c, self.lnk,
                                 self._lnP_0, **self.filter_params)
        elif isinstance(self.filter, basestring):
            filter = get_filter(self.filter,
                                rho_mean=self.mean_dens,
                                delta_c=self.delta_c,
                                lnk=self.lnk,
                                lnp=self._lnP_0,
                                **self.filter_params)

        return filter
Exemple #6
0
	def get_objects(self,table_name,**kwargs):
		"""	Get all objects/rows from table
		
			Args
				table_name:  String.  Name of table(model)
				filter: String.  Type of filter to use on results

			Notes:
				Queries use ad-hoc filtering so it's expected that results aren't cached (TODO:  But it might be worthwhile to do so)
		"""
		
		if 'filter' in kwargs:
			filter = filters.get_filter(kwargs['filter'])
			statement = "SELECT * from {0} WHERE {1} {2} {3}".format(table_name,filter[0],filter[1],filter[2])
		else:
			statement = "SELECT * from {0}".format(table_name)

		print statement
		self.execute(statement)
		results = self.fetchall()
		
		return results
Exemple #7
0
import numpy as np

from film import get_film_layers
from filters import get_filter

# Films
EBT2 = get_film_layers('EBT2')
EBT3 = get_film_layers('EBT3')
HDV2 = get_film_layers('HDV2')
HD810= get_film_layers('HD810')

# Filters
Al = get_filter('Al', 6)
Fe = get_filter('Fe', 250)
Fe_thick = get_filter('Fe', 500)

def get_SCAP_stack(shot, flatten=True):
    if shot < 5193:
        print('Shot number too low!')
        return []
    if shot > 5238:
        print ('Shot number too high!')

    layers = [
        Al,
        HDV2, HDV2, HDV2, HDV2,
        Fe,
        HDV2, EBT3,
        Fe,
        HDV2, EBT3,
        Fe,
Exemple #8
0
#!/usr/bin/env python
import sys
import argparse
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import events
import filters
from collections import defaultdict
from matplotlib.colors import ColorConverter

parser = argparse.ArgumentParser(description='Print histogram of events')
filters.add_all_filters(parser)
args = parser.parse_args()
filter = filters.get_filter(args)

# x_range = (1029553.184, 1029553.190)
#x_range = (1029333.805010, 1029333.825010)
x_range = None


fig, ax = plt.subplots()

palette = {
    events.TimelineElement.RUNNING: 'green',
    events.TimelineElement.SLEEPING: 'white',
    events.TimelineElement.SLEEPING_UNINTERRUPTIBLY: 'lightblue',
    events.TimelineElement.PREEMPTED: 'lightgrey',
    events.TimelineElement.WOKEN: 'red',
}

rgb_palette = dict((k, ColorConverter().to_rgb(c)) for k, c in palette.iteritems())