diff --git a/.flake8 b/.flake8 deleted file mode 100644 index afbac91a1..000000000 --- a/.flake8 +++ /dev/null @@ -1,14 +0,0 @@ -[flake8] -ignore = - E402 - E501 - W291 - W293 - W503 - W601 -max-line-length = 88 -exclude = - development/* -select = - E - W diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 38e4505d0..b0984de3d 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -23,11 +23,15 @@ jobs: python-version: ${{ env.PYTHON }} - name: Install build - run: pip install build + run: pip install build twine - name: Build a binary wheel and a source tarball run: | python -m build + + - name: Twine Check + run: twine check dist/* + - name: Publish to PyPI if: startsWith(github.event.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@v1.9.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 80aa39a7f..57bcc9b9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: 'hera_cal/data/' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: check-added-large-files @@ -22,7 +22,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.5.0 + rev: v0.9.1 hooks: # Run the linter. - id: ruff diff --git a/hera_cal/io.py b/hera_cal/io.py index e7c82eaf9..a1dbf9286 100644 --- a/hera_cal/io.py +++ b/hera_cal/io.py @@ -1762,8 +1762,8 @@ def get_file_times(filepaths, filetype='uvh5'): assert AIPY, "you need aipy to use the miriad filetype" uv = aipy.miriad.UV(f) # get integration time - int_time = uv['inttime'] / (units.si.day.in_units(units.si.s)) - int_time_rad = uv['inttime'] * 2 * np.pi / (units.si.sday.in_units(units.si.s)) + int_time = uv['inttime'] / (units.si.day.to(units.si.s)) + int_time_rad = uv['inttime'] * 2 * np.pi / (units.si.sday.to(units.si.s)) # get start and stop, add half an integration start_lst = uv['lst'] + int_time_rad / 2.0 start_time = uv['time'] + int_time / 2.0 diff --git a/hera_cal/noise.py b/hera_cal/noise.py index 69ba8259a..61dbc8d40 100644 --- a/hera_cal/noise.py +++ b/hera_cal/noise.py @@ -92,7 +92,7 @@ def predict_noise_variance_from_autos(bl, data, dt=None, df=None, nsamples=None, Noise variance predicted on baseline bl in units of data squared. ''' if dt is None: - dt = infer_dt(data.times_by_bl, bl) * units.si.day.in_units(units.si.s) + dt = infer_dt(data.times_by_bl, bl) * units.si.day.to(units.si.s) if df is None: assert (len(data.freqs) > 1) # cannot infer channel width if only one channel is present df = np.median(np.ediff1d(data.freqs)) @@ -102,7 +102,7 @@ def predict_noise_variance_from_autos(bl, data, dt=None, df=None, nsamples=None, auto_bl1, auto_bl2 = (bl[0], bl[0], join_pol(ap1, ap1)), (bl[1], bl[1], join_pol(ap2, ap2)) else: auto_bl1, auto_bl2 = (auto_ant, auto_ant, join_pol(ap1, ap1)), (auto_ant, auto_ant, join_pol(ap2, ap2)) - + var = np.abs(data[auto_bl1] * data[auto_bl2] / dt / df) if nsamples is not None: return var / nsamples[bl] diff --git a/hera_cal/tests/mock_uvdata.py b/hera_cal/tests/mock_uvdata.py index f9f3f19f9..1139cae47 100644 --- a/hera_cal/tests/mock_uvdata.py +++ b/hera_cal/tests/mock_uvdata.py @@ -173,7 +173,7 @@ def add_noise_to_uvd(uvd, autos: bool = False): hd = io.to_HERAData(uvd) data, flags, nsamples = hd.read() - dt = (data.times[1] - data.times[0]) * units.si.day.in_units(units.si.s) + dt = (data.times[1] - data.times[0]) * units.si.day.to(units.si.s) df = data.freqs[1] - data.freqs[0] for bl in data.bls(): diff --git a/pyproject.toml b/pyproject.toml index 6f2cae199..b9b6b31f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,61 @@ write_to = "hera_cal/_version.py" parentdir_prefix_version = "hera_cal-" fallback_version = "0.0.0" +[project] +name = "hera-calibration" +description = "A collection of calibration routines to run on the HERA instrument." +readme = "README.md" +authors = [ + {name="HERA Team"}, +] +license = {text="BSD"} +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Scientific/Engineering :: Astronomy", + "Topic :: Scientific/Engineering :: Physics", +] +dynamic=["version"] +requires-python = ">=3.9" +dependencies = [ + 'numpy>=1.10', + "scipy>=1.9.0", + "h5py", + "hdf5plugin", + "astropy", + "astropy-healpix", + "pyuvdata>=3.1.3", + "linsolve", + "hera_qm>=2.2.0", + "scikit-learn", + "hera-filters", + "line_profiler", + "aipy", + "rich", + "jax", + "jaxlib", + "optax", + "attrs", + "frozendict", + "toml", +] + +[project.optional-dependencies] +dev = [ + "pytest", + "pre-commit", + "pytest-cov", + "hera_sim>=4.3.0", + "pytest-xdist", + "hypothesis", + "ruff", +] + [tool.pytest] addopts = "--ignore=scripts --cov=hera_cal --cov-config=.coveragerc" @@ -58,11 +113,16 @@ select = [ # "UP", # pyupgrade ] +exclude = [ + "scripts/notebooks/*.ipynb", # For now, ignore notebooks when linting. +] + ignore = [ "E402", "E501", "W291", "W293", + "A005", # module io shadows python stdlib # Following Rulesets we really don't want "AIR", # airflow - unused library "ASYNC", # async -- unused library diff --git a/scripts/notebooks/omnical_convergence.ipynb b/scripts/notebooks/omnical_convergence.ipynb index 987f70bf7..80fcdfee6 100644 --- a/scripts/notebooks/omnical_convergence.ipynb +++ b/scripts/notebooks/omnical_convergence.ipynb @@ -204,15 +204,15 @@ " k = kde.gaussian_kde(res)\n", " xi, yi = np.mgrid[x.min():x.max():nbins*1j, y.min():y.max():nbins*1j]\n", " zi = k(np.vstack([xi.flatten(), yi.flatten()]))\n", - " plt.xlabel('$\\Delta$g, real')\n", - " plt.ylabel('$\\Delta$g, imag')\n", + " plt.xlabel(r'$\\Delta$g, real')\n", + " plt.ylabel(r'$\\Delta$g, imag')\n", " plt.xlim(-lim,lim); plt.ylim(-lim,lim)\n", " ax.grid(b=True, which='major', color='k', linestyle='-')\n", " \n", " ax2 = plt.subplot(122, sharey=ax)\n", " plt.grid()\n", " _ = plt.contour(xi, yi, zi.reshape(xi.shape), alpha=.5)\n", - " plt.xlabel('$\\Delta$g, real')\n", + " plt.xlabel(r'$\\Delta$g, real')\n", " plt.xlim(-lim,lim)\n", " plt.setp(ax2.get_yticklabels(), visible=False)\n", " ax2.grid(b=True, which='major', color='k', linestyle='-')" @@ -657,7 +657,7 @@ " err = [np.sqrt(np.average(np.abs(r)**2) / r.size) for r in res]\n", " color = 'rgbk'[i]\n", " _ = plt.semilogy(ants, avg, color+'.', label=label+' <$x-x_0$>')\n", - " _ = plt.semilogy(ants, err, color+'x', label=label+' $\\sigma$')\n", + " _ = plt.semilogy(ants, err, color+'x', label=label+r' $\\sigma$')\n", "plt.ylabel('Residual Deviation')\n", "plt.xlabel('Antenna Index')\n", "plt.legend()\n", @@ -764,7 +764,7 @@ "for i in range(4):\n", " sol = sols[i]\n", " if i == 0:\n", - " label1, label2 = '<$x-x_0$>', '$\\sigma$'\n", + " label1, label2 = '<$x-x_0$>', r'$\\sigma$'\n", " else:\n", " label1, label2 = '', ''\n", " sol_degen = info.remove_degen(antpos, sol, degen_sol=gains)\n", diff --git a/scripts/notebooks/running_smooth_cal.ipynb b/scripts/notebooks/running_smooth_cal.ipynb index 73bab8c97..ff23d5b24 100644 --- a/scripts/notebooks/running_smooth_cal.ipynb +++ b/scripts/notebooks/running_smooth_cal.ipynb @@ -216,7 +216,7 @@ "plt.subplot(121)\n", "plt.imshow(np.angle(original_gains[ant]) / (~cs.flag_grids[ant]), cmap='inferno', aspect='auto', extent=extent)\n", "plt.colorbar(label='Phase (radians)')\n", - "plt.title('Unfiltered: ' + str(ant));\n", + "plt.title('Unfiltered: ' + str(ant))\n", "plt.xlabel('Frequency (MHz)')\n", "plt.ylabel('JD -' + str(int(np.floor(cs.time_grid[0]))))\n", "\n", diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index fac120105..000000000 --- a/setup.cfg +++ /dev/null @@ -1,11 +0,0 @@ -[aliases] -test=pytest - - -[pycodestyle] -ignore = E402,E501,W291,W293,W503,W601 -filename = *.py -exclude = build/,docs/,.pytest_cache,.svn,CVS,.bzr,.hg,.git,__pycache__,dist/,scripts/,hera_cal.egg-info,hera_cal/data/ - -[pydocstyle] -convention = numpy diff --git a/setup.py b/setup.py deleted file mode 100644 index 05bdfb683..000000000 --- a/setup.py +++ /dev/null @@ -1,88 +0,0 @@ -from setuptools import setup - -import os -import sys -import json -from pathlib import Path - -sys.path.append("hera_cal") - - -def package_files(package_dir, subdirectory): - # walk the input package_dir/subdirectory - # return a package_data list - paths = [] - directory = os.path.join(package_dir, subdirectory) - for (path, directories, filenames) in os.walk(directory): - for filename in filenames: - path = path.replace(package_dir + '/', '') - paths.append(os.path.join(path, filename)) - return paths - - -data_files = package_files('hera_cal', 'data') -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - -setup_args = { - 'name': 'hera-calibration', - 'author': 'HERA Team', - 'url': 'https://github.com/HERA-Team/hera_cal', - 'license': 'BSD', - 'description': 'collection of calibration routines to run on the HERA instrument.', - 'long_description': long_description, - 'long_description_content_type': 'text/markdown', - 'package_dir': {'hera_cal': 'hera_cal'}, - 'packages': ['hera_cal'], - 'include_package_data': True, - 'scripts': ['scripts/extract_hh.py', 'scripts/post_redcal_abscal_run.py', - 'scripts/apply_cal.py', 'scripts/delay_filter_run.py', - 'scripts/lstbin_run.py', 'scripts/extract_autos.py', - 'scripts/smooth_cal_run.py', 'scripts/redcal_run.py', - 'scripts/auto_reflection_run.py', 'scripts/noise_from_autos.py', - 'scripts/query_ex_ants.py', 'scripts/red_average.py', - 'scripts/time_average.py', 'scripts/tophat_frfilter_run.py', 'scripts/model_calibration_run.py', - 'scripts/time_chunk_from_baseline_chunks_run.py', 'scripts/chunk_files.py', 'scripts/transfer_flags.py', - 'scripts/flag_all.py', 'scripts/throw_away_flagged_antennas.py', 'scripts/select_spw_ranges.py', - 'scripts/multiply_gains.py', 'scripts/lstbin_simple.py', 'scripts/subselect.py'], - 'package_data': {'hera_cal': data_files}, - 'python_requires': '>=3.9', - 'install_requires': [ - 'numpy>=1.10', - 'scipy>=1.9.0', - 'h5py', - 'hdf5plugin', - 'astropy', - 'astropy-healpix', - 'pyuvdata@git+https://github.com/RadioAstronomySoftwareGroup/pyuvdata', - 'linsolve', - 'hera_qm>=2.2.0', - 'scikit-learn', - 'hera-filters', - "line_profiler", - 'aipy', - "rich", - "jax", - "jaxlib", - "optax", - 'attrs', - 'frozendict', - "toml", - ], - 'extras_require': { - 'dev': [ - "pytest", - "pre-commit", - "pytest-cov", - "hera_sim @ git+https://github.com/hera-team/hera_sim@use-uvdata-new", - "pytest-xdist", - "hypothesis", - "ruff", - ] - }, - 'zip_safe': False, -} - - -if __name__ == '__main__': - setup(*(), **setup_args)