Geometric distortion and astrometric calibration of the JWST MIRI Medium Resolution Spectrometer

Context. The Medium-Resolution integral ﬁeld Spectrometer (MRS) of MIRI on board JWST performs spectroscopy between 5 and 28 µ m, with a ﬁeld of view varying from ∼ 13 to ∼ 56 arcsec square. The optics of the MRS introduce substantial distortion, and this needs to be rectiﬁed in order to reconstruct the observed astrophysical scene. Aims. We aim to use data from the JWST / MIRI commissioning and cycle 1 calibration phase, to derive the MRS geometric distortion and astrometric solution, a critical step in the calibration of MRS data. These solutions come in the form of transform matrices that map the detector pixels to spatial coordinates of a local MRS coordinate system called α / β , to the global JWST observatory coordinates V2 / V3. Methods. For every MRS spectral band and each slice dispersed on the detector, the transform of detector pixels to α / β is ﬁt by a two-dimensional polynomial, using a raster of point source observations. The dispersed trace of the point source on the detector is initially estimated by ﬁtting a one-dimensional empirical function, and then iterating on the ﬁst distortion solution using forward modelling of the point spread function model based on the webbpsf python package. A polynomial transform is used to map the coordinates from α / β to V2 / V3. Results. We calibrated the distortion of all 198 discrete slices of the MIRI / MRS IFUs, and derived an updated Field of View (FoV) for each MRS spectral band. The precision of the distortion solution is estimated to be better than one tenth of a spatial resolution element, with a root mean square (rms) of 10 milli-arcsecond (mas) at 5 µ m, to 23 mas at 27 µ m. Finally we ﬁnd that the wheel positioning repeatability causes an additional astrometric error of rms 30 mas. Conclusions. We have demonstrated the MRS astrometric calibration strategy and analysis for all four integral ﬁeld units, and all spectral bands of the MRS enabling the calibration of MRS spectra. This is a critical step in the data pipeline of every MRS observation, especially for science with spatially resolved objects. The distortion calibration was folded into the JWST pipeline in Calibration Reference Data System (CRDS) context jwst_1094.pmap. The distortion calibration precision meets the pre-launch requirement, and the estimated total astrometric uncertainty is 50 mas.


Introduction
The Mid-Infrared Instrument (MIRI; Wright et al. 2015Wright et al. , 2023;;Rieke et al. 2015b) is one of four science instruments on board the James Webb Space Telescope (JWST; Gardner et al. 2023) and it is the only instrument operating in the mid-infrared (MIR).The MIRI Medium Resolution Spectrometer (MRS; Wells et al. 2015;Argyriou et al. 2023) is an integral field spectrometer (IFS) providing moderate-resolution spectroscopy (R ∼ 4000 -1500; Jones et al. 2023) over the wavelength range from 4.9 to 27.9 µm (Labiano et al. 2021;Argyriou et al. 2023).In the near-infrared (NIR; 0.6-5.3µm) the Near Infrared Spectrometer (NIRSpec; Böker et al. 2023) also provides an IFS mode that is similar to the MRS.
The advantage of an IFS is that it retains information for both spatial coordinates of the astronomical scene being observed A53, page 1 of 16 Fig. 1.Illustration of MRS coordinate systems.Left: detector coordinates contain the 2D spectra projected by the IFU on the MIRI detectors as curved slices.Middle: local MRS slicer coordinates are changing from band to band and represent the alignment of the slicer optic, with α being the along-slice and β the across-slice coordinate.Right: JWST coordinate system V2+V3 is defined by the JWST Optical Telescope Element (OTE) and is shared among all instruments.Note: this panel is not to scale with the actual dimensions since the MRS FoV is very small.using image slicers (Allington-Smith 2006).The MRS employs one image slicer for each spectral channel (see Figs. 1 and 2).Each image slicer splits one of the spatial dimensions into distinct slices before dispersing the light.The number of slices depends on the physical geometry of the image slicer, optimised for the spectral and spatial resolution element of each MRS channel.The data that are imaged on the MRS detectors are akin to having multiple single slit spectra, one for each slice in a spectral channel.In order to reconstruct the scene observed on the sky one must map each pixel of the detector to a position in right ascension (RA), declination (Dec), and wavelength, accounting for the optical distortion that is typically present in IFS.
In this work, we present the derivation of the geometric distortion and astrometric calibration of the MRS, an essential product of the JWST data processing pipeline.The MRS is spatially and spectrally under-sampled at all wavelengths by design, and requires at least two dithered exposures to be Nyquist sampled.The sampling artefacts and cube reconstruction algorithm are detailed in Law et al. (2023).The optical distortion itself needs to be corrected to sub-pixel precision, since even small residuals can introduce systematic errors in the science products, given the under-sampled point spread function (PSF) core.A well calibrated distortion over the full field of view (FoV) and spectral range is required to maximise the optical quality of the instrument and restore the diffraction-limited performance provided by JWST that is distorted by the optics of the MRS.An accurate plate scale enables a consistent spectro-photometric calibration over the full FoV and reduces errors in the surface brightness estimation for extended sources (Gordon et al. 2022).
In Sect.2, we introduce the relevant coordinate frames and transforms used in the JWST calibration pipeline and discuss the origin of the optical distortion in the MRS.In Sect.3, we describe the different data sources used to derive the distortion calibration and the methods used to estimate the point source traces on the detector.In Sect.4, we detail the analysis steps that were used to derive the geometric and astrometric distortion transforms.Finally, in Sect.5, we discuss the precision of the distortion solution achieved through this work, the astrometric stability due to the repeatability of the grating wheel, and the lessons learned for the astrometric calibration of an IFU instrument for application in future projects.

Brief optical description of the MRS
The optical layout of the MRS is shown in Fig. 2. The light enters the MRS from the JWST focal plane via a pick-off mirror and is relayed to a series of three dichroic filters (D) that split the light into the four MRS spectral channels (1-4) denoted with the different colours in Fig. 2. The dichroic filters are always configured in such a way that the same sub-band (SHORT, MEDIUM, LONG or A, B, C) is observed at one time 1 .The dichroic-filtered light is fed to the input of the four MRS integral field units (IFU), while two blocking filters and corresponding light traps prevent unwanted stray-light from entering the spectrometer.
When entering the IFU of one of the four MRS spectral channels, the input focal plane is anamorphically magnified and re-imaged onto the image slicer of that channel.The image slicer consists of thin mirrors, diamond turned onto a common substrate in a pyramid-like manner (see Fig. 6 in Wells et al. 2015).Each channel has a different number of slicing mirrors, with 21, 17, 16, and 12 for channels 1, 2, 3, and 4, respectively.Each slice is separated spatially by the angle of the slicer mirrors towards a re-imaging mirror with a pupil mask placed in Fig. 2. Optical layout diagram of the MRS.Blue, green, orange, and red identify the paths of the four spectral channels, from 1 to 4, respectively.D stands for dichroic filters, G for diffraction gratings, and FPA is the focal plane assembly where the detectors are located.The figure is adopted from Wright et al. (2023).
the intermediate pupil plane to control the stray-light.The reimaging mirrors create an image of each slice on a slit-let mask that defines the output of the spectral channel IFU.The beams from the slits are then collimated by a mirror and diffracted by the diffraction grating (G) that is located on the reverse side of the same wheel as the dichroic filter that transmitted the wavelengths for the specific spectral channel.The MRS incorporates two wheels, denoted as the dichroic grating wheel assembly A (DGA-A) and dichroic grating wheel assembly B (DGA-B).The first diffraction order of the grating-diffracted beam is imaged onto the detector.The MRS camera optics combine the beams of two channels (1 and 2 and then 3 and 4) and focus the light onto the short wavelength (MIRIFUSHORT) and the long wavelength (MIRIFULONG) Si:As IBC detectors (Rieke et al. 2015a;Argyriou et al. 2020a), respectively2 .

MRS coordinate systems
There are three coordinate systems that are relevant for this work and the MRS, illustrated in Fig. 1.These are (i) the MRS detector coordinates, (ii) the local MRS coordinates, and (iii) the JWST telescope coordinates which are connected to the right ascension (RA) and declination (Dec) of an astronomical object in the sky.
First, the detector coordinates are defined by the pixels of the detector arrays that have a dimension of (1032, 1024).The horizontal axis of the detector is roughly aligned with the MRS IFU image slicer along-slice (denoted as α) spatial coordinate, and the vertical axis is roughly aligned with the dispersion direction, shown on the left panel of Fig. 1.We note that we assume zeroindexed arrays and therefore define the centre of the lower left pixel as (x, y) = (0, 0).
Second, the local MRS coordinates are aligned to the image slicer along-and across-slice direction, denoted as local due to the fact that they are unique to each MRS sub-band.Due to small alignment differences of the slicer optic and the dichroic filters, the slicer location of each MRS sub-band projected on the sky are not perfectly concentric, yielding small boresight and rotation offsets.The along-slice coordinate is defined as α and the across-slice coordinate as β, and both have units of arcseconds.The coordinate β is often used interchangeably with the term "slice," referring to an individual sliced image created by the slicer and dispersed onto the detector.While it does not have a physical connection to the slicer, a third coordinate referring to the wavelength and denoted as λ, is often used in conjunction with α/β to complete the three dimensional (3D) coordinate system of the MRS IFU.In the context of the overall MRS instrument calibration, such as optical distortion, wavelength calibration, fringing, stray-light, and PSF (Wells et al. 2015;Argyriou et al. 2020b;Labiano et al. 2021); together with the detector coordinates, the vector (α, β, λ) operates as a A53, page 3 of 16 Patapis, P., et al.: A&A, 682, A53 (2024) self-contained coordinate system as it offers an intuitive view of the optics.
Third, the JWST Observatory coordinate system is defined and shared among all instruments.It is defined by two orthogonal coordinates on the JWST primary aperture plane called V3, that points towards the secondary mirror support structure, and V2 orthogonal to V33 , as shown in the right panel of Fig. 1.A third coordinate, V1, which is the telescope symmetry axis completes the coordinate system.These coordinates enable the observatory to slew towards a target on-sky and align the target with the instrument selected for the observation.Additionally, it enables dithering strategies and pointing offsets that are essential to some observing modes like coronagraphy and IFU spectroscopy.The coordinates (V2+V3) are given in units of arcseconds.The JWST coordinate system connects to RA and Dec through the V3 position angle (PA), that measures the rotation of the observatory with respect to north when projected on sky.All this information is contained in the JWST Science Instrument Aperture File (SIAF) on board the observatory, with V2+V3 also often referred to as SIAF coordinates.The MRS FoV is located on the far right of the JWST FoV at a distance of 20 arc-seconds from the top right corner of the MIRI Imager, as seen in the right panel of Fig. 1.The FoV of MIRI are rotated with respect to V3 by an angle of ∼4.8 • for the imager, and ∼7.6 • to ∼8.8 • for the MRS, as shown in Fig. 1.

Geometric distortion
Ideally, the optics would disperse and image the spectra of each slice orthogonal to the detector, and similar to most conventional spectrographs, this is not the case for the MRS.The anamorphic optics, as well as the slicer and camera optics introduce significant optical distortion to the imaged field, resulting in the spectra being projected onto the detector as curved lines.This curvature is illustrated in the left panel of Fig. 1 and is typical for slit spectrometers, usually referred to as keystone and smile distortion (Yokoya et al. 2010).The distortion in the along-slice spatial direction is more subtle than just a curved spectrum on the detector; the plate scale (detector pixel subtended angle on the sky), is changing non-linearly as a function of position in the field and wavelength, differently for each slice.This intra-slice distortion appears in both the dispersion and the spatial direction, and the rectification of these coordinates, from detector pixels to MRS local coordinates (α, β, λ), is a crucial step in the JWST calibration pipeline in order to reconstruct the observed astronomical scene and conserve the optical quality of the MRS.
We define two terms.First, lines on the detector that trace a constant value of α are denoted as iso-α lines.Second, lines that trace constant wavelength (λ) are denoted as iso-λ lines (the wavelength distortion calibration based on ground test data is described in detail by Labiano et al. 2021).The transformation of pixel coordinates to local MRS coordinates is referred to as a "detector-to-cube" transformation and is described by a set of polynomial transforms for each sub-band (1A to 4C).Each transform maps the coordinates (x, y) to α, λ as: with K α,s and K λ,s denoting the polynomial coefficient matrices and x s as a reference pixel in the middle of each slice.The polynomial orders were estimated by minimising the residuals of the spectral trace without introducing extrapolation artefacts at the edges of the slices.The β coordinate is discrete and only depends on the slice number since it is collapsed when dispersing the light on the detector.The value of β is given by Eq. ( 3).
where β 0 is the β coordinate of the centre of slice 1 and ∆β the slice width of each channel in arc-seconds.The specific values for each of the MRS spectral channels are tabulated in Table 1, taken from Wells et al. (2015).We define s = 1 at the centre of the first slice, with the edges of the slice being s ± 0.5.There are two transformations to be made.The first is from detector pixels (x, y, s) to (α, β, λ) to account for the MRS specific distortion of each sub-band and, in a second step, we transform the local MRS coordinates (α, β, λ) to the JWST global coordinates (V2+V3).This second transform accounts for distortion introduced by the JWST Optical Telescope Element (OTE), which all instruments are subject to, as well as placing the FoV of the MRS (α, β), that is slightly rotated, onto V2+V3.This is shown in the right panel of Fig. 1.The coordinate transform from (α, β) to V2 + V3 is given by a second order polynomial: where T Ch,V2 , T Ch,V3 are the polynomial coefficient matrices for V2 and V3, respectively.The polynomial order was determined on prior modelling of the distortion at the field location of the MRS and the minimisation of residuals.

Commissioning and cycle 1 calibration
Over the course of the JWST commissioning, the dedicated observations listed in Table 2 were executed to validate and update the distortion of MIRI.For the MRS, the goal was to check the geometric distortion, derive the field transform from local MRS coordinates to the JWST SIAF, update the boresight offsets with respect to the MIRI Imager, and test the MRS dither patterns.The first programme that was used is JWST programme identifier (PID) 1012, consisting of exposures of the MRS internal calibration lamp, which fully illuminates the detector slices and was used to derive the detector slice mask.To help derive the astrometric calibration, the strategy was to observe bright stars with the MRS, including simultaneous MIRI imaging and parallel FGS observations.Both FGS and the MIRI Imager, with their large FoV, contained many stars with very precise astrometric information from Gaia (Lindegren et al. 2016;Gaia Collaboration 2018).PID 1049 and 1050 were part of the PSF measurement and provided very bright sources for channels 3/4 and channels 1/2, respectively.For PID 1049 a red planetary nebula (SMP LMC-58) was observed in the dither patterns optimised for the long channels (3, 4) of the MRS.In PID 1050 a photometric standard A-star (HD 163466) was observed in the point source optimised dither pattern of the channel 1, as well in an extended source dither pattern and at the instrument boresight.
As described in Sect.4, additional observations were needed in order to improve the distortion solution of the MRS.A cycle 1 calibration programme (PID 1524, observation 16) was designed and executed as one of the first calibration programmes post-commissioning, with the goal of characterising the MRS distortion in detail.A custom dither pattern of a bright O-star, 10 Lac, was uploaded to the observatory, which would place the point source to three or more positions in the along-slice direction α for most slices of each channel.This enables the fitting of the plate scale for each slice with the required second-order polynomial (Glauser et al. 2010).The custom dither pattern that includes 57 points is shown in Fig. 3, which shows its overlap with the slicer of each channel.More specifically, 10 Lac was chosen as the target since it was bright enough to be time efficiently observed with 20 frames (∼55 s) per integration, provided sufficient S/N up to channel 4C, and had emission lines that could be used to calibrate the wavelength distortion of the MRS.Finally, subsequent observations of 10 Lac (PID 1524, observation 17) and observations of standard A and G stars through cycle 1 photometric calibration programmes (1536, 1538) that included target acquisition (TA) enabled the astrometric precision monitoring of the MRS.
The standard JWST MIRI MRS pipeline4 (Labiano et al. 2016;Bushouse et al. 2022) was used to process the raw data files from the observations.First the Detector1Pipeline was ran to obtain rate files, namely, slope images (Morrison et al. 2023).From the Spec2Pipeline that deals with the calibration of spectroscopic modes of JWST (for the MRS see Argyriou et al. 2023), we applied processing steps straylight_step and fringe_flat, that mitigate the scattered light and detector fringing effects since these might have biased our analysis.The distortion and astrometric calibration folds into the first step of Spec2Pipeline, that is the assign_wcs.For the derivation of the MRS distortion this step was not applied, and the distortion was derived based on measuring the spectral traces on the detector, as described in Sect.3.2.Dedicated background observations A53, page 5 of 16 for each observation were subtracted on the detector level as rate files.

Detector-based point source tracing
Here, we briefly present the methods used to trace a point source on the detector of the MRS, also shown in Fig. 4.These form the basis of the whole subsequent distortion calibration.There are two quantities that are extracted from the detector: (i) the acrossslice position β of the point source, and (ii) the along-slice, iso-α trace as a function of detector position (x, y).
As per point (i) in the across-slice direction the point source is sampled by the IFU image slicer mirror slices and the goal of the detector-fitting is to estimate the sub-slice position (or slicer coordinate β) of the source.The signal in each slice on the detector is summed, to effectively integrate over the along-slice direction α, and fitted against the slice index s with a pseudo-Voigt profile5 .The validity of this method was tested by taking a theoretical PSF model, sampling it by the number and width of the slices for each MRS band, and comparing the estimated parameter with the input coordinate.The error of the fit in the simulated tests was approximately of the order of a few percent of the slice width.In the bottom right panel of Fig. 4, an example of the slicer coordinate estimation in channel 3 using the bright star from PID 1524 is shown.
As per point (ii) the iso-α can be traced in each slice in two different ways.First, using an empirical PSF profile fit directly on the detector signal.This can be done in a row-by-row manner, or along an iso-λ, with the pixels belonging to a given wavelength bin of a slice identified and fitted by the profile.Both a Gaussian and a pseudo-Voigt function were tested with the Voigt function resulting in a better fit (shown in Labiano et al. 2021, Fig. 4).The pseudo-Voigt function is motivated by the fact that the light scattered within the MIRI detectors (Gáspár et al. 2021) produces elongated wings for the MRS PSF (Argyriou et al. 2023;Patapis et al., in prep.), and a similar behaviour is also seen in the MIRI Imager (Dicken et al., in prep.).For slices that contain a significant fraction of the PSF core the iso-α traces are well fitted this way, since the PSF is symmetric, the centre of the empirical profile coincides with the centre of the PSF.
For slices illuminated by the PSF wings and not containing a significant part of the PSF core (mainly in channels 3 and 4), we estimate the iso-α traces on the detector using forward modelling of the theoretical MRS PSF as shown in Fig. 5.The MRS PSF was modelled using the python package webbpsf The centre of the webbPSF model is optimised to match the data on the detector and estimate the centre of the given point source exposure.For accurately centred slices this works well, while for slices further from the PSF centre, the discrepancy between model and data is larger; however, the source centre estimation is not significantly affected.(Perrin et al. 2016) and was broadened by convolution with a Gaussian kernel to match the optical quality observed in flight.The detailed description of this model and the commissioning PSF analysis for the MRS is described in Patapis et al. in prep.The PSF model is then interpolated onto the detector using the distortion model and iterating with each update of the distortion.In Fig. 5, we show that the PSF model and distortion solution from ground are sufficient to reproduce the profile of a point source on the detector within 5% for slices close to the PSF core (top-right panel in Fig. 5) and worsening to residual error of ∼20% for slices further away (bottom right panel in Fig. 5).Even with higher residuals, the error on the centre is in the order to 10% of a pixel.This validity of the fitting was tested for multiple locations in the FoV, different rows on the detector, and for all bands.

Systematic errors from ground calibration
A preliminary calibration of the MRS geometric distortion was performed using the ground calibration data (Glauser et al. 2010;Wells et al. 2015), based on the optical design model of the MRS (modelled using the ray tracing software Zemax OpticStudio).That original analysis was performed using reconstructed cubes, median-collapsed in wavelength, while applying slice to slice corrections.The solution from the tweaked Zemax OpticStudio model was precise to approximately 0.5-1 resolution element depending on the band, however, the following issues observed in ground and flight data have motivated a new derivation of the distortion solution for the MRS.
First, the initial calibration used the cubes median-collapsed in wavelength to correct the MRS optical design model.This collapsing in wavelength left a significant systematic error in α as a function of wavelength, of the order of a pixel (see Sect. 3.2.3 in Argyriou 2021).The systematic error was partially corrected by re-fitting the ground data on the detector level which mitigated the issue (see Appendix A).However, when tested on flight data, at the top of the detector and for all available points a similar systematic was present, underestimating the iso-α trace compared to the middle and bottom of the detector by half a pixel.With comparisons between bands pointing towards a global distortion systematic error, it potentially stems from issues in the optics of the test illumination source setup used in ground testing.
Second, by comparing the commanded offsets in V2+V3 coordinates with the ones estimated from fitting the point source centre on the detector, we found misalignment between slices in some bands, while in other bands (especially those in channel 3) there was evident magnification errors within the slices.All these systematic errors are probably tied to discrepancies in the estimated coordinate transforms using the ground test data, given the low S/N, non-diffraction-limited and asymmetric PSF and distortion of optical test setup, and a lack of point source data for more recent observatory level campaigns.These errors are of the order of 1 pixel.
In order to minimise these systematic residuals in the alpha distortion calibration and to derive the astrometric calibration that maps the local MRS coordinates to the V2+V3 coordinate frame, we use the PID 1524 cycle 1 calibration observations of the O-star 10 Lac shown in Fig. 3.The updated distortion transforms are then tested on the commissioning observations to estimate the residual error in the distortion, as well as the estimated absolute astrometric error.

Correction of telescope attitude matrix
Although target acquisition can reliably place a star in the MIRI MRS to an accuracy of about 30 mas 6 , the absolute position information of the world coordinate solution (WCS) association with any given observation is typically only accurate to about 300 mas due to a combination of errors in the guide star catalogue and uncertainty in the spacecraft roll angle.For the purposes of calibrating the absolute location of the MRS within the telescope focal plane we therefore obtained simultaneous FGS and MIRI imaging data in parallel with the dithered MRS observations.
Using 25 bright stars in the FGS imaging field with Gaia DR3 (Gaia Collaboration 2018) astrometry, we re-derived the telescope attitude matrix for each of our exposures, improving the absolute positional accuracy of the WCS to 30 mas.The FGS and MIRI imaging data likewise were used to confirm that the relative accuracy of the commanded dither offsets was good to 10 mas or better, which was deemed more than sufficient for our analysis.

Detector slice mask
We began the analysis by deriving the detector slice mask that maps the projected slits on the MRS detectors.For a spatially homogeneous extended source illumination of the MRS, the signal within a slice is flat across the MRS FoV, dropping off rapidly at the edges.This allows for the derivation of the FoV limits along these slices (x-direction) for each detector row.We did so solely on the basis of the signal values on the detector and no other calibration information was required.The extended illumination was provided by flight observations of the internal calibration source from PID 1012.
To derive the FoV limits on the detector plane for each slice, we have to measure the drop in throughput at the slice edges.The deviation of the overall throughput in each slice from an ideal boxcar function, however, makes this a non-trivial challenge.The derivation of an accurate slice mask is thus limited by the accurate definition of the throughput at the slice edges.
The algorithm to derive a slice mask performs the following three steps for all slices in a MRS channel for each detector row.Firstly, the minima (troughs) in the signal separating the slices are identified as shown in the top plot of Fig. 6.These minima bound the slices in each channel.Secondly, the throughput of each slice is determined by first fitting a 3rd order polynomial to the signal values of the pixels that are well within the slice (5 pixels from the slice edges).This is shown in the middle right plot of Fig. 6.The signal between two minima surrounding the slice is then divided by the fitted 3rd order polynomial, this yields an estimation of the slice throughput as shown middle left plot of Fig. 6.Thirdly, a throughput criterion is used to define the leftmost and right-most pixel that contributes to a slice (edges of the MRS FoV).We show the result for one detector row in channel 1, in the bottom plot of Fig. 6.
Iterating the above steps for each detector row produces a 2D slice mask.In fact, we have defined not one, but nine slice masks using this method.These nine slice masks correspond to different slice throughput levels, from 10% throughput to 90% throughput.The JWST MIRI/MRS pipeline uses an 80% transmission cut-off by default.This value was chosen due to the steep throughput decline and the fact that our spectro-photometric calibration uncertainty gets larger at the edges of the slices.

Field of view definition
As seen in Fig. 3, not every slice of the dither pattern in PID 1524 (observation 16) has point sources centred on it.We identified which exposures had signal in a given slice by iterating through all exposures, and finding the three along α that had the maximum signal in the slice.These exposures were then selected to calculate the V2+V3 to α/β transform.We fitted their slicer coordinate on the detector using the pseudo-Voigt profile fitting shown in Fig. 4.Then, using the matrix form of a coordinate rotation Eqs. ( 6) and ( 7), the FoV was defined based on the V2 + V3 coordinates reported in the metadata.
This assumes that the V2 + V3 field is not significantly distorted over the size of the FoV of the MRS.Even if the field distortion is not negligible, we implicitly incorporate this distortion term in the α distortion model.The absolute α coordinate does not need to be correct in this step since we are mainly interested in ∆α, the distance of the points along the α coordinate in order to calibrate the slice specific distortion.The final α+ β system is defined after the new α distortion is derived.

Along-slice α distortion calibration
With the relative astrometry derived from the V2+V3 transform derived in Sect.4.4, we can measure and fit the distortion in the iso-α traces for every slice in each of the 12 spectral sub-bands (1A-4C).As described in Sect.3.2, with the forward modelling of the PSF, we were able to fit the signal on the detector even for slices that do not contain the core of the PSF.We fit the α distortion with a (N x, Ny) = (2, 4) order polynomial.These values for A53, page 8 of 16 the polynomial provided enough flexibility to fit the distortion everywhere on the detector without suffering from over-fitting especially at the edges of slices.Finally, we set the local MRS coordinate field to be centred around zero.We calculated the α FoV limits for each slice using the detector slice mask and the newly derived α distortion and subtract the mean FoV value from the intercept coefficient of the polynomial transform of each slice.

Local MRS to JWST V2 + V3 coordinates transform
The last step of the analysis is to refine the V2 + V3 to α+ β transform, this time using the calibrated α distortion.This yields important parameters for the boresight offsets of the MRS bands in the V2+V3 frame that is used by FGS to guide targets to the MRS and perform dithering offsets.The optimised dither pattern can be re-calculated given the new distortion and V2 + V3 to α+ β transform, and a polynomial transform shown in Eqs. ( 4) and ( 5) is fitted.In Fig. 7, we show the final footprints of the MRS FoV of each band in the V2+V3 coordinate system and in Table 3, we list the relevant parameters for each band.

Verification and estimated precision
To test the validity of the full chain of calibration we use other point source observations from PID 1049 and PID 1050, comparing their predicted locations in α/β to the ones measured from the data.The results are shown in Fig. 8 and the numbers reported in Table 4.In the top panel, a single observation of the A-star from PID 1050 was used to compare the iso-α trace.For each row, the centre of the point source is fitted using the Voigt profile and transformed into α, λ using the distortion solution from Wells et al. (2015), the pre-launch distortion (Appendix A), and the distortion derived from flight data.Since the star should have a fixed spatial coordinate (α, β) as a function of wavelength, this Notes.The angle refers to the rotation of the MRS slicer coordinate frame with respect to the JWST V3 coordinate.The angle estimate uncertainty is 10% for channels 1-3 and 20% for channel 4.
illustrates the improvement of the latest distortion model.The residual modulation of the iso-α trace that is seen in the bottom panel of Fig. 8, we plot the distribution of the residual between expected α based on the pointing telemetry, and the measured iso-α trace from the detector for all (10-13) individual dithers per band.Since we were interested in the relative error within a given MRS band, we subtracted the mean residual, so that the distributions ended up centred around zero.This removes any global offset which can arise from pointing errors or repeatability issues discussed in Sect.5.1.The standard deviation of a fitted Gaussian distribution to the residuals is reported, satisfying in all bands the tenth of a resolution element goal set out for the MRS α distortion.
Another example of illustrating that the distortion solution works as intended is to visualise a point source in the reconstructed cube.In Fig. 9, we show an A star (PID 1050, observation 9) in band 1A, with all ten dither positions combined with the size of the pixel in the cube (also referred to as spaxel, see Law et al. 2023 for details) set to 0.05 ′′ and binned over a broad wavelength bin of 0.05 µm in order to increase the signal-to-noise ratio (S/N).This oversampling of the MRS PSF is possible because of the number of dithers available in the given observation, but also the fact that a broad wavelength bin naturally samples the PSF better due to the iso-α trace being curved on the detector.The JWST PSF is revealed in detail, and we also observe the wings of the PSF at high S/N.

Repeatability of the grating wheel assembly
During commissioning, it was found that the repeatability of the angular positioning of the wheel induced measurable astrometric offsets.Each time the wheel moves between observations to select a different dichroic filter and grating setting, it returns to a given position with some uncertainty of around 0.5-1 pixels projected on the detector, based on the MIRI optical model.For example, the NIRSpec grating wheel also shows similar repeatability performance, which was already known from A53, page 9 of 16 ground testing (Böker et al. 2023) and mostly affects the dispersion direction.For NIRSpec, two sensors measure these offsets and accordingly adjust the distortion model to compensate for it (Alves de Oliveira et al. 2022).Unfortunately for the MRS, the positioning sensors do not have the required resolution to measure the changes in the wheel position.We note that the MRS DGA wheels were designed in such a way that repeatability in the dispersion direction would be very precise and no measurable repeatability error has been reported in flight.
In order to assess the repeatability of the astrometric solution we compared results across about ten different observations of standard stars obtained throughout the cycle 1 calibration programme using data from PIDs 1050, 1524, 1536, and 1538.Each of these programmes used target acquisition to observe wellknown point sources in all twelve MRS bands, and all used a standard dither pattern (except PID 1524 Observation 16, which used the custom 57-point pattern).For each observation, we constructed a full 5-28 micron data cube and measured the centroid location of the target star as a function of wavelength in this cube.
We plot the result in Fig. 10, showing the relative offset from the median position in the alpha and beta directions as a function of wavelength.While the β direction positions are extremely stable from band to band, we note more significant jumps between individual bands in the α direction, with an rms of about 30 mas.This represents roughly a 1/5 detector pixel or better repeatability overall, albeit with some extreme cases in which the offsets A53, page 10 of 16 Patapis, P., et al.: A&A, 682, A53 (2024)   can be as large as about 1/2 pixel.In Channel 2B for instance, we note a significant difference between -0.05 arcsec and +0.07 arcsec between successive observations of 10 Lac (blue and red points) during which the observatory remained in fine guide status and the only mechanism that moved between two sets of dithers was the DGA wheel.Another fact pointing towards the wheel repeatability being the issue is the fact that the channel 1-4 and 2-3 offsets are anti-correlated, as one would expect from the optics of the MRS.The gratings of these pairs (1-4, 2-3) are respectively located on the same DGA wheel, and due to an additional reflection for channels 3 and 4, an offset in angle of the wheel will move the beam towards the opposite direction compared to channels 1 and 2.
For calibration purposes, we fit the average offset from the mean for each of the twelve bands and applied this boresight offset to the latest distortion reference files.This ensures that the astrometric location of a star is on average consistent across all MRS bands, even if repeatability can sometimes cause deviations from this mean position for individual observations.
The impact of the wheel repeatability on the data reduction and science products of the MRS was tested using the repeated measurement of PID 1524 (observation 17).We compared the exposures for band 2B which showed the worst offset (Fig. 10, 2B in blue and red points).No measurable change in the calibrated iso-α trace, besides a constant astrometric offset, is found.Presumably, the displacement of the beam due to the diffraction grating is still within the linear regime of the distortion.Therefore, with no significant distortion effects, there are some minor issues that arise from the non-repeatability of the source on the detector between different dichroic settings.First, for extended sources where the astrometry cannot be measured in the data, the alignment of the bands in the 3D cube will not be exact and spatial features will appear to shift between bands.Due to the wavelength overlap between the bands, such cases can potentially be mitigated by examining the common wavelengths and the behaviour of any features from one band to the other.Second, dedicated point source fringe flats based on calibration observations would not be directly applicable since the point source fringes change rapidly from pixel to pixel on the detector (Argyriou et al. 2020b;Gasman et al. 2023).Third, astrometric measurements of the same source from different epochs might be biased and should include the repeatability error in its uncertainty.Finally, due to the relatively small FoV, complex scenes involving extended structures of interest or multiple sources need to be planned more carefully, taking into account the additional astrometric uncertainty of 100 mas.

Lessons learned for future calibration
Due to its design and operating wavelengths, the MRS is a challenging instrument to calibrate.A series of instrumental effects are present due to a combination of design choices and peculiarities of the MIRI detectors, such as spectral fringing, scattered light within the detector, under-sampling of the PSF, and optical distortion (Argyriou et al. 2023).The following list identifies some of the insights for testing an IFU, after a decade of calibration work performed by the instrument team.
-Testing the MRS in the lab, at conditions representative of its flight status is challenging.The MIRI Telescope Simulator, built specifically for testing MIRI, could not provide a bright diffraction limited point source at all wavelengths, due to a combination of optical distortions of the test setup and lack of flux of the test light source.Therefore, the early investment and development of a robust testing facility is key.
-For calibrating the distortion and astrometry pre-flight, a well-defined point source that can be steered precisely in the FoV of the IFU is required, correlated to a distortion free reference frame.This could potentially be the steering stage X, Y positions.Even with its limitations the ground testing provided many insights into the distortion of the MRS, and was able to deliver a preliminary calibration.
-Hardware tested in flight will potentially reveal new instrumental systematic errors that were not caught in the instrument testing on ground.Therefore, planning for dedicated commissioning observations for all key parameters is essential.
A53, page 11 of 16 Patapis, P., et al.: A&A, 682, A53 (2024) Fig. 10.Change in the PSF centroid location as a function of wavelength for 5-28 µm data cubes constructed from dithered observations of a variety of standard stars observed by PIDs 1050, 1524, 1536, and 1538 (processed using the distortion solution derived in this work).The top panel shows offsets along the α direction, and the lower panel offsets along the β direction.Three different sets of data points are given for 10 Lac Observation 17 as these data were obtained during three complete rotations of the DGA assembly while the guide star remained locked explicitly to test the position repeatability of the DGA.While the typical rms is much better than 10 mas for the β direction, repeatability in the α direction is about 30 mas rms.
Additionally, allowing for the flexible project management of commissioning was valuable in adapting the observations and tests based on the first sets of data that were obtained.
-Finally, careful planning and development of the optimised dither pattern used for PID 1524 (observation 16) enabled the calibration of the distortion efficiently using a bright star.Additionally the same data set could be used for multiple additional tests like wavelength, fringing, optical quality, and photometric calibration as a function of the position in the FoV.

Summary
We have derived the full astrometric distortion solution of the MRS, based on flight data.The calibration of JWST field coordinates V2 + V3 to the local MRS slicer coordinates α/β is required for the operation of the MRS, used during pointing and dithering of observations.The transform from detector to α/β and subsequently V2 + V3, enables the pipeline to correct for the optical distortion introduced due to the IFUs, a required step for the rectification of the 2D detector data into 3D cubes, that reconstruct the observed astronomical scene and allow for the extraction of spectra.A good understanding of the distortion might enable modelling of the MRS PSF and application of optimised forward modelling approaches for MRS data.The final precision of the distortion solution ranges from 10 mas in channels 1-3, up to 23 mas in channel 4. The total astrometric uncertainty of a given MRS exposure with target acquisition is estimated to be 50 mas, given by σ 2 distortion + σ 2 T A + σ 2 repeatability .ensure the minimisation converged, we restricted the evaluation of the loss function within an aperture of 0.5" around the point source (∼3 slices on the image slicer).This process yielded new centroids which were in turn used to calculate the new transform with Eq.A.1.Second, using the distortion solution derived earlier, the PSF model is projected onto the detector for every row to estimate the iso-α trace accounting for the shape of the PSF.This is repeated for every point in the raster scan, and the distortion was estimated again on the updated traces.The projection uses the estimate of the slice coordinate from the detector to provide the PSF αprofile expected in the slice of interest.Typically this only works for slices either containing the peak of the PSF, or the slices adjacent to that, due to the low S/N of the FM data.Here, the scipy function interp1d was used, once again with a linear interpolation.
With the iso-α traces and MTS to α/β field transform based upon the FM PSF, we re-calculated all the distortion polynomial coefficients as in Sect.Appendix A.4. Article number, page 16 of 16

Fig. 3 .
Fig. 3. Dither points from commissioning and cycle 1 calibration, with each panel illustrating the outline of each channel's slicer.The black crosses correspond to the dither pattern of 10 Lac executed during PID 1524 (observation 16), optimised to characterise the intra-slice distortion.The red points correspond to the point and extended dither pattern optimised for channel 1 (PID 1050, observation 9), and the violet points correspond to the point source dither pattern of channel 3 (PID 1049, observation 2).

Fig. 4 .
Fig. 4. Detector tracing for MRS point sources.Top row: detector images of bright star 10 Lac from PID 1524 showing left the IFUSHORT detector (channels 1 and 2), and right IFULONG (channels 3 and 4).Bottom left: single row of detector showing the PSF projected on it and fit with pseudo-Voigt function (inset) to estimate the centre in the detector x (corresponding to α) coordinate.The centre of the trace for the brightest slice (core of the PSF) coincides with the centre of the PSF.Bottom right: collapsed signal over a given number of detector rows in each slice is fitted with a pseudo-Voigt profile to estimate the across slice coordinate s (equivalent to β).
Fig. 5. Forward modelling of the MRS webbPSF used for the estimation of iso-α trace.The detector trace is determined by collapsing the corresponding slice in the webbPSF model along β and projecting the α profile of the PSF to the detector using the estimated distortion solution.The centre of the webbPSF model is optimised to match the data on the detector and estimate the centre of the given point source exposure.For accurately centred slices this works well, while for slices further from the PSF centre, the discrepancy between model and data is larger; however, the source centre estimation is not significantly affected.

Fig. 6 .
Fig. 6.Slice-masking process based on internal calibration source exposures measured in flight (PID 1012).Top: signal of single detector row of calibration source, and finding the minima of the extended illumination correspond to the slice gaps.Middle: normalising the illumination in order to calculate the transmission factors.Bottom: with the normalised slices, the pixel locations of various transmission levels for each slice and each row are calculated.

Fig. 7 .
Fig. 7. MRS band footprints in V2+V3 coordinates.This corresponds to the FoV of the MRS on sky, information that is used for pointing and dithering with the MRS.

Fig. 8 .
Fig. 8. Relative distortion residuals.Top: point source trace on the detector was extracted from PID 1050, and the distortion solution from Wells et al. (2015), and this work was used to transform the iso-α trace into α, λ coordinates.Since the point source should have a fixed spatial coordinate, this illustrates the improvement in the distortion model using the flight data.The residual modulation originates from the under-sampling of the MRS PSF.Bottom: distribution of iso-α residuals for all dither point of PID 1049 and PID 1050, obtained by applying the distortion transforms derived in this work.

Fig. 9 .
Fig. 9. MRS Optical quality (band 1A) with data from PID 1050 enabled by the distortion solution derived in this work.The cube building step (Law et al. 2023) uses a spaxel size of 0.05 ′′ and a wavelength bin of 0.05 µm with the drizzle algorithm in IFUALIGN mode, which builds the cube in the α, β coordinate frame.The diffraction pattern (JWST 'petals') of the PSF is revealed.

Fig. A. 3 .
Fig. A.3.Estimation of the MTS PSF from the FM PSF observations.The individual dithers are combined into a higher resolution PSF, revealing the shape of the MTS point source.This PSF can be used when iterating the distortion solution in order to improve centroid estimation.

Fig. A. 4 .
Fig. A.4. Forward modelling of the FM PSF used for the estimation of α, β centroids, and the iso-α trace.Top left: High resolution interpolated model of FM PSF.Top right: Reconstructed cube of a single point source exposure using the initial distortion solution.Bottom right: Model PSF interpolated on the grid of the cube to match the observed data.Bottom left: Difference between the data and projected PSF model.

Table 2 .
Commissioning and cycle 1 calibration programmes and stars used for the in-flight calibration.

Table 3 .
MRS field of view in global JWST coordinate system after finalising the distortion solution based on PID 1524.

Table 4 .
Argyriou et al. (2023)rtion calibration.Notes.The values for α correspond to the rms of all observations that were tested.Wavelength values are taken fromArgyriou et al. (2023)and converted into pixels assuming the central wavelength of the band.