Skip to content

Commit

Permalink
Merge pull request #847 from BradleySappington/manual_lint
Browse files Browse the repository at this point in the history
Manual lint
  • Loading branch information
mperrin authored May 17, 2024
2 parents 0957cd7 + fb960d9 commit fd96a6d
Show file tree
Hide file tree
Showing 26 changed files with 215 additions and 455 deletions.
6 changes: 3 additions & 3 deletions dev_utils/field_dependence/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@

# Disable Pint's old fallback behavior (must come before importing Pint)
import os
import copy

os.environ['PINT_ARRAY_PROTOCOL_FALLBACK'] = '0'

import pint
import pint # noqa

units = pint.UnitRegistry()
Q_ = units.Quantity

# Silence NEP 18 warning
import warnings
import warnings # noqa

with warnings.catch_warnings():
warnings.simplefilter('ignore')
Q_([])

import copy


def embed(n, m):
Expand Down
6 changes: 4 additions & 2 deletions dev_utils/package_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import stsynphot

from synphot.exceptions import SynphotError

WebbPSF_basepath = os.getenv(
'WEBBPSF_PATH', default=os.path.dirname(os.path.dirname(os.path.abspath(webbpsf.__file__))) + os.sep + 'data'
)
Expand All @@ -21,11 +23,11 @@ def norm_one_filter(instrument, filter_, clobber=False):
t.add_keyword('TELESCOP', 'JWST')
t.add_keyword('INSTRUME', instrument)
t.add_keyword('FILTER', filter_)
t.add_keyword('SOURCE', f'{_SYNPHOT_PKG}, normalized to peak=1')
t.add_keyword('SOURCE', f'{_SYNPHOT_PKG}, normalized to peak=1') # TODO - NOT DEFINED _SYNPHOT_PKG

t.write('%s/%s/filters/%s_throughput.fits' % (WebbPSF_basepath, instrument, filter_))
print('Wrote throughput.fits for %s %s' % (instrument, filter_))
except:
except SynphotError:
print('Error for %s %s' % (instrument, filter_))


Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

intersphinx_mapping.update(
intersphinx_mapping.update( # noqa - defined in star import
{
"poppy": ("http://poppy-optics.readthedocs.io/", None),
}
Expand Down
83 changes: 0 additions & 83 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,86 +133,3 @@ omit = [
"*/webbpsf/*/*/tests/*",
"*/webbpsf/version*",
]

# Ensure ruff is in line with .pep8speaks.yml
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

line-length = 125
indent-width = 4

# Assume Python 3.10
target-version = "py310"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "W"]
ignore = [
"W191", # indentation contains tabs
"W505", # doc line too long
"E401", # multiple imports on one line
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "single"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = true

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
3 changes: 1 addition & 2 deletions webbpsf/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def get_detector_ipc_model(inst, header):
elif inst == 'MIRI':
webbpsf.webbpsf_core._log.info('Detector IPC: MIRI')

a = webbpsf.constants.INSTRUMENT_IPC_DEFAULT_KERNEL_PARAMETERS[inst]
alpha = webbpsf.constants.INSTRUMENT_IPC_DEFAULT_KERNEL_PARAMETERS[inst][0]
beta = webbpsf.constants.INSTRUMENT_IPC_DEFAULT_KERNEL_PARAMETERS[inst][1]
c = webbpsf.constants.INSTRUMENT_IPC_DEFAULT_KERNEL_PARAMETERS[inst][2] # real observation noise adjustment
Expand Down Expand Up @@ -107,7 +106,7 @@ def get_detector_ipc_model(inst, header):
nchannel = int(yposition) // 512
try:
flag = maskimage[nchannel, int(xposition)]
except:
except IndexError:
# This marks the pixel as non-void by default if the maskimage is not
# read in properly
flag = 0
Expand Down
19 changes: 7 additions & 12 deletions webbpsf/gridded_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import astropy.convolution
import numpy as np
import poppy
from astropy.io import fits
from astropy.nddata import NDData
from photutils.psf import GriddedPSFModel

import poppy
import webbpsf.detectors


Expand Down Expand Up @@ -150,15 +151,6 @@ def __init__(
"""

# Before doing anything else, check that we have GriddedPSFModel
try:
from photutils.psf import GriddedPSFModel
except ImportError:
try:
from photutils import GriddedPSFModel
except ImportError:
raise ImportError('This method requires photutils >= 0.6')

# Pull WebbPSF instance
self.webb = instrument
self.instr = instrument.name
Expand Down Expand Up @@ -232,7 +224,7 @@ def _set_detectors(self, filt, detectors):
det = CreatePSFLibrary.nrca_short_detectors
elif self.instr == 'NIRCam' and filt in CreatePSFLibrary.nrca_long_filters:
det = CreatePSFLibrary.nrca_long_detectors
elif type(detectors) is str:
elif isinstance(detectors, str):
det = detectors.split()
else:
raise TypeError('Method of setting detectors is not valid')
Expand Down Expand Up @@ -583,7 +575,10 @@ def display_psf_grid(grid, zoom_in=True, figsize=(14, 12), scale_range=1e-4, dif
import matplotlib
import matplotlib.pyplot as plt

tuple_to_int = lambda t: (int(t[0]), int(t[1]))
def tuple_to_int(t):
if isinstance(t, tuple):
return (int(t[0]), int(t[1]))


def show_grid_helper(grid, data, title='Grid of PSFs', vmax=0, vmin=0, scale='log'):
npsfs = grid.data.shape[0]
Expand Down
4 changes: 2 additions & 2 deletions webbpsf/jupyter_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def show_notebook_interface_wfi(instrument):
from matplotlib import pyplot as plt

try:
import synphot
import synphot # noqa TODO verify synphot is indeeded needed
except ImportError:
raise ImportError('For now, synphot must be installed to use the notebook interface')

Expand Down Expand Up @@ -224,7 +224,7 @@ def show_notebook_interface_jwst(instrument):
instrument = instrument(instrument)

try:
import synphot
import synphot # noqa TODO verify synphot is indeeded needed
except ImportError:
raise ImportError('For now, synphot must be installed to use the notebook interface')

Expand Down
10 changes: 3 additions & 7 deletions webbpsf/mast_wss.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def get_opd_at_time(date, choice='closest', verbose=False, output_path=None):
elif choice == 'average':
if verbose:
print(f'User requested calculating OPD time averaged around {date}')
fn_pre = mast_retrieve_opd(pre_opd_fn, output_path=output_path)
fn_post = mast_retrieve_opd(post_opd_fn, output_path=output_path)
mast_retrieve_opd(pre_opd_fn, output_path=output_path) # TODO - define pre_opd_fn now or skip?
mast_retrieve_opd(post_opd_fn, output_path=output_path)
raise NotImplementedError('Not yet implemented')
elif choice == 'closest':
closest_fn, closest_dt = (
Expand Down Expand Up @@ -424,15 +424,11 @@ def add_columns_to_track_corrections(opdtable):
"""
#
dates = astropy.time.Time(opdtable['date'], format='isot')
pre_or_post = []

for row in opdtable:
pre_or_post.append(infer_pre_or_post_correction(row))

where_pre = ['pre' in a for a in pre_or_post]
where_post = ['post' in a for a in pre_or_post]

# Add column for is this WFS measurement made immediately after a correction
opdtable['wfs_measurement_type'] = pre_or_post
opdtable['is_post_correction'] = ['post' in a for a in pre_or_post]
Expand Down Expand Up @@ -698,7 +694,7 @@ def download_wfsc_images(program=None, obs=None, verbose=False, **kwargs):
filetable = query_wfsc_images_latest(**kwargs)
else:
if verbose:
print(f'Querying WFSC images from program {prog}, observation {obs}')
print(f'Querying WFSC images from program {program}, observation {obs}')
filetable = query_wfsc_images_by_program(program, obs, **kwargs)

# If we found > 0 available files for that visit, then we're done searching and can go on to download
Expand Down
Loading

0 comments on commit fd96a6d

Please sign in to comment.