tools¶
A collection of helper functions to support pysiaf calculations and functionalities.
- pysiaf.utils.tools.compute_roundtrip_error(A, B, C, D, offset_x=0.0, offset_y=0.0, verbose=False, instrument='', grid_amplitude=None)[source]¶
Return the roundtrip error of the distortion transformations specified by A,B,C,D.
Test whether the forward and inverse idl-sci transformations are consistent.
- Parameters:
- Anumpy array
polynomial coefficients
- Bnumpy array
polynomial coefficients
- Cnumpy array
polynomial coefficients
- Dnumpy array
polynomial coefficients
- offset_xfloat
Offset subtracted from input coordinate
- offset_yfloat
Offset subtracted from input coordinate
- verbosebool
verbosity
- instrumentstr
Instrument name
- Returns:
- error_estimation_metric, dx.mean(), dy.mean(), dx.std(), dy.std(), datatuple
mean and std of errors, data used in computations
- pysiaf.utils.tools.convert_polynomial_coefficients(A_in, B_in, C_in, D_in, oss=False, inverse=False, parent_aperture=None)[source]¶
Emulate some transformation made in nircam_get_polynomial_both.
Written by Johannes Sahlmann 2018-02-18, structure largely based on nircamtrans.py code by Colin Cox.
- Parameters:
- A_innumpy array
polynomial coefficients
- B_innumpy array
polynomial coefficients
- C_innumpy array
polynomial coefficients
- D_innumpy array
polynomial coefficients
- ossbool
Whether this is an OSS aperture or not
- inversebool
Whether this is forward or backward/inverse transformation
- parent_aperturestr
Name of parent aperture
- Returns:
- AR, BR, CR, DR, V3SciXAngle, V3SciYAngle, V2Ref, V3Reftuple of arrays and floats
Converted polynomial coefficients
- pysiaf.utils.tools.correct_V3SciXAngle(V3SciXAngle_deg)[source]¶
Correct input angle.
- Parameters:
- V3SciXAngle_deg
- Returns:
- V3SciXAngle_degfloat
- pysiaf.utils.tools.correct_V3SciYAngle(V3SciYAngle_deg)[source]¶
Correct input angle.
- Parameters:
- V3SciYAngle_deg
- Returns:
- V3SciYAngle_deg_correctedfloat
- pysiaf.utils.tools.get_grid_coordinates(n_side, centre, x_width, y_width=None, max_radius=None)[source]¶
Return tuple of arrays that contain the coordinates on a regular grid.
- Parameters:
- n_side: int
Number of points per side. The returned arrays have n_side**2 entries.
- centre: tuple of floats
Center coordinate
- x_width: float
Extent of the grid in the first dimension
- t_width: float
Extent of the grid in the second dimension
- Returns:
- xarray
- yarray
- pysiaf.utils.tools.is_ipython()[source]¶
Function that returns True if the user is in an ipython session and False if they are not
- pysiaf.utils.tools.jwst_fgs_to_fgs_matrix(direction='fgs2_to_fgs1', siaf=None, verbose=False)[source]¶
Return JWST FGS1_OSS to FGS2_OSS transformation matrix as stored in LoadsPRD.
- Parameters:
- siafpysiaf.Siaf instance
JWST FGS SIAF content
- Returns:
- R12ndarray
rotation matrix
References
- pysiaf.utils.tools.match_v2v3(aperture_1, aperture_2, verbose=False, match_v2_only=False)[source]¶
Modify the X[Y]DetRef,X[Y]SciRef attributes of aperture_2 such that V2Ref,V3Ref of both apertures match.
Also shift the polynomial coefficients to reflect the new reference point origin and for NIRCam recalculate angles.
- Parameters:
- aperture_1
pysiaf.Aperture object
Aperture whose V2,V3 reference position is to be used
- aperture_2
pysiaf.Aperture object
The V2,V3 reference position is to be altered to match that of aperture_1
- verbosebool
verbosity
- aperture_1
- Returns:
- new_aperture_2:
pysiaf.Aperture object
An aperture object derived from aperture_2 but with some parameters changed to match altered V2V3.
- new_aperture_2:
- pysiaf.utils.tools.revert_correct_V3SciXAngle(V3SciXAngle_deg)[source]¶
Return corrected V3SciXAngle.
- Parameters:
- V3SciXAngle_degfloat
Angle in deg
- Returns:
- V3SciXAngle_degfloat
Angle in deg
- pysiaf.utils.tools.revert_correct_V3SciYAngle(V3SciYAngle_deg)[source]¶
Return corrected V3SciYAngle.
Only correct if the original V3SciYAngle in [0,180) deg
- Parameters:
- V3SciYAngle_degfloat
angle in deg
- Returns:
- V3SciYAngle_degfloat
Angle in deg
- pysiaf.utils.tools.set_reference_point_and_distortion(instrument, aperture, parent_aperture)[source]¶
Set V2Ref and V3ref and distortion coefficients for an aperture with a parent_aperture.
- Parameters:
- instrumentstr
Instrument name
- aperture
pysiaf.Aperture
object Aperture
- parent_aperture
pysiaf.Aperture
object Parent aperture
- pysiaf.utils.tools.v3sciyangle_to_v3idlyangle(v3sciyangle)[source]¶
Convert V3SciYAngle to V3IdlYAngle.
- Parameters:
- v3sciyanglefloat
angle
- Returns:
- v3sciyanglefloat
angle
- pysiaf.utils.tools.write_matrix_to_file(matrix, file, comments=None, format='jwst_fsw_patch_request')[source]¶
Write the elements of a matrix to a text file.
- Parameters:
- matrixndarray
the matrix
- filestr
output file name
- commentsdict
comments to include in the commented file header
- formatstr
Formatting of matrix elements in output