class ScaleChannels(ChannelTransform): """ Scale each channel of an Image PatternGenerator by a different factor. The list of channel factors should be the same length as the number of channels. Otherwise, if the factors provided are fewer than the channels of the Image, the remaining channels will not be scaled. If they are more, then only the first N factors are used. """ channel_factors = param.Dynamic(default=[1.0, 1.0, 1.0], doc=""" Channel scaling factors.""") def __call__(self, channel_data): # safety check num_channels = min(len(channel_data), len(self.channel_factors)) for i in range(num_channels): #TFALERT: Not sure why this is required, it should work out of the box #Maybe because channel_factors should be a param.List rather than #param.Dynamic? if (callable(self.channel_factors[i])): channel_data[i] = channel_data[i] * self.channel_factors[i]() else: channel_data[i] = channel_data[i] * self.channel_factors[i] channel_data[i][channel_data[i] > 1] = 1.0 return channel_data
class TestPO(param.Parameterized): inst = param.Parameter(default=[1,2,3],instantiate=True) notinst = param.Parameter(default=[1,2,3],instantiate=False) const = param.Parameter(default=1,constant=True) ro = param.Parameter(default="Hello",readonly=True) ro2 = param.Parameter(default=object(),readonly=True,instantiate=True) dyn = param.Dynamic(default=1)
class TestPO(param.Parameterized): inst = param.Parameter(default=[1,2,3],instantiate=True) notinst = param.Parameter(default=[1,2,3],instantiate=False, per_instance=False) const = param.Parameter(default=1,constant=True) ro = param.Parameter(default="Hello",readonly=True) ro2 = param.Parameter(default=object(),readonly=True,instantiate=True) ro_label = param.Parameter(default=object(), label='Ro Label') ro_format = param.Parameter(default=object()) dyn = param.Dynamic(default=1)
class _BigDumbParams(param.Parameterized): action = param.Action(default_action, allow_None=True) array = param.Array(np.array([1.0, 2.0])) boolean = param.Boolean(True, allow_None=True) callable = param.Callable(default_action, allow_None=True) class_selector = param.ClassSelector(int, is_instance=False, allow_None=True) color = param.Color("#FFFFFF", allow_None=True) composite = param.Composite(["action", "array"], allow_None=True) try: data_frame = param.DataFrame( pd.DataFrame({"A": 1.0, "B": np.arange(5)}), allow_None=True ) except TypeError: data_frame = param.DataFrame(pd.DataFrame({"A": 1.0, "B": np.arange(5)})) date = param.Date(datetime.now(), allow_None=True) date_range = param.DateRange((datetime.min, datetime.max), allow_None=True) dict_ = param.Dict({"foo": "bar"}, allow_None=True, doc="dict means dictionary") dynamic = param.Dynamic(default=default_action, allow_None=True) file_selector = param.FileSelector( os.path.join(FILE_DIR_DIR, "LICENSE"), path=os.path.join(FILE_DIR_DIR, "*"), allow_None=True, ) filename = param.Filename( os.path.join(FILE_DIR_DIR, "LICENSE"), allow_None=True ) foldername = param.Foldername(os.path.join(FILE_DIR_DIR), allow_None=True) hook_list = param.HookList( [CallableObject(), CallableObject()], class_=CallableObject, allow_None=True ) integer = param.Integer(10, allow_None=True) list_ = param.List([1, 2, 3], allow_None=True, class_=int) list_selector = param.ListSelector([2, 2], objects=[1, 2, 3], allow_None=True) magnitude = param.Magnitude(0.5, allow_None=True) multi_file_selector = param.MultiFileSelector( [], path=os.path.join(FILE_DIR_DIR, "*"), allow_None=True, check_on_set=True, ) number = param.Number(-10.0, allow_None=True, doc="here is a number") numeric_tuple = param.NumericTuple((5.0, 10.0), allow_None=True) object_selector = param.ObjectSelector( False, objects={"False": False, "True": 1}, allow_None=True ) path = param.Path(os.path.join(FILE_DIR_DIR, "LICENSE"), allow_None=True) range_ = param.Range((-1.0, 2.0), allow_None=True) series = param.Series(pd.Series(range(5)), allow_None=True) string = param.String("foo", allow_None=True, doc="this is a string") tuple_ = param.Tuple((3, 4, "fi"), allow_None=True) x_y_coordinates = param.XYCoordinates((1.0, 2.0), allow_None=True)
class TestPO2(param.Parameterized): x = param.Dynamic( default=numbergen.UniformRandom(lbound=-1, ubound=1, seed=30)) y = param.Dynamic(default=1.0)
class TestPO1(param.Parameterized): x = param.Dynamic(default=numbergen.UniformRandom(lbound=-1, ubound=1, seed=1), doc="nothing") y = param.Dynamic(default=1)
class TestPO3(param.Parameterized): x = param.Dynamic(default=numbergen.UniformRandom( name='xgen', time_dependent=True))