From 970cf88169558034d2ba8c489ffe1841c2524f8d Mon Sep 17 00:00:00 2001 From: Magnus Haw Date: Fri, 10 Mar 2023 10:02:50 -0800 Subject: [PATCH 01/12] added additional layout cmd for arbitrary aspect ratio plots --- crappy/blocks/grapher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/crappy/blocks/grapher.py b/crappy/blocks/grapher.py index d463139b..03295577 100644 --- a/crappy/blocks/grapher.py +++ b/crappy/blocks/grapher.py @@ -142,6 +142,7 @@ def prepare(self) -> None: mng.window.wm_geometry("+%s+%s" % self._window_pos) # Ready to show the window + plt.tight_layout() plt.show(block=False) plt.pause(.001) From 0b7544fc1bdd1aa87116a5b28e048ec8f06c8323 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Fri, 10 Mar 2023 22:40:49 +0100 Subject: [PATCH 02/12] Updated version to 1.5.11 --- crappy/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crappy/__version__.py b/crappy/__version__.py index b876044d..149ba725 100644 --- a/crappy/__version__.py +++ b/crappy/__version__.py @@ -1,3 +1,3 @@ # coding: utf-8 -__version__ = '1.5.10' +__version__ = '1.5.11' From 395cc3363131ba2bc73d93e43cd63a0bf8bb260d Mon Sep 17 00:00:00 2001 From: Magnus Haw Date: Mon, 13 Mar 2023 11:56:30 -0700 Subject: [PATCH 03/12] replaced clear button with 'c' keypress --- crappy/blocks/grapher.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crappy/blocks/grapher.py b/crappy/blocks/grapher.py index d463139b..0631ddf9 100644 --- a/crappy/blocks/grapher.py +++ b/crappy/blocks/grapher.py @@ -9,10 +9,8 @@ try: import matplotlib.pyplot as plt - from matplotlib.widgets import Button except (ModuleNotFoundError, ImportError): plt = OptionalModule("matplotlib") - Button = OptionalModule("matplotlib") class Grapher(Block): @@ -108,6 +106,7 @@ def prepare(self) -> None: self._figure = plt.figure(figsize=self._window_size) self._canvas = self._figure.canvas self._ax = self._figure.add_subplot(111) + self._figure.canvas.mpl_connect('key_press_event', self.on_press) # Add the lines or the dots self._lines = [] @@ -132,16 +131,13 @@ def prepare(self) -> None: # Add a grid plt.grid() - # Adds a button for clearing the graph - self._clear_button = Button(plt.axes([.8, .02, .15, .05]), 'Clear') - self._clear_button.on_clicked(self._clear) - # Set the dimensions if required if self._window_pos: mng = plt.get_current_fig_manager() mng.window.wm_geometry("+%s+%s" % self._window_pos) # Ready to show the window + plt.tight_layout() plt.show(block=False) plt.pause(.001) @@ -220,3 +216,7 @@ def _clear(self, *_, **__) -> None: line.set_ydata([]) self.factor = [1 for _ in self._labels] self.counter = [0 for _ in self._labels] + + def on_press(self, event): + if event.key == 'c': + self._clear() From 84737b1df9c2c6a64434a417c27ff7705d69859a Mon Sep 17 00:00:00 2001 From: Magnus Haw Date: Tue, 14 Mar 2023 16:44:01 -0700 Subject: [PATCH 04/12] added title to communicate new keypress clear --- crappy/blocks/grapher.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crappy/blocks/grapher.py b/crappy/blocks/grapher.py index 0631ddf9..1a0aefa0 100644 --- a/crappy/blocks/grapher.py +++ b/crappy/blocks/grapher.py @@ -107,6 +107,7 @@ def prepare(self) -> None: self._canvas = self._figure.canvas self._ax = self._figure.add_subplot(111) self._figure.canvas.mpl_connect('key_press_event', self.on_press) + self._ax.set_title('(Press c to clear the graph)', fontsize='small',loc='right') # Add the lines or the dots self._lines = [] @@ -220,3 +221,5 @@ def _clear(self, *_, **__) -> None: def on_press(self, event): if event.key == 'c': self._clear() + + \ No newline at end of file From 630cd83236f3773350e573b74269e43388c16839 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 30 Aug 2023 13:23:08 +0200 Subject: [PATCH 05/12] [fix] Bug in example code in the documentation --- docs/source/tutorials/gettingstarted.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/source/tutorials/gettingstarted.rst b/docs/source/tutorials/gettingstarted.rst index bf552b43..1f98a26d 100644 --- a/docs/source/tutorials/gettingstarted.rst +++ b/docs/source/tutorials/gettingstarted.rst @@ -346,8 +346,7 @@ previous sections: gen = crappy.blocks.Generator([ {'type': 'constant', 'value': 1000, 'condition': 'delay=3'}, - {'type': 'ramp', 'speed': 100, 'condition': 'delay=5', - 'cmd': 0}, + {'type': 'ramp', 'speed': 100, 'condition': 'delay=5'}, {'type': 'constant', 'value': 1800, 'condition': 'delay=3'}, {'type': 'constant', 'value': 500, 'condition': 'delay=3'}, {'type': 'sine', 'amplitude': 2000, 'offset': 1000, 'freq': .3, @@ -370,7 +369,7 @@ previous sections: kd=0.05, out_max=10, out_min=-10, - i_limit=0.5, + i_limit=(-5, 5), target_label='command_speed', labels=['t(s)', 'voltage'], input_label='actual_speed') @@ -389,7 +388,7 @@ outputted by the PID block. Finally the grapher needs to know the current speed and the command speed, just like the PID. So let's add the appropriate links : .. code-block:: python - :emphasize-lines: 37-45 + :emphasize-lines: 36-44 import crappy @@ -397,8 +396,7 @@ and the command speed, just like the PID. So let's add the appropriate links : gen = crappy.blocks.Generator([ {'type': 'constant', 'value': 1000, 'condition': 'delay=3'}, - {'type': 'ramp', 'speed': 100, 'condition': 'delay=5', - 'cmd': 0}, + {'type': 'ramp', 'speed': 100, 'condition': 'delay=5'}, {'type': 'constant', 'value': 1800, 'condition': 'delay=3'}, {'type': 'constant', 'value': 500, 'condition': 'delay=3'}, {'type': 'sine', 'amplitude': 2000, 'offset': 1000, 'freq': .3, @@ -422,7 +420,7 @@ and the command speed, just like the PID. So let's add the appropriate links : kd=0.05, out_max=10, out_min=-10, - i_limit=0.5, + i_limit=(-5, 5), target_label='command_speed', labels=['t(s)', 'voltage'], input_label='actual_speed') From 0588f91ea6e48004c7a7bac0518a7bde46f1227c Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 30 Aug 2023 13:43:06 +0200 Subject: [PATCH 06/12] [fix] Wrong Python version given in .readthedocs.yml --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index ab074b53..891f48f4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -11,7 +11,7 @@ sphinx: # Optionally set the version of Python and requirements required to build your docs python: - version: "3.8" + version: "3.9" install: - method: setuptools path: . From 2fbbbbd917ac734035aef24dd121a82641ff3eb9 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 30 Aug 2023 13:50:54 +0200 Subject: [PATCH 07/12] [fix] Deprecated format for .readthedocs.yml --- .readthedocs.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 891f48f4..82e829e8 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -10,9 +10,18 @@ sphinx: configuration: docs/source/conf.py # Optionally set the version of Python and requirements required to build your docs +build: + os: ubuntu-22.04 + tools: + python: "3.9" + +sphinx: + builder: html + configuration: docs/source/conf.py + fail_on_warning: true + python: - version: "3.9" - install: - - method: setuptools - path: . - - requirements: requirements.txt + install: + - requirements: requirements.txt + - method: pip + path: . From c9688a2557581178cd8d22324da6c1878648fc5a Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 30 Aug 2023 13:57:53 +0200 Subject: [PATCH 08/12] [fix] Deprecated format for intershpinx_mapping in conf.py --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0f489978..8a2343fe 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -209,4 +209,4 @@ # -- Options for intersphinx extension --------------------------------------- # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} +intersphinx_mapping = {'python': ('https://docs.python.org/3', None)} From 716e626a0d366466ad3686bb7e6a2a1ddb737771 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Sun, 5 Nov 2023 15:39:33 +0100 Subject: [PATCH 09/12] chore: add warnings signaling deprecated features in version 2.0.0 --- crappy/__init__.py | 8 +++ crappy/_global.py | 8 ++- crappy/actuator/actuator.py | 4 ++ crappy/actuator/biotens.py | 17 ++++++ crappy/actuator/cmDrive.py | 16 +++++ crappy/actuator/fakemotor.py | 11 ++++ crappy/actuator/motorkit_pump.py | 10 +++ crappy/actuator/oriental.py | 17 ++++++ crappy/actuator/pololu_tic.py | 7 +++ crappy/actuator/servostar.py | 18 ++++++ crappy/actuator/tra6ppd.py | 8 +++ crappy/blocks/autoDrive.py | 7 +++ crappy/blocks/block.py | 68 +++++++++++++++++++++ crappy/blocks/camera.py | 17 +++++- crappy/blocks/client_server.py | 7 +++ crappy/blocks/dashboard.py | 8 +++ crappy/blocks/discorrel.py | 11 ++++ crappy/blocks/displayer.py | 11 ++++ crappy/blocks/disve.py | 13 ++++ crappy/blocks/drawing.py | 10 +++ crappy/blocks/fake_machine.py | 10 +++ crappy/blocks/generator.py | 8 +++ crappy/blocks/generator_path/constant.py | 4 ++ crappy/blocks/generator_path/custom.py | 4 ++ crappy/blocks/generator_path/cyclic.py | 4 ++ crappy/blocks/generator_path/cyclic_ramp.py | 6 ++ crappy/blocks/generator_path/inertia.py | 6 ++ crappy/blocks/generator_path/path.py | 4 ++ crappy/blocks/generator_path/protection.py | 6 ++ crappy/blocks/generator_path/ramp.py | 4 ++ crappy/blocks/generator_path/sine.py | 4 ++ crappy/blocks/gpucorrel.py | 11 ++++ crappy/blocks/gpuve.py | 11 ++++ crappy/blocks/grapher.py | 16 +++++ crappy/blocks/gui.py | 4 ++ crappy/blocks/hdf_recorder.py | 7 +++ crappy/blocks/ioblock.py | 5 ++ crappy/blocks/machine.py | 5 ++ crappy/blocks/mean.py | 7 +++ crappy/blocks/multiplex.py | 13 ++++ crappy/blocks/pid.py | 8 +++ crappy/blocks/reader.py | 10 +++ crappy/blocks/recorder.py | 10 +++ crappy/blocks/sink.py | 6 ++ crappy/blocks/ucontroller.py | 5 ++ crappy/blocks/videoExtenso.py | 13 ++++ crappy/camera/bispectral.py | 41 +++++++++++++ crappy/camera/camera.py | 13 ++++ crappy/camera/cameralink.py | 7 +++ crappy/camera/fakeCamera.py | 4 ++ crappy/camera/file_reader.py | 4 ++ crappy/camera/gstreamer.py | 16 +++++ crappy/camera/jai.py | 7 +++ crappy/camera/opencv.py | 4 ++ crappy/camera/pi_camera.py | 4 ++ crappy/camera/seek_thermal_pro.py | 4 ++ crappy/camera/xiapi.py | 12 ++++ crappy/inout/ads1115.py | 7 +++ crappy/inout/comedi.py | 6 ++ crappy/inout/daqmx.py | 4 ++ crappy/inout/fake_inout.py | 4 ++ crappy/inout/gpio_pwm.py | 4 ++ crappy/inout/gpio_switch.py | 7 +++ crappy/inout/gsm.py | 7 +++ crappy/inout/kollmorgen.py | 4 ++ crappy/inout/labjackT7.py | 4 ++ crappy/inout/labjackUE9.py | 4 ++ crappy/inout/mcp9600.py | 7 +++ crappy/inout/mprls.py | 7 +++ crappy/inout/nau7802.py | 9 +++ crappy/inout/ni_daqmx.py | 4 ++ crappy/inout/opsens.py | 4 ++ crappy/inout/piJuice.py | 4 ++ crappy/inout/spectrum.py | 4 ++ crappy/inout/t7Streamer.py | 4 ++ crappy/inout/waveshare_ad_da.py | 4 ++ crappy/inout/waveshare_ad_da_ft232h.py | 7 +++ crappy/inout/waveshare_high_precision.py | 4 ++ crappy/links/link.py | 50 +++++++++++++++ crappy/modifier/demux.py | 4 ++ crappy/modifier/differentiate.py | 4 ++ crappy/modifier/integrate.py | 4 ++ crappy/modifier/mean.py | 4 ++ crappy/modifier/median.py | 4 ++ crappy/modifier/moving_avg.py | 4 ++ crappy/modifier/moving_med.py | 4 ++ crappy/modifier/offset.py | 4 ++ crappy/modifier/trig_on_change.py | 4 ++ crappy/modifier/trig_on_value.py | 4 ++ crappy/tool/cameraConfig.py | 10 ++- crappy/tool/cameraConfigBoxes.py | 4 ++ crappy/tool/cameraConfigTools.py | 9 +++ crappy/tool/discorrel.py | 4 ++ crappy/tool/discorrelConfig.py | 7 +++ crappy/tool/disve.py | 4 ++ crappy/tool/disveConfig.py | 4 ++ crappy/tool/ft232h/ft232h.py | 6 ++ crappy/tool/ft232h/ft232h_server.py | 8 +++ crappy/tool/ft232h/i2c_message_ft232h.py | 4 ++ crappy/tool/ft232h/usb_server.py | 18 ++++++ crappy/tool/gpucorrel.py | 4 ++ crappy/tool/videoextenso.py | 14 +++++ crappy/tool/videoextensoConfig.py | 9 +++ 103 files changed, 884 insertions(+), 3 deletions(-) diff --git a/crappy/__init__.py b/crappy/__init__.py index 8bbf4914..1aeb70c3 100644 --- a/crappy/__init__.py +++ b/crappy/__init__.py @@ -4,6 +4,7 @@ from numpy import frombuffer, uint8 from ._global import OptionalModule from webbrowser import open +from warnings import warn from . import actuator from . import camera @@ -17,9 +18,16 @@ # For compatibility (deprecated!) condition = modifier +warn("Version 1.5.11 of Crappy is the last one before 2.0.0, that will " + "contain many breaking changes.\nThe warnings displayed in the terminal " + "should help you identify how to modify your scripts when upgrading to " + "2.0.0.", FutureWarning) + # Quick access to documentation def doc(): + warn("The doc function will be renamed to docs in version 2.0.0", + FutureWarning) open('https://crappy.readthedocs.io/en/latest/') diff --git a/crappy/_global.py b/crappy/_global.py index 62b509c3..247e1779 100644 --- a/crappy/_global.py +++ b/crappy/_global.py @@ -1,5 +1,8 @@ # coding:utf-8 +from warnings import warn + + class OptionalModule: """Placeholder for optional dependencies when not installed @@ -28,7 +31,10 @@ def __call__(self, *_, **__): class CrappyStop(Exception): """Error to raise when Crappy is terminating""" - pass + def __init__(self): + warn("The CrappyStop Exception will be removed in version 2.0.0", + DeprecationWarning) + super().__init__() class DefinitionError(Exception): diff --git a/crappy/actuator/actuator.py b/crappy/actuator/actuator.py index 3029a7b6..1710440b 100644 --- a/crappy/actuator/actuator.py +++ b/crappy/actuator/actuator.py @@ -2,6 +2,7 @@ from time import sleep from typing import Optional +from warnings import warn from .._global import DefinitionError @@ -64,6 +65,9 @@ def set_position(self, position. A speed value can optionally be provided for specifying the speed at which the actuator should move for getting to the desired position.""" + warn("The speed argument of set_position will not be optional anymore in " + "version 2.0.0, and will be None if no speed is set", FutureWarning) + print(f"WARNING ! Trying to drive the Actuator {type(self).__name__} in " f"position but it does not define a set_position method !\n" f"No command sent to the actuator.") diff --git a/crappy/actuator/biotens.py b/crappy/actuator/biotens.py index 5cff72cf..c1489cf4 100644 --- a/crappy/actuator/biotens.py +++ b/crappy/actuator/biotens.py @@ -3,6 +3,7 @@ from struct import pack, unpack from typing import Union, Optional import time +from warnings import warn from .actuator import Actuator from .._global import OptionalModule @@ -58,6 +59,10 @@ def __init__(self, baudrate (:obj:`int`, optional): Set the corresponding baud rate. """ + if baudrate != 19200: + warn("The baudrate argument will be removed in version 2.0.0", + FutureWarning) + Actuator.__init__(self) self.port = port self.baudrate = baudrate @@ -134,6 +139,8 @@ def reset_position(self) -> None: def reset(self) -> None: """""" + warn("The reset method will be removed in version 2.0.0", FutureWarning) + pass def stop(self) -> None: @@ -155,6 +162,9 @@ def close(self) -> None: def clear_errors(self) -> None: """Clears error in motor registers.""" + warn("The clear_errors method will be removed in version 2.0.0", + FutureWarning) + command = b'\x52\x52\x52\xFF\x00' +\ convert_to_byte(35, 'B') +\ convert_to_byte(4, 'B') +\ @@ -214,6 +224,9 @@ def set_position(self, """Pilot in position mode, needs speed and final position to run (in `mm/min` and `mm`).""" + warn("The speed argument of set_position will not be optional anymore in " + "version 2.0.0, and will be None if no speed is set", FutureWarning) + if speed is None: raise ValueError("The Biotens actuator needs both a position and a speed" " command when driven in position mode !") @@ -287,6 +300,10 @@ def get_position(self) -> float: raise IOError("Could not read biotens pos!") def _get_position(self) -> Union[float, None]: + + warn("The _get_position method will be removed in version 2.0.0", + DeprecationWarning) + try: self.ser.readlines() except serial.SerialException: diff --git a/crappy/actuator/cmDrive.py b/crappy/actuator/cmDrive.py index eac970fa..505d13d4 100644 --- a/crappy/actuator/cmDrive.py +++ b/crappy/actuator/cmDrive.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Optional +from warnings import warn from .actuator import Actuator from .._global import OptionalModule @@ -23,6 +24,9 @@ def __init__(self, port: str = '/dev/ttyUSB0', baudrate: int = 9600) -> None: baudrate (:obj:`int`, optional): Set the corresponding baud rate. """ + warn("The CM_drive Actuator will be renamed to SchneiderMDrive23 in " + "version 2.0.0", FutureWarning) + Actuator.__init__(self) self.port = port self.baudrate = baudrate @@ -75,6 +79,9 @@ def close(self) -> None: def clear_errors(self) -> None: """Reset errors.""" + warn("The clear_errors method will be removed in version 2.0.0", + FutureWarning) + self.ser.write("CLRFAULT\r\n") self.ser.write("OPMODE 0\r\n EN\r\n") @@ -99,6 +106,12 @@ def set_position(self, """Pilot in position mode, needs speed and final position to run (in `mm/min` and `mm`).""" + warn("The speed argument of set_position will not be optional anymore in " + "version 2.0.0, and will be None if no speed is set", FutureWarning) + + warn("The motion_type argument of set_position will be removed in version " + "2.0.0 ", FutureWarning) + self.ser.close() # close serial connection before to avoid errors self.ser.open() # open serial port @@ -114,6 +127,9 @@ def set_position(self, def move_home(self) -> None: """Reset the position to zero.""" + warn("The move_home method will be removed in version 2.0.0", + FutureWarning) + self.ser.open() # open serial port # send 'MH' ASCII characters for requesting to the motor to return at pos 0 self.ser.write('MA 0\r') diff --git a/crappy/actuator/fakemotor.py b/crappy/actuator/fakemotor.py index a448d016..d7cf3116 100644 --- a/crappy/actuator/fakemotor.py +++ b/crappy/actuator/fakemotor.py @@ -1,6 +1,7 @@ # coding: utf-8 from time import time +from warnings import warn from .actuator import Actuator @@ -38,6 +39,13 @@ def __init__(self, initial_pos(:obj:`float`, optional): (turns) """ + warn("The Fake_motor Actuator will be renamed to FakeDCMotor in version " + "2.0.0", FutureWarning) + + if sim_speed != 1: + warn("The sim_speed argument will be renamed to simulation_speed in " + "version 2.0.0", FutureWarning) + super().__init__() self.inertia = inertia self.torque = torque @@ -68,6 +76,9 @@ def update(self) -> None: Supposes `u` is constant for the interval `dt`. """ + warn("The update method will be renamed to _update in version 2.0.0", + FutureWarning) + t1 = time() * self.sim_speed dt = (t1 - self.t) self.t = t1 diff --git a/crappy/actuator/motorkit_pump.py b/crappy/actuator/motorkit_pump.py index 29482e73..1d522c2d 100644 --- a/crappy/actuator/motorkit_pump.py +++ b/crappy/actuator/motorkit_pump.py @@ -3,6 +3,7 @@ from struct import pack_into from time import sleep from typing import Union +from warnings import warn from .actuator import Actuator from .._global import OptionalModule from ..tool import ft232h_server as ft232h, Usb_server @@ -81,6 +82,9 @@ def __init__(self, board. """ + warn("The DC_motor_hat class will be removed in version 2.0.0", + FutureWarning) + if not all(i in range(1, 5) for i in motor_nrs): raise ValueError("The DC motor hat can only drive up to 4 DC motors at " "a time !") @@ -201,6 +205,12 @@ def __init__(self, serial number of the ft232h to use for communication. """ + warn("The Motorkit_pump Actuator will be renamed to DCMotorHat in version " + "2.0.0", FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument of the Motorkit_pump Actuator will be " + "removed in version 2.0.0") + if not isinstance(backend, str) or backend not in motor_hat_backends: raise ValueError("backend should be in {}".format(motor_hat_backends)) self._backend = backend diff --git a/crappy/actuator/oriental.py b/crappy/actuator/oriental.py index 3229df8e..c0d4985a 100644 --- a/crappy/actuator/oriental.py +++ b/crappy/actuator/oriental.py @@ -2,6 +2,7 @@ from time import sleep from typing import Optional +from warnings import warn from .actuator import Actuator from .._global import OptionalModule @@ -31,6 +32,9 @@ def __init__(self, gain (:obj:`float`, optional): The gain for speed commands. """ + warn("The Oriental Actuator will be renamed to OrientalARDK in version " + "2.0.0", FutureWarning) + Actuator.__init__(self) self.baudrate = baudrate self.port = port @@ -53,6 +57,9 @@ def open(self) -> None: self.ser.write(b"TD " + ACCEL+b'\n') # Deceleration time def clear_errors(self) -> None: + + warn("The clear_errors method will be renamed to _clear_errors in version " + "2.0.0", FutureWarning) self.ser.write(b"ALMCLR\n") def close(self) -> None: @@ -68,6 +75,9 @@ def stop(self) -> None: self.speed = 0 def reset(self) -> None: + + warn("The reset method will be removed in version 2.0.0", FutureWarning) + self.clear_errors() self.ser.write(b"RESET\n") self.ser.write("TALK{}\n".format(self.num_device).encode('ASCII')) @@ -101,9 +111,16 @@ def set_speed(self, cmd: float) -> None: self.speed = signed_speed def set_home(self) -> None: + + warn("The set_home method will be removed in version 2.0.0", FutureWarning) + self.ser.write(b'preset\n') def move_home(self) -> None: + + warn("The move_home method will be removed in version 2.0.0", + FutureWarning) + self.ser.write(b'EHOME\n') def set_position(self, diff --git a/crappy/actuator/pololu_tic.py b/crappy/actuator/pololu_tic.py index 896e57e4..7bf07ea9 100644 --- a/crappy/actuator/pololu_tic.py +++ b/crappy/actuator/pololu_tic.py @@ -4,6 +4,7 @@ from threading import Thread, RLock from time import sleep from typing import Union, Dict +from warnings import warn from .actuator import Actuator from .._global import OptionalModule @@ -429,6 +430,9 @@ def __init__(self, ``crappy`` before starting the assay, in the `ticgui`. """ + warn("The Pololu_tic Actuator will be renamed to PololuTic in version " + "2.0.0", FutureWarning) + Actuator.__init__(self) if backend not in Tic_backends: @@ -748,6 +752,9 @@ def set_position(self, position: float, speed: float = None) -> None: given position. """ + warn("The speed argument of set_position will not be optional anymore in " + "version 2.0.0, and will be None if no speed is set", FutureWarning) + if speed is not None: self._set_max_speed(speed) diff --git a/crappy/actuator/servostar.py b/crappy/actuator/servostar.py index 99e14379..fdbdc874 100644 --- a/crappy/actuator/servostar.py +++ b/crappy/actuator/servostar.py @@ -2,6 +2,7 @@ from multiprocessing import Lock from typing import Union +from warnings import warn from .actuator import Actuator from .._global import OptionalModule @@ -28,6 +29,9 @@ def __init__(self, mode (:obj:`str`, optional): Can be `'analog'` or `'serial'`. """ + warn("The Servostar Actuator will be renamed to ServoStar300 in version " + "2.0.0", FutureWarning) + Actuator.__init__(self) self.devname = device self.mode = mode @@ -59,6 +63,11 @@ def set_position(self, dec: float = 200) -> None: """Go to the position specified at the given speed and acceleration.""" + warn("The speed argument of set_position will not be optional anymore in " + "version 2.0.0, and will be None if no speed is set", FutureWarning) + warn("The acc and dec arguments of set_position will be removed in " + "version 2.0.0", FutureWarning) + if self.last is pos: return if isinstance(pos, bool): @@ -107,6 +116,9 @@ def get_position(self) -> Union[float, None]: def set_mode_serial(self) -> None: """Sets the serial input as setpoint.""" + warn("The set_mode_serial method will be renamed to _set_mode_serial in " + "version 2.0.0", FutureWarning) + self.lock.acquire() self.ser.flushInput() self.ser.write('OPMODE 8\r\n') @@ -116,6 +128,9 @@ def set_mode_serial(self) -> None: def set_mode_analog(self) -> None: """Sets the analog input as setpoint.""" + warn("The set_mode_analog method will be renamed to _set_mode_analog in " + "version 2.0.0", FutureWarning) + self.last = None self.lock.acquire() self.ser.flushInput() @@ -126,6 +141,9 @@ def set_mode_analog(self) -> None: def clear_errors(self) -> None: """Clears error in motor registers.""" + warn("The clear_errors method will be removed in version 2.0.0", + FutureWarning) + self.ser.flushInput() self.ser.write("CLRFAULT\r\n") diff --git a/crappy/actuator/tra6ppd.py b/crappy/actuator/tra6ppd.py index 802c8c12..cdfc4dab 100644 --- a/crappy/actuator/tra6ppd.py +++ b/crappy/actuator/tra6ppd.py @@ -2,6 +2,7 @@ from time import sleep from re import findall +from warnings import warn from .actuator import Actuator from .._global import OptionalModule @@ -32,6 +33,10 @@ def __init__(self, baudrate: The serial baud rate. port: Path to the serial port to connect to. """ + + warn("The Tra6ppd Actuator will be renamed to NewportTRA6PPD in version " + "2.0.0", FutureWarning) + self._max_speed = 0.2 self._min_position = 0 self._max_position = 6 @@ -74,6 +79,9 @@ def set_position(self, and 0.2 mm/s. """ + warn("The speed argument of set_position will not be optional anymore in " + "version 2.0.0, and will be None if no speed is set", FutureWarning) + # Clamping the speed command into the allowed interval speed_clamped = max(min(self._max_speed, speed), 0) diff --git a/crappy/blocks/autoDrive.py b/crappy/blocks/autoDrive.py index aecdbffb..6c265dab 100644 --- a/crappy/blocks/autoDrive.py +++ b/crappy/blocks/autoDrive.py @@ -2,6 +2,7 @@ from time import time from typing import Dict, Any, Optional +from warnings import warn from .block import Block from ..actuator import actuator_list @@ -51,6 +52,12 @@ def __init__(self, verbose: If :obj:`True`, prints the looping frequency of the block. """ + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The AutoDrive Block will be renamed to AutoDriveVideoExtenso in " + "version 2.0.0", FutureWarning) + super().__init__() self.labels = ['t(s)', 'diff(pix)'] self.freq = freq diff --git a/crappy/blocks/block.py b/crappy/blocks/block.py index 4d6166a4..5a92cc4e 100644 --- a/crappy/blocks/block.py +++ b/crappy/blocks/block.py @@ -6,6 +6,7 @@ from weakref import WeakSet from pickle import UnpicklingError from typing import Union, Optional, List, Dict, Any +from warnings import warn from ..links import Link from .._global import CrappyStop @@ -108,12 +109,16 @@ def run(self) -> None: @classmethod def get_status(cls) -> List[str]: + warn("The get_status classmethod will be removed in version 2.0.0", + DeprecationWarning) return [x.status for x in cls.instances] @classmethod def all_are(cls, s: str) -> bool: """Returns :obj:`True` only if all processes status are `s`.""" + warn("The all_are classmethod will be removed in version 2.0.0", + DeprecationWarning) lst = cls.get_status() return len(set(lst)) == 1 and s in lst @@ -130,6 +135,9 @@ def renice_all(cls, high_prio: bool = True, **_) -> None: lower the niceness of processes. """ + warn("The high_prio argument of renice_all will be renamed to allow_root " + "in version 2.0.0", DeprecationWarning) + if "win" in platform: # Not supported on Windows yet return @@ -143,6 +151,10 @@ def prepare_all(cls, verbose: bool = True) -> None: """Starts all the blocks processes (``block.prepare``), but not the main loop.""" + warn("The verbose argument of prepare_all will be renamed to log_level " + "in version 2.0.0, and its type will be int and not bool", + DeprecationWarning) + if verbose: def vprint(*args): print("[prepare]", *args) @@ -161,6 +173,10 @@ def launch_all(cls, t0: Optional[float] = None, verbose: bool = True, bg: bool = False) -> None: + + warn("The t0, verbose, and bg arguments of launch_all will be removed in " + "version 2.0.0", DeprecationWarning) + if verbose: def vprint(*args): print("[launch]", *args) @@ -211,6 +227,10 @@ def vprint(*_): print("Crappy terminated, blocks status:") for b in cls.instances: print(b, b.status) + warn("Version 1.5.11 of Crappy is the last one before 2.0.0, that will " + "contain many breaking changes.\nThe warnings displayed in the " + "terminal should help you identify how to modify your scripts when " + "upgrading to 2.0.0.", FutureWarning) @classmethod def start_all(cls, @@ -218,6 +238,15 @@ def start_all(cls, verbose: bool = True, bg: bool = False, high_prio: bool = False) -> None: + + warn("The t0 and bg arguments of start_all will be removed in version " + "2.0.0", DeprecationWarning) + warn("The verbose argument of start_all will be renamed to log_level in " + "version 2.0.0, and will expect an int type instead of a bool", + DeprecationWarning) + warn("The high_prio argument of start_all will be renamed to allow_root " + "in version 2.0.0", DeprecationWarning) + cls.prepare_all(verbose) if high_prio and any([b.niceness < 0 for b in cls.instances]): print("[start] High prio: root permission needed to renice") @@ -228,6 +257,9 @@ def start_all(cls, def stop_all(cls, verbose: bool = True) -> None: """Stops all the blocks (``crappy.stop``).""" + warn("The verbose argument of stop_all will be removed in version 2.0.0", + DeprecationWarning) + if verbose: def vprint(*args): print("[stop]", *args) @@ -272,6 +304,9 @@ def handle_freq(self) -> None: """For block with a given number of `loops/s` (use ``freq`` attribute to set it).""" + warn("The handle_freq method will be renamed to _handle_freq in version " + "2.0.0", DeprecationWarning) + self._MB_loops += 1 t = time() if hasattr(self, 'freq') and self.freq: @@ -300,6 +335,9 @@ def launch(self, t0: float) -> None: in seconds after epoch). """ + warn("The launch method will be removed in version 2.0.0", + DeprecationWarning) + if self.status == "idle": print(self, ": Called launch on unprepared process!") self.start() @@ -321,6 +359,9 @@ def status(self) -> str: - `"error"`: An error occurred and the block stopped. """ + warn("The status property will be removed in version 2.0.0", + DeprecationWarning) + if self.pid is not None: while self.pipe1.poll(): try: @@ -340,6 +381,10 @@ def status(self) -> str: @status.setter def status(self, s: str) -> None: + + warn("The status property will be removed in version 2.0.0", + DeprecationWarning) + assert self.pid is not None, "Cannot set status from outside of the " \ "process!" self.pipe2.send(s) @@ -391,6 +436,9 @@ def recv_all(self) -> Dict[str, list]: If the same label comes from multiple links, it may be overridden ! """ + warn("The recv_all method will be renamed to recv_data in version 2.0.0", + DeprecationWarning) + r = {} for i in self.inputs: if i.poll(): @@ -403,6 +451,8 @@ def poll(self) -> bool: Returns True if l.poll() is True for any input link l. """ + warn("The poll method will be renamed to data_available in version " + "2.0.0", DeprecationWarning) return any((link.poll for link in self.inputs)) def recv_all_last(self) -> Dict[str, float]: @@ -412,6 +462,9 @@ def recv_all_last(self) -> Dict[str, float]: receiving block is slower than the block upstream """ + warn("The recv_all_last method will be renamed to recv_last_data in " + "version 2.0.0", DeprecationWarning) + ret = {} for link in self.inputs: data = link.recv_last(blocking=False) @@ -437,6 +490,9 @@ def get_last(self, blocking: bool = True) -> Dict[str, Any]: will return instantaneously, giving the latest known reading. """ + warn("The get_last method will be renamed to recv_all_data in version " + "2.0.0", DeprecationWarning) + # Initializing the buffer if self._last_values is None: self._last_values = [dict() for _ in self.inputs] @@ -471,6 +527,9 @@ def get_all_last(self, blocking: bool = True) -> Dict[str, list]: received for each label. """ + warn("The get_all_last method will be renamed to recv_all_data in version " + "2.0.0", DeprecationWarning) + if self._all_last_values is None: self._all_last_values = {link: dict() for link in self.inputs} @@ -502,6 +561,9 @@ def recv_all_delay(self, :meth:`Link.recv_chunk` on each link. """ + warn("The recv_all_delay method will be renamed to recv_all_data_raw in " + "version 2.0.0", DeprecationWarning) + def poll(inputs: List[Link], rcv: List[Dict[str, list]]) -> None: """Polls all the incoming links and saves the received values. @@ -546,6 +608,9 @@ def drop(self, num: Optional[Union[list, str]] = None) -> None: instantly. """ + warn("The drop method will be removed in version 2.0.0", + DeprecationWarning) + if num is None: num = range(len(self.inputs)) elif not isinstance(num, list): @@ -585,4 +650,7 @@ def stop(self) -> None: print("[%r] Stopped correctly" % self) def __repr__(self) -> str: + + warn("The __repr__ method will be removed in version 2.0.0", + DeprecationWarning) return str(type(self)) + " (" + str(self.pid or "Not running") + ")" diff --git a/crappy/blocks/camera.py b/crappy/blocks/camera.py index 3caa8523..5e75e4a9 100644 --- a/crappy/blocks/camera.py +++ b/crappy/blocks/camera.py @@ -6,6 +6,7 @@ from time import time, strftime, gmtime from re import fullmatch from types import MethodType +from warnings import warn from .block import Block from .displayer import Displayer @@ -125,6 +126,13 @@ def __init__(self, **kwargs: Any additional argument to pass to the camera. """ + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if img_name: + warn("The img_name argument will be replaced by img_extension in " + "version 2.0.0", FutureWarning) + super().__init__() self.verbose = verbose @@ -305,6 +313,9 @@ def _save(self, img: np.ndarray, path: str) -> None: """Simply saves the given image to the given path using the selected backend.""" + warn("The _save method will be removed in version 2.0.0", + DeprecationWarning) + if self._save_backend == 'sitk': Sitk.WriteImage(Sitk.GetImageFromArray(img), path) @@ -318,12 +329,16 @@ def _additional_loop(self, meta: Dict[str, Any], img: np.ndarray) -> None: """Additional action to perform in the loop, used by subclasses of the Camera block.""" - ... + warn("The _additional_loop method will be removed in version 2.0.0", + DeprecationWarning) @staticmethod def _draw_box(img: np.ndarray, box: Box) -> None: """Draws a box on top of an image.""" + warn("The _draw_box method will be removed in version 2.0.0", + DeprecationWarning) + if box.no_points(): return diff --git a/crappy/blocks/client_server.py b/crappy/blocks/client_server.py index 873d6292..bf93a0c4 100644 --- a/crappy/blocks/client_server.py +++ b/crappy/blocks/client_server.py @@ -11,6 +11,7 @@ from pickle import loads, dumps, UnpicklingError from socket import timeout, gaierror from itertools import chain +from warnings import warn try: import paho.mqtt.client as mqtt @@ -185,6 +186,12 @@ def __init__(self, ('sign',) """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The Client_server Block will be renamed to ClientServer in version " + "2.0.0", FutureWarning) Block.__init__(self) self.niceness = -10 diff --git a/crappy/blocks/dashboard.py b/crappy/blocks/dashboard.py index 33bcc7ae..04ed8b9c 100644 --- a/crappy/blocks/dashboard.py +++ b/crappy/blocks/dashboard.py @@ -2,6 +2,7 @@ from typing import List import tkinter as tk +from warnings import warn from .block import Block @@ -12,6 +13,9 @@ class Dashboard_window(tk.Tk): def __init__(self, labels: List[str]) -> None: """Initializes the GUI and sets the layout.""" + warn("The Dashboard_window class will be renamed to DashboardWindow in " + "version 2.0.0", DeprecationWarning) + super().__init__() self.title('Dashboard') self.resizable(False, False) @@ -68,6 +72,10 @@ def __init__(self, verbose: If :obj:`True`, prints the looping frequency of the block. freq: If set, the block will try to loop at this frequency. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) super().__init__() self.verbose = verbose diff --git a/crappy/blocks/discorrel.py b/crappy/blocks/discorrel.py index 2263e779..1d60a5dd 100644 --- a/crappy/blocks/discorrel.py +++ b/crappy/blocks/discorrel.py @@ -3,6 +3,7 @@ import numpy as np from typing import Callable, Optional, Union, List, Dict, Any from pathlib import Path +from warnings import warn from ..tool import DISCorrel as Dis from ..tool import DISConfig, Box @@ -150,6 +151,13 @@ def __init__(self, given. **kwargs: Any additional argument to pass to the camera. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if img_name: + warn("The img_name argument will be replaced by img_extension in " + "version 2.0.0", FutureWarning) super().__init__(camera=camera, transform=transform, @@ -243,6 +251,9 @@ def _additional_loop(self, meta: Dict[str, Any], img: np.ndarray) -> None: """Getting the updated values from the correlation and updating the displayer.""" + warn("The _additional_loop method will be removed in version 2.0.0", + DeprecationWarning) + data = self._dis.get_data(img, self._residual) self.send([meta['t(s)'], meta] + data) diff --git a/crappy/blocks/displayer.py b/crappy/blocks/displayer.py index ae182db3..5a0caf54 100644 --- a/crappy/blocks/displayer.py +++ b/crappy/blocks/displayer.py @@ -3,6 +3,7 @@ import numpy as np from typing import Optional from time import time +from warnings import warn from .._global import OptionalModule try: @@ -52,6 +53,10 @@ def __init__(self, 'cv2', 'mpl' """ + warn("The Displayer class will be moved to " + "crappy.blocks.camera_processes.Displayer in version 2.0.0", + DeprecationWarning) + self._title = title self._framerate = framerate @@ -80,6 +85,9 @@ def __init__(self, def prepare(self) -> None: """Calls the right prepare method depending on the chosen backend.""" + warn("The prepare method will be removed in version 2.0.0", + DeprecationWarning) + if self._backend == 'cv2': self._prepare_cv2() elif self._backend == 'mpl': @@ -93,6 +101,9 @@ def update(self, img: np.ndarray) -> None: img: The image to display on the displayer. """ + warn("The update method will be removed in version 2.0.0", + DeprecationWarning) + # Making sure the image is not being refreshed too often if time() - self._last_upd < 1 / self._framerate: return diff --git a/crappy/blocks/disve.py b/crappy/blocks/disve.py index 8bf7deac..866bc591 100644 --- a/crappy/blocks/disve.py +++ b/crappy/blocks/disve.py @@ -3,6 +3,7 @@ from typing import List, Tuple, Optional, Callable, Union, Dict, Any import numpy as np from pathlib import Path +from warnings import warn from ..tool import DISVE as VE, DISVE_config, Spot_boxes from .camera import Camera from .displayer import Displayer @@ -146,6 +147,15 @@ def __init__(self, of the image. **kwargs: Any additional argument to pass to the camera. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if img_name: + warn("The img_name argument will be replaced by img_extension in " + "version 2.0.0", FutureWarning) + warn("The DISVE Block will be renamed to DICVE in version 2.0.0", + FutureWarning) self._patches = Spot_boxes() self._patches.set_spots(patches) @@ -231,6 +241,9 @@ def finish(self) -> None: def _additional_loop(self, meta: Dict[str, Any], img: np.ndarray) -> None: """Simply calculates the displacement and sends it to downstream blocks.""" + warn("The _additional_loop method will be removed in version 2.0.0", + DeprecationWarning) + ret = self._ve.calculate_displacement(img) self.send([meta['t(s)'], meta] + ret) diff --git a/crappy/blocks/drawing.py b/crappy/blocks/drawing.py index 061ff6ab..45c2ab9f 100644 --- a/crappy/blocks/drawing.py +++ b/crappy/blocks/drawing.py @@ -3,6 +3,7 @@ from datetime import timedelta from time import time from typing import Tuple, List, Dict, Any, Optional +from warnings import warn from .block import Block from .._global import OptionalModule @@ -72,6 +73,9 @@ def __init__(self, color from blue to red depending on this value. """ + warn("The Dot_text class will be renamed to DotText in version 2.0.0", + DeprecationWarning) + x, y = coord self._text = text self._label = label @@ -172,6 +176,12 @@ def __init__(self, in the incoming links. The ``text`` will then be updated with this data. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The Drawing Block will be renamed to Canvas in version 2.0.0", + FutureWarning) super().__init__() self.freq = freq diff --git a/crappy/blocks/fake_machine.py b/crappy/blocks/fake_machine.py index 4ee43445..c0cfc75a 100644 --- a/crappy/blocks/fake_machine.py +++ b/crappy/blocks/fake_machine.py @@ -3,6 +3,7 @@ from time import time import numpy as np from typing import Callable, Dict, Optional +from warnings import warn from .block import Block @@ -58,6 +59,15 @@ def __init__(self, freq: The block will try to loop at this frequency. verbose: If :obj:`True`, prints the looping frequency of the block. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if k != 8.4E6: + warn("The k argument will be replaced by rigidity in version 2.0.0", + FutureWarning) + warn("The Fake_machine Block will be renamed to FakeMachine in version " + "2.0.0", FutureWarning) super().__init__() self.freq = freq diff --git a/crappy/blocks/generator.py b/crappy/blocks/generator.py index f124994b..f6e0fc65 100644 --- a/crappy/blocks/generator.py +++ b/crappy/blocks/generator.py @@ -4,6 +4,7 @@ from typing import Dict, List, Any, Optional, Iterator from itertools import cycle from copy import deepcopy +from warnings import warn from .block import Block from . import generator_path @@ -75,6 +76,13 @@ def __init__(self, type, any applicable parameter(s), and the stop condition(s). Refer to the documentation of each signal shape to which information to give. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if cycle_label != 'cycle': + warn("The cycle_label argument will be replaced by path_index_label in " + "version 2.0.0", FutureWarning) Block.__init__(self) diff --git a/crappy/blocks/generator_path/constant.py b/crappy/blocks/generator_path/constant.py index 12e899d6..e1fb589c 100644 --- a/crappy/blocks/generator_path/constant.py +++ b/crappy/blocks/generator_path/constant.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Union, Dict +from warnings import warn from .path import Path, condition_type @@ -25,6 +26,9 @@ def __init__(self, value: The value to send. """ + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) self._condition = self.parse_condition(condition) diff --git a/crappy/blocks/generator_path/custom.py b/crappy/blocks/generator_path/custom.py index 35b87fd6..1a4df445 100644 --- a/crappy/blocks/generator_path/custom.py +++ b/crappy/blocks/generator_path/custom.py @@ -4,6 +4,7 @@ from numpy import loadtxt, interp from typing import Dict, Union import pathlib +from warnings import warn from .path import Path @@ -37,6 +38,9 @@ def __init__(self, delimiter: The delimiter between columns in the file, usually a coma. """ + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) array = loadtxt(pathlib.Path(filename), delimiter=delimiter) diff --git a/crappy/blocks/generator_path/cyclic.py b/crappy/blocks/generator_path/cyclic.py index 453a61f3..afc439e0 100644 --- a/crappy/blocks/generator_path/cyclic.py +++ b/crappy/blocks/generator_path/cyclic.py @@ -3,6 +3,7 @@ from time import time from typing import Union, Dict from itertools import cycle, islice +from warnings import warn from .path import Path, condition_type @@ -54,6 +55,9 @@ def __init__(self, {'type': 'constant', 'value': 0, 'condition': 'AIN1<1'}] * 5 """ + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) # Creates an interator object with a given length diff --git a/crappy/blocks/generator_path/cyclic_ramp.py b/crappy/blocks/generator_path/cyclic_ramp.py index 9acfecd1..e5af76f3 100644 --- a/crappy/blocks/generator_path/cyclic_ramp.py +++ b/crappy/blocks/generator_path/cyclic_ramp.py @@ -3,6 +3,7 @@ from time import time from typing import Union, Dict, Optional from itertools import cycle, islice +from warnings import warn from .path import Path, condition_type @@ -57,6 +58,11 @@ def __init__(self, {'type': 'ramp', 'value': -2, 'condition': 'AIN1<1'}] * 5 """ + warn("The Cyclic_ramp Path will be renamed to CyclicRamp in version 2.0.0", + FutureWarning) + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) if init_value is None and _last_cmd is None: diff --git a/crappy/blocks/generator_path/inertia.py b/crappy/blocks/generator_path/inertia.py index a67760dc..072ebfb2 100644 --- a/crappy/blocks/generator_path/inertia.py +++ b/crappy/blocks/generator_path/inertia.py @@ -2,6 +2,7 @@ from numpy import trapz from typing import Union, Dict +from warnings import warn from .path import Path, condition_type @@ -48,6 +49,11 @@ def __init__(self, given ! """ + warn("The Inertia Path will be renamed to Integrator in version 2.0.0", + FutureWarning) + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) if init_value is None and _last_cmd is None: diff --git a/crappy/blocks/generator_path/path.py b/crappy/blocks/generator_path/path.py index 5162ee23..40c9968c 100644 --- a/crappy/blocks/generator_path/path.py +++ b/crappy/blocks/generator_path/path.py @@ -3,6 +3,7 @@ from time import time from typing import Callable, Union, Dict, Optional from re import split, IGNORECASE, match +from warnings import warn condition_type = Callable[[Dict[str, list]], bool] @@ -18,6 +19,9 @@ def __init__(self, _last_cmd: Optional[float] = None) -> None: """Simply sets the arguments.""" + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + self.t0 = _last_time self.last_cmd = _last_cmd if _last_cmd is not None else 0 diff --git a/crappy/blocks/generator_path/protection.py b/crappy/blocks/generator_path/protection.py index 62265b4a..77b9970e 100644 --- a/crappy/blocks/generator_path/protection.py +++ b/crappy/blocks/generator_path/protection.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Union, Dict +from warnings import warn from .path import Path, condition_type @@ -42,6 +43,11 @@ def __init__(self, This generator path never ends, it doesn't have a stop condition. """ + warn("The Protection Path will be renamed to Conditional in version 2.0.0", + FutureWarning) + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) # Setting the attributes diff --git a/crappy/blocks/generator_path/ramp.py b/crappy/blocks/generator_path/ramp.py index 4ead4463..c152d347 100644 --- a/crappy/blocks/generator_path/ramp.py +++ b/crappy/blocks/generator_path/ramp.py @@ -2,6 +2,7 @@ from time import time from typing import Union, Dict, Optional +from warnings import warn from .path import Path, condition_type @@ -31,6 +32,9 @@ def __init__(self, first one in the list of dicts, this argument must be given ! """ + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) if init_value is None and _last_cmd is None: diff --git a/crappy/blocks/generator_path/sine.py b/crappy/blocks/generator_path/sine.py index 3370f0d7..74ecc8d9 100644 --- a/crappy/blocks/generator_path/sine.py +++ b/crappy/blocks/generator_path/sine.py @@ -3,6 +3,7 @@ from time import time from numpy import sin, pi from typing import Union, Dict +from warnings import warn from .path import Path, condition_type @@ -34,6 +35,9 @@ def __init__(self, phase: The phase of the sine (in radians). """ + warn("The _last_time and _last_cmd arguments will be removed in version " + "2.0.0", DeprecationWarning) + Path.__init__(self, _last_time, _last_cmd) # Setting the attributes diff --git a/crappy/blocks/gpucorrel.py b/crappy/blocks/gpucorrel.py index 8aef3bb4..99fcb455 100644 --- a/crappy/blocks/gpucorrel.py +++ b/crappy/blocks/gpucorrel.py @@ -3,6 +3,7 @@ import numpy as np from typing import Callable, Union, Optional, List, Dict, Any from pathlib import Path +from warnings import warn from ..tool import GPUCorrel as GPUCorrel_tool from .camera import Camera @@ -147,6 +148,13 @@ def __init__(self, along with the other information under the label ``'res'``. **kwargs: Any additional argument to pass to the camera. """ + + if img_name: + warn("The img_name argument will be replaced by img_extension in " + "version 2.0.0", FutureWarning) + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) super().__init__(camera=camera, transform=transform, @@ -246,6 +254,9 @@ def _additional_loop(self, meta: Dict[str, Any], img: np.ndarray) -> None: the data. """ + warn("The _additional_loop method will be removed in version 2.0.0", + DeprecationWarning) + out = [meta['t(s)'], meta] out += self._correl.get_disp(img.astype(np.float32)).tolist() diff --git a/crappy/blocks/gpuve.py b/crappy/blocks/gpuve.py index 091639b8..0540680d 100644 --- a/crappy/blocks/gpuve.py +++ b/crappy/blocks/gpuve.py @@ -3,6 +3,7 @@ import numpy as np from typing import Callable, Optional, List, Union, Tuple, Dict, Any from pathlib import Path +from warnings import warn from .._global import OptionalModule from ..tool import GPUCorrel as GPUCorrel_tool @@ -114,6 +115,13 @@ def __init__(self, convergence is neither too slow nor too fast. **kwargs: Any additional argument to pass to the camera. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if img_name: + warn("The img_name argument will be replaced by img_extension in " + "version 2.0.0", FutureWarning) # Setting now the pycuda context to avoid setting it multiple times pycuda.driver.init() @@ -201,6 +209,9 @@ def _additional_loop(self, meta: Dict[str, Any], img: np.ndarray) -> None: """Gets the updated positions of the patches, and sends it to the downstream blocks.""" + warn("The _additional_loop method will be removed in version 2.0.0", + DeprecationWarning) + out = [meta['t(s)'], meta] for correl, (oy, ox, h, w) in zip(self._correls, self._patches): out.extend(correl.get_disp(img[oy:oy + h, diff --git a/crappy/blocks/grapher.py b/crappy/blocks/grapher.py index 1a0aefa0..8380fabf 100644 --- a/crappy/blocks/grapher.py +++ b/crappy/blocks/grapher.py @@ -2,6 +2,7 @@ import numpy as np from typing import Optional, Tuple +from warnings import warn from _tkinter import TclError from .block import Block @@ -82,6 +83,13 @@ def __init__(self, will plot a dynamic graph displaying the last 30 chunks of data. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if maxpt != 20000: + warn("The maxpt argument will be renamed to max_pt in version 2.0.0", + FutureWarning) Block.__init__(self) self.niceness = 10 @@ -212,6 +220,10 @@ def finish(self) -> None: plt.close("all") def _clear(self, *_, **__) -> None: + + warn("The _clear method will be removed in version 2.0.0", + DeprecationWarning) + for line in self._lines: line.set_xdata([]) line.set_ydata([]) @@ -219,6 +231,10 @@ def _clear(self, *_, **__) -> None: self.counter = [0 for _ in self._labels] def on_press(self, event): + + warn("The on_press method will be renamed to _on_press in version 2.0.0", + DeprecationWarning) + if event.key == 'c': self._clear() diff --git a/crappy/blocks/gui.py b/crappy/blocks/gui.py index b48e16a6..c581f000 100644 --- a/crappy/blocks/gui.py +++ b/crappy/blocks/gui.py @@ -1,6 +1,7 @@ # coding: utf-8 from time import time +from warnings import warn from .block import Block from .._global import OptionalModule @@ -27,6 +28,9 @@ def __init__(self, spam: bool = False,) -> None: """Sets the args and initializes the parent class.""" + warn("The GUI Block will be renamed to Button in version 2.0.0", + FutureWarning) + Block.__init__(self) self.freq = freq self.spam = spam diff --git a/crappy/blocks/hdf_recorder.py b/crappy/blocks/hdf_recorder.py index a634cc51..7c45cbb5 100644 --- a/crappy/blocks/hdf_recorder.py +++ b/crappy/blocks/hdf_recorder.py @@ -3,6 +3,7 @@ import numpy as np from typing import Union, Optional from pathlib import Path +from warnings import warn from .._global import OptionalModule @@ -54,6 +55,12 @@ def __init__(self, freq: The block will try to loop at this frequency. verbose: If :obj:`True`, prints the looping frequency of the block. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The Hdf_recorder Block will be renamed to HDFRecorder in version " + "2.0.0", FutureWarning) Block.__init__(self) if freq is not None: diff --git a/crappy/blocks/ioblock.py b/crappy/blocks/ioblock.py index 6d6a8990..cf8d16f3 100644 --- a/crappy/blocks/ioblock.py +++ b/crappy/blocks/ioblock.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Union, List, Optional +from warnings import warn from .block import Block from ..inout import inout_dict @@ -70,6 +71,10 @@ def __init__(self, verbose: If :obj:`True`, prints the looping frequency of the block. **kwargs: The arguments to be passed to the :ref:`In / Out` class. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) super().__init__() self.niceness = -10 diff --git a/crappy/blocks/machine.py b/crappy/blocks/machine.py index 35ef5b3c..83f8c3d2 100644 --- a/crappy/blocks/machine.py +++ b/crappy/blocks/machine.py @@ -2,6 +2,7 @@ from time import time from typing import Dict, List, Any, Optional +from warnings import warn from .block import Block from ..actuator import actuator_list @@ -59,6 +60,10 @@ def __init__(self, return the value of :meth:`get_speed` under this label. This key is not mandatory. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) super().__init__() self.freq = freq diff --git a/crappy/blocks/mean.py b/crappy/blocks/mean.py index c941d7a5..f6dc1b3e 100644 --- a/crappy/blocks/mean.py +++ b/crappy/blocks/mean.py @@ -2,6 +2,7 @@ import numpy as np from typing import List, Optional +from warnings import warn from .block import Block @@ -37,6 +38,12 @@ def __init__(self, verbose: If :obj:`True`, prints the looping frequency of the block. freq: The block will try to loop at this frequency. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The Mean_block Block will be renamed to MeanBlock in version 2.0.0", + FutureWarning) super().__init__() self.verbose = verbose diff --git a/crappy/blocks/multiplex.py b/crappy/blocks/multiplex.py index 6104df91..e92fd261 100644 --- a/crappy/blocks/multiplex.py +++ b/crappy/blocks/multiplex.py @@ -2,6 +2,7 @@ from numpy import interp, array, searchsorted, concatenate from itertools import chain +from warnings import warn from .block import Block @@ -37,6 +38,12 @@ def __init__(self, verbose: If :obj:`True`, prints information about the looping frequency of the block. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The Multiplex Block will be renamed to Multiplexer in version 2.0.0", + FutureWarning) Block.__init__(self) @@ -109,6 +116,9 @@ def finish(self) -> None: def _get_data(self) -> None: """Receives data from the upstream links.""" + warn("The _get_data method will be removed in version 2.0.0", + DeprecationWarning) + for link in self.inputs: # Receiving data from each link, non-blocking to prevent accumulation data = link.recv_chunk(blocking=False) @@ -126,6 +136,9 @@ def _send_data(self) -> None: """Interpolates the previously received data, and sends the result to the downstream blocks.""" + warn("The _send_data method will be removed in version 2.0.0", + DeprecationWarning) + # Making sure all the necessary data has been received for interpolating if all(timestamp[-1] > self._t for timestamp in self._timestamps.values()) and any( diff --git a/crappy/blocks/pid.py b/crappy/blocks/pid.py index efcbfd2b..0bfafbcd 100644 --- a/crappy/blocks/pid.py +++ b/crappy/blocks/pid.py @@ -2,6 +2,7 @@ from time import time from typing import List, Optional, Tuple +from warnings import warn from .block import Block @@ -53,6 +54,13 @@ def __init__(self, freq: The block will try to loop at this frequency. verbose: If :obj:`True`, prints the looping frequency of the block. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if target_label != 'cmd': + warn("The target_label argument will be renamed to setpoint_label in " + "version 2.0.0", FutureWarning) # Attributes of the parent class super().__init__() diff --git a/crappy/blocks/reader.py b/crappy/blocks/reader.py index 3191b544..8f75bd12 100644 --- a/crappy/blocks/reader.py +++ b/crappy/blocks/reader.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Optional +from warnings import warn from .block import Block @@ -20,6 +21,12 @@ def __init__(self, freq: The block will try to loop at this frequency. verbose: If :obj:`True`, the looping frequency will be printed every 2s. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The Reader Block will be renamed to LinkReader in version 2.0.0", + FutureWarning) Block.__init__(self) self.freq = freq @@ -42,5 +49,8 @@ def loop(self) -> None: def _instance_index(cls) -> int: """Returns the index of the current instance.""" + warn("The _additional_loop method will be renamed to _get_index in " + "version 2.0.0", DeprecationWarning) + cls._index += 1 return cls._index diff --git a/crappy/blocks/recorder.py b/crappy/blocks/recorder.py index 8f5ba280..adc8b7a5 100644 --- a/crappy/blocks/recorder.py +++ b/crappy/blocks/recorder.py @@ -3,6 +3,7 @@ from time import sleep from typing import List, Optional, Dict, Any, Union from pathlib import Path +from warnings import warn from .block import Block @@ -36,6 +37,12 @@ def __init__(self, freq: The block will try to loop at this frequency. verbose: If :obj:`True`, prints the looping frequency of the block. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + warn("The filename argument will be renamed to file_name in version 2.0.0", + FutureWarning) super().__init__() self.niceness = -5 @@ -108,6 +115,9 @@ def finish(self) -> None: def _save(self, data: Dict[str, List[Any]]): """Saves only the data carried by the specified labels to the file.""" + warn("The _save method will be removed in version 2.0.0", + DeprecationWarning) + # Keeping only the data that needs to be saved data = {key: val for key, val in data.items() if key in self._labels} diff --git a/crappy/blocks/sink.py b/crappy/blocks/sink.py index 02e9a353..763b2913 100644 --- a/crappy/blocks/sink.py +++ b/crappy/blocks/sink.py @@ -1,5 +1,7 @@ # coding: utf-8 +from warnings import warn + from .block import Block @@ -10,6 +12,10 @@ def __init__(self, verbose: bool = False, freq: float = 10) -> None: """Sets the args and initializes the parent class.""" + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) super().__init__() self.verbose = verbose diff --git a/crappy/blocks/ucontroller.py b/crappy/blocks/ucontroller.py index db20dbac..5e9aaf60 100644 --- a/crappy/blocks/ucontroller.py +++ b/crappy/blocks/ucontroller.py @@ -4,6 +4,7 @@ from .._global import OptionalModule from struct import unpack from time import time +from warnings import warn try: from serial import Serial from serial.serialutil import SerialException @@ -65,6 +66,10 @@ def __init__(self, information. freq (:obj:`float`, optional): The looping frequency of the block. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) super().__init__() diff --git a/crappy/blocks/videoExtenso.py b/crappy/blocks/videoExtenso.py index 7a082a3d..8206c40f 100644 --- a/crappy/blocks/videoExtenso.py +++ b/crappy/blocks/videoExtenso.py @@ -3,6 +3,7 @@ from typing import Callable, Union, Optional, List, Dict, Any import numpy as np from pathlib import Path +from warnings import warn from ..tool.videoextenso import LostSpotError, VideoExtenso as Ve from ..tool.videoextensoConfig import VE_config @@ -150,6 +151,15 @@ def __init__(self, noise, but also takes a bit more time compared to no blurring. **kwargs: Any additional argument to pass to the camera. """ + + if verbose: + warn("The verbose argument will be replaced by display_freq and debug " + "in version 2.0.0", FutureWarning) + if img_name: + warn("The img_name argument will be replaced by img_extension in " + "version 2.0.0", FutureWarning) + warn("The Video_extenso Block will be renamed to VideoExtenso in version " + "2.0.0", FutureWarning) super().__init__(camera=camera, transform=transform, @@ -223,6 +233,9 @@ def _additional_loop(self, meta: Dict[str, Any], img: np.ndarray) -> None: """Gets the data from the latest image, sends it, and updates the display.""" + warn("The _additional_loop method will be removed in version 2.0.0", + DeprecationWarning) + # Trying to process the incoming images if not self._lost_spots: try: diff --git a/crappy/camera/bispectral.py b/crappy/camera/bispectral.py index 3c834f23..89de00c9 100644 --- a/crappy/camera/bispectral.py +++ b/crappy/camera/bispectral.py @@ -2,6 +2,7 @@ import numpy as np from typing import Tuple +from warnings import warn from .cameralink import Cl_camera table = (0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, @@ -65,6 +66,9 @@ class Bispectral(Cl_camera): def __init__(self) -> None: """""" + warn("The Bispectral Camera will be renamed to BiSpectral in version " + "2.0.0", FutureWarning) + super().__init__() self.add_scale_setting('width', 1, 640, self._get_w, self._set_w, 640) self.add_scale_setting('height', 1, 512, self._get_h, self._set_h, 512) @@ -136,6 +140,10 @@ def _set_it2(self, val: int) -> None: self.set_it(self._get_it1(), val) def send_cmd(self, cmd: str) -> str: + + warn("The send_cmd method will be renamed to _send_cmd in version 2.0.0", + FutureWarning) + r = self.cap.serialWrite(add_crc(cmd)) if not check_crc(r) or r[1] != 'Y': print('WARNING! Incorrect reply!') @@ -145,12 +153,19 @@ def set_external_trigger(self, val) -> None: """Sets the external trigger to val by toggling the value of the 3rd bit of register 102.""" + warn("The set_external_trigger method will be renamed to " + "_set_external_trigger in version 2.0.0", FutureWarning) + if val: self.send_cmd('@W1027C') # 3rd bit to 1 else: self.send_cmd('@W10274') # 3rd bit to 0 def get_roi(self) -> tuple: + + warn("The get_roi method will be renamed to _get_roi in version 2.0.0", + FutureWarning) + x1min_lsb = self.send_cmd("@R1D0") x1min_msb = self.send_cmd("@R1D1") y1min_lsb = self.send_cmd("@R1D2") @@ -166,6 +181,10 @@ def get_roi(self) -> tuple: return xmin, ymin, xmax, ymax def set_roi(self, xmin: int, ymin: int, xmax: int, ymax: int) -> None: + + warn("The set_roi method will be renamed to _set_roi in version 2.0.0", + FutureWarning) + if (xmin, xmax, ymin, ymax) != (0, 0, 639, 511): self.send_cmd('@W1A080') # Set to windowed mode else: @@ -189,6 +208,10 @@ def set_roi(self, xmin: int, ymin: int, xmax: int, ymax: int) -> None: self.send_cmd("@W1D7" + msb_ymax) def get_it(self) -> tuple: + + warn("The get_it method will be renamed to _get_it in version 2.0.0", + FutureWarning) + mc = 10.35 # MHz it1_lsb = self.send_cmd("@R1B4") it1_mid = self.send_cmd("@R1B5") @@ -201,6 +224,10 @@ def get_it(self) -> tuple: return it1 / mc, it2 / mc # IT in µs def set_it(self, it1: int, it2: int) -> None: + + warn("The set_it method will be renamed to _set_it in version 2.0.0", + FutureWarning) + mc = 10.35 it1 = int(mc * it1) it2 = int(mc * it2) @@ -222,6 +249,10 @@ def set_it(self, it1: int, it2: int) -> None: self.send_cmd("@W1BA" + it2_msb) def get_trigg_freq(self) -> float: + + warn("The get_trigg_freq method will be renamed to _get_trigg_freq in " + "version 2.0.0", FutureWarning) + mc = 10350000 # Hz p_lsb = self.send_cmd("@R1B0") p_mid = self.send_cmd("@R1B1") @@ -230,6 +261,10 @@ def get_trigg_freq(self) -> float: return mc / p def set_trigg_freq(self, freq: float) -> None: + + warn("The set_trigg_freq method will be renamed to _set_trigg_freq in " + "version 2.0.0", FutureWarning) + mc = 10350000 # Hz period = int(mc / freq) p_lsb = hexlify(period % 256) @@ -244,6 +279,9 @@ def set_trigg_freq(self, freq: float) -> None: def get_sensor_temperature(self) -> float: """Returns sensor temperature in Kelvin.""" + warn("The get_sensor_temperature method will be removed in version 2.0.0", + FutureWarning) + gain = .01 lsb = self.send_cmd('@R160') msb = self.send_cmd('@R161') @@ -252,5 +290,8 @@ def get_sensor_temperature(self) -> float: def get_ambiant_temperature(self) -> float: """Returns temperature of the board in °C.""" + warn("The get_ambiant_temperature method will be removed in version 2.0.0", + FutureWarning) + t = self.send_cmd('@R173') return int(t, 16) diff --git a/crappy/camera/camera.py b/crappy/camera/camera.py index 122013bd..e745a416 100644 --- a/crappy/camera/camera.py +++ b/crappy/camera/camera.py @@ -3,6 +3,7 @@ from typing import Callable, Optional, Tuple, Union, Any, Dict from time import sleep import numpy as np +from warnings import warn from .._global import DefinitionError @@ -51,6 +52,9 @@ def __init__(self, default: The default value to assign to the setting. """ + warn("The Cam_setting class will be renamed to CameraSetting in version " + "2.0.0", DeprecationWarning) + # Attributes shared by all the settings self.name = name self.default = default @@ -103,6 +107,9 @@ def __init__(self, default: The default value to assign to the setting. """ + warn("The Cam_bool_setting class will be renamed to CameraBoolSetting in " + "version 2.0.0", DeprecationWarning) + super().__init__(name, getter, setter, default) @@ -132,6 +139,9 @@ def __init__(self, default: The default value to assign to the setting. """ + warn("The Cam_scale_setting class will be renamed to CameraScaleSetting " + "in version 2.0.0", DeprecationWarning) + self.lowest = lowest self.highest = highest self.type = int if isinstance(lowest + highest, int) else float @@ -184,6 +194,9 @@ def __init__(self, default: The default value to assign to the setting. """ + warn("The Cam_choice_setting class will be renamed to CameraChoiceSetting " + "in version 2.0.0", DeprecationWarning) + self.choices = choices if default is None: diff --git a/crappy/camera/cameralink.py b/crappy/camera/cameralink.py index c64403b3..12ffda50 100644 --- a/crappy/camera/cameralink.py +++ b/crappy/camera/cameralink.py @@ -6,6 +6,7 @@ from time import time from typing import Optional, Tuple import numpy as np +from warnings import warn from .camera import Camera from .._global import OptionalModule @@ -33,6 +34,9 @@ def __init__(self) -> None: Using a config file is recommended over changing all settings manually. """ + warn("The Cl_camera Camera will be renamed to BaslerIronmanCameraLink in " + "version 2.0.0", FutureWarning) + super().__init__() self.add_scale_setting("framespersec", 1, 200, self._get_framespersec, @@ -45,6 +49,9 @@ def open(self, **kwargs) -> None: """Opens the camera.""" + warn("The numdevice argument of open will be renamed to num_device in " + "version 2.0.0", FutureWarning) + if camera_type is None and config_file is not None: with open(config_file, 'r') as file: r = file.readlines() diff --git a/crappy/camera/fakeCamera.py b/crappy/camera/fakeCamera.py index 6e146ddd..2cdc7f14 100644 --- a/crappy/camera/fakeCamera.py +++ b/crappy/camera/fakeCamera.py @@ -3,6 +3,7 @@ from time import time, strftime, gmtime from typing import Tuple, Optional, Dict, Any import numpy as np +from warnings import warn from .camera import Camera @@ -18,6 +19,9 @@ class Fake_camera(Camera): def __init__(self) -> None: """Initializes the parent class and instantiates the settings.""" + warn("The Fake_camera Camera will be renamed to FakeCamera in version " + "2.0.0", FutureWarning) + super().__init__() self._frame_nr = -1 diff --git a/crappy/camera/file_reader.py b/crappy/camera/file_reader.py index f85a810f..e9045311 100644 --- a/crappy/camera/file_reader.py +++ b/crappy/camera/file_reader.py @@ -5,6 +5,7 @@ import numpy as np from pathlib import Path from re import fullmatch +from warnings import warn from .camera import Camera from .._global import OptionalModule, CrappyStop @@ -38,6 +39,9 @@ class File_reader(Camera): def __init__(self) -> None: """Initializes the parent class and sets a few attributes.""" + warn("The File_reader Camera will be renamed to FileReader in version " + "2.0.0", FutureWarning) + super().__init__() # These attributes will come in use later on diff --git a/crappy/camera/gstreamer.py b/crappy/camera/gstreamer.py index 82434f52..bcfba135 100644 --- a/crappy/camera/gstreamer.py +++ b/crappy/camera/gstreamer.py @@ -8,6 +8,7 @@ from subprocess import Popen, PIPE, run from platform import system from re import findall, split, search +from warnings import warn try: import cv2 @@ -48,6 +49,9 @@ class Camera_gstreamer(Camera): def __init__(self) -> None: """Simply initializes the instance attributes.""" + warn("The Camera_gstreamer Camera will be renamed to CameraGstreamer in " + "version 2.0.0", FutureWarning) + super().__init__() Gst.init(None) @@ -346,6 +350,9 @@ def _restart_pipeline(self, exposure (:obj:`int`, optional): The new exposure value to set. """ + warn("The exposure argument of _restart_pipeline will be removed in " + "version 2.0.0", DeprecationWarning) + # Stops the previous pipeline self._pipeline.set_state(Gst.State.NULL) @@ -527,6 +534,9 @@ def _set_exposure(self, exposure: int) -> None: Only works when the platform is Linux. """ + warn("The _set_exposure method will be removed in version 2.0.0", + DeprecationWarning) + self._restart_pipeline(self._get_pipeline(), exposure=exposure) def _get_exposure(self) -> int: @@ -535,6 +545,9 @@ def _get_exposure(self) -> int: Only works when the platform is Linux. """ + warn("The _get_exposure method will be removed in version 2.0.0", + DeprecationWarning) + # Trying to run v4l2-ctl to get the exposure value if self._device is not None: command = ['v4l2-ctl', '-d', self._device, '-C', @@ -566,6 +579,9 @@ def _get_format(self) -> str: """Parses the v4l2-ctl -V command to get the current image format as an index.""" + warn("The _get_format method will be removed in version 2.0.0", + DeprecationWarning) + # Sending the v4l2-ctl command if self._device is not None: command = ['v4l2-ctl', '-d', str(self._device), '-V'] diff --git a/crappy/camera/jai.py b/crappy/camera/jai.py index 0c88b046..5a5236c2 100644 --- a/crappy/camera/jai.py +++ b/crappy/camera/jai.py @@ -2,6 +2,7 @@ from typing import Optional, Tuple import numpy as np +from warnings import warn from .cameralink import Cl_camera from .._global import OptionalModule @@ -25,6 +26,9 @@ class Jai8(Cl_camera): def __init__(self) -> None: """""" + warn("The Jai8 Camera will be renamed to JaiGO5000CPMCL8Bits in version " + "2.0.0", FutureWarning) + super().__init__() self.add_scale_setting('width', 1, 2560, self._get_w, self._set_w, 2560) @@ -81,6 +85,9 @@ class Jai(Jai8): def __init__(self) -> None: """""" + warn("The Jai Camera will be renamed to JaiGO5000CPMCL in version 2.0.0", + FutureWarning) + super().__init__() self.add_choice_setting('data_format', ('10 bits', '12 bits'), self._get_format, self._set_format, '12 bits') diff --git a/crappy/camera/opencv.py b/crappy/camera/opencv.py index 34ff525c..7c55f203 100644 --- a/crappy/camera/opencv.py +++ b/crappy/camera/opencv.py @@ -6,6 +6,7 @@ from platform import system from subprocess import run from re import findall, split, search +from warnings import warn from .camera import Camera from .._global import OptionalModule @@ -35,6 +36,9 @@ class Camera_opencv(Camera): def __init__(self) -> None: """Sets variables and adds the channels setting.""" + warn("The Camera_opencv Camera will be renamed to CameraOpencv in version " + "2.0.0", FutureWarning) + super().__init__() self._cap = None diff --git a/crappy/camera/pi_camera.py b/crappy/camera/pi_camera.py index 0f7bc35e..5ad1eb78 100644 --- a/crappy/camera/pi_camera.py +++ b/crappy/camera/pi_camera.py @@ -6,6 +6,7 @@ from .._global import OptionalModule import numpy as np from threading import Thread, RLock +from warnings import warn try: import cv2 @@ -36,6 +37,9 @@ class Picamera(Camera): def __init__(self) -> None: """Instantiates the available settings.""" + warn("The Picamera Camera will be renamed to RaspberryPiCamera in version " + "2.0.0", FutureWarning) + super().__init__() self._cam = PiCamera() diff --git a/crappy/camera/seek_thermal_pro.py b/crappy/camera/seek_thermal_pro.py index 8fc7325c..31d3343b 100644 --- a/crappy/camera/seek_thermal_pro.py +++ b/crappy/camera/seek_thermal_pro.py @@ -5,6 +5,7 @@ from .._global import OptionalModule import numpy as np from time import time +from warnings import warn try: import usb.util @@ -66,6 +67,9 @@ class Seek_thermal_pro(Camera): def __init__(self) -> None: """Selects the right USB device.""" + warn("The Seek_thermal_pro Camera will be renamed to SeekThermalPro in " + "version 2.0.0", FutureWarning) + super().__init__() self._calib = None diff --git a/crappy/camera/xiapi.py b/crappy/camera/xiapi.py index 533dd2b6..3cd26959 100644 --- a/crappy/camera/xiapi.py +++ b/crappy/camera/xiapi.py @@ -8,6 +8,7 @@ from time import time from typing import Optional, Tuple import numpy as np +from warnings import warn from .camera import Camera from .._global import OptionalModule @@ -24,6 +25,9 @@ class Xiapi(Camera): def __init__(self) -> None: """""" + warn("The Xiapi Camera will be renamed to XiAPI in version 2.0.0", + FutureWarning) + super().__init__() self._cam = xiapi.Camera() @@ -38,6 +42,10 @@ def open(self, sn: Optional[str] = None, **kwargs) -> None: Else, it will open any camera. """ + + if sn is not None: + warn("The sn argument of open will be renamed to serial_number in " + "version 2.0.0", FutureWarning) if sn is not None: self._cam.open_device_by_SN(sn) @@ -133,6 +141,10 @@ def _set_aeag(self, aeag: bool) -> None: self._cam.set_param('aeag', int(aeag)) def _set_extt(self, trig: bool) -> None: + + warn("The _set_extt method will be renamed to _set_ext_trig in version " + "2.0.0", DeprecationWarning) + if trig: self._cam.set_gpi_mode('XI_GPI_TRIGGER') self._cam.set_trigger_source('XI_TRG_EDGE_RISING') diff --git a/crappy/inout/ads1115.py b/crappy/inout/ads1115.py index 813987d0..bdc3c668 100644 --- a/crappy/inout/ads1115.py +++ b/crappy/inout/ads1115.py @@ -3,6 +3,7 @@ from time import time from re import findall from typing import Union, List, Optional +from warnings import warn from .inout import InOut from ..tool import ft232h_server as ft232h, Usb_server from .._global import OptionalModule @@ -171,6 +172,12 @@ def __init__(self, voltages higher than `VDD` !! """ + warn("The Ads1115 InOut will be renamed to ADS1115 in version 2.0.0", + FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument will be removed in version 2.0.0", + FutureWarning) + if not isinstance(backend, str) or backend not in Ads1115_backends: raise ValueError("backend should be in {}".format(Ads1115_backends)) self._backend = backend diff --git a/crappy/inout/comedi.py b/crappy/inout/comedi.py index c5f113a7..d99a339d 100644 --- a/crappy/inout/comedi.py +++ b/crappy/inout/comedi.py @@ -3,6 +3,7 @@ from time import time from typing import Optional, List from dataclasses import dataclass +from warnings import warn from .inout import InOut from ..tool import comedi_bind as comedi @@ -113,6 +114,11 @@ def __init__(self, as the shortest given list. """ + warn("The subdevice argument will be renamed to sub_device in version " + "2.0.0", FutureWarning) + warn("The out_subdevice argument will be renamed to out_sub_device in " + "version 2.0.0", FutureWarning) + super().__init__() self._device_name = device.encode() diff --git a/crappy/inout/daqmx.py b/crappy/inout/daqmx.py index 5f836bd6..8bfd7ed9 100644 --- a/crappy/inout/daqmx.py +++ b/crappy/inout/daqmx.py @@ -4,6 +4,7 @@ from time import time from typing import List, Optional from dataclasses import dataclass +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -115,6 +116,9 @@ def __init__(self, as the shortest given list. """ + warn("The Daqmx InOut will be renamed to DAQmx in version 2.0.0", + FutureWarning) + super().__init__() self._device = device diff --git a/crappy/inout/fake_inout.py b/crappy/inout/fake_inout.py index 794fac03..41217c4b 100644 --- a/crappy/inout/fake_inout.py +++ b/crappy/inout/fake_inout.py @@ -2,6 +2,7 @@ from time import time from typing import List +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -21,6 +22,9 @@ class Fake_inout(InOut): def __init__(self) -> None: """Not much to do here.""" + warn("The Fake_inout InOut will be renamed to FakeInOut in version 2.0.0", + FutureWarning) + super().__init__() def open(self) -> None: diff --git a/crappy/inout/gpio_pwm.py b/crappy/inout/gpio_pwm.py index 48dbdd3d..9e332a33 100644 --- a/crappy/inout/gpio_pwm.py +++ b/crappy/inout/gpio_pwm.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Optional +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -57,6 +58,9 @@ def __init__(self, work but may decrease the available frequency range. """ + warn("The Gpio_pwm InOut will be renamed to GPIOPWM in version 2.0.0", + FutureWarning) + super().__init__() if pin_out not in range(2, 28): diff --git a/crappy/inout/gpio_switch.py b/crappy/inout/gpio_switch.py index 4274886b..72b9b5cb 100644 --- a/crappy/inout/gpio_switch.py +++ b/crappy/inout/gpio_switch.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Optional, Union +from warnings import warn from .inout import InOut from .._global import OptionalModule from ..tool import ft232h_server as ft232h, Usb_server, ft232h_pin_nr @@ -59,6 +60,12 @@ def __init__(self, to use for communication. """ + warn("The Gpio_switch InOut will be renamed to GPIOSwitch in version " + "2.0.0", FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument will be removed in version 2.0.0", + FutureWarning) + # Checking that the backend is valid if not isinstance(backend, str) or backend not in gpio_switch_backends: raise ValueError("backend should be in {}".format(gpio_switch_backends)) diff --git a/crappy/inout/gsm.py b/crappy/inout/gsm.py index 2db75e5b..9a0d200a 100644 --- a/crappy/inout/gsm.py +++ b/crappy/inout/gsm.py @@ -2,6 +2,7 @@ from time import sleep from typing import List +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -39,6 +40,9 @@ def __init__(self, baudrate(:obj:`int`, optional): Serial baudrate, between 1200 and 115200. """ + warn("The Gsm InOut will be renamed to Sim868 in version 2.0.0", + FutureWarning) + super().__init__() try: self._ser = Serial(port, baudrate) @@ -83,6 +87,9 @@ def _send_mess(self, message: str) -> None: message: The text message to send. """ + warn("The _send_mess method will be removed in version 2.0.0", + DeprecationWarning) + for number in self._numbers: count = 0 self._ser.write(b'AT' + b'\r\n') diff --git a/crappy/inout/kollmorgen.py b/crappy/inout/kollmorgen.py index 24ef29d5..91f0482c 100644 --- a/crappy/inout/kollmorgen.py +++ b/crappy/inout/kollmorgen.py @@ -3,6 +3,7 @@ from time import time from struct import pack, unpack from typing import List +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -57,6 +58,9 @@ def __init__(self, an :obj:`int`. """ + warn("The Koll InOut will be renamed to KollmorgenAKDPDMM in version " + "2.0.0", FutureWarning) + super().__init__() # Making sure the given mode is correct diff --git a/crappy/inout/labjackT7.py b/crappy/inout/labjackT7.py index b7b2cbf1..9791f725 100644 --- a/crappy/inout/labjackT7.py +++ b/crappy/inout/labjackT7.py @@ -4,6 +4,7 @@ from typing import List, Optional, Dict, Any, Union, Tuple from itertools import chain from dataclasses import dataclass, field +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -197,6 +198,9 @@ def __init__(self, hardware safety ! """ + warn("The Labjack_t7 InOut will be renamed to LabjackT7 in version 2.0.0", + FutureWarning) + super().__init__() # Identifiers for the device to open diff --git a/crappy/inout/labjackUE9.py b/crappy/inout/labjackUE9.py index d7e2096e..b3971fa4 100644 --- a/crappy/inout/labjackUE9.py +++ b/crappy/inout/labjackUE9.py @@ -3,6 +3,7 @@ from time import time from typing import Optional, List from dataclasses import dataclass +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -74,6 +75,9 @@ def __init__(self, if they had the same length as the shortest given list. """ + warn("The Labjack_ue9 InOut will be renamed to LabjackUE9 in version " + "2.0.0", FutureWarning) + super().__init__() # Setting the defaults for arguments that are not given diff --git a/crappy/inout/mcp9600.py b/crappy/inout/mcp9600.py index ff47b166..a293b746 100644 --- a/crappy/inout/mcp9600.py +++ b/crappy/inout/mcp9600.py @@ -2,6 +2,7 @@ from time import time from typing import Optional, List +from warnings import warn from .inout import InOut from ..tool import ft232h_server as ft232h, Usb_server from .._global import OptionalModule @@ -170,6 +171,12 @@ def __init__(self, """ + warn("The Mcp9600 InOut will be renamed to MCP9600 in version 2.0.0", + FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument will be removed in version 2.0.0", + FutureWarning) + if not isinstance(backend, str) or backend not in Mcp9600_backends: raise ValueError("backend should be in {}".format(Mcp9600_backends)) self._backend = backend diff --git a/crappy/inout/mprls.py b/crappy/inout/mprls.py index d3b20435..5841f4de 100644 --- a/crappy/inout/mprls.py +++ b/crappy/inout/mprls.py @@ -2,6 +2,7 @@ from time import time from typing import Union, Optional, List +from warnings import warn from .inout import InOut from .._global import OptionalModule from ..tool import ft232h_server as ft232h, Usb_server, i2c_msg_ft232h @@ -84,6 +85,12 @@ def __init__(self, serial number of the FT232H to use for communication. """ + warn("The Mprls InOut will be renamed to MPRLS in version 2.0.0", + FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument will be removed in version 2.0.0", + FutureWarning) + if not isinstance(backend, str) or backend not in mprls_backends: raise ValueError("backend should be in {}".format(mprls_backends)) self._backend = backend diff --git a/crappy/inout/nau7802.py b/crappy/inout/nau7802.py index 67175205..0fa7fa3b 100644 --- a/crappy/inout/nau7802.py +++ b/crappy/inout/nau7802.py @@ -2,6 +2,7 @@ from time import time, sleep from typing import Union, Optional, List +from warnings import warn from .inout import InOut from ..tool import ft232h_server as ft232h, Usb_server from .._global import OptionalModule @@ -177,6 +178,14 @@ def __init__(self, serial number of the ft232h to use for communication. """ + warn("The Nau7802 InOut will be renamed to NAU7802 in version 2.0.0", + FutureWarning) + warn('The backend argument will be removed in version 2.0.0', + FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument will be removed in version 2.0.0", + FutureWarning) + if backend not in NAU7802_Backends: raise ValueError("backend should be in {}".format(NAU7802_Backends)) diff --git a/crappy/inout/ni_daqmx.py b/crappy/inout/ni_daqmx.py index 11394ac7..e74e71cc 100755 --- a/crappy/inout/ni_daqmx.py +++ b/crappy/inout/ni_daqmx.py @@ -7,6 +7,7 @@ from re import fullmatch from collections import defaultdict from itertools import chain +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -121,6 +122,9 @@ def __init__(self, `'max_val'` arguments are internally set by default to `0` and `5`. """ + warn("The Nidaqmx InOut will be renamed to NIDAQmx in version 2.0.0", + FutureWarning) + super().__init__() # Setting the number of samples per acquisition for streamer mode diff --git a/crappy/inout/opsens.py b/crappy/inout/opsens.py index e23071a4..53ab254a 100644 --- a/crappy/inout/opsens.py +++ b/crappy/inout/opsens.py @@ -2,6 +2,7 @@ from time import time from typing import List +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -28,6 +29,9 @@ def __init__(self, PicoSens. """ + warn("The Opsens InOut will be renamed to HandySens in version 2.0.0", + FutureWarning) + super().__init__() self._addr = device diff --git a/crappy/inout/piJuice.py b/crappy/inout/piJuice.py index ea21820f..427878f0 100644 --- a/crappy/inout/piJuice.py +++ b/crappy/inout/piJuice.py @@ -2,6 +2,7 @@ from typing import Dict, Any, List from time import time +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -69,6 +70,9 @@ def __init__(self, default address is 0x14. """ + warn("The Pijuice InOut will be renamed to PiJuice in version 2.0.0", + FutureWarning) + super().__init__() if not isinstance(i2c_port, int): raise TypeError("i2c_port should be an int") diff --git a/crappy/inout/spectrum.py b/crappy/inout/spectrum.py index 5b87c035..a2193a38 100644 --- a/crappy/inout/spectrum.py +++ b/crappy/inout/spectrum.py @@ -3,6 +3,7 @@ import numpy as np from time import time from typing import List, Optional +from warnings import warn from .inout import InOut from ..tool import pyspcm as spc @@ -45,6 +46,9 @@ def __init__(self, bytes. The default is 65kB. """ + warn("The Spectrum InOut will be renamed to SpectrumM2I4711 in version " + "2.0.0", FutureWarning) + super().__init__() # Setting the args diff --git a/crappy/inout/t7Streamer.py b/crappy/inout/t7Streamer.py index 72388cce..c9113a0f 100644 --- a/crappy/inout/t7Streamer.py +++ b/crappy/inout/t7Streamer.py @@ -5,6 +5,7 @@ from typing import List, Dict, Any, Optional, Tuple from dataclasses import dataclass, field from itertools import chain +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -133,6 +134,9 @@ def __init__(self, """ + warn("The T7_streamer InOut will be renamed to T7Streamer in version " + "2.0.0", FutureWarning) + super().__init__() if len(channels) * scan_rate > 100000: diff --git a/crappy/inout/waveshare_ad_da.py b/crappy/inout/waveshare_ad_da.py index 94ead5f6..11e7b90c 100644 --- a/crappy/inout/waveshare_ad_da.py +++ b/crappy/inout/waveshare_ad_da.py @@ -4,6 +4,7 @@ from time import sleep, time from re import fullmatch, findall from typing import Union, Optional, List +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -190,6 +191,9 @@ def __init__(self, up with `5V`. Same goes for the DAC. """ + warn("The Waveshare_ad_da InOut will be renamed to WaveshareADDA in " + "version 2.0.0", FutureWarning) + InOut.__init__(self) if gain_hardware not in Ads1256_gain: diff --git a/crappy/inout/waveshare_ad_da_ft232h.py b/crappy/inout/waveshare_ad_da_ft232h.py index ff5962a1..8c3c4497 100644 --- a/crappy/inout/waveshare_ad_da_ft232h.py +++ b/crappy/inout/waveshare_ad_da_ft232h.py @@ -3,6 +3,7 @@ from time import time, sleep from re import fullmatch, findall from typing import List, Union, Optional +from warnings import warn from .inout import InOut from ..tool import ft232h_server as ft232h, Usb_server @@ -193,6 +194,12 @@ def __init__(self, up with `5V`. Same goes for the DAC. """ + warn("The Waveshare_ad_da_ft232h InOut will be renamed to " + "WaveshareADDAFT232H in version 2.0.0", FutureWarning) + if ft232h_ser_num is not None: + warn("The ft232h_ser_num argument will be removed in version 2.0.0, and " + "should now be passed to the IOBlock", FutureWarning) + Usb_server.__init__(self, serial_nr=ft232h_ser_num if ft232h_ser_num else '', backend='ft232h') diff --git a/crappy/inout/waveshare_high_precision.py b/crappy/inout/waveshare_high_precision.py index 552463d3..5b951a11 100644 --- a/crappy/inout/waveshare_high_precision.py +++ b/crappy/inout/waveshare_high_precision.py @@ -3,6 +3,7 @@ from time import time, sleep from re import fullmatch, findall from typing import Union, List, Optional +from warnings import warn from .inout import InOut from .._global import OptionalModule @@ -186,6 +187,9 @@ def __init__(self, would be read as 4.7V after the PGA, not 4.8V ! Beware ! """ + warn("The Waveshare_high_precision InOut will be renamed to " + "WaveshareHighPrecision in version 2.0.0", FutureWarning) + super().__init__() self._gain = gain self._offset = offset diff --git a/crappy/links/link.py b/crappy/links/link.py index 1f887b43..6a45d158 100644 --- a/crappy/links/link.py +++ b/crappy/links/link.py @@ -5,6 +5,7 @@ from threading import Thread from copy import copy from typing import Callable, Union, Any, Dict, Optional, List +from warnings import warn from .._global import CrappyStop from ..modifier import Modifier @@ -55,6 +56,22 @@ def __init__(self, in the order in which they are instantiated in the code. """ + if input_block is None: + warn("input_block will become a mandatory argument of Link in version " + "2.0.0", FutureWarning) + if output_block is None: + warn("output_block will become a mandatory argument of Link in version " + "2.0.0", FutureWarning) + if conditions is not None: + warn("The conditions argument of Link will be removed in version 2.0.0, " + "use modifiers instead", FutureWarning) + if timeout != 1: + warn("The timeout argument of Link will be removed in version 2.0.0", + FutureWarning) + if action != 'warn': + warn("The action argument of Link will be removed in version 2.0.0", + FutureWarning) + # For compatibility (condition is deprecated, use modifier) if conditions is not None: if modifiers is not None: @@ -79,6 +96,9 @@ def __init__(self, def _count_links(cls) -> int: """Simply increments the link count and returns it.""" + warn("The _count_links method will be renamed to _get_count in version " + "2.0.0", DeprecationWarning) + cls.count += 1 return cls.count @@ -124,6 +144,9 @@ def send(self, value: Union[Dict[str, Any], str]) -> None: def _send_timeout(self, value: Union[Dict[str, Any], str]) -> None: """Method for sending data with a given timeout on the link.""" + warn("The _send_timeout method will be removed in version 2.0.0", + DeprecationWarning) + try: # Sending if the value is None or a string if self._modifiers is None or isinstance(value, str): @@ -172,6 +195,9 @@ def recv(self, blocking: bool = True) -> Optional[Dict[str, Any]]: pipe is empty. """ + warn("The blocking argument will be removed in version 2.0.0", + DeprecationWarning) + try: if blocking or self.poll(): # Simply collecting the data to receive @@ -215,6 +241,9 @@ def poll(self) -> bool: def clear(self) -> None: """Flushes the link.""" + warn("The clear method will be removed in version 2.0.0", + DeprecationWarning) + while self.poll(): self._in.recv_bytes() @@ -231,6 +260,9 @@ def recv_last(self, blocking: bool = False) -> Optional[Dict[str, Any]]: Unlike :meth:`recv`, default is non blocking. """ + warn("The blocking argument will be removed in version 2.0.0", + DeprecationWarning) + # First, block if necessary data = self.recv(blocking) if data is None: @@ -254,6 +286,9 @@ def recv_chunk(self, If ``blocking`` is :obj:`True`, will wait for at least one data. """ + warn("The blocking argument will be removed in version 2.0.0", + DeprecationWarning) + # First, block if necessary and return if the link is empty ret = self.recv(blocking) if ret is None: @@ -299,6 +334,9 @@ def recv_delay(self, delay: float) -> Dict[str, List[Any]]: Also, it will return at least one reading. """ + warn("The recv_delay method will be removed in version 2.0.0", + DeprecationWarning) + t_init = time() # This first call to recv is blocking ret = self.recv(blocking=True) @@ -330,6 +368,9 @@ def recv_chunk_no_stop(self) -> Optional[Dict[str, List[Any]]]: """Experimental feature, to be used in :meth:`finish` methods to recover the final remaining data (possibly after a stop signal).""" + warn("The recv_chunk_no_stop method will be removed in version 2.0.0", + DeprecationWarning) + # First, collecting all the remaining data recv = [] while self.poll(): @@ -384,6 +425,15 @@ def link(in_block, in which they are instantiated in the code. """ + if condition is not None: + warn("The condition argument will be removed in version 2.0.0, use " + "modifier instead", FutureWarning) + if timeout != 1: + warn("The timeout argument will be removed in version 2.0.0", + FutureWarning) + if action != 'warn': + warn("The action argument will be removed in version 2.0.0", FutureWarning) + # Forcing the conditions and modifiers into lists if condition is not None and not isinstance(condition, list): condition = [condition] diff --git a/crappy/modifier/demux.py b/crappy/modifier/demux.py index f643534c..b73d42fb 100644 --- a/crappy/modifier/demux.py +++ b/crappy/modifier/demux.py @@ -2,6 +2,7 @@ import numpy as np from typing import Dict, Any, Union, List, Tuple +from warnings import warn from .modifier import Modifier @@ -54,6 +55,9 @@ def evaluate(self, data: Dict[str, np.ndarray]) -> Dict[str, Any]: """Retrieves for each label its value in the stream, also gets the corresponding timestamp, and returns them.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # If there are no rows or no column, cannot perform the demux if 0 in data[self._stream_label].shape: return data diff --git a/crappy/modifier/differentiate.py b/crappy/modifier/differentiate.py index c69312f9..012d3a7c 100644 --- a/crappy/modifier/differentiate.py +++ b/crappy/modifier/differentiate.py @@ -2,6 +2,7 @@ from .modifier import Modifier from typing import Optional, Dict, Any +from warnings import warn class Diff(Modifier): @@ -33,6 +34,9 @@ def evaluate(self, data: Dict[str, Any]) -> Dict[str, Any]: """Gets the data from the upstream block, updates the differentiation value and returns it.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # For the first received data, storing it and returning 0 if self._last_t is None or self._last_val is None: self._last_t = data[self._time_label] diff --git a/crappy/modifier/integrate.py b/crappy/modifier/integrate.py index 88c550b8..abd05377 100644 --- a/crappy/modifier/integrate.py +++ b/crappy/modifier/integrate.py @@ -2,6 +2,7 @@ from .modifier import Modifier from typing import Optional, Dict, Any +from warnings import warn class Integrate(Modifier): @@ -34,6 +35,9 @@ def evaluate(self, data: Dict[str, Any]) -> Dict[str, Any]: """Gets the data from the upstream block, updates the integration value and returns it.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # For the first received data, storing it and returning 0 if self._last_t is None or self._last_val is None: self._last_t = data[self._time_label] diff --git a/crappy/modifier/mean.py b/crappy/modifier/mean.py index 90f49592..002ddd19 100644 --- a/crappy/modifier/mean.py +++ b/crappy/modifier/mean.py @@ -2,6 +2,7 @@ import numpy as np from typing import Dict, Any, Optional +from warnings import warn from .modifier import Modifier @@ -33,6 +34,9 @@ def evaluate(self, data: Dict[str, Any]) -> Optional[Dict[str, Any]]: If there are not enough points, doesn't return anything. """ + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # Initializing the buffer if self._buf is None: self._buf = {key: [value] for key, value in data.items()} diff --git a/crappy/modifier/median.py b/crappy/modifier/median.py index f3680803..f4dff6bc 100644 --- a/crappy/modifier/median.py +++ b/crappy/modifier/median.py @@ -2,6 +2,7 @@ import numpy as np from typing import Dict, Any, Optional +from warnings import warn from .modifier import Modifier @@ -33,6 +34,9 @@ def evaluate(self, data: Dict[str, Any]) -> Optional[Dict[str, Any]]: If there are not enough points, doesn't return anything. """ + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # Initializing the buffer if self._buf is None: self._buf = {key: [value] for key, value in data.items()} diff --git a/crappy/modifier/moving_avg.py b/crappy/modifier/moving_avg.py index cd9bdc2d..037351cb 100644 --- a/crappy/modifier/moving_avg.py +++ b/crappy/modifier/moving_avg.py @@ -2,6 +2,7 @@ import numpy as np from typing import Dict, Any +from warnings import warn from .modifier import Modifier @@ -28,6 +29,9 @@ def evaluate(self, data: Dict[str, Any]) -> Dict[str, Any]: """Receives data from the upstream block, computes the average of every label and replaces the original data with it.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # Initializing the buffer if self._buf is None: self._buf = {key: [value] for key, value in data.items()} diff --git a/crappy/modifier/moving_med.py b/crappy/modifier/moving_med.py index 4824b5c3..5f4ca424 100644 --- a/crappy/modifier/moving_med.py +++ b/crappy/modifier/moving_med.py @@ -2,6 +2,7 @@ import numpy as np from typing import Dict, Any +from warnings import warn from .modifier import Modifier @@ -28,6 +29,9 @@ def evaluate(self, data: Dict[str, Any]) -> Dict[str, Any]: """Receives data from the upstream block, computes the median of every label and replaces the original data with it.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # Initializing the buffer if self._buf is None: self._buf = {key: [value] for key, value in data.items()} diff --git a/crappy/modifier/offset.py b/crappy/modifier/offset.py index a588bab4..500bf663 100644 --- a/crappy/modifier/offset.py +++ b/crappy/modifier/offset.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Dict, Any, List, Union, Tuple +from warnings import warn from .modifier import Modifier @@ -57,6 +58,9 @@ def evaluate(self, data: Dict[str, Any]) -> Dict[str, Any]: """If the compensations are not set, sets them, anf then offsets the required labels.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # During the first loop, calculating the compensation values if not self._compensated: self._compensations = {label: -data[label] + offset for label, offset in diff --git a/crappy/modifier/trig_on_change.py b/crappy/modifier/trig_on_change.py index 1308a42a..5fc258ae 100644 --- a/crappy/modifier/trig_on_change.py +++ b/crappy/modifier/trig_on_change.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Optional, Dict, Any +from warnings import warn from .modifier import Modifier @@ -27,6 +28,9 @@ def evaluate(self, data: Dict[str, Any]) -> Optional[Dict[str, Any]]: """Compares the received value with the last sent one, and if they're different sends the received data and stores the latest value.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + # Storing the first received value and returning the data if self._last is None: self._last = data[self._label] diff --git a/crappy/modifier/trig_on_value.py b/crappy/modifier/trig_on_value.py index 8a55fbff..e3eeb29c 100644 --- a/crappy/modifier/trig_on_value.py +++ b/crappy/modifier/trig_on_value.py @@ -2,6 +2,7 @@ from .modifier import Modifier from typing import Optional, Tuple, Dict, Any, Union, List +from warnings import warn class Trig_on_value(Modifier): @@ -34,5 +35,8 @@ def evaluate(self, data: Dict[str, Any]) -> Optional[Dict[str, Any]]: """Checks if the value of ``label`` is in the predefined set of accepted values, and if so transmits the data.""" + warn("The evaluate method will be renamed to __call__ in version 2.0.0", + FutureWarning) + if data[self._label] in self._values: return data diff --git a/crappy/tool/cameraConfig.py b/crappy/tool/cameraConfig.py index e785150f..92756cb2 100644 --- a/crappy/tool/cameraConfig.py +++ b/crappy/tool/cameraConfig.py @@ -6,6 +6,7 @@ from time import time, sleep from typing import Optional, Tuple from functools import partial +from warnings import warn from .._global import OptionalModule from .cameraConfigTools import Zoom @@ -39,6 +40,9 @@ def __init__(self, camera) -> None: camera: The camera object in charge of acquiring the images. """ + warn("The Camera_config class will be renamed to CameraConfig in version " + "2.0.0", DeprecationWarning) + super().__init__() self._camera = camera @@ -253,7 +257,8 @@ def _bind_canvas_left_click(self) -> None: """This method is meant to simplify the modification of the left button behavior in subclasses.""" - pass + warn("The _bind_canvas_left_click method will be removed in version 2.0.0", + DeprecationWarning) def _bind_mouse(self, _: tk.Event) -> None: """Binds the mousewheel to the settings canvas scrollbar when the user @@ -757,6 +762,9 @@ def _hist_func(x: np.ndarray, _: np.ndarray, histo: np.ndarray): """Function passed to the :meth:`np.fromfunction` method for building the histogram.""" + warn("The _hist_func method will be removed in version 2.0.0", + DeprecationWarning) + return np.where(x <= histo, 0, 255) def _resize_hist(self) -> None: diff --git a/crappy/tool/cameraConfigBoxes.py b/crappy/tool/cameraConfigBoxes.py index 4584220a..a81e2063 100644 --- a/crappy/tool/cameraConfigBoxes.py +++ b/crappy/tool/cameraConfigBoxes.py @@ -2,6 +2,7 @@ import numpy as np import tkinter as tk +from warnings import warn from .cameraConfig import Camera_config from .cameraConfigTools import Box, Spot_boxes @@ -18,6 +19,9 @@ class behaves the exact same way as its parent class. It is not used as is by def __init__(self, camera) -> None: """Initializes the parent class and sets the spots container.""" + warn("The Camera_config_with_boxes class will be renamed to " + "CameraConfigBoxes in version 2.0.0", DeprecationWarning) + self._spots = Spot_boxes() self._select_box = Box() super().__init__(camera) diff --git a/crappy/tool/cameraConfigTools.py b/crappy/tool/cameraConfigTools.py index 93393b20..ad959742 100644 --- a/crappy/tool/cameraConfigTools.py +++ b/crappy/tool/cameraConfigTools.py @@ -2,6 +2,7 @@ from dataclasses import dataclass from typing import Optional, Tuple, List +from warnings import warn @dataclass @@ -128,6 +129,9 @@ def get_patch(self) -> (int, int, int, int): """Returns the information of the box in the patch format, for compatibility with other blocks.""" + warn("The get_patch method will be removed in version 2.0.0", + DeprecationWarning) + return (self.y_start, self.x_start, self.y_end - self.y_start, self.x_end - self.x_start) @@ -162,6 +166,11 @@ class Spot_boxes: _index = -1 + def __post_init__(self) -> None: + + warn("The Spot_boxes class will be renamed to SpotsBoxes in version 2.0.0", + DeprecationWarning) + def __getitem__(self, i: int) -> Optional[Box]: if i == 0: return self.spot_1 diff --git a/crappy/tool/discorrel.py b/crappy/tool/discorrel.py index 24331611..053e3c76 100644 --- a/crappy/tool/discorrel.py +++ b/crappy/tool/discorrel.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import List, Optional +from warnings import warn from .._global import OptionalModule from .cameraConfigTools import Box from .fields import get_res, get_field, allowed_fields @@ -58,6 +59,9 @@ def __init__(self, less than patch size. """ + warn("The DISCorrel class will be renamed to DISCorrelTool in version " + "2.0.0", DeprecationWarning) + if fields is not None and not all((field in allowed_fields for field in fields)): raise ValueError(f"The only allowed values for the fields " diff --git a/crappy/tool/discorrelConfig.py b/crappy/tool/discorrelConfig.py index 27b68f4f..136a6da0 100644 --- a/crappy/tool/discorrelConfig.py +++ b/crappy/tool/discorrelConfig.py @@ -3,6 +3,7 @@ import tkinter as tk from typing import Optional from copy import deepcopy +from warnings import warn from .cameraConfigBoxes import Camera_config_with_boxes from .cameraConfigTools import Box @@ -17,6 +18,9 @@ class DISConfig(Camera_config_with_boxes): def __init__(self, camera) -> None: """Initializes the parent class and sets the correl box.""" + warn("The DISConfig class will be renamed to DISCorrelConfig in version " + "2.0.0", DeprecationWarning) + self._correl_box = Box() self._draw_correl_box = True @@ -32,6 +36,9 @@ def _bind_canvas_left_click(self) -> None: """Binds the left mouse button click for drawing the box on which the correlation will be performed.""" + warn("The _bind_canvas_left_click method will be removed in version 2.0.0", + DeprecationWarning) + self._img_canvas.bind('', self._start_box) self._img_canvas.bind('', self._extend_box) self._img_canvas.bind('', self._stop_box) diff --git a/crappy/tool/disve.py b/crappy/tool/disve.py index 97d1725f..cd1244e8 100644 --- a/crappy/tool/disve.py +++ b/crappy/tool/disve.py @@ -2,6 +2,7 @@ import numpy as np from typing import List, Tuple +from warnings import warn from .._global import OptionalModule from .cameraConfigTools import Spot_boxes, Box @@ -71,6 +72,9 @@ def __init__(self, of the image. """ + warn("The DISVE class will be renamed to DICVETool in version 2.0.0", + DeprecationWarning) + # These attributes are accessed by the parent class self._patches = patches self._offsets = [(0, 0) for _ in patches] diff --git a/crappy/tool/disveConfig.py b/crappy/tool/disveConfig.py index ec435c58..cfc0b8c5 100644 --- a/crappy/tool/disveConfig.py +++ b/crappy/tool/disveConfig.py @@ -2,6 +2,7 @@ from typing import Optional import tkinter as tk +from warnings import warn from .cameraConfigBoxes import Camera_config_with_boxes from .cameraConfigTools import Box, Spot_boxes @@ -21,6 +22,9 @@ def __init__(self, camera, patches: Spot_boxes) -> None: patches: The patches to follow for image correlation. """ + warn("The DISVE_config class will be renamed to DICVEConfig in version " + "2.0.0", DeprecationWarning) + super().__init__(camera) # Setting the patches diff --git a/crappy/tool/ft232h/ft232h.py b/crappy/tool/ft232h/ft232h.py index 8b1149b2..e07319a4 100644 --- a/crappy/tool/ft232h/ft232h.py +++ b/crappy/tool/ft232h/ft232h.py @@ -4,6 +4,7 @@ from collections import namedtuple from struct import calcsize, unpack, pack from typing import Union, Callable, Optional +from warnings import warn from ..._global import OptionalModule try: @@ -114,6 +115,8 @@ class Find_serial_number: the usb.core.find method.""" def __init__(self, serial_number: str) -> None: + warn("The Find_serial_number class will be renamed to FindSerialNumber in " + "version 2.0.0", DeprecationWarning) self.serial_number = serial_number def __call__(self, device) -> bool: @@ -214,6 +217,9 @@ def __init__(self, """ + warn("The ft232h class will be renamed to FT232H in version 2.0.0", + DeprecationWarning) + if mode not in ft232h_modes: raise ValueError("mode should be in {}".format(ft232h_modes)) self._ft232h_mode = mode diff --git a/crappy/tool/ft232h/ft232h_server.py b/crappy/tool/ft232h/ft232h_server.py index 84af4a30..b937a6e4 100644 --- a/crappy/tool/ft232h/ft232h_server.py +++ b/crappy/tool/ft232h/ft232h_server.py @@ -6,6 +6,7 @@ from _io import FileIO from multiprocessing.synchronize import RLock from time import time, sleep +from warnings import warn from .ft232h import ft232h from ..._global import OptionalModule @@ -198,6 +199,13 @@ def __init__(self, """ + warn("The ft232h_server class will be renamed to FT232HServer in version " + "2.0.0", DeprecationWarning) + warn("The block_number argument will be renamed to block_index in version " + "2.0.0", DeprecationWarning) + warn("The current_lock argument will be renamed to shared_lock in version " + "2.0.0", DeprecationWarning) + self._block_number = block_number self._current_file = current_file self._command_file = command_file diff --git a/crappy/tool/ft232h/i2c_message_ft232h.py b/crappy/tool/ft232h/i2c_message_ft232h.py index 89fc590a..c3db9d0b 100644 --- a/crappy/tool/ft232h/i2c_message_ft232h.py +++ b/crappy/tool/ft232h/i2c_message_ft232h.py @@ -1,6 +1,7 @@ # coding: utf-8 from typing import Optional, Iterable +from warnings import warn class i2c_msg_ft232h: @@ -23,6 +24,9 @@ def __init__(self, written. """ + warn("The i2c_msg_ft232h class will be renamed to I2CMessage in version " + "2.0.0", DeprecationWarning) + if type_ not in ['r', 'w']: raise ValueError("type_ should be either 'r' or 'w' !") diff --git a/crappy/tool/ft232h/usb_server.py b/crappy/tool/ft232h/usb_server.py index c46fcf8a..fc687ea1 100644 --- a/crappy/tool/ft232h/usb_server.py +++ b/crappy/tool/ft232h/usb_server.py @@ -6,6 +6,7 @@ from _io import FileIO from tempfile import TemporaryFile from typing import List, Dict, Any +from warnings import warn from ..._global import OptionalModule try: from usb.core import find, Device, USBTimeoutError @@ -54,6 +55,19 @@ def __init__(self, objects. """ + warn("The Server_process class will be renamed to USBServer in version " + "2.0.0", DeprecationWarning) + warn("The new_block_recv argument will be removed in version 2.0.0", + DeprecationWarning) + warn("The current_file argument will be removed in version 2.0.0", + DeprecationWarning) + warn("The lock_pool argument will be removed in version 2.0.0", + DeprecationWarning) + warn("The current_lock argument will be removed in version 2.0.0", + DeprecationWarning) + warn("The dev_dict argument will be removed in version 2.0.0", + DeprecationWarning) + super().__init__() self.new_block_recv = new_block_recv @@ -290,6 +304,10 @@ def __init__(self, serial_nr: str, backend: str) -> None: is not ``'ft232h'``. """ + warn("The Usb_server class will be removed in version 2.0.0, and fused " + "with the Server_process class into the USBServer class", + DeprecationWarning) + self._serial_nr = serial_nr self._backend = backend diff --git a/crappy/tool/gpucorrel.py b/crappy/tool/gpucorrel.py index 5ae667e3..5203d6f1 100644 --- a/crappy/tool/gpucorrel.py +++ b/crappy/tool/gpucorrel.py @@ -7,6 +7,7 @@ from typing import Any, Tuple, Optional, Union, List from pathlib import Path from itertools import chain +from warnings import warn from .fields import get_field from .._global import OptionalModule @@ -539,6 +540,9 @@ def __init__(self, convergence is neither too slow nor too fast. """ + warn("The GPUCorrel class will be renamed to GPUCorrelTool in version " + "2.0.0", DeprecationWarning) + self._context = context self._verbose = verbose diff --git a/crappy/tool/videoextenso.py b/crappy/tool/videoextenso.py index 22651f25..ae1db4f5 100644 --- a/crappy/tool/videoextenso.py +++ b/crappy/tool/videoextenso.py @@ -6,6 +6,7 @@ import numpy as np from itertools import combinations from time import sleep +from warnings import warn from .._global import OptionalModule from .cameraConfigBoxes import Spot_boxes, Box @@ -90,6 +91,13 @@ def __init__(self, noise, but also takes a bit more time compared to no blurring. """ + warn("The VideoExtenso class will be renamed to VideoExtensoTool in " + "version 2.0.0", DeprecationWarning) + warn("The num_spots argument will be removed in version 2.0.0", + DeprecationWarning) + warn("The min_area argument will be removed in version 2.0.0", + DeprecationWarning) + if num_spots is not None and num_spots not in range(1, 5): raise ValueError("num_spots should be either None, 1, 2, 3 or 4 !") self._num_spots = num_spots @@ -134,6 +142,9 @@ def detect_spots(self, A Spot_boxes object containing all the detected spots. """ + warn("The detect_spots method will be removed in version 2.0.0", + DeprecationWarning) + # First, blurring the image if asked to if self._blur is not None and self._blur > 1: img = cv2.medianBlur(img, self._blur) @@ -214,6 +225,9 @@ def detect_spots(self, def save_length(self) -> bool: """Saves the initial length in x and y between the detected spots.""" + warn("The save_length method will be removed in version 2.0.0", + DeprecationWarning) + # Cannot determine a length if no spots was detected if self.spots.empty(): print("[VideoExtenso] Cannot save L0, no spots selected yet !") diff --git a/crappy/tool/videoextensoConfig.py b/crappy/tool/videoextensoConfig.py index 2f5331f5..a64ec2ba 100644 --- a/crappy/tool/videoextensoConfig.py +++ b/crappy/tool/videoextensoConfig.py @@ -2,6 +2,7 @@ import tkinter as tk from typing import Optional +from warnings import warn from .cameraConfigBoxes import Camera_config_with_boxes from .cameraConfigTools import Box @@ -22,6 +23,11 @@ def __init__(self, camera, video_extenso) -> None: video_extenso: The video extenso tool in charge of tracking the spots. """ + warn("The VE_config class will be renamed to VideoExtensoConfig in " + "version 2.0.0", DeprecationWarning) + warn("The video_extenso argument will be removed in version 2.0.0", + DeprecationWarning) + self._video_extenso = video_extenso super().__init__(camera) @@ -29,6 +35,9 @@ def _bind_canvas_left_click(self) -> None: """Binds the left mouse button click for drawing the box in which the spots will be searched.""" + warn("The _bind_canvas_left_click method will be removed in version 2.0.0", + DeprecationWarning) + self._img_canvas.bind('', self._start_box) self._img_canvas.bind('', self._extend_box) self._img_canvas.bind('', self._stop_box) From 397fa427fe8d9e59741a77e4433bfd86a6076a5a Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Sun, 5 Nov 2023 16:07:40 +0100 Subject: [PATCH 10/12] fix: crash on startup when drawing boxes on top of the displayed image --- crappy/blocks/camera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crappy/blocks/camera.py b/crappy/blocks/camera.py index 5e75e4a9..4e295614 100644 --- a/crappy/blocks/camera.py +++ b/crappy/blocks/camera.py @@ -339,7 +339,7 @@ def _draw_box(img: np.ndarray, box: Box) -> None: warn("The _draw_box method will be removed in version 2.0.0", DeprecationWarning) - if box.no_points(): + if box is None or box.no_points(): return x_top, x_bottom, y_left, y_right = box.sorted() From 5d447ec5480d1cfdb156b51aed5dbbb7c88e9251 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Sun, 5 Nov 2023 16:07:59 +0100 Subject: [PATCH 11/12] fix: multiple examples not running as expected --- Examples/correl_advanced.py | 4 +--- Examples/correl_fake_test.py | 4 ++-- Examples/correl_strain_controlled_fake_test.py | 4 ++-- Examples/dio_daqmx.py | 10 ++++++---- Examples/discorrel_basic.py | 2 +- Examples/gpucorrel_fake_test.py | 4 ++-- Examples/read_write.py | 2 +- Examples/tensile_1.py | 1 + Examples/thermocouple_daqmx.py | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Examples/correl_advanced.py b/Examples/correl_advanced.py index 75f25d44..46e5d166 100644 --- a/Examples/correl_advanced.py +++ b/Examples/correl_advanced.py @@ -52,15 +52,13 @@ 'uxx', 'uyy', 'uxy', # Quadratic def (x) 'vxx', 'vyy', 'vxy'], # Quadratic def (y) verbose=2, # To print info - show_diff=True, # Display the residual - # (slow!) - drop=False, # Disable data picker mask=mask, levels=4, # Reduce the number of levels iterations=3, # and of iteration resampling_factor=2.5, # aggressive # resampling labels=[ # Needed to name our custom field + 't(s)', 'meta', 'x', 'y', 'r', 'Exx', 'Eyy', 'Exy', 'Ux2', 'Uy2', 'Uxy', 'Vx2', 'Vy2', 'Vxy'], diff --git a/Examples/correl_fake_test.py b/Examples/correl_fake_test.py index d9873ee2..c52aa118 100644 --- a/Examples/correl_fake_test.py +++ b/Examples/correl_fake_test.py @@ -70,8 +70,8 @@ def __call__(self, exx: float, eyy: float) -> np.ndarray: # The block performing the DIC dis = crappy.blocks.DISCorrel('', show_image=True, - labels=['t(s)', 'x', 'y', 'measured_Exx(%)', - 'measured_Eyy(%)'], + labels=['t(s)', 'meta', 'x', 'y', + 'measured_Exx(%)', 'measured_Eyy(%)'], image_generator=Apply_strain_img(img), verbose=True, display_images=True) # This modifier will generate an image with the values of strain diff --git a/Examples/correl_strain_controlled_fake_test.py b/Examples/correl_strain_controlled_fake_test.py index fa057af0..7244604c 100644 --- a/Examples/correl_strain_controlled_fake_test.py +++ b/Examples/correl_strain_controlled_fake_test.py @@ -74,8 +74,8 @@ def __call__(self, exx: float, eyy: float) -> np.ndarray: # The block performing the DIC dis = crappy.blocks.DISCorrel('', display_images=True, - labels=['t(s)', 'x', 'y', 'measured_Exx(%)', - 'measured_Eyy(%)'], + labels=['t(s)', 'meta', 'x', 'y', + 'measured_Exx(%)', 'measured_Eyy(%)'], verbose=True, iterations=0, finest_scale=2, image_generator=Apply_strain_img(img)) diff --git a/Examples/dio_daqmx.py b/Examples/dio_daqmx.py index 156b582b..a6c26c01 100644 --- a/Examples/dio_daqmx.py +++ b/Examples/dio_daqmx.py @@ -38,10 +38,12 @@ def change_name(data, prev: str, new: str): gen = crappy.blocks.Generator([dict(type='cyclic', value1=0, value2=1, condition1="delay=1", condition2="delay=1")], repeat=True) - io = crappy.blocks.IOBlock("Nidaqmx", device="Dev2", - channels=[dict(name='ai0'), dict(name='di0'), - dict(name='ao0'), dict(name='do1')], - samplerate=100, + io = crappy.blocks.IOBlock("Nidaqmx", + channels=[dict(name='Dev2/ai0'), + dict(name='Dev2/di0'), + dict(name='Dev2/ao0'), + dict(name='Dev2/do1')], + sample_rate=100, labels=['t(s)', 'ai0', 'di0'], cmd_labels=['cmd', 'cmd2']) crappy.link(gen, io) diff --git a/Examples/discorrel_basic.py b/Examples/discorrel_basic.py index e4aec65d..bc32008c 100644 --- a/Examples/discorrel_basic.py +++ b/Examples/discorrel_basic.py @@ -12,7 +12,7 @@ if __name__ == "__main__": dis = crappy.blocks.DISCorrel('Webcam', fields=['x', 'y'], - labels=['t(s)', 'x(pix)', 'y(pix)'], + labels=['t(s)', 'meta', 'x(pix)', 'y(pix)'], display_images=True) graph = crappy.blocks.Grapher(('x(pix)', 'y(pix)')) diff --git a/Examples/gpucorrel_fake_test.py b/Examples/gpucorrel_fake_test.py index 592e946a..4862ac91 100644 --- a/Examples/gpucorrel_fake_test.py +++ b/Examples/gpucorrel_fake_test.py @@ -72,8 +72,8 @@ def __call__(self, exx: float, eyy: float) -> np.ndarray: # The block performing the DIC dis = crappy.blocks.GPUCorrel('', verbose=True, - labels=['t(s)', 'x', 'y', 'measured_Exx(%)', - 'measured_Eyy(%)'], + labels=['t(s)', 'meta', 'x', 'y', + 'measured_Exx(%)', 'measured_Eyy(%)'], fields=['x', 'y', 'exx', 'eyy'], levels=3, image_generator=Apply_strain_img(img)) # This modifier will generate an image with the values of strain diff --git a/Examples/read_write.py b/Examples/read_write.py index e4f98f97..b8296449 100644 --- a/Examples/read_write.py +++ b/Examples/read_write.py @@ -23,7 +23,7 @@ cmd_label='cmd') io = crappy.blocks.IOBlock(name, labels=['t(s)', 'chan0'], - cmd_labels=['cmd'], out_channels=0, verbose=True) + cmd_labels=['cmd'], verbose=True) crappy.link(sg, io) g = crappy.blocks.Grapher(('t(s)', 'chan0')) diff --git a/Examples/tensile_1.py b/Examples/tensile_1.py index 188af5b1..00c3dd0a 100644 --- a/Examples/tensile_1.py +++ b/Examples/tensile_1.py @@ -24,6 +24,7 @@ "type": "ramp", "speed": SPEED / 60, # Convert to mm/s (in ramps, speed is always # in unit/s) + 'init_value': 0, "condition": None} # No exit condition: we will stop the test manually # Let's create the first block: the generator diff --git a/Examples/thermocouple_daqmx.py b/Examples/thermocouple_daqmx.py index 0f88f1f4..90768875 100644 --- a/Examples/thermocouple_daqmx.py +++ b/Examples/thermocouple_daqmx.py @@ -21,7 +21,7 @@ type='thrmcpl', thermocouple_type='K') for c_name in chan_names], - samplerate=14. / len(channels), + sample_rate=14. / len(channels), labels=['t(s)', 'stream'] if STREAMER else labels, streamer=STREAMER) From 5c8cbc041f2f7d1739635b03b3eb31cfddb8145f Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Sun, 5 Nov 2023 16:27:12 +0100 Subject: [PATCH 12/12] fix: add missing dependencies for building online documentation --- .readthedocs.yml | 6 +----- docs/source/requirements.txt | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 docs/source/requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml index 82e829e8..ef240e11 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -5,10 +5,6 @@ # Required version: 2 -# Build documentation in the docs/ directory with Sphinx -sphinx: - configuration: docs/source/conf.py - # Optionally set the version of Python and requirements required to build your docs build: os: ubuntu-22.04 @@ -22,6 +18,6 @@ sphinx: python: install: - - requirements: requirements.txt + - requirements: docs/source/requirements.txt - method: pip path: . diff --git a/docs/source/requirements.txt b/docs/source/requirements.txt new file mode 100644 index 00000000..e84e4e4f --- /dev/null +++ b/docs/source/requirements.txt @@ -0,0 +1,2 @@ +numpy==1.24.3 +sphinx-rtd-theme==1.3.0 \ No newline at end of file