Skip to content

Commit 6893f47

Browse files
JP-3769: Add code style F, E, W rules (#9076)
2 parents e012b4e + 5c741f3 commit 6893f47

File tree

83 files changed

+559
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+559
-448
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,12 @@ the 'main' branch.
163163
runs several different checks including running the unit tests, ensuring
164164
the documentation builds, checking for code style issues (see the [PEP8](https://peps.python.org/pep-0008/) style guide),
165165
and ensuring any changes are covered by unit tests. The CI runs upon opening
166-
a PR, and will re-run any time you push commits to that branch.
167-
* You will need to add a change log entry in CHANGES.rst if your contribution
168-
is a new feature or bug fix. An entry is not required for small fixes like typos.
166+
a PR, and will re-run any time you push commits to that branch.
167+
* Our code style checker uses [ruff](https://docs.astral.sh/ruff/), and using
168+
`ruff check` locally can be helpful to identify style issues before opening a PR.
169+
* You will need to add a change log entry in changes/PRID.fragmenttype.rst
170+
if your contribution is a new feature or bug fix.
171+
An entry is not required for small fixes like typos.
169172
* Your PR will need to be reviewed and approved by at least two maintainers.
170173
They may require changes from you before your code can be merged, in which
171174
case you will need to go back and make these changes and push them (they will

changes/9076.general.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added more code style rules

jwst/ami/ami_analyze_step.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def override_bandpass(self):
4747
"""
4848
Read bandpass from asdf file and use it to override the default.
4949
50-
Expects an array of [effstims, wave_m]
50+
Expects an array of [effstims, wave_m]
5151
(i.e. np.array((effstims,wave_m)).T) stored as 'bandpass' in asdf file,
5252
where effstims are normalized countrates (unitless) and wave_m are the
5353
wavelengths across the filter at which to compute the model (meters).
54-
54+
5555
Returns
5656
-------
5757
bandpass: array
@@ -65,21 +65,21 @@ def override_bandpass(self):
6565
# assume it is an array of the correct shape
6666
wavemin = np.min(bandpass[:,1])
6767
wavemax = np.max(bandpass[:,1])
68-
self.log.info('User-defined bandpass provided:')
68+
self.log.info('User-defined bandpass provided:')
6969
self.log.info('\tOVERWRITING ALL NIRISS-SPECIFIC FILTER/BANDPASS VARIABLES')
7070
self.log.info(f'Using {bandpass.shape[0]} wavelengths for fit.')
7171
self.log.info(f'Wavelength min: {wavemin:.3e} \t Wavelength max: {wavemax:.3e}')
7272

7373
# update attribute and return
74-
self.bandpass = bandpass
74+
self.bandpass = bandpass
7575
return bandpass
7676

7777
except FileNotFoundError:
7878
message = f'File {self.bandpass} could not be found at the specified location.'
7979
raise Exception(message)
8080

8181
except KeyError:
82-
message1 = 'ASDF file does not contain the required "bandpass" key. '
82+
message1 = 'ASDF file does not contain the required "bandpass" key. '
8383
message2 = 'See step documentation for info on creating a custom bandpass ASDF file.'
8484
raise Exception((message1 + message2))
8585

@@ -90,9 +90,9 @@ def override_bandpass(self):
9090

9191
def override_affine2d(self):
9292
"""
93-
Read user-input affine transform from ASDF file.
93+
Read user-input affine transform from ASDF file.
9494
95-
Makes an Affine2d object (see utils.Affine2D class).
95+
Makes an Affine2d object (see utils.Affine2D class).
9696
Input should contain mx,my,sx,sy,xo,yo,rotradccw.
9797
"""
9898
try:
@@ -117,7 +117,7 @@ def override_affine2d(self):
117117
affine2d = None
118118

119119
except KeyError:
120-
message1 = 'ASDF file does not contain all of the required keys: mx, my, sx, sy ,xo, yo, rotradccw. '
120+
message1 = 'ASDF file does not contain all of the required keys: mx, my, sx, sy ,xo, yo, rotradccw. '
121121
message2 = 'See step documentation for info on creating a custom affine2d ASDF file.'
122122
self.log.info((message1 + message2))
123123
self.log.info('\t **** DEFAULTING TO USE IDENTITY TRANSFORM ****')

jwst/ami/bp_fix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ def fourier_corr(data, pxdq, fmas):
209209
210210
References
211211
----------
212-
M. J. Ireland, Phase errors in diffraction-limited imaging: contrast limits
213-
for sparse aperture masking, Monthly Notices of the Royal Astronomical
214-
Society, Volume 433, Issue 2, 01 August 2013, Pages 1718–1728,
215-
https://doi.org/10.1093/mnras/stt859
212+
M. J. Ireland, Phase errors in diffraction-limited imaging: contrast limits
213+
for sparse aperture masking, Monthly Notices of the Royal Astronomical
214+
Society, Volume 433, Issue 2, 01 August 2013, Pages 1718–1728,
215+
https://doi.org/10.1093/mnras/stt859
216216
"""
217217

218218
# Get the dimensions.

jwst/ami/instrument_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def __init__(self,
2929
"""
3030
Initialize NIRISS class for NIRISS/AMI instrument.
3131
32-
Module for defining all instrument characteristics including data format,
32+
Module for defining all instrument characteristics including data format,
3333
wavelength info, and mask geometry.
3434
3535
Parameters
3636
----------
3737
filt: string
3838
filter name
39-
39+
4040
nrm_model: NRMModel datamodel
4141
datamodel containing mask geometry information
4242

jwst/ami/lg_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
class LgModel:
2121
"""
22-
A class for conveniently dealing with an "NRM object."
23-
22+
A class for conveniently dealing with an "NRM object."
23+
2424
This should be able to take an NRMDefinition object for mask geometry.
2525
Defines mask geometry and detector-scale parameters.
2626
Simulates PSF (broadband or monochromatic)
@@ -195,8 +195,8 @@ def make_model(
195195
"""
196196
Generates the fringe model.
197197
198-
Use the attributes of the object with a bandpass that is either a single
199-
wavelength or a list of tuples of the form
198+
Use the attributes of the object with a bandpass that is either a single
199+
wavelength or a list of tuples of the form
200200
[(weight1, wavl1), (weight2, wavl2),...]. The model is
201201
a collection of fringe intensities, where nholes = 7 means the model
202202
has a @D slice for each of 21 cosines, 21 sines, a DC-like, and a flux
@@ -300,7 +300,7 @@ def fit_image(
300300
"""
301301
Run a least-squares fit on an input image.
302302
303-
Find the appropriate wavelength scale and rotation.
303+
Find the appropriate wavelength scale and rotation.
304304
If a model is not specified then this
305305
method will find the appropriate wavelength scale, rotation (and
306306
hopefully centering as well -- This is not written into the object yet,
@@ -425,7 +425,7 @@ def improve_scaling(
425425
self, img, scaleguess=None, rotstart=0.0, centering="PIXELCENTERED"
426426
):
427427
"""
428-
Determine the scale and rotation that best fits the data.
428+
Determine the scale and rotation that best fits the data.
429429
430430
Correlations
431431
are calculated in the image plane, in anticipation of data with many

jwst/ami/mask_definition_ami.py

Lines changed: 104 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,108 +5,108 @@
55

66
class NRMDefinition():
77

8-
def __init__(self, nrm_model, maskname='jwst_ami', chooseholes=None):
9-
"""
10-
Set attributes of NRMDefinition class.
11-
12-
Get hole centers and other mask geometry details from NRMModel, apply rotations/flips
13-
as necessary and set them as attributes.
14-
15-
Parameters
16-
----------
17-
nrm_model: NRMModel
18-
datamodel containing NRM reference file data
19-
maskname: string
20-
Identifier for mask geometry; default 'jwst_ami', optional
21-
chooseholes: list
22-
None, or e.g. ['B2', 'B4', 'B5', 'B6'] for a four-hole mask, optional
23-
If None, use real seven-hole mask
24-
"""
25-
26-
if maskname not in ['jwst_ami','jwst_g7s6c']:
27-
raise ValueError("Mask name not supported")
28-
29-
self.maskname = maskname # there's only one mask but this is used in oifits
30-
self.hdia = nrm_model.flat_to_flat
31-
self.activeD = nrm_model.diameter
32-
self.OD = nrm_model.pupil_circumscribed
33-
self.ctrs = []
34-
35-
self.read_nrm_model(nrm_model, chooseholes=chooseholes)
36-
37-
def read_nrm_model(self, nrm_model, chooseholes=None):
38-
"""
39-
Calculate hole centers with appropriate rotation.
40-
41-
Parameters
42-
----------
43-
nrm_model: NRMModel
44-
datamodel containing NRM reference file data
45-
chooseholes: list
46-
None, or e.g. ['B2', 'B4', 'B5', 'B6'] for a four-hole mask
47-
48-
Returns
49-
-------
50-
f2f: float
51-
flat-to-flat distance of mask holes
52-
ctrs_asbuilt: array
53-
Actual hole centers [meters]
54-
"""
55-
56-
ctrs_asdesigned = np.array([[nrm_model.x_a1, nrm_model.y_a1], # B4 -> B4
57-
[nrm_model.x_a2, nrm_model.y_a2], # C5 -> C2
58-
[nrm_model.x_a3, nrm_model.y_a3], # B3 -> B5
59-
[nrm_model.x_a4, nrm_model.y_a4], # B6 -> B2
60-
[nrm_model.x_a5, nrm_model.y_a5], # C6 -> C1
61-
[nrm_model.x_a6, nrm_model.y_a6], # B2 -> B6
62-
[nrm_model.x_a7, nrm_model.y_a7]]) # C1 -> C6
63-
64-
65-
66-
holedict = {} # as_built names, C2 open, C5 closed, but as designed coordinates
67-
# Assemble holes by actual open segment names (as_built). Either the full mask or the
68-
# subset-of-holes mask will be V2-reversed after the as_designed centers are defined
69-
# Debug orientations with b4,c6,[c2]
70-
allholes = ('b4', 'c2', 'b5', 'b2', 'c1', 'b6', 'c6')
71-
72-
for hole, coords in zip(allholes,ctrs_asdesigned):
73-
holedict[hole] = coords
74-
75-
if chooseholes: # holes B4 B5 C6 asbuilt for orientation testing
76-
holelist = []
77-
for h in allholes:
78-
if h in chooseholes:
79-
holelist.append(holedict[h])
80-
ctrs_asdesigned = np.array(holelist)
81-
82-
ctrs_asbuilt = ctrs_asdesigned.copy()
83-
84-
# create 'live' hole centers in an ideal, orthogonal undistorted xy pupil space,
85-
# eg maps open hole C5 in as_designed to C2 as_built, eg C4 unaffected....
86-
ctrs_asbuilt[:, 0] *= -1
87-
88-
# LG++ rotate hole centers by 90 deg to match MAST o/p DMS PSF with
89-
# no affine2d transformations 8/2018 AS
90-
# LG++ The above aligns the hole pattern with the hex analytic FT,
91-
# flat top & bottom as seen in DMS data. 8/2018 AS
92-
ctrs_asbuilt = rotate2dccw(ctrs_asbuilt, np.pi / 2.0) # overwrites attributes
93-
94-
# create 'live' hole centers in an ideal, orthogonal undistorted xy pupil space,
95-
self.ctrs = ctrs_asbuilt
96-
97-
def showmask(self):
98-
"""
99-
Calculate the diameter of the smallest centered circle (D)
100-
enclosing the live mask area
101-
102-
Returns
103-
-------
104-
Diameter of the smallest centered circle
105-
106-
"""
107-
radii = []
108-
for ctr in self.ctrs:
109-
radii.append(math.sqrt(ctr[0] * ctr[0] + ctr[1] * ctr[1]))
110-
111-
return 2.0 * (max(radii) + 0.5 * self.hdia)
8+
def __init__(self, nrm_model, maskname='jwst_ami', chooseholes=None):
9+
"""
10+
Set attributes of NRMDefinition class.
11+
12+
Get hole centers and other mask geometry details from NRMModel, apply rotations/flips
13+
as necessary and set them as attributes.
14+
15+
Parameters
16+
----------
17+
nrm_model: NRMModel
18+
datamodel containing NRM reference file data
19+
maskname: string
20+
Identifier for mask geometry; default 'jwst_ami', optional
21+
chooseholes: list
22+
None, or e.g. ['B2', 'B4', 'B5', 'B6'] for a four-hole mask, optional
23+
If None, use real seven-hole mask
24+
"""
25+
26+
if maskname not in ['jwst_ami','jwst_g7s6c']:
27+
raise ValueError("Mask name not supported")
28+
29+
self.maskname = maskname # there's only one mask but this is used in oifits
30+
self.hdia = nrm_model.flat_to_flat
31+
self.activeD = nrm_model.diameter
32+
self.OD = nrm_model.pupil_circumscribed
33+
self.ctrs = []
34+
35+
self.read_nrm_model(nrm_model, chooseholes=chooseholes)
36+
37+
def read_nrm_model(self, nrm_model, chooseholes=None):
38+
"""
39+
Calculate hole centers with appropriate rotation.
40+
41+
Parameters
42+
----------
43+
nrm_model: NRMModel
44+
datamodel containing NRM reference file data
45+
chooseholes: list
46+
None, or e.g. ['B2', 'B4', 'B5', 'B6'] for a four-hole mask
47+
48+
Returns
49+
-------
50+
f2f: float
51+
flat-to-flat distance of mask holes
52+
ctrs_asbuilt: array
53+
Actual hole centers [meters]
54+
"""
55+
56+
ctrs_asdesigned = np.array([[nrm_model.x_a1, nrm_model.y_a1], # B4 -> B4
57+
[nrm_model.x_a2, nrm_model.y_a2], # C5 -> C2
58+
[nrm_model.x_a3, nrm_model.y_a3], # B3 -> B5
59+
[nrm_model.x_a4, nrm_model.y_a4], # B6 -> B2
60+
[nrm_model.x_a5, nrm_model.y_a5], # C6 -> C1
61+
[nrm_model.x_a6, nrm_model.y_a6], # B2 -> B6
62+
[nrm_model.x_a7, nrm_model.y_a7]]) # C1 -> C6
63+
64+
65+
66+
holedict = {} # as_built names, C2 open, C5 closed, but as designed coordinates
67+
# Assemble holes by actual open segment names (as_built). Either the full mask or the
68+
# subset-of-holes mask will be V2-reversed after the as_designed centers are defined
69+
# Debug orientations with b4,c6,[c2]
70+
allholes = ('b4', 'c2', 'b5', 'b2', 'c1', 'b6', 'c6')
71+
72+
for hole, coords in zip(allholes,ctrs_asdesigned):
73+
holedict[hole] = coords
74+
75+
if chooseholes: # holes B4 B5 C6 asbuilt for orientation testing
76+
holelist = []
77+
for h in allholes:
78+
if h in chooseholes:
79+
holelist.append(holedict[h])
80+
ctrs_asdesigned = np.array(holelist)
81+
82+
ctrs_asbuilt = ctrs_asdesigned.copy()
83+
84+
# create 'live' hole centers in an ideal, orthogonal undistorted xy pupil space,
85+
# eg maps open hole C5 in as_designed to C2 as_built, eg C4 unaffected....
86+
ctrs_asbuilt[:, 0] *= -1
87+
88+
# LG++ rotate hole centers by 90 deg to match MAST o/p DMS PSF with
89+
# no affine2d transformations 8/2018 AS
90+
# LG++ The above aligns the hole pattern with the hex analytic FT,
91+
# flat top & bottom as seen in DMS data. 8/2018 AS
92+
ctrs_asbuilt = rotate2dccw(ctrs_asbuilt, np.pi / 2.0) # overwrites attributes
93+
94+
# create 'live' hole centers in an ideal, orthogonal undistorted xy pupil space,
95+
self.ctrs = ctrs_asbuilt
96+
97+
def showmask(self):
98+
"""
99+
Calculate the diameter of the smallest centered circle (D)
100+
enclosing the live mask area
101+
102+
Returns
103+
-------
104+
Diameter of the smallest centered circle
105+
106+
"""
107+
radii = []
108+
for ctr in self.ctrs:
109+
radii.append(math.sqrt(ctr[0] * ctr[0] + ctr[1] * ctr[1]))
110+
111+
return 2.0 * (max(radii) + 0.5 * self.hdia)
112112

0 commit comments

Comments
 (0)