diff --git a/factory_jones.ipynb b/factory_jones.ipynb index 7499bdb..ecc50d8 100644 --- a/factory_jones.ipynb +++ b/factory_jones.ipynb @@ -277,7 +277,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[\u001b[38;2;128;05;128m2025-02-10 18:36:47,271\u001b[0m] \u001b[38;2;50;50;205m INFO\u001b[0m\u001b[38;2;112;128;144m viperlog: \u001b[0m Module path: \u001b[38;2;50;50;205m/home/mystletainn/Development/calviper/src/calviper\u001b[0m \n" + "[\u001b[38;2;128;05;128m2025-02-11 18:08:21,944\u001b[0m] \u001b[38;2;50;50;205m INFO\u001b[0m\u001b[38;2;112;128;144m viperlog: \u001b[0m Module path: \u001b[38;2;50;50;205m/home/mystletainn/Development/calviper/src/calviper\u001b[0m \n" ] } ], @@ -287,7 +287,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "id": "6403894b-a634-45a8-9219-05aed71457f1", "metadata": {}, "outputs": [], @@ -297,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "id": "cd1ff35b-9d90-49ed-95d7-a47d5f001f61", "metadata": {}, "outputs": [ @@ -692,30 +692,30 @@ " MATRIX (time, baseline_id, frequency, p, q) complex64 11MB (1+0j) ...\n", "Attributes:\n", " calibration_type: gain\n", - " observation_info: {'observer': ['lknee'], 'project': 'uid://A002/X1f841f...
  • calibration_type :
    gain
    observation_info :
    {'observer': ['lknee'], 'project': 'uid://A002/X1f841f/X21d', 'release_date': '1858-11-17T00:00:00.000000000'}
  • " ], "text/plain": [ " Size: 15MB\n", @@ -901,7 +901,7 @@ " observation_info: {'observer': ['lknee'], 'project': 'uid://A002/X1f841f..." ] }, - "execution_count": 11, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -912,7 +912,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "id": "7ccb777d-9509-4d19-a2c1-77d53c9564f9", "metadata": {}, "outputs": [ @@ -922,7 +922,7 @@ "(957, 10, 8, 2)" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -933,7 +933,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "id": "d785e421-250d-4f03-9338-e143789889f4", "metadata": {}, "outputs": [ @@ -949,7 +949,7 @@ " * baseline_id (baseline_id) int64 360B 0 1 2 3 4 5 6 ... 39 40 41 42 43 44)" ] }, - "execution_count": 13, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -1211,6 +1211,18 @@ "id": "f089e820-c07e-473c-b13b-09667e504aac", "metadata": {}, "outputs": [], + "source": [ + "import xarray as xr\n", + "\n", + "xr.DataArray()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c33a49d5-b470-4245-832e-9cf117a2c8ed", + "metadata": {}, + "outputs": [], "source": [] } ], diff --git a/src/calviper/factory/gain.py b/src/calviper/factory/gain.py index 0922bf9..712ac6d 100644 --- a/src/calviper/factory/gain.py +++ b/src/calviper/factory/gain.py @@ -33,12 +33,18 @@ def matrix(self) -> np.ndarray: return self._matrix @matrix.setter - def matrix(self, array: np.ndarray) -> None: + def matrix(self, data: np.ndarray) -> None: # (self.n_times, self.n_baselines, self.n_channels, _, _) = array.shape # There should be a check on the shape here. I don't think we want to allow, for instance, # an axis to be averaged while also having the dimensions stored in the object not change. - self._matrix = array + self._matrix = data + + @property + def parameter(self, data: Union[xr.DataArray, np.ndarray]) -> None: + if type(data) == np.ndarray: + assert len(data.shape) < 4, logger.error("Parameter dimensions can't be larger then four.") + dims = None def example(self): logger.info("This is a gain matrix specific function that does something with the data.") diff --git a/src/calviper/math/tools.py b/src/calviper/math/tools.py index 984526e..488e395 100644 --- a/src/calviper/math/tools.py +++ b/src/calviper/math/tools.py @@ -147,7 +147,7 @@ def build_visibility_matrix_singleton(array: np.ndarray, index_a: np.ndarray, in @numba.njit() def build_visibility_matrix(array: np.ndarray, index_a: np.ndarray, index_b: np.ndarray) -> np.ndarray: """ - Build a visibility matrix from a visibility array with zeros for autocorrelation. + Build a visibility matrix from a visibility array with zeros for auto-correlation. :param index_b: :param index_a: :param array: (numpy.ndarray) visibility array @@ -161,6 +161,7 @@ def build_visibility_matrix(array: np.ndarray, index_a: np.ndarray, index_b: np. # Dimensions are (n_baselines, n_channel, n_polarization) but we are replacing the first index with n_antenna _, n_channel, n_polarization = array.shape + n_polarization = int(np.sqrt(n_polarization)) # Build matrix # -- Building a matrix that works better with the regression algorithm. I would really prefer not to diff --git a/testing.ipynb b/testing.ipynb index 4db50c9..16c9044 100644 --- a/testing.ipynb +++ b/testing.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "27576dd1-0204-418e-8bf7-d8cc58c67397", "metadata": {}, "outputs": [], @@ -21,23 +21,10 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "bc47abd7-51e9-4f85-ac77-4f00a5caae25", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "from IPython.display import display, HTML\n", "\n", @@ -46,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "d499db1b-ece5-439d-8314-480fd04e3a95", "metadata": {}, "outputs": [], @@ -57,21 +44,10 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "868b54cd-e0db-4243-bd26-aee45746b24a", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10,)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "df_gains = pd.read_csv(\"gains.csv\")\n", "gains = df_gains.gain.apply(complex).to_numpy()\n", @@ -80,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "5acb93c9-8985-4d0a-b305-b8aa2fd8a8af", "metadata": {}, "outputs": [], @@ -96,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "cdef1479-cb2d-486e-adb9-6550f14e8dcf", "metadata": {}, "outputs": [], @@ -122,21 +98,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "49ad6a73-c7c8-4cb4-b379-264bdcdd8ddb", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10, 10)" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "X = build_vis(vis, ant_a, ant_b)\n", "X.shape" @@ -144,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "a8dff2b3-fdbb-40f5-a347-ce651971dc51", "metadata": {}, "outputs": [], @@ -154,23 +119,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "fe938bb3-f311-4624-90bf-7c34705646db", "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "not enough values to unpack (expected 4, got 2)", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m g \u001b[38;5;241m=\u001b[39m \u001b[43msolver\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mvis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mX\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43miterations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43moptimizer\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptimizer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mMeanSquaredError\u001b[49m\u001b[43m(\u001b[49m\u001b[43malpha\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.2\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43mstopping\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1e-2\u001b[39;49m\n\u001b[1;32m 6\u001b[0m \u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Development/calviper/src/calviper/math/solver/least_squares.py:94\u001b[0m, in \u001b[0;36mLeastSquaresSolver.solve\u001b[0;34m(self, vis, iterations, optimizer, stopping)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msolve\u001b[39m(\u001b[38;5;28mself\u001b[39m, vis, iterations, optimizer\u001b[38;5;241m=\u001b[39mMeanSquaredError(), stopping\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1e-3\u001b[39m):\n\u001b[1;32m 91\u001b[0m \u001b[38;5;66;03m# This is an attempt to do the solving in a vectorized way\u001b[39;00m\n\u001b[1;32m 92\u001b[0m \n\u001b[1;32m 93\u001b[0m \u001b[38;5;66;03m# Unpack the shape\u001b[39;00m\n\u001b[0;32m---> 94\u001b[0m n_channel, n_polarization, n_antenna1, n_antenna2 \u001b[38;5;241m=\u001b[39m vis\u001b[38;5;241m.\u001b[39mshape\n\u001b[1;32m 96\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m n_antenna1 \u001b[38;5;241m==\u001b[39m n_antenna2, logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAntenna indices don\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt match\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 98\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparameter \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mtile(\u001b[38;5;241m0.1\u001b[39m \u001b[38;5;241m*\u001b[39m np\u001b[38;5;241m.\u001b[39mones(n_antenna1, dtype\u001b[38;5;241m=\u001b[39mnp\u001b[38;5;241m.\u001b[39mcomplex64), reps\u001b[38;5;241m=\u001b[39m[n_channel, n_polarization, \u001b[38;5;241m1\u001b[39m])\n", - "\u001b[0;31mValueError\u001b[0m: not enough values to unpack (expected 4, got 2)" - ] - } - ], + "outputs": [], "source": [ "g = solver.solve(\n", " vis=X,\n",