Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix_lm_grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin2 committed Jul 18, 2024
2 parents 14966e9 + a038bd8 commit 0cc8b97
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 17 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,37 @@ jobs:
fetch-depth: 0

- name: Prepare mamba installation
if: matrix.install-method == 'mamba'
if: matrix.install-method == 'mamba' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false
env:
PYTHON_VERSION: ${{ matrix.python-version }}
run: |
# setup correct python version
sed -i -e "s/- python.*/- python=$PYTHON_VERSION/g" environment.yml
- name: mamba setup
if: matrix.install-method == 'mamba'
if: matrix.install-method == 'mamba' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
cache-downloads: true

- name: Install dependencies
env:
PYTHON_VERSION: ${{ matrix.python-version }}
run: |
python --version
pip install pytest-cov restructuredtext-lint pytest-xdist 'coverage!=6.3.0'
pip install .[all]
pip install -e .[all]
pip freeze
pip list
- name: List installed package versions (conda)
if: matrix.environment-type == 'mamba'
run: micromamba list

- name: Tests
run: |
py.test --cov --cov-report=xml
pytest --cov --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
1 change: 1 addition & 0 deletions docs/changes/31.maintenance.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- use observation class to pass sampling options to the fits writer
- include writer in tests
3 changes: 3 additions & 0 deletions docs/changes/33.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changes to `vis_loop` function in `visibility.py`:
- add a an optional tqdm progress bar to get a visual confirmation the calculation is still running
- add optional `batch_size` parameter to control memory consumption
1 change: 1 addition & 0 deletions docs/changes/35.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- switch from setup.py to pyproject.toml
12 changes: 8 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
# A conda environment with all useful packages for pyvisgen developers
name: pyvisgen
channels:
- pytorch
- defaults
- conda-forge
dependencies:
- python
- astropy<=6.1.0
- pytorch
- numpy
- matplotlib
- pip
- pip:
- towncrier
- -e .
- towncrier
- jupyter
- pytest
- pytest-cov
- pytest-runner
94 changes: 94 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "pyvisgen"
version = "0.2.0"
description = "Simulate radio interferometer observations and visibility generation with the RIME formalism."
readme = "README.md"
authors = [
{name = "Kevin Schmidt, Felix Geyer, Stefan Fröse"},
]
maintainers = [
{name = "Kevin Schmidt", email = "[email protected]"},
{name = "Felix Geyer", email = "[email protected]"},
]
license = {text = "MIT"}
classifiers = [
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Astronomy",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Information Analysis",
"Development Status :: 4 - Beta",
]

requires-python = ">=3.10"

dependencies = [
"numpy",
"astropy<=6.1.0",
"torch",
"matplotlib",
"ipython",
"scipy",
"pandas",
"toml",
"pytest",
"pytest-cov",
"jupyter",
"astroplan",
"torch",
"tqdm",
"numexpr",
"click",
"h5py",
"natsort",
"pre-commit",
]

[project.scripts]
pyvisgen_create_dataset = "pyvisgen.simulation.scripts.create_dataset:main"

[tool.setuptools.packages.find]
where = ["pyvisgen"]

[tool.towncrier]
package = "ctapipe"
directory = "docs/changes"
filename = "CHANGES.rst"
template = "docs/changes/template.rst"
# let towncrier create proper links to the merged PR
issue_format = "`#{issue} <https://github.com/cta-observatory/ctapipe/pull/{issue}>`__"

[tool.towncrier.fragment.feature]
name = "New Features"
showcontent = true

[tool.towncrier.fragment.bugfix]
name = "Bug Fixes"
showcontent = true

[tool.towncrier.fragment.api]
name = "API Changes"
showcontent = true

[tool.towncrier.fragment.datamodel]
name = "Data Model Changes"
showcontent = true

[tool.towncrier.fragment.optimization]
name = "Refactoring and Optimization"
showcontent = true

[tool.towncrier.fragment.maintenance]
name = "Maintenance"
showcontent = true

[[tool.towncrier.section]]
name = ""
path = ""
2 changes: 1 addition & 1 deletion pyvisgen/fits/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_vis_hdu(data, obs, layout="vlba", source_name="sim-source-0"):
ra = obs.ra.cpu().numpy().item()
dec = obs.dec.cpu().numpy().item()
freq = obs.ref_frequency.cpu().numpy().item()
freq_d = obs.bandwidths.cpu().numpy().item()
freq_d = obs.bandwidths[0].cpu().numpy().item()

ws = wcs.WCS(naxis=7)
ws.wcs.crpix = [1, 1, 1, 1, 1, 1, 1]
Expand Down
11 changes: 9 additions & 2 deletions pyvisgen/simulation/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pyvisgen.simulation.scan as scan

from tqdm import tqdm


@dataclass
class Visibilities:
Expand Down Expand Up @@ -37,7 +39,7 @@ def add(self, visibilities):
]


def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full"):
def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100, show_progress=False):
torch.set_num_threads(num_threads)
torch._dynamo.config.suppress_errors = True

Expand Down Expand Up @@ -93,7 +95,12 @@ def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full"):
else:
raise ValueError("Unsupported mode!")

for p in torch.arange(bas[:].shape[1]).split(1000):
batches = torch.arange(bas[:].shape[1]).split(batch_size)

if show_progress:
batches = tqdm(batches)

for p in batches:
bas_p = bas[:][:, p]

int_values = torch.cat(
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
packages=find_packages(),
install_requires=[
"numpy",
"astropy",
"matplotlib",
"ipython",
"scipy",
Expand Down
Empty file added tests/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_create_sampling_rc():
def test_vis_loop():
import torch

import pyvisgen.fits.writer as writer
from pyvisgen.simulation.data_set import create_observation
from pyvisgen.simulation.visibility import vis_loop
from pyvisgen.utils.data import load_bundles, open_bundles
Expand Down Expand Up @@ -57,3 +58,9 @@ def test_vis_loop():
# num_vis_calc = vis_data.base_num[vis_data.date == vis_data.date[0]].shape[0]
# dunno what's going on here
# assert num_vis_theory == num_vis_calc
#

out_path = Path(conf["out_path_fits"])
out = out_path / Path("vis_0.fits")
hdu_list = writer.create_hdu_list(vis_data, obs)
hdu_list.writeto(out, overwrite=True)

0 comments on commit 0cc8b97

Please sign in to comment.