From c85cd1c3d43ac5c07329b847490ae67c71910e6a Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 12:44:14 +0100 Subject: [PATCH 01/29] feat: include access to ska array postions via ska-ost-array-config package --- src/py21cmsense/observatory.py | 35 +++++++++++++++++++++++++++++++++- tests/test_observatory.py | 4 ++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index f1bba59..ce843f4 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -57,7 +57,7 @@ class Observatory: Note that longitude is not required, as we assume an isotropic sky. Trcv Receiver temperature, either a temperature Quantity, or a callable that - taakes a single frequency Quantity and returns a temperature Quantity. + takes a single frequency Quantity and returns a temperature Quantity. min_antpos, max_antpos The minimum/maximum radial distance to include antennas (from the origin of the array). Assumed to be in units of meters if no units are supplied. @@ -222,6 +222,39 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa obj = cls.from_yaml(fl, frequency=frequency) return obj.clone(**kwargs) + @classmethod + def from_ska(cls, subarray_type: str, array_type = 'low', frequency: tp.Frequency | None = None, **kwargs) -> Observatory: + """Instantiate an SKA Observatory. + + Parameters + ---------- + array_type + The type of array to use. Options are "low" and "mid". + subarray_type + The type of subarray to use. Options are "AA4", "AA*", "AA1", "AA2", "AA0.5", and "custom" + + Other Parameters + ---------------- + All other parameters passed will be passed into the LowSubArray or MidSubAray class. + See the documentation of the ska-ost-array-config package for more information. + """ + try: + from ska_ost_array_config.array_config import LowSubArray, MidSubArray + except ImportError: + raise ImportError("ska-ost-array-config package is required, see https://gitlab.com/ska-telescope/ost/ska-ost-array-config") + if array_type == 'low': + subarray = LowSubArray(subarray_type, **kwargs) + elif array_type == 'mid': + subarray = MidSubArray(subarray_type, **kwargs) + else: + raise ValueError("array_type must be 'low' or 'mid'.") + antpos = subarray.array_config.xyz.data * un.m + print(antpos.shape, antpos.min(), antpos.max()) + _beam = beam.GaussianBeam(frequency=frequency if frequency is not None else 150.*un.MHz, + dish_size = 35.*un.m) + lat = subarray.array_config.location.lat.rad *un.rad + return cls(antpos=antpos, beam=_beam, latitude = lat, Trcv = 100. * un.K) + @cached_property def baselines_metres(self) -> tp.Meters: """Raw baseline distances in metres for every pair of antennas. diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 59ef827..a1c3733 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -204,6 +204,10 @@ def test_from_yaml(bm): with pytest.raises(ValueError, match="yaml_file must be a string filepath"): Observatory.from_yaml(3) +def test_from_ska(): + ska = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.*units.MHz) + ska = Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.*units.MHz) + ska = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.*units.MHz) def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From 47a4a475b25d756a712fce4d76e2c490f2c5bccf Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 13:27:31 +0100 Subject: [PATCH 02/29] feat: include access to ska array postions via ska-ost-array-config package --- ci/testing.yaml | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/ci/testing.yaml b/ci/testing.yaml index 746dc6d..aa23a44 100644 --- a/ci/testing.yaml +++ b/ci/testing.yaml @@ -19,3 +19,4 @@ dependencies: - matplotlib - pip: - methodtools + - ska-ost-array-config diff --git a/pyproject.toml b/pyproject.toml index bdc2fb5..74cc210 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ dependencies = [ "rich", "attrs", "hickleable>=0.1.1", + "ska-ost-array-config", ] [project.optional-dependencies] From c9de48031d48205b868e7dbb22aa07f985688a00 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:28:34 +0000 Subject: [PATCH 03/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/py21cmsense/observatory.py | 21 +++++++++++++-------- tests/test_observatory.py | 8 +++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index ce843f4..09cddfc 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -223,7 +223,9 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa return obj.clone(**kwargs) @classmethod - def from_ska(cls, subarray_type: str, array_type = 'low', frequency: tp.Frequency | None = None, **kwargs) -> Observatory: + def from_ska( + cls, subarray_type: str, array_type="low", frequency: tp.Frequency | None = None, **kwargs + ) -> Observatory: """Instantiate an SKA Observatory. Parameters @@ -241,19 +243,22 @@ def from_ska(cls, subarray_type: str, array_type = 'low', frequency: tp.Frequen try: from ska_ost_array_config.array_config import LowSubArray, MidSubArray except ImportError: - raise ImportError("ska-ost-array-config package is required, see https://gitlab.com/ska-telescope/ost/ska-ost-array-config") - if array_type == 'low': + raise ImportError( + "ska-ost-array-config package is required, see https://gitlab.com/ska-telescope/ost/ska-ost-array-config" + ) + if array_type == "low": subarray = LowSubArray(subarray_type, **kwargs) - elif array_type == 'mid': + elif array_type == "mid": subarray = MidSubArray(subarray_type, **kwargs) else: raise ValueError("array_type must be 'low' or 'mid'.") antpos = subarray.array_config.xyz.data * un.m print(antpos.shape, antpos.min(), antpos.max()) - _beam = beam.GaussianBeam(frequency=frequency if frequency is not None else 150.*un.MHz, - dish_size = 35.*un.m) - lat = subarray.array_config.location.lat.rad *un.rad - return cls(antpos=antpos, beam=_beam, latitude = lat, Trcv = 100. * un.K) + _beam = beam.GaussianBeam( + frequency=frequency if frequency is not None else 150.0 * un.MHz, dish_size=35.0 * un.m + ) + lat = subarray.array_config.location.lat.rad * un.rad + return cls(antpos=antpos, beam=_beam, latitude=lat, Trcv=100.0 * un.K) @cached_property def baselines_metres(self) -> tp.Meters: diff --git a/tests/test_observatory.py b/tests/test_observatory.py index a1c3733..a59b5d5 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -204,10 +204,12 @@ def test_from_yaml(bm): with pytest.raises(ValueError, match="yaml_file must be a string filepath"): Observatory.from_yaml(3) + def test_from_ska(): - ska = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.*units.MHz) - ska = Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.*units.MHz) - ska = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.*units.MHz) + ska = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) + ska = Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.0 * units.MHz) + ska = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.0 * units.MHz) + def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From e87894db8b5dc04bc89c46bd74453bbe2d5b4dd4 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 13:31:27 +0100 Subject: [PATCH 04/29] feat: include access to ska array postions via ska-ost-array-config package --- src/py21cmsense/observatory.py | 7 ++++--- tests/test_observatory.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index ce843f4..b69c244 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -231,7 +231,8 @@ def from_ska(cls, subarray_type: str, array_type = 'low', frequency: tp.Frequen array_type The type of array to use. Options are "low" and "mid". subarray_type - The type of subarray to use. Options are "AA4", "AA*", "AA1", "AA2", "AA0.5", and "custom" + The type of subarray to use. Options are "AA4", "AA*", "AA1", "AA2", "AA0.5", + and "custom" Other Parameters ---------------- @@ -241,7 +242,8 @@ def from_ska(cls, subarray_type: str, array_type = 'low', frequency: tp.Frequen try: from ska_ost_array_config.array_config import LowSubArray, MidSubArray except ImportError: - raise ImportError("ska-ost-array-config package is required, see https://gitlab.com/ska-telescope/ost/ska-ost-array-config") + raise ImportError("ska-ost-array-config package is required," + + "see https://gitlab.com/ska-telescope/ost/ska-ost-array-config") if array_type == 'low': subarray = LowSubArray(subarray_type, **kwargs) elif array_type == 'mid': @@ -249,7 +251,6 @@ def from_ska(cls, subarray_type: str, array_type = 'low', frequency: tp.Frequen else: raise ValueError("array_type must be 'low' or 'mid'.") antpos = subarray.array_config.xyz.data * un.m - print(antpos.shape, antpos.min(), antpos.max()) _beam = beam.GaussianBeam(frequency=frequency if frequency is not None else 150.*un.MHz, dish_size = 35.*un.m) lat = subarray.array_config.location.lat.rad *un.rad diff --git a/tests/test_observatory.py b/tests/test_observatory.py index a1c3733..4df9ef0 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -205,9 +205,9 @@ def test_from_yaml(bm): Observatory.from_yaml(3) def test_from_ska(): - ska = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.*units.MHz) - ska = Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.*units.MHz) - ska = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.*units.MHz) + Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.*units.MHz) + Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.*units.MHz) + Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.*units.MHz) def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From 33deb47c55bee1acf7450da62e5edc92d6094d67 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:34:30 +0000 Subject: [PATCH 05/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/py21cmsense/observatory.py | 4 ++-- tests/test_observatory.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index ca3a053..96519b3 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -245,8 +245,8 @@ def from_ska( from ska_ost_array_config.array_config import LowSubArray, MidSubArray except ImportError: raise ImportError( - "ska-ost-array-config package is required, "+ - "see https://gitlab.com/ska-telescope/ost/ska-ost-array-config" + "ska-ost-array-config package is required, " + + "see https://gitlab.com/ska-telescope/ost/ska-ost-array-config" ) if array_type == "low": subarray = LowSubArray(subarray_type, **kwargs) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 8f949be..f2a01fc 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -206,9 +206,10 @@ def test_from_yaml(bm): def test_from_ska(): - Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.*units.MHz) - Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.*units.MHz) - Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.*units.MHz) + Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) + Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.0 * units.MHz) + Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.0 * units.MHz) + def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From 38bcb4c9a55e583ef53f86fe6253a7b4354dcef5 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 13:49:42 +0100 Subject: [PATCH 06/29] feat: include access to ska array postions via ska-ost-array-config package --- .github/workflows/testsuite.yaml | 4 ++++ ci/testing.yaml | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml index 102e0b9..1347069 100644 --- a/.github/workflows/testsuite.yaml +++ b/.github/workflows/testsuite.yaml @@ -41,6 +41,10 @@ jobs: pip install .[test] conda list + - name: Install ska-ost-array + run: | + pip install ska-ost-array-config --extra-index-url https://artefact.skao.int/repository/pypi-internal/simple + - name: Run Tests run: | python -m pytest --cov=py21cmsense --cov-config=.coveragerc --cov-report xml:./coverage.xml diff --git a/ci/testing.yaml b/ci/testing.yaml index aa23a44..746dc6d 100644 --- a/ci/testing.yaml +++ b/ci/testing.yaml @@ -19,4 +19,3 @@ dependencies: - matplotlib - pip: - methodtools - - ska-ost-array-config From 5dc5b08ab10001e63b01409fc6a8ceb8c6f3b8a9 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 13:54:04 +0100 Subject: [PATCH 07/29] feat: include access to ska array postions via ska-ost-array-config package --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 74cc210..bdc2fb5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,6 @@ dependencies = [ "rich", "attrs", "hickleable>=0.1.1", - "ska-ost-array-config", ] [project.optional-dependencies] From 2aa5081eeabd51f22ab22d928b6162198b4ca42c Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 14:00:24 +0100 Subject: [PATCH 08/29] feat: include access to ska array postions via ska-ost-array-config package --- .github/workflows/testsuite.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml index 1347069..5c8f85f 100644 --- a/.github/workflows/testsuite.yaml +++ b/.github/workflows/testsuite.yaml @@ -43,7 +43,10 @@ jobs: - name: Install ska-ost-array run: | - pip install ska-ost-array-config --extra-index-url https://artefact.skao.int/repository/pypi-internal/simple + git clone https://gitlab.com/ska-telescope/ost/ska-ost-array-config.git + cd ska-ost-array-config + poetry install + cd .. - name: Run Tests run: | From 5b66042f47aadf526077c8812fb515d507bcb471 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 14:04:25 +0100 Subject: [PATCH 09/29] feat: include access to ska array postions via ska-ost-array-config package --- .github/workflows/testsuite.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml index 5c8f85f..ea1204c 100644 --- a/.github/workflows/testsuite.yaml +++ b/.github/workflows/testsuite.yaml @@ -40,7 +40,10 @@ jobs: run: | pip install .[test] conda list - + - name: Install Poetry + run: | + pipx install poetry + poetry --version - name: Install ska-ost-array run: | git clone https://gitlab.com/ska-telescope/ost/ska-ost-array-config.git From 55e9de69e812508a5267da4db0a97a0e59bca21a Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 14:11:25 +0100 Subject: [PATCH 10/29] feat: include access to ska array postions via ska-ost-array-config package --- .github/workflows/run-docs-code.yaml | 11 +++++++++++ .github/workflows/test-with-warnings.yaml | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/.github/workflows/run-docs-code.yaml b/.github/workflows/run-docs-code.yaml index 841b403..21d8466 100644 --- a/.github/workflows/run-docs-code.yaml +++ b/.github/workflows/run-docs-code.yaml @@ -40,6 +40,17 @@ jobs: pip install . pip install papermill ipykernel conda list + + - name: Install Poetry + run: | + pipx install poetry + poetry --version + - name: Install ska-ost-array + run: | + git clone https://gitlab.com/ska-telescope/ost/ska-ost-array-config.git + cd ska-ost-array-config + poetry install + cd .. - name: Install ipykernel run: python -m ipykernel install --user --name sense --display-name "sense" diff --git a/.github/workflows/test-with-warnings.yaml b/.github/workflows/test-with-warnings.yaml index ca4439e..ba2c5a0 100644 --- a/.github/workflows/test-with-warnings.yaml +++ b/.github/workflows/test-with-warnings.yaml @@ -40,6 +40,16 @@ jobs: run: | pip install .[test] conda list + - name: Install Poetry + run: | + pipx install poetry + poetry --version + - name: Install ska-ost-array + run: | + git clone https://gitlab.com/ska-telescope/ost/ska-ost-array-config.git + cd ska-ost-array-config + poetry install + cd .. - name: Run Tests run: | From d48c32ace88cda207de17907067a17bd79eb8762 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:11:36 +0000 Subject: [PATCH 11/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/run-docs-code.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-docs-code.yaml b/.github/workflows/run-docs-code.yaml index 21d8466..9875cf3 100644 --- a/.github/workflows/run-docs-code.yaml +++ b/.github/workflows/run-docs-code.yaml @@ -40,7 +40,7 @@ jobs: pip install . pip install papermill ipykernel conda list - + - name: Install Poetry run: | pipx install poetry From fc1d776e184d81c1ee729572a6b33c789ed9f5de Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 14:14:25 +0100 Subject: [PATCH 12/29] feat: include access to ska array postions via ska-ost-array-config package --- src/py21cmsense/observatory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index 96519b3..487c496 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -243,11 +243,11 @@ def from_ska( """ try: from ska_ost_array_config.array_config import LowSubArray, MidSubArray - except ImportError: + except ImportError as exception: raise ImportError( "ska-ost-array-config package is required, " + "see https://gitlab.com/ska-telescope/ost/ska-ost-array-config" - ) + ) from exception if array_type == "low": subarray = LowSubArray(subarray_type, **kwargs) elif array_type == "mid": From 5f8a024b2042c11ee8fc35dfef73795f21903bcf Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Fri, 13 Dec 2024 14:21:59 +0100 Subject: [PATCH 13/29] feat: include access to ska array postions via ska-ost-array-config package --- .github/workflows/test-with-warnings.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-with-warnings.yaml b/.github/workflows/test-with-warnings.yaml index ba2c5a0..53965b4 100644 --- a/.github/workflows/test-with-warnings.yaml +++ b/.github/workflows/test-with-warnings.yaml @@ -40,10 +40,10 @@ jobs: run: | pip install .[test] conda list - - name: Install Poetry - run: | - pipx install poetry - poetry --version + - name: Install Poetry + run: | + pipx install poetry + poetry --version - name: Install ska-ost-array run: | git clone https://gitlab.com/ska-telescope/ost/ska-ost-array-config.git From 5a2748b6fb13ad9e4166c0f2ef98615a0733f50c Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Mon, 16 Dec 2024 13:46:20 +0100 Subject: [PATCH 14/29] feat: include access to ska array postions via ska-ost-array-config package --- .../using_builtin_observatories.ipynb | 32 +++++++++++++++++++ src/py21cmsense/observatory.py | 25 ++++++++++----- tests/test_observatory.py | 18 +++++++++-- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/docs/tutorials/using_builtin_observatories.ipynb b/docs/tutorials/using_builtin_observatories.ipynb index 92178d6..ebd6c30 100644 --- a/docs/tutorials/using_builtin_observatories.ipynb +++ b/docs/tutorials/using_builtin_observatories.ipynb @@ -146,6 +146,38 @@ "print(obs.frequency)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can also create an observatory from a specific SKA configuration provided by `ska-ost-array-config` package (see https://gitlab.com/ska-telescope/ost/ska-ost-array-config for installation instructions) using the `from_ska` method:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "obs = Observatory.from_ska(subarray_type = 'AA*', array_type=\"low\", Trcv = 100.0 * un.K, frequency = 75.0 * un.MHz)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can create a custom array by passing additional parameters to the array class (see `ska-ost-array-config` documentation). For example, to select all core stations, add 6 stations in the E1 cluster, and remove two stations from the core array:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "custom_obs = Observatory.from_ska(subarray_type = 'custom', array_type=\"low\", Trcv = 100.0 * un.K, frequency = 75.0 * un.MHz, custom_stations=\"C*, E1-*\", exclude_stations=\"C1,C2\")" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index 487c496..ae09457 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -204,7 +204,8 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa ---------- profile A string label identifying the observatory. Available built-in observatories - can be obtained with :func:`get_builtin_profiles`. + can be obtained with :func:`get_builtin_profiles`. For more up-to-date SKA profiles, + check the :func:`from_ska` method. frequency The frequency at which to specify the observatory. @@ -224,22 +225,30 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa @classmethod def from_ska( - cls, subarray_type: str, array_type="low", frequency: tp.Frequency | None = None, **kwargs + cls, subarray_type: str, array_type="low", Trcv = tp.Temperature | Callable = attr.ib(100 * un.K), + frequency: tp.Frequency | None = 150.0 * un.MHz, **kwargs ) -> Observatory: """Instantiate an SKA Observatory. Parameters ---------- - array_type - The type of array to use. Options are "low" and "mid". subarray_type The type of subarray to use. Options are "AA4", "AA*", "AA1", "AA2", "AA0.5", and "custom" + array_type, optional + The type of array to use. Options are "low" and "mid". + Default is "low". + Trcv, optional + Receiver temperature, either a temperature Quantity, or a callable that + takes a single frequency Quantity and returns a temperature Quantity. + Default is 100 K. + frequency, optional + The frequency at which to specify the observatory. Default is 150 MHz. Other Parameters ---------------- - All other parameters passed will be passed into the LowSubArray or MidSubAray class. - See the documentation of the ska-ost-array-config package for more information. + All other parameters passed will be passed into the LowSubArray or MidSubArray class. + See the documentation of the ska-ost-array-config package for more information on these classes. """ try: from ska_ost_array_config.array_config import LowSubArray, MidSubArray @@ -256,10 +265,10 @@ def from_ska( raise ValueError("array_type must be 'low' or 'mid'.") antpos = subarray.array_config.xyz.data * un.m _beam = beam.GaussianBeam( - frequency=frequency if frequency is not None else 150.0 * un.MHz, dish_size=35.0 * un.m + frequency=frequency, dish_size=35.0 * un.m ) lat = subarray.array_config.location.lat.rad * un.rad - return cls(antpos=antpos, beam=_beam, latitude=lat, Trcv=100.0 * un.K) + return cls(antpos=antpos, beam=_beam, latitude=lat, Trcv=Trcv) @cached_property def baselines_metres(self) -> tp.Meters: diff --git a/tests/test_observatory.py b/tests/test_observatory.py index f2a01fc..bc0ad9c 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -206,10 +206,22 @@ def test_from_yaml(bm): def test_from_ska(): - Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) + from ska_ost_array_config.array_config import LowSubArray, MidSubArray + obs = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) + low_aastar = LowSubArray(subarray_type="AA*") + assert obs.antpos.shape[0] == low_aastar.array_config.xyz.data.shape Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.0 * units.MHz) - Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.0 * units.MHz) - + obs = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.0 * units.MHz) + low_aa4 = LowSubArray(subarray_type="AA4") + assert obs.antpos.shape[0] == low_aa4.array_config.xyz.data.shape + obs = Observatory.from_ska(subarray_type = 'custom', array_type="low", Trcv = 100.0 * un.K, frequency = 150.0 * un.MHz, custom_stations="C*,E1-*", exclude_stations="C1,C2") + low_custom = LowSubArray( + subarray_type="custom", custom_stations="C*,E1-*" + ) # selects all core stations and 6 stations in the E1 cluster + assert obs.antpos.shape[0] == low_custom.array_config.xyz.data.shape + + + def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From 40e087bac5b0e307f093a05e12c1f6fb0e6e4ba9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:46:32 +0000 Subject: [PATCH 15/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../using_builtin_observatories.ipynb | 13 +++++++++++-- tests/test_observatory.py | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/tutorials/using_builtin_observatories.ipynb b/docs/tutorials/using_builtin_observatories.ipynb index ebd6c30..ef203a2 100644 --- a/docs/tutorials/using_builtin_observatories.ipynb +++ b/docs/tutorials/using_builtin_observatories.ipynb @@ -159,7 +159,9 @@ "metadata": {}, "outputs": [], "source": [ - "obs = Observatory.from_ska(subarray_type = 'AA*', array_type=\"low\", Trcv = 100.0 * un.K, frequency = 75.0 * un.MHz)" + "obs = Observatory.from_ska(\n", + " subarray_type=\"AA*\", array_type=\"low\", Trcv=100.0 * un.K, frequency=75.0 * un.MHz\n", + ")" ] }, { @@ -175,7 +177,14 @@ "metadata": {}, "outputs": [], "source": [ - "custom_obs = Observatory.from_ska(subarray_type = 'custom', array_type=\"low\", Trcv = 100.0 * un.K, frequency = 75.0 * un.MHz, custom_stations=\"C*, E1-*\", exclude_stations=\"C1,C2\")" + "custom_obs = Observatory.from_ska(\n", + " subarray_type=\"custom\",\n", + " array_type=\"low\",\n", + " Trcv=100.0 * un.K,\n", + " frequency=75.0 * un.MHz,\n", + " custom_stations=\"C*, E1-*\",\n", + " exclude_stations=\"C1,C2\",\n", + ")" ] }, { diff --git a/tests/test_observatory.py b/tests/test_observatory.py index bc0ad9c..0998308 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -206,7 +206,8 @@ def test_from_yaml(bm): def test_from_ska(): - from ska_ost_array_config.array_config import LowSubArray, MidSubArray + from ska_ost_array_config.array_config import LowSubArray + obs = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) low_aastar = LowSubArray(subarray_type="AA*") assert obs.antpos.shape[0] == low_aastar.array_config.xyz.data.shape @@ -214,14 +215,19 @@ def test_from_ska(): obs = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.0 * units.MHz) low_aa4 = LowSubArray(subarray_type="AA4") assert obs.antpos.shape[0] == low_aa4.array_config.xyz.data.shape - obs = Observatory.from_ska(subarray_type = 'custom', array_type="low", Trcv = 100.0 * un.K, frequency = 150.0 * un.MHz, custom_stations="C*,E1-*", exclude_stations="C1,C2") + obs = Observatory.from_ska( + subarray_type="custom", + array_type="low", + Trcv=100.0 * un.K, + frequency=150.0 * un.MHz, + custom_stations="C*,E1-*", + exclude_stations="C1,C2", + ) low_custom = LowSubArray( - subarray_type="custom", custom_stations="C*,E1-*" - ) # selects all core stations and 6 stations in the E1 cluster + subarray_type="custom", custom_stations="C*,E1-*" + ) # selects all core stations and 6 stations in the E1 cluster assert obs.antpos.shape[0] == low_custom.array_config.xyz.data.shape - - def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From 4cd5fc1b166eff572d85632d00965e2883789269 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Mon, 16 Dec 2024 13:49:21 +0100 Subject: [PATCH 16/29] feat: include access to ska array postions via ska-ost-array-config package --- src/py21cmsense/observatory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index ae09457..f5c0752 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -225,7 +225,7 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa @classmethod def from_ska( - cls, subarray_type: str, array_type="low", Trcv = tp.Temperature | Callable = attr.ib(100 * un.K), + cls, subarray_type: str, array_type: str ="low", Trcv: tp.Temperature | Callable = attr.ib(100 * un.K), frequency: tp.Frequency | None = 150.0 * un.MHz, **kwargs ) -> Observatory: """Instantiate an SKA Observatory. From 0c25f63905db66edace3cb401d6e9d40b15e81a8 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Mon, 16 Dec 2024 14:04:17 +0100 Subject: [PATCH 17/29] feat: include access to ska array postions via ska-ost-array-config package --- src/py21cmsense/observatory.py | 3 ++- tests/test_observatory.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index f5c0752..25887cb 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -225,7 +225,7 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa @classmethod def from_ska( - cls, subarray_type: str, array_type: str ="low", Trcv: tp.Temperature | Callable = attr.ib(100 * un.K), + cls, subarray_type: str, array_type: str ="low", Trcv: tp.Temperature | Callable = 100 * un.K, frequency: tp.Frequency | None = 150.0 * un.MHz, **kwargs ) -> Observatory: """Instantiate an SKA Observatory. @@ -257,6 +257,7 @@ def from_ska( "ska-ost-array-config package is required, " + "see https://gitlab.com/ska-telescope/ost/ska-ost-array-config" ) from exception + if array_type == "low": subarray = LowSubArray(subarray_type, **kwargs) elif array_type == "mid": diff --git a/tests/test_observatory.py b/tests/test_observatory.py index bc0ad9c..feca48d 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -209,16 +209,16 @@ def test_from_ska(): from ska_ost_array_config.array_config import LowSubArray, MidSubArray obs = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) low_aastar = LowSubArray(subarray_type="AA*") - assert obs.antpos.shape[0] == low_aastar.array_config.xyz.data.shape + assert obs.antpos.shape == low_aastar.array_config.xyz.data.shape Observatory.from_ska(subarray_type="AA*", array_type="mid", frequency=300.0 * units.MHz) obs = Observatory.from_ska(subarray_type="AA4", array_type="low", frequency=300.0 * units.MHz) low_aa4 = LowSubArray(subarray_type="AA4") - assert obs.antpos.shape[0] == low_aa4.array_config.xyz.data.shape - obs = Observatory.from_ska(subarray_type = 'custom', array_type="low", Trcv = 100.0 * un.K, frequency = 150.0 * un.MHz, custom_stations="C*,E1-*", exclude_stations="C1,C2") + assert obs.antpos.shape == low_aa4.array_config.xyz.data.shape + obs = Observatory.from_ska(subarray_type = 'custom', array_type="low", Trcv = 200.0 * units.K, frequency = 150.0 * units.MHz, custom_stations="C*,E1-*", exclude_stations="C1,C2") low_custom = LowSubArray( - subarray_type="custom", custom_stations="C*,E1-*" - ) # selects all core stations and 6 stations in the E1 cluster - assert obs.antpos.shape[0] == low_custom.array_config.xyz.data.shape + subarray_type="custom", custom_stations="C*,E1-*", exclude_stations="C1,C2" + ) # selects all core stations and 6 stations in the E1 cluster and exclude core stations C1 and C2 + assert obs.antpos.shape == low_custom.array_config.xyz.data.shape From 43b04b617d7067dd0872b09c2e09e6d396a68a33 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:06:12 +0000 Subject: [PATCH 18/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/py21cmsense/observatory.py | 12 +++++++----- tests/test_observatory.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index 25887cb..1225fe5 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -225,8 +225,12 @@ def from_profile(cls, profile: str, frequency: tp.Frequency | None = None, **kwa @classmethod def from_ska( - cls, subarray_type: str, array_type: str ="low", Trcv: tp.Temperature | Callable = 100 * un.K, - frequency: tp.Frequency | None = 150.0 * un.MHz, **kwargs + cls, + subarray_type: str, + array_type: str = "low", + Trcv: tp.Temperature | Callable = 100 * un.K, + frequency: tp.Frequency | None = 150.0 * un.MHz, + **kwargs, ) -> Observatory: """Instantiate an SKA Observatory. @@ -265,9 +269,7 @@ def from_ska( else: raise ValueError("array_type must be 'low' or 'mid'.") antpos = subarray.array_config.xyz.data * un.m - _beam = beam.GaussianBeam( - frequency=frequency, dish_size=35.0 * un.m - ) + _beam = beam.GaussianBeam(frequency=frequency, dish_size=35.0 * un.m) lat = subarray.array_config.location.lat.rad * un.rad return cls(antpos=antpos, beam=_beam, latitude=lat, Trcv=Trcv) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 57f3184..cfa310f 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -216,16 +216,16 @@ def test_from_ska(): low_aa4 = LowSubArray(subarray_type="AA4") assert obs.antpos.shape == low_aa4.array_config.xyz.data.shape obs = Observatory.from_ska( - subarray_type="custom", - array_type="low", - Trcv=100.0 * un.K, - frequency=150.0 * un.MHz, - custom_stations="C*,E1-*", - exclude_stations="C1,C2", - ) + subarray_type="custom", + array_type="low", + Trcv=100.0 * un.K, + frequency=150.0 * un.MHz, + custom_stations="C*,E1-*", + exclude_stations="C1,C2", + ) low_custom = LowSubArray( - subarray_type="custom", custom_stations="C*,E1-*", exclude_stations="C1,C2" - ) # selects all core stations and 6 stations in the E1 cluster and exclude core stations C1 and C2 + subarray_type="custom", custom_stations="C*,E1-*", exclude_stations="C1,C2" + ) # selects all core stations and 6 stations in the E1 cluster and exclude core stations C1 and C2 assert obs.antpos.shape == low_custom.array_config.xyz.data.shape From c8210392782c4229125d6fa62f79a61ee4736ef3 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Mon, 16 Dec 2024 14:10:43 +0100 Subject: [PATCH 19/29] feat: include access to ska array postions via ska-ost-array-config package --- tests/test_observatory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 57f3184..49b9a9f 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -218,8 +218,8 @@ def test_from_ska(): obs = Observatory.from_ska( subarray_type="custom", array_type="low", - Trcv=100.0 * un.K, - frequency=150.0 * un.MHz, + Trcv=100.0 * units.K, + frequency=150.0 * units.MHz, custom_stations="C*,E1-*", exclude_stations="C1,C2", ) From b87d265e6f9cc71ece3c215633c89a590b114268 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:11:31 +0000 Subject: [PATCH 20/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_observatory.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index f93f0bf..a737541 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -216,13 +216,13 @@ def test_from_ska(): low_aa4 = LowSubArray(subarray_type="AA4") assert obs.antpos.shape == low_aa4.array_config.xyz.data.shape obs = Observatory.from_ska( - subarray_type="custom", - array_type="low", - Trcv=100.0 * units.K, - frequency=150.0 * units.MHz, - custom_stations="C*,E1-*", - exclude_stations="C1,C2", - ) + subarray_type="custom", + array_type="low", + Trcv=100.0 * units.K, + frequency=150.0 * units.MHz, + custom_stations="C*,E1-*", + exclude_stations="C1,C2", + ) low_custom = LowSubArray( subarray_type="custom", custom_stations="C*,E1-*", exclude_stations="C1,C2" ) # selects all core stations and 6 stations in the E1 cluster and exclude core stations C1 and C2 From 3ff7c2b2476139f44ff6ce0056654ce5ad6ed5a4 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Mon, 16 Dec 2024 14:21:24 +0100 Subject: [PATCH 21/29] feat: include access to ska array postions via ska-ost-array-config package --- src/py21cmsense/observatory.py | 4 ++-- tests/test_observatory.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index 1225fe5..ca35147 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -228,7 +228,7 @@ def from_ska( cls, subarray_type: str, array_type: str = "low", - Trcv: tp.Temperature | Callable = 100 * un.K, + Trcv: tp.Temperature | Callable = 100 * un.K, # noqa N803 frequency: tp.Frequency | None = 150.0 * un.MHz, **kwargs, ) -> Observatory: @@ -252,7 +252,7 @@ def from_ska( Other Parameters ---------------- All other parameters passed will be passed into the LowSubArray or MidSubArray class. - See the documentation of the ska-ost-array-config package for more information on these classes. + See the documentation of the ska-ost-array-config package for more information. """ try: from ska_ost_array_config.array_config import LowSubArray, MidSubArray diff --git a/tests/test_observatory.py b/tests/test_observatory.py index f93f0bf..836103c 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -224,8 +224,9 @@ def test_from_ska(): exclude_stations="C1,C2", ) low_custom = LowSubArray( - subarray_type="custom", custom_stations="C*,E1-*", exclude_stations="C1,C2" - ) # selects all core stations and 6 stations in the E1 cluster and exclude core stations C1 and C2 + subarray_type="custom", + custom_stations="C*,E1-*", exclude_stations="C1,C2" + ) # selects all core stations, 6 stations in the E1 cluster, excludes core stations C1 and C2 assert obs.antpos.shape == low_custom.array_config.xyz.data.shape From da7da51df03e2c665373623e9b3e2b570304f34b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:22:10 +0000 Subject: [PATCH 22/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/py21cmsense/observatory.py | 2 +- tests/test_observatory.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index ca35147..eabda04 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -228,7 +228,7 @@ def from_ska( cls, subarray_type: str, array_type: str = "low", - Trcv: tp.Temperature | Callable = 100 * un.K, # noqa N803 + Trcv: tp.Temperature | Callable = 100 * un.K, # noqa N803 frequency: tp.Frequency | None = 150.0 * un.MHz, **kwargs, ) -> Observatory: diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 4d3c5de..a5bad18 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -224,8 +224,7 @@ def test_from_ska(): exclude_stations="C1,C2", ) low_custom = LowSubArray( - subarray_type="custom", - custom_stations="C*,E1-*", exclude_stations="C1,C2" + subarray_type="custom", custom_stations="C*,E1-*", exclude_stations="C1,C2" ) # selects all core stations, 6 stations in the E1 cluster, excludes core stations C1 and C2 assert obs.antpos.shape == low_custom.array_config.xyz.data.shape From ef9e317139a89b65da834005d30a210bb60a9506 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Wed, 8 Jan 2025 21:16:38 +0100 Subject: [PATCH 23/29] feat: tests for ska-ost-array-config --- src/py21cmsense/observatory.py | 2 +- tests/test_observatory.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index eabda04..6ab6521 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -512,7 +512,7 @@ def grid_baselines( -------- grid_baselines_coherent : Coherent sum over baseline groups of the output of this method. - grid_basleine_incoherent : + grid_baseline_incoherent : Incoherent sum over baseline groups of the output of this method. """ if baselines is not None: diff --git a/tests/test_observatory.py b/tests/test_observatory.py index a5bad18..f454157 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -206,7 +206,10 @@ def test_from_yaml(bm): def test_from_ska(): - from ska_ost_array_config.array_config import LowSubArray + from ska_ost_array_config.array_config import LowSubArray, UVW + from ska_ost_array_config.simulation_utils import simulate_observation + from astropy.time import Time + from astropy.coordinates import SkyCoord obs = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) low_aastar = LowSubArray(subarray_type="AA*") @@ -228,6 +231,31 @@ def test_from_ska(): ) # selects all core stations, 6 stations in the E1 cluster, excludes core stations C1 and C2 assert obs.antpos.shape == low_custom.array_config.xyz.data.shape + # Simulate visibilities and retreive the UVW values + # ref_time = Time.now() + # zenith = SkyCoord( + # alt=90 * units.deg, + # az=0 * units.deg, + # frame="altaz", + # obstime=ref_time, + # location=low_custom.array_config.location, + # ).icrs + # vis = simulate_observation( + # array_config=low_custom.array_config, + # phase_centre=zenith, + # start_time=ref_time, + # ref_freq=50e6, # Dummy value. We are after uvw values in [m] + # chan_width=1e3, # Dummy value. We are after uvw values in [m] + # n_chan=1, + # ) + # uvw = UVW.UVW(vis, ignore_autocorr=False) + # uvw_m = uvw.uvdist_m + # print(uvw_m.shape, uvw_m.min(), uvw_m.max()) # max is 1239.7 + # uvws = obs.grid_baselines(coherent=True).flatten() + # print(uvws.shape, uvws.min(), uvws.max()) # max is 1605.0 + # assert np.allclose(uvws, uvw_m) + + def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From c434a645354a530b02488f6178b337435ea1d438 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:18:39 +0000 Subject: [PATCH 24/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_observatory.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index f454157..e8f5bd5 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -206,10 +206,7 @@ def test_from_yaml(bm): def test_from_ska(): - from ska_ost_array_config.array_config import LowSubArray, UVW - from ska_ost_array_config.simulation_utils import simulate_observation - from astropy.time import Time - from astropy.coordinates import SkyCoord + from ska_ost_array_config.array_config import LowSubArray obs = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) low_aastar = LowSubArray(subarray_type="AA*") @@ -256,7 +253,6 @@ def test_from_ska(): # assert np.allclose(uvws, uvw_m) - def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm) From d1c53ffafe63c3b1831fbc1f0098ca88d667c679 Mon Sep 17 00:00:00 2001 From: DanielaBreitman Date: Thu, 9 Jan 2025 19:08:46 +0100 Subject: [PATCH 25/29] feat: tests for ska-ost-array-config --- tests/test_observatory.py | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index f454157..8e32d88 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -232,28 +232,25 @@ def test_from_ska(): assert obs.antpos.shape == low_custom.array_config.xyz.data.shape # Simulate visibilities and retreive the UVW values - # ref_time = Time.now() - # zenith = SkyCoord( - # alt=90 * units.deg, - # az=0 * units.deg, - # frame="altaz", - # obstime=ref_time, - # location=low_custom.array_config.location, - # ).icrs - # vis = simulate_observation( - # array_config=low_custom.array_config, - # phase_centre=zenith, - # start_time=ref_time, - # ref_freq=50e6, # Dummy value. We are after uvw values in [m] - # chan_width=1e3, # Dummy value. We are after uvw values in [m] - # n_chan=1, - # ) - # uvw = UVW.UVW(vis, ignore_autocorr=False) - # uvw_m = uvw.uvdist_m - # print(uvw_m.shape, uvw_m.min(), uvw_m.max()) # max is 1239.7 - # uvws = obs.grid_baselines(coherent=True).flatten() - # print(uvws.shape, uvws.min(), uvws.max()) # max is 1605.0 - # assert np.allclose(uvws, uvw_m) + ref_time = Time.now() + zenith = SkyCoord( + alt=90 * units.deg, + az=0 * units.deg, + frame="altaz", + obstime=ref_time, + location=low_custom.array_config.location, + ).icrs + vis = simulate_observation( + array_config=low_custom.array_config, + phase_centre=zenith, + start_time=ref_time, + ref_freq=50e6, # Dummy value. We are after uvw values in [m] + chan_width=1e3, # Dummy value. We are after uvw values in [m] + n_chan=1, + ) + uvw = UVW.UVW(vis, ignore_autocorr=False) + uvw_m = uvw.uvdist_m + assert np.allclose(obs.longest_baseline/obs.metres_to_wavelengths, uvw_m.max()*units.m) From 3f9a0470e748819d2ff094daf8eb878533858871 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:09:46 +0000 Subject: [PATCH 26/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_observatory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 14c18ee..a0271d1 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -247,7 +247,7 @@ def test_from_ska(): ) uvw = UVW.UVW(vis, ignore_autocorr=False) uvw_m = uvw.uvdist_m - assert np.allclose(obs.longest_baseline/obs.metres_to_wavelengths, uvw_m.max()*units.m) + assert np.allclose(obs.longest_baseline / obs.metres_to_wavelengths, uvw_m.max() * units.m) def test_get_redundant_baselines(bm): From 12fd80259020f65eada07d9143ed057ecf658f81 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Fri, 10 Jan 2025 09:26:04 +0100 Subject: [PATCH 27/29] test: fix imports in ska test --- tests/test_observatory.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index a0271d1..4539bc7 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -7,7 +7,8 @@ import pytest import pyuvdata from astropy import units -from astropy.coordinates import EarthLocation +from astropy.coordinates import EarthLocation, SkyCoord +from astropy.time import Time from py21cmsense import Observatory from py21cmsense.baseline_filters import BaselineRange @@ -206,7 +207,9 @@ def test_from_yaml(bm): def test_from_ska(): + from ska_ost_array_config import UVW from ska_ost_array_config.array_config import LowSubArray + from ska_ost_array_config.simulation_utils import simulate_observation obs = Observatory.from_ska(subarray_type="AA*", array_type="low", frequency=300.0 * units.MHz) low_aastar = LowSubArray(subarray_type="AA*") From b1d0a420aa8bc9f377aa9f7fcf40f007249cc817 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Fri, 10 Jan 2025 10:42:09 +0100 Subject: [PATCH 28/29] ci: don't require ska stuff for warnings tests --- .github/workflows/test-with-warnings.yaml | 10 ---------- tests/test_observatory.py | 2 ++ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-with-warnings.yaml b/.github/workflows/test-with-warnings.yaml index 53965b4..ca4439e 100644 --- a/.github/workflows/test-with-warnings.yaml +++ b/.github/workflows/test-with-warnings.yaml @@ -40,16 +40,6 @@ jobs: run: | pip install .[test] conda list - - name: Install Poetry - run: | - pipx install poetry - poetry --version - - name: Install ska-ost-array - run: | - git clone https://gitlab.com/ska-telescope/ost/ska-ost-array-config.git - cd ska-ost-array-config - poetry install - cd .. - name: Run Tests run: | diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 4539bc7..bd0edb4 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -207,6 +207,8 @@ def test_from_yaml(bm): def test_from_ska(): + pytest.importorskip("ska_ost_array_config") + from ska_ost_array_config import UVW from ska_ost_array_config.array_config import LowSubArray from ska_ost_array_config.simulation_utils import simulate_observation From ed3fcf416c18857c6f5d67b75290dfcb1dc61540 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Fri, 10 Jan 2025 11:45:47 +0100 Subject: [PATCH 29/29] test: cover exceptions in ska code --- src/py21cmsense/observatory.py | 2 +- tests/test_observatory.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/py21cmsense/observatory.py b/src/py21cmsense/observatory.py index fe7d084..f75603c 100644 --- a/src/py21cmsense/observatory.py +++ b/src/py21cmsense/observatory.py @@ -256,7 +256,7 @@ def from_ska( """ try: from ska_ost_array_config.array_config import LowSubArray, MidSubArray - except ImportError as exception: + except ImportError as exception: # pragma: no cover raise ImportError( "ska-ost-array-config package is required, " + "see https://gitlab.com/ska-telescope/ost/ska-ost-array-config" diff --git a/tests/test_observatory.py b/tests/test_observatory.py index bd0edb4..a4850a3 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -254,6 +254,11 @@ def test_from_ska(): uvw_m = uvw.uvdist_m assert np.allclose(obs.longest_baseline / obs.metres_to_wavelengths, uvw_m.max() * units.m) + with pytest.raises(ValueError, match="array_type must be"): + Observatory.from_ska( + subarray_type="AA*", array_type="non-existent", frequency=300.0 * units.MHz + ) + def test_get_redundant_baselines(bm): a = Observatory(antpos=np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0]]) * units.m, beam=bm)