Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update VisCPU simulator wrapper to match vis_cpu v1 #233

Merged
merged 15 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]
defaults:
run:
# Adding -l {0} ensures conda can be found properly in each step
Expand Down
11 changes: 11 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[settings]
line_length=88
indent=' '
skip=.tox,.venv,build,dist
known_standard_library=setuptools,pkg_resources
known_test=pytest
known_first_party=vis_cpu
sections=FUTURE,STDLIB,COMPAT,TEST,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section=THIRDPARTY
multi_line_output=3
profile=black
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ repos:
rev: v1.9.0
hooks:
- id: rst-backticks

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.1
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.2
hooks:
- id: setup-cfg-fmt
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ Changelog
dev-version
===========

v3.0.0
======

Removed
-------

- Finally removed ability to set ``use_pixel_beams`` and ``bm_pix`` on the VisCPU
simulator. This was removed in v1.0.0 of ``vis_cpu``.
- Official support for py37.

Internals
---------

- Added isort and pyupgrade pre-commit hooks for cleaner code.

v2.3.4 [2022.06.08]
===================

Expand Down
1 change: 0 additions & 1 deletion config_examples/simulator.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
simulator: VisCPU
use_pixel_beams: false
precision: 2
ref_time: mean
correct_source_positions: true
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand Down
51 changes: 29 additions & 22 deletions hera_sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,43 @@
from pathlib import Path

try:
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version
except ImportError:
steven-murray marked this conversation as resolved.
Show resolved Hide resolved
from importlib_metadata import version, PackageNotFoundError
from importlib_metadata import PackageNotFoundError, version

try:
DATA_PATH = Path(__file__).parent / "data"
CONFIG_PATH = Path(__file__).parent / "config"
__version__ = version(__name__)
except PackageNotFoundError:
except PackageNotFoundError: # pragma: no cover
# package is not installed
pass


from . import __yaml_constructors
from . import adjustment
from . import antpos
from . import cli_utils
from . import foregrounds
from . import interpolators
from . import io
from . import noise
from . import rfi
from . import sigchain
from .visibilities import simulators, load_simulator_from_yaml
from . import eor
from . import utils
from . import simulate
from . import beams
from .simulate import Simulator
from . import (
__yaml_constructors,
adjustment,
antpos,
beams,
cli_utils,
eor,
foregrounds,
interpolators,
io,
noise,
rfi,
sigchain,
simulate,
utils,
)
from .components import (
SimulationComponent,
component,
get_all_components,
get_model,
get_models,
)
from .defaults import defaults
from .components import SimulationComponent, component
from .components import get_all_components, get_model, get_models
from .interpolators import Tsky, Bandpass, Beam
from .interpolators import Bandpass, Beam, Tsky
from .simulate import Simulator
from .visibilities import load_simulator_from_yaml, simulators
8 changes: 3 additions & 5 deletions hera_sim/__yaml_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

This may need to be updated if the :mod:`.interpolators` module is updated.
"""
import yaml
import astropy.units as u
import inspect
import warnings
import yaml

import astropy.units as u

from . import interpolators
from . import antpos
from . import antpos, interpolators


def make_interp_constructor(tag, interpolator):
Expand Down
11 changes: 5 additions & 6 deletions hera_sim/adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import copy
import logging
import numpy as np
import os
import pathlib

import numpy as np
from scipy.interpolate import interp1d, RectBivariateSpline
from warnings import warn

from pyuvdata import UVData
from pyuvdata.utils import polnum2str
from scipy.interpolate import RectBivariateSpline, interp1d
from warnings import warn

from .simulate import Simulator
from .utils import _listify

try:
# Import hera_cal functions.
from hera_cal.io import to_HERAData
from hera_cal.abscal import get_d2m_time_map
from hera_cal.io import to_HERAData
from hera_cal.utils import lst_rephase

HERA_CAL = True
Expand Down
1 change: 1 addition & 0 deletions hera_sim/antpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
to the ENU position of the antennas.
"""
import numpy as np

from .components import component

# FIXME: old docstrings state that the positions are returned in topocentric
Expand Down
5 changes: 3 additions & 2 deletions hera_sim/beams.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Module defining analytic polynomial beams."""
import numpy as np
from pyuvsim import AnalyticBeam
from numpy.polynomial.chebyshev import chebval
from pyuvsim import AnalyticBeam

from . import utils


Expand Down Expand Up @@ -383,7 +384,7 @@ def interp(self, az_array, za_array, freq_array, **kwargs):
if self.beam_type == "power":
# Cross-multiplying feeds, adding vector components
pairs = [(i, j) for i in range(2) for j in range(2)]
power_data = np.zeros((1, 1, 4) + beam_values.shape, dtype=np.float)
power_data = np.zeros((1, 1, 4) + beam_values.shape, dtype=float)
for pol_i, pair in enumerate(pairs):
power_data[:, :, pol_i] = (
interp_data[0, :, pair[0]] * np.conj(interp_data[0, :, pair[1]])
Expand Down
5 changes: 3 additions & 2 deletions hera_sim/cli_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Useful helper functions and argparsers for running simulations via CLI."""
import itertools
import numpy as np
import os
import warnings
import numpy as np
from pyuvdata import UVData

from .defaults import SEASON_CONFIGS
from .simulate import Simulator
from pyuvdata import UVData


def get_filing_params(config: dict):
Expand Down
23 changes: 12 additions & 11 deletions hera_sim/components.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""A module providing discoverability features for hera_sim."""

from __future__ import annotations

import re
from abc import abstractmethod, ABCMeta
from abc import ABCMeta, abstractmethod
from collections import defaultdict
from copy import deepcopy
from .defaults import defaults
from typing import Dict, Optional, Tuple, Type
from types import new_class
from collections import defaultdict

from .defaults import defaults

_available_components = {}

Expand Down Expand Up @@ -37,7 +38,7 @@ class determine how to apply the effect simulated by
#: Whether this systematic multiplies existing visibilities
is_multiplicative: bool = False

_alias: Tuple[str] = tuple()
_alias: tuple[str] = tuple()
steven-murray marked this conversation as resolved.
Show resolved Hide resolved

# Keyword arguments for the Simulator to extract from the data
_extract_kwargs = set()
Expand Down Expand Up @@ -81,7 +82,7 @@ class or not. Classes that are not abstract are
cls._models[name] = cls

@classmethod
def get_aliases(cls) -> Tuple[str]:
def get_aliases(cls) -> tuple[str]:
"""Get all the aliases by which this model can be identified."""
return (cls.__name__.lower(),) + cls._alias

Expand Down Expand Up @@ -162,7 +163,7 @@ def _extract_param_section(docstring):
return param_section.partition(section_headings[1])[0]

@classmethod
def get_models(cls, with_aliases=False) -> Dict[str, SimulationComponent]:
def get_models(cls, with_aliases=False) -> dict[str, SimulationComponent]:
"""Get a dictionary of models associated with this component."""
if with_aliases:
return deepcopy(cls._models)
Expand Down Expand Up @@ -221,20 +222,20 @@ class and implementing (at least) the :meth:`__call__` method. Some of these are
return cls


def get_all_components(with_aliases=False) -> Dict[str, Dict[str, SimulationComponent]]:
def get_all_components(with_aliases=False) -> dict[str, dict[str, SimulationComponent]]:
"""Get a dictionary of component names mapping to a dictionary of models."""
return {
cmp_name.lower(): cmp.get_models(with_aliases)
for cmp_name, cmp in _available_components.items()
}


def get_models(cmp: str, with_aliases: bool = False) -> Dict[str, SimulationComponent]:
def get_models(cmp: str, with_aliases: bool = False) -> dict[str, SimulationComponent]:
"""Get a dict of model names mapping to model classes for a particular component."""
return get_all_components(with_aliases)[cmp.lower()]


def get_all_models(with_aliases: bool = False) -> Dict[str, SimulationComponent]:
def get_all_models(with_aliases: bool = False) -> dict[str, SimulationComponent]:
"""Get a dictionary of model names mapping to their classes for all possible models.

See Also
Expand All @@ -250,7 +251,7 @@ def get_all_models(with_aliases: bool = False) -> Dict[str, SimulationComponent]
return out


def get_model(mdl: str, cmp: Optional[str] = None) -> Type[SimulationComponent]:
def get_model(mdl: str, cmp: str | None = None) -> type[SimulationComponent]:
"""Get a particular model, based on its name.

Parameters
Expand Down
10 changes: 5 additions & 5 deletions hera_sim/data/tutorials_data/end_to_end/make_mock_catalog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Script for making a mock point source catalog."""
from pyuvsim.simsetup import initialize_uvdata_from_params
from astropy.coordinates import EarthLocation, Latitude, Longitude
from astropy import units
import argparse
import numpy as np
from pyuvsim import create_mock_catalog
from astropy import units
from astropy.coordinates import EarthLocation, Latitude, Longitude
from pyradiosky import SkyModel
import argparse
from pyuvsim import create_mock_catalog
from pyuvsim.simsetup import initialize_uvdata_from_params


def make_mock_catalog(
Expand Down
12 changes: 6 additions & 6 deletions hera_sim/defaults.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Module for interfacing with package-wide default parameters."""

import yaml
import inspect
import functools
import inspect
import warnings

import yaml
from os import path

from .config import CONFIG_PATH

SEASON_CONFIGS = {
Expand All @@ -20,7 +20,7 @@ class _Singleton(type):

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]


Expand Down Expand Up @@ -198,7 +198,7 @@ def _set_config(self, config):
self._config_name = config
config = SEASON_CONFIGS[config]
# load in the raw configuration
with open(config, "r") as conf:
with open(config) as conf:
self._raw_config = yaml.load(conf.read(), Loader=yaml.FullLoader)
elif isinstance(config, dict):
# set the raw configuration dictionary to config
Expand Down Expand Up @@ -290,7 +290,7 @@ def _check_config(self):
)
for param, flag in flags.items():
if flag:
warning += "{}\n".format(param)
warning += f"{param}\n"
warning += (
"Please check your configuration, as only the last "
"value specified for each parameter will be used."
Expand Down
5 changes: 3 additions & 2 deletions hera_sim/eor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"""

import numpy as np
from .components import component
from . import utils
from typing import Optional

from . import utils
from .components import component


@component
class EoR:
Expand Down
5 changes: 3 additions & 2 deletions hera_sim/interpolators.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""This module provides interfaces to different interpolation classes."""
import warnings
import numpy as np
import warnings
from cached_property import cached_property
from os import path
from scipy.interpolate import RectBivariateSpline, interp1d

from hera_sim import DATA_PATH
from os import path

INTERP_OBJECTS = {
"1d": (
Expand Down
Loading