diff --git a/devices/devices/pcc.py b/devices/devices/pcc.py index 8b567da2f092b528384e543240d7884757d1e714..38b02a02c0e4f028b7b56f302d906294bc014b6d 100644 --- a/devices/devices/pcc.py +++ b/devices/devices/pcc.py @@ -32,6 +32,8 @@ from clients.attribute_wrapper import attribute_wrapper from devices.hardware_device import hardware_device from common.lofar_logging import device_logging_to_python, log_exceptions from common.lofar_git import get_version +from common.lofar_environment import isProduction +from toolkit.archiver import Archiver __all__ = ["PCC", "main"] @@ -110,6 +112,8 @@ class PCC(hardware_device): RCU_translator_busy_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_translator_busy_R"], datatype=numpy.bool_) RCU_version_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_version_R"], datatype=numpy.str_, dims=(32,)) + test_att = RCU_temperature_R + @log_exceptions() def delete_device(self): """Hook to delete resources allocated in init_device. @@ -159,6 +163,21 @@ class PCC(hardware_device): self.warn_stream("error while setting the PCC attribute {} read/write function. {}".format(i, e)) self.OPCua_client.start() + + # TODO(Stefano): check if all attributes are ready to be archived + # add an attribute for testing purpose + self.archiver = Archiver() # define a standard archiver + attr_name = str(self.get_name()+'/'+self.test_att.get_name()).lower() + if isProduction(): + # Add attribute to subscriber list if not already present + try: + result = self.archiver.check_attribute_in_archiving_list(attr_name) + self.debug_stream("ARCHIVING: %s added to archiving list" % result) + except Exception as e: + self.warn_stream("error while adding attributes to archiving list. {}".format(e)) + else: + # Remove attribute from subscriber list to prevent automatic archiving + self.archiver.remove_attribute_from_archiver(attr_name) diff --git a/jupyter-notebooks/PCC_archive_attribute.ipynb b/jupyter-notebooks/PCC_archive_attribute.ipynb index fb1c2d05932d6543fb95fca33aab8e750e710238..67875c1bce318afaf1eab021c60f30b313ff1fda 100644 --- a/jupyter-notebooks/PCC_archive_attribute.ipynb +++ b/jupyter-notebooks/PCC_archive_attribute.ipynb @@ -15,6 +15,17 @@ "from matplotlib import pyplot as plt" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "a3b8ab54", + "metadata": {}, + "outputs": [], + "source": [ + "from common.lofar_environment import isProduction\n", + "print(isProduction())" + ] + }, { "cell_type": "code", "execution_count": null, @@ -24,13 +35,15 @@ "source": [ "# Define an attribute for archiving\n", "device_name = 'LTS/PCC/1'\n", - "attr_name = 'rcu_temperature_r'\n", - "attr_fq_name = str(device_name+'/'+attr_name).lower()\n", - "archiver = Archiver()\n", - "\n", "d=DeviceProxy(device_name) \n", "state = str(d.state())\n", - "print(state)" + "print(state)\n", + "\n", + "archiver = Archiver()\n", + "\n", + "# Attribute chosen to be archived\n", + "attr_name = 'rcu_temperature_r'\n", + "attr_fq_name = str(device_name+'/'+attr_name).lower()" ] }, { @@ -40,8 +53,10 @@ "metadata": {}, "outputs": [], "source": [ - "# Print the list of the attributes ready to be archived\n", - "print(archiver.es.AttributeList)" + "# Print the list of the attributes in the event subscriber\n", + "# If any attribute is present, its archiving will begin when device will reach ON state,\n", + "# Otherwise, attribute will be added to the list at the device initializing phase only in PRODUCTION mode\n", + "archiver.get_subscriber_attributes()" ] }, { @@ -52,8 +67,10 @@ "outputs": [], "source": [ "# Start the device\n", + "#d.set_timeout_millis(5000)\n", "if state == \"OFF\":\n", - " d.initialise()\n", + " # Workaround to avoid device timeout error\n", + " d.command_inout_asynch(cmd_name='Initialise')\n", " time.sleep(1)\n", "state = str(d.state())\n", "if state == \"STANDBY\":\n", @@ -63,6 +80,17 @@ " print(\"Device is now in ON state\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab496017", + "metadata": {}, + "outputs": [], + "source": [ + "# Modify attribute archiving features\n", + "archiver.update_archiving_attribute(attr_fq_name,polling_period=1000,event_period=1000,strategy='RUN')" + ] + }, { "cell_type": "code", "execution_count": null, @@ -113,6 +141,7 @@ "metadata": {}, "outputs": [], "source": [ + "# Initialise the retriever object and print the archived attributes in the database\n", "retriever = Retriever()\n", "retriever.get_all_archived_attributes()" ] @@ -127,7 +156,7 @@ "# Retrieve records in the last n hours (works even with decimals)\n", "\n", "# Use alternatively one of the following two methods to retrieve data (last n hours or interval)\n", - "records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.04)\n", + "records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.1)\n", "#records = retriever.get_attribute_value_by_interval(attr_fq_name,'2021-09-01 16:00:00', '2021-09-01 16:03:00')\n", "\n", "if not records:\n", @@ -170,7 +199,7 @@ "\n", "heatmap = np.array(array_values,dtype=np.float)\n", "fig = plt.figure()\n", - "#plt.rcParams['figure.figsize'] = [32, 64]\n", + "plt.rcParams['figure.figsize'] = [128, 64]\n", "#plt.rcParams['figure.dpi'] = 128\n", "ax = fig.add_subplot(111)\n", "im = ax.imshow(heatmap, interpolation='nearest',cmap='coolwarm')\n", @@ -188,7 +217,7 @@ "ax.set_title('Archived data for '+ attr_fq_name)\n", "ax.grid()\n", "cbar = fig.colorbar(ax=ax, mappable=im, orientation='horizontal')\n", - "#plt.show()" + "plt.show()" ] }, { @@ -201,7 +230,7 @@ "# Turn off the device\n", "d.off()\n", "# Remove attribute from archiving list\n", - "archiver.remove_attribute_from_archiver(attr_fq_name)" + "#archiver.remove_attribute_from_archiver(attr_fq_name)" ] }, {