Skip to content

Commit

Permalink
fixed bare excepts, restored ambiguous variable ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Jan 15, 2025
1 parent 9e46aa8 commit 6e0ba9c
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions changes/9076.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added more code style rules
8 changes: 4 additions & 4 deletions jwst/ami/lg_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ def simulate(self, fov=None, bandpass=None, over=None, psf_offset=(0, 0)):
nspec = 0
# accumulate polychromatic oversampled psf in the object

for w, ll in bandpass: # w: wavelength's weight, l: lambda (wavelength)
for w, l in bandpass: # w: wavelength's weight, l: lambda (wavelength)
self.psf_over += w * analyticnrm2.psf(
self.pixel, # det pixel, rad
fov, # in detpix number
over,
self.ctrs,
self.d,
ll,
l,
self.phi,
psf_offset, # det pixels
self.affine2d,
Expand Down Expand Up @@ -251,12 +251,12 @@ def make_model(
(self.N * (self.N - 1) + 1, self.over * self.fov, self.over * self.fov)
)

for w, ll in bandpass: # w: weight, l: lambda (wavelength)
for w, l in bandpass: # w: weight, l: lambda (wavelength)
# model_array returns the envelope and fringe model as a list of
# oversampled fov x fov slices
pb, ff = analyticnrm2.model_array(
self.modelctrs,
ll,
l,
self.over,
self.modelpix,
self.fov,
Expand Down
4 changes: 2 additions & 2 deletions jwst/associations/lib/process_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __iter__(self):
while True:
try:
yield self.popleft()
except:
except Exception:
break


Expand Down Expand Up @@ -252,7 +252,7 @@ def __iter__(self):
while True:
try:
yield self.popleft()
except:
except Exception:
break

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion jwst/associations/lib/rules_level3_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def _add_items(self,
def __repr__(self):
try:
file_name, json_repr = self.ioregistry['json'].dump(self)
except:
except Exception:
return str(self.__class__)
return json_repr

Expand Down
6 changes: 3 additions & 3 deletions jwst/associations/tests/test_process_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_process_queue():
idx += 1
try:
to_add = items_to_add[idx]
except:
except IndexError:
pass
else:
queue.extend(to_add)
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_process_queue_sorted():
idx += 1
try:
to_add = items_to_add[idx]
except:
except IndexError:
pass
else:
queue.extend(to_add)
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_process_queue_dups():
idx += 1
try:
to_add = items_to_add[idx]
except:
except IndexError:
pass
else:
queue.extend(to_add)
Expand Down
3 changes: 2 additions & 1 deletion jwst/cube_build/cube_build_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from . import ifu_cube
from . import data_types
import asdf
from asdf.exceptions import ValidationError
from ..assign_wcs.util import update_s_region_keyword
from ..stpipe import Step, record_step_status
from pathlib import Path
Expand Down Expand Up @@ -562,7 +563,7 @@ def check_offset_file(self):

try:
af = asdf.open(self.offset_file, custom_schema=DATA_PATH/'ifuoffset.schema.yaml')
except:
except ValidationError:
schema_message = ('Validation Error for offset file. Fix the offset file. \n' + \
'The offset file needs to have the same number of elements ' + \
'in the three lists: filename, raoffset and decoffset.\n' +\
Expand Down
8 changes: 4 additions & 4 deletions jwst/fits_generator/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def write_observation_identifiers(id):
#
try:
os.remove(filename)
except:
except FileNotFoundError:
pass
## try:
f1 = open(filename, 'w')
Expand All @@ -61,7 +61,7 @@ def remove_observation_identifiers(obsid):
'''Remove the observation identifiers file'''
try:
os.remove(obsid)
except:
except FileNotFoundError:
pass
return

Expand All @@ -77,10 +77,10 @@ def pre_clean():
for file in previous_files:
try:
os.remove(file)
except:
except FileNotFoundError:
pass
os.chdir('..')
except:
except FileNotFoundError:
os.mkdir('previous')
filelist = os.listdir('.')
for file in filelist:
Expand Down
2 changes: 1 addition & 1 deletion jwst/fits_generator/create_dms_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def split_data_and_refout(hdulist):
hdulist[0].data = detectordata
try:
del hdulist[1]
except:
except IndexError:
pass
refhdu = fits.ImageHDU()
refhdu.data = refout
Expand Down
14 changes: 7 additions & 7 deletions jwst/fits_generator/input_file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def is_miri_ifu(hdulist):
return True
else:
return False
except:
except KeyError:
return False

def is_miri_lrs(hdulist):
Expand All @@ -344,7 +344,7 @@ def is_miri_lrs(hdulist):
return True
else:
return False
except:
except KeyError:
return False

def is_nirspec_fm1(hdulist):
Expand Down Expand Up @@ -385,7 +385,7 @@ def is_nirspec_ips(hdulist):
try:
if hdulist[0].header[keywordname].strip():
return True
except:
except KeyError:
return False

def is_nirspec_irs2(hdulist):
Expand All @@ -411,7 +411,7 @@ def is_tfi(hdulist):
return True
else:
return False
except:
except KeyError:
return False

def is_niriss(hdulist):
Expand All @@ -421,7 +421,7 @@ def is_niriss(hdulist):
return True
else:
return False
except:
except KeyError:
return False

def is_niriss_spec_vert(hdulist):
Expand All @@ -433,7 +433,7 @@ def is_niriss_spec_vert(hdulist):
return True
else:
return False
except:
except KeyError:
return False

def is_niriss_spec_horiz(hdulist):
Expand All @@ -444,7 +444,7 @@ def is_niriss_spec_horiz(hdulist):
return True
else:
return False
except:
except KeyError:
return False

input_file_types = [
Expand Down
4 changes: 2 additions & 2 deletions jwst/fits_generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def select_type(fitsfile, level):
sca_id = int(hdulist[0].header['SCA_ID'])
try:
si = sca_to_si_mapping[sca_id]
except KeyError:
except KeyError: # no mapping for that sca_id
raise ValueError(
"Can not automatically determine filetype from file")
except:
except KeyError: # no sca_id keyword in header
raise ValueError("No SCA_ID keyword present")
elif input_file_types.is_ncont(hdulist):
si = 'nircam_ncont'
Expand Down
12 changes: 6 additions & 6 deletions jwst/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,21 +806,21 @@ def _get_boundary_points(xmin, xmax, ymin, ymax, dx=None, dy=None, shrink=0):
b = np.s_[0:sx] # bottom edge
r = np.s_[sx:sx + sy] # right edge
t = np.s_[sx + sy:2 * sx + sy] # top edge
ll = np.s_[2 * sx + sy:2 * sx + 2 * sy] # left
l = np.s_[2 * sx + sy:2 * sx + 2 * sy] # left

x[b] = np.linspace(xmin, xmax, sx, False)
y[b] = ymin
x[r] = xmax
y[r] = np.linspace(ymin, ymax, sy, False)
x[t] = np.linspace(xmax, xmin, sx, False)
y[t] = ymax
x[ll] = xmin
y[ll] = np.linspace(ymax, ymin, sy, False)
x[l] = xmin
y[l] = np.linspace(ymax, ymin, sy, False)

area = (xmax - xmin) * (ymax - ymin)
center = (0.5 * (xmin + xmax), 0.5 * (ymin + ymax))

return x, y, area, center, b, r, t, ll
return x, y, area, center, b, r, t, l


def compute_image_pixel_area(wcs):
Expand Down Expand Up @@ -849,7 +849,7 @@ def compute_image_pixel_area(wcs):
ra, dec, center = np.nan, np.nan, (np.nan, np.nan)
while xmin < xmax and ymin < ymax:
try:
x, y, image_area, center, b, r, t, ll = _get_boundary_points(
x, y, image_area, center, b, r, t, l = _get_boundary_points(
xmin=xmin,
xmax=xmax,
ymin=ymin,
Expand All @@ -867,7 +867,7 @@ def compute_image_pixel_area(wcs):
limits = [ymin, xmax, ymax, xmin]

for j in range(4):
sl = [b, r, t, ll][k]
sl = [b, r, t, l][k]
if not (np.all(np.isfinite(ra[sl])) and
np.all(np.isfinite(dec[sl]))):
limits[k] += dxy[k]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ select = [
# "LOG",
]
ignore = [
"E741", # ambiguous variable name (O/0, l/I, etc.)
]

[tool.ruff.lint.pydocstyle]
Expand Down

0 comments on commit 6e0ba9c

Please sign in to comment.