Skip to content

Commit

Permalink
some pep8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrin committed Feb 6, 2024
1 parent a6a6f0d commit 2ccc748
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions webbpsf/mast_wss.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ def get_visit_nrc_ta_image(visitid, verbose=True, kind='cal'):
from astroquery.mast import Mast
keywords = {
'visit_id': [visitid[1:]], # note: drop the initial character 'V'
#'category': ['CAL'],
'exp_type': ['NRC_TACQ']
}

Expand All @@ -616,7 +615,7 @@ def set_params(parameters):
filename = t[0]['filename']

# If user manually specifies rate or uncal, retrieve that instead
if kind=='rate' or kind=='uncal':
if kind == 'rate' or kind == 'uncal':
filename = filename.replace('_cal.fits', f'_{kind}.fits')

Check warning on line 619 in webbpsf/mast_wss.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/mast_wss.py#L618-L619

Added lines #L618 - L619 were not covered by tests

if verbose:
Expand All @@ -629,7 +628,8 @@ def set_params(parameters):
except urllib.error.HTTPError as err:
if err.code == 401: # Unauthorized

Check warning on line 629 in webbpsf/mast_wss.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/mast_wss.py#L626-L629

Added lines #L626 - L629 were not covered by tests
# Use MAST API to allow retrieval of exclusive access data, if relevant
import astroquery, tempfile
import astroquery
import tempfile
mast_api_token = os.environ.get('MAST_API_TOKEN', None)
mast_obs = astroquery.mast.ObservationsClass(mast_api_token)
uri = f"mast:JWST/product/{filename}"
Expand Down
4 changes: 2 additions & 2 deletions webbpsf/match_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def setup_sim_to_match_file(filename_or_HDUList, verbose=True, plot=False):
if header['PUPIL'].startswith('MASK'):
inst.pupil_mask = header['PUPIL']
if 'CORONMSK' in header:
inst.image_mask = header['CORONMSK'].replace('MASKA', 'MASK') # note, have to modify the value slightly for
# consistency with the labels used in webbpsf
inst.image_mask = header['CORONMSK'].replace('MASKA', 'MASK') # note, have to modify the value slightly for

Check warning on line 42 in webbpsf/match_data.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/match_data.py#L41-L42

Added lines #L41 - L42 were not covered by tests
# consistency with the labels used in webbpsf
inst.set_position_from_aperture_name(header['APERNAME']) # Redo this, in case the image_mask setting auto switched it to something else
elif inst.name == 'MIRI':
if inst.filter in ['F1065C', 'F1140C', 'F1550C']:
Expand Down
11 changes: 5 additions & 6 deletions webbpsf/trending.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ def vprint(*args, **kwargs):

#### Functions for image comparisons
def show_nrc_ta_img(visitid, ax=None, return_handles=False):
""" Retrieve and display a WFS target acq image"""
""" Retrieve and display a NIRCam target acq image"""

hdul = webbpsf.mast_wss.get_visit_nrc_ta_image(visitid)

Expand All @@ -1624,6 +1624,7 @@ def show_nrc_ta_img(visitid, ax=None, return_handles=False):
if return_handles:
return hdul, ax, norm, cmap, bglevel


def nrc_ta_image_comparison(visitid, verbose=False, show_centroid=False):
""" Retrieve a NIRCam target acq image and compare to a simulation
Expand All @@ -1645,7 +1646,7 @@ def nrc_ta_image_comparison(visitid, verbose=False, show_centroid=False):

im_obs_clean = im_obs.copy()
im_obs_clean[im_obs_dq & 1] = np.nan # Mask out any DO_NOT_USE pixels.
im_obs_clean = astropy.convolution.interpolate_replace_nans(im_obs_clean, kernel=np.ones((5,5)))
im_obs_clean = astropy.convolution.interpolate_replace_nans(im_obs_clean, kernel=np.ones((5, 5)))

Check warning on line 1649 in webbpsf/trending.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/trending.py#L1647-L1649

Added lines #L1647 - L1649 were not covered by tests

# Make a matching sim
nrc = webbpsf.setup_sim_to_match_file(hdul, verbose=False)
Expand Down Expand Up @@ -1681,7 +1682,7 @@ def nrc_ta_image_comparison(visitid, verbose=False, show_centroid=False):
try:
oss_cen = misc_jwst.engdb.extract_oss_TA_centroids(osslog, 'V' + hdul[0].header['VISIT_ID'])

Check warning on line 1683 in webbpsf/trending.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/trending.py#L1681-L1683

Added lines #L1681 - L1683 were not covered by tests
# Convert from full-frame (as used by OSS) to detector subarray coords:
oss_cen_sci = nrc._detector_geom_info.aperture.det_to_sci( *oss_cen)
oss_cen_sci = nrc._detector_geom_info.aperture.det_to_sci(*oss_cen)
oss_cen_sci_pythonic = np.asarray(oss_cen_sci) - 1 # convert from 1-based pixel indexing to 0-based
oss_centroid_text = f"\n OSS centroid: {oss_cen_sci_pythonic[0]:.2f}, {oss_cen_sci_pythonic[1]:.2f}"
axes[0].scatter(oss_cen_sci_pythonic[0], oss_cen_sci_pythonic[1], color='0.5', marker='+', s=50)
Expand Down Expand Up @@ -1710,13 +1711,11 @@ def nrc_ta_image_comparison(visitid, verbose=False, show_centroid=False):
transform=axes[0].transAxes,
color='white')


if verbose:
print(f"Star coords from WCS: {targ_coords_pix}")
if oss_cen_sci_pythonic is not None:
print(f"WCS offset = {np.asarray(targ_coords_pix) - oss_cen_sci_pythonic} pix")

Check warning on line 1717 in webbpsf/trending.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/trending.py#L1714-L1717

Added lines #L1714 - L1717 were not covered by tests

#print(oss_cen_sci_pythonic)
except ImportError:
oss_centroid_text = ""

Expand Down Expand Up @@ -1750,6 +1749,6 @@ def nrc_ta_image_comparison(visitid, verbose=False, show_centroid=False):
plt.tight_layout()


outname = f'wfs_ta_comparison_{visitid}.pdf'
outname = f'nrc_ta_comparison_{visitid}.pdf'

Check warning on line 1752 in webbpsf/trending.py

View check run for this annotation

Codecov / codecov/patch

webbpsf/trending.py#L1752

Added line #L1752 was not covered by tests
plt.savefig(outname)
print(f" => {outname}")

0 comments on commit 2ccc748

Please sign in to comment.