# On The Spherical Clothoid

Alexandru Ionut

###### Abstract

We revisit a nonlinear spline primitive for 3-space first studied by Even
Mehlum. It is the spherical clothoid, the spherical curve with geodesic
curvature a linear function of arc length. We present its Cartesian coordinate
functions using confluent hypergeometric functions (the Kummer functions) and
its stereographic projection onto the complex plane. New Humbert series
results are also presented along with generating function formulas related to
the associated Meixner-Pollaczek polynomials.

##  1 Notation

The Pochhammer symbol:

$(q)_{n}=q(q+1)\dots(q+n-1)=\frac{\Gamma(q+n)}{\Gamma(q)}$

Gauss’ hypergeometric series [1]:

${}_{2}F_{1}(a,b,c;z)=\sum_{m=0}^{\infty}\frac{(a)_{m}(b)_{m}}{(c)_{m}}\frac{z^{m}}{m!}$

The confluent hypergeometric functions (the Kummer function) [2]:

${}_{1}F_{1}(a,b;z)=\sum_{m=0}^{\infty}\frac{(a)_{m}}{(b)_{m}}\frac{z^{m}}{m!}$

Humbert hypergeometric series in 2 variables [3, 4]:

$\phi_{1}(a,b,c;x,y)=\sum_{m,n=0}^{\infty}\frac{(a)_{m+n}(b)_{m}}{(c)_{m+n}}\frac{x^{m}}{m!}\frac{y^{n}}{n!}$
$\phi_{2}(b_{1},b_{2},c;x,y)=\sum_{m,n=0}^{\infty}\frac{(b_{1})_{m}(b_{2})_{n}}{(c)_{m+n}}\frac{x^{m}}{m!}\frac{y^{n}}{n!}$
$\Xi_{1}(a_{1},a_{2},b,c;x,y)=\sum_{m,n=0}^{\infty}\frac{(a_{1})_{m}(a_{2})_{n}(b)_{m}}{(c)_{m+n}}\frac{x^{m}}{m!}\frac{y^{n}}{n!}$

The parabolic cylinder functions, even and odd solutions to
$\frac{d^{2}y}{dz^{2}}-(\frac{1}{4}z^{2}+a)y=0$ (19.2.1, 19.2.2 in [5]):

$y_{1}(a;z)=e^{\frac{-z^{2}}{4}}\,_{1}F_{1}\left(\frac{1}{2}a+\frac{1}{4},\frac{1}{2};\frac{z^{2}}{2}\right)$
$y_{2}(a;z)=ze^{\frac{-z^{2}}{4}}\,_{1}F_{1}\left(\frac{1}{2}a+\frac{3}{4},\frac{3}{2};\frac{z^{2}}{2}\right)$

The associated Meixner-Pollaczek polynomials $Q_{n}^{\lambda}(x;\phi,c)$ [6,
7] defined by the recurrence relation:

$\displaystyle 0=$
$\displaystyle\phantom{+}(n+c+1)Q_{n+1}^{\lambda}(x;\phi,c)$
$\displaystyle-2[(n+\lambda+c)\cos\phi+x\sin\phi]Q_{n}^{\lambda}(x;\phi,c)$
$\displaystyle+(n+2\lambda+c-1)Q_{n-1}^{\lambda}(x;\phi,c)$

where $n=0,1,2...$ and $Q_{-1}^{\lambda}(x;\phi,c)=0$,
$Q_{0}^{\lambda}(x;\phi,c)=1$

##  2 Summary of prior work

In mathematics, the word _spline_ has come to mean a function defined
piecewise by polynomials with certain continuity constraints. We are
interested in a more general concept i.e. nonlinear splines meaning the curve
primitive, the building block of the spline, can be an analytic function. In
English, The term _spline_ goes back centuries referring to the flexible strip
of wood used by draftsmen to draw smooth curves. Lead weights called _ducks_
or _whales_ held the spline in place at certain points and the strip would
take the shape that minimized the bending energy yielding a smooth curve. This
shape arising in the physical world corresponds to the minimum energy curve
(MEC) i.e. the curve that minimizes the $L^{2}$ norm of curvature (see [8] for
a more comprehensive treatise).

We can also examine the MEC spline element in 3D space. First we recall that
the intrinsic quantities needed to describe the shape of a space curve are its
curvature $\kappa$ and torsion $\tau$ as functions of arc length $s$. Mehlum
derived the relationship between curvature and torsion for this curve and a
differential equation characterizing the curvature (1.4 and 1.3 in[9]):

$\kappa^{2}\tau=C$ (1)
$\left[(\kappa^{2})^{\prime}\right]^{2}+\kappa^{2}\left[(\kappa^{2}-2D)^{2}-4\psi^{2}\right]+4C^{2}=0$
(2)

$C$, $D$, and $\psi$ are constants.

The calculus of variations problem is solved without the approximation that
leads to the ubiquitous cubic spline. However, working with the MEC in
practical applications can have its own drawbacks. Mehlum goes on to study a
modified version of the differential equation for curvature. (1.5 and 1.6 in
[9]) Assuming $\kappa^{2}\ll 2D$ yields:

$\left[(\kappa^{2})^{\prime}\right]^{2}-4\alpha^{2}\kappa^{2}+4C^{2}=0$ (3)

$\alpha=\psi^{2}-D^{2}$ is a constant. We have a simple solution:

$\kappa^{2}=\alpha^{2}s^{2}+\frac{C^{2}}{\alpha^{2}}$ (4)

When $C=0$ the resulting planar curve is the clothoid i.e. curvature is a
linear function of arc length. The clothoid has since been heavily
investigated in the theory of nonlinear planar splines [10, 11, 8]. For all
other $C$, Mehlum discovered that this curve lies on a sphere and that
$R=\frac{\alpha}{C}$ (2.16 in [9]). Mehlum and Wimp bring up a known necessary
and sufficient condition for a space curve to be spherical (2.8 in [12]):

$\frac{\tau}{\kappa}-\Big{(}\frac{\kappa^{\prime}}{\tau\kappa^{2}}\Big{)}^{\prime}=0$
(5)

Mehlum and Resch [9] go on to describe this curve with a geometric/kinematic
construction by rolling a sphere without slipping or twisting on a planar
clothoid. They thereby reveal that this is the spherical curve with geodesic
curvature a linear function of arc length (see[13], Theorem 2.3):

$\kappa_{g}=\alpha s$ (6)

It is fitting to call it the sherical clothoid, a term first coined by Ülo
Lumiste [14] in work unrelated to the theory of nonlinear splines.

Mehlum manages to express the cartesian coordinate functions of the spherical
clothoid using Humbert series $\phi_{1}$, $\phi_{2}$ and some more common
functions.

##  3 Novel results

###  3.1 Simplified hypergeometric Representation

The main purpose of this work is to present a simpler hypergeometric
representation of the coordinate functions. Without loss of generality, we
will restrict our attention to the case $R=1$ since all other curves can be
obtained with simple scaling. Let $\bm{r}(s)=(x(s),y(s),z(s))$ be the
parametric equation of our space curve. We consider the differential equation
and initial conditions first examined by Mehlum (1.13, 2.17, 2.18, 2.19 and
2.21 in [9]):

$\begin{cases}\bm{r}^{\prime\prime\prime\prime}(s)+(\alpha^{2}s^{2}+1)\bm{r}^{\prime\prime}(s)+3\alpha^{2}s\bm{r}^{\prime}(s)=\bm{0}\\\
\bm{r}(0)=(0,0,0)\\\ \bm{r}^{\prime}(0)=(1,0,0)\\\
\bm{r}^{\prime\prime}(0)=(0,1,0)\\\
\bm{r}^{\prime\prime\prime}(0)=(-1,0,\alpha)\\\ \end{cases}$ (7)

The following solution holds:

$\begin{cases}x(s)=\Re\left(s\,_{1}F_{1}\left(-\frac{\mathrm{i}}{8\,\alpha},\frac{1}{2};-\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\,_{1}F_{1}\left(\frac{\mathrm{i}}{8\,\alpha}+\frac{1}{2},\frac{3}{2};\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\right)\\\
y(s)=-2{\left|\,{}_{1}F_{1}\left(\frac{\mathrm{i}}{8\,\alpha},\frac{1}{2};\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\right|}^{2}+2\\\
z(s)=\Im\left(s\,_{1}F_{1}\left(-\frac{\mathrm{i}}{8\,\alpha},\frac{1}{2};-\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\,_{1}F_{1}\left(\frac{\mathrm{i}}{8\,\alpha}+\frac{1}{2},\frac{3}{2};\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\right)\end{cases}$ (8)

$x$, $y$ and $z$ can also be expressed equivalently using conjugation instead
of using real and imaginary parts and the absolute value. Consult Appendix A
for a computer-assisted proof using Mathematica.

Figure 1: Plot of the spherical clothoid for $\alpha=1$ and $s\in[-5,5]$

###  3.2 Derivation

We begin by investigating a loose end from the kinematic construction. The
following system of equations describes the rolling without slipping and
twisting of a unit sphere on a planar clothoid with scale factor $\alpha$ (see
3 in [15] and 29a in [16]) :

$\frac{d}{ds}\begin{pmatrix}\tilde{x}\\\ \tilde{y}\\\
\tilde{z}\end{pmatrix}=\begin{pmatrix}0&0&-\sin\left(\frac{\alpha
s^{2}}{2}\right)\\\ 0&0&\cos\left(\frac{\alpha s^{2}}{2}\right)\\\
\sin\left(\frac{\alpha s^{2}}{2}\right)&-\cos\left(\frac{\alpha
s^{2}}{2}\right)&0\end{pmatrix}\begin{pmatrix}\tilde{x}\\\ \tilde{y}\\\
\tilde{z}\end{pmatrix}$ (9)

We introduce two new complex variables (see 10 in [15], 8 in [16]):

$\tilde{x}=ab^{*}+ba^{*},\tilde{y}=\mathrm{i}\left(ab^{*}-ba^{*}\right),\tilde{z}=aa^{*}-bb^{*}.$
(10)

This tool was first presented by Feynman, Vernon and Hellwarth to
geometrically represent the Schrödinger equation of a two-level quantum system
[17]. $a$ and $b$ must satsfy the following system in order for
$\tilde{x}$,$\tilde{y}$ and $\tilde{z}$ to satisfy (9):

$\mathrm{i}\frac{d}{ds}\begin{pmatrix}a\\\
b\end{pmatrix}=-\frac{1}{2}\begin{pmatrix}0&e^{-\mathrm{i}\alpha s^{2}/2}\\\
e^{\mathrm{i}\alpha s^{2}/2}&0\end{pmatrix}\begin{pmatrix}a\\\ b\end{pmatrix}$
(11)

We are now left with a system that can be solved directly in a computer
algebra system. Consult Appendix B for a solution using Mathematica. This
system arises in the Landau-Zener problem (4, [18]). In fact, Zener first
solved this system analytically using parabolic cylinder functions in this
quantum physics context.
We then obtain the solution to Mehlum’s equation using (10) again and a rigid
motion to satisfy the initial conditions.

###  3.3 Stereographic projection

Figure 2: Plot of the spherical clothoid and its stereographic projection for
$\alpha=1$ and $s\in[0,5]$

Stereographic projection is a mapping that projects the sphere onto the plane.
Circles on the sphere are mapped to circles on the plane (as long as they do
not pass through the point of projection) and loxodromes are mapped to
logarithmic spirals. We shift the sphere to center it on the origin and
consider the stereographic projection of our curve onto the complex plane:

$\begin{split}\zeta(s)&=X(s)+\mathrm{i}Y(s)\\\
&=\frac{x(s)+\mathrm{i}z(s)}{1-(y(s)-1)}\\\
&=\frac{s\,_{1}F_{1}\left(\frac{\mathrm{i}}{8\,\alpha}+\frac{1}{2},\frac{3}{2};\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)}{2\,_{1}F_{1}\left(\frac{\mathrm{i}}{8\,\alpha},\frac{1}{2};\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)}\end{split}$ (12)

We also have an alternative representation using a quotient of odd and even
parabolic cylinder functions:

$\zeta(s)=\frac{e^{-\mathrm{i}\pi/4}\;y_{2}\left(\frac{\mathrm{i}}{4\alpha}-\frac{1}{2};e^{\mathrm{i}\pi/4}\sqrt{\alpha}s\right)}{2\sqrt{\alpha}\;\;\;\,y_{1}\left(\frac{\mathrm{i}}{4\alpha}-\frac{1}{2};e^{\mathrm{i}\pi/4}\sqrt{\alpha}s\right)}$
(13)

###  3.4 Humbert series corollaries

Let us revisit Mehlum and Wimp’s work on the spherical clothoid. We begin with
Mehlum’s hypergeometric expression for $y$ restricted to the unit sphere (2.54
in [9]):

$y(s)=1-\phi_{2}\left(\frac{\mathrm{i}}{4\,\alpha},-\frac{\mathrm{i}}{4\,\alpha},\frac{1}{2};\frac{\mathrm{i}\,\alpha
s^{2}}{2},-\frac{\mathrm{i}\,\alpha s^{2}}{2}\right)$ (14)

Combining this work with our new representation yields a novel reduction
formula for a special form of $\phi_{2}$:

$\phi_{2}\left(a,-a,\frac{1}{2};x,-x\right)=2\,_{1}F_{1}\left(\frac{a}{2},\frac{1}{2};x\right)\,_{1}F_{1}\left(-\frac{a}{2},\frac{1}{2};-x\right)-1$
(15)

We can use some suggestions in Mehlum’s work to obtain an expression for
$x+\mathrm{i}z$ using $\phi_{1}$ special forms and less mysterious functions
(see Appendix B for the derivation):

$\begin{split}&u=\frac{\sqrt{\pi}\cos(\pi\frac{\mathrm{i}}{4\,\alpha})\Gamma\left(-\frac{\mathrm{i}}{4\,\alpha}-\frac{1}{2}\right)}{\frac{\mathrm{i}}{4\,\alpha}\Gamma\left(-\frac{\mathrm{i}}{8\,\alpha}\right)^{2}}\\\
&v=-\frac{\sqrt{\pi}\cos(\pi\frac{\mathrm{i}}{4\,\alpha})\Gamma\left(\frac{\mathrm{i}}{4\,\alpha}-\frac{1}{2}\right)}{2\Gamma\left(\frac{\mathrm{i}}{8\,\alpha}+\frac{1}{2}\right)^{2}}\\\
&\phi_{1}=\phi_{1}\left(\frac{\mathrm{i}}{4\,\alpha}+1,\frac{\mathrm{i}}{4\,\alpha},\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2};\frac{1}{2},\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\\\
&\phi_{1}^{*}=\phi_{1}\left(-\frac{\mathrm{i}}{4\,\alpha}+1,-\frac{\mathrm{i}}{4\,\alpha},-\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2};\frac{1}{2},-\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\\\
&x(s)+\mathrm{i}\,z(s)=s\left(u\,e^{-\frac{\mathrm{i}\,\alpha
s^{2}}{2}}\phi_{1}+v\,e^{\frac{\mathrm{i}\,\alpha
s^{2}}{2}}\phi_{1}^{*}\right)\end{split}$ (16)

Once again combining this with our new representation yields a new identity:

$\begin{split}&\phantom{-}\frac{\sqrt{\pi}\cos(\pi
a)\Gamma\left(-a-\frac{1}{2}\right)}{a\Gamma\left(-\frac{a}{2}\right)^{2}}e^{-x}\phi_{1}\left(a+1,a,a+\frac{3}{2};\frac{1}{2},x\right)\\\
&-\frac{\sqrt{\pi}\cos(\pi
a)\Gamma\left(a-\frac{1}{2}\right)}{2\Gamma\left(\frac{a+1}{2}\right)^{2}}e^{x}\phi_{1}\left(-a+1,-a,-a+\frac{3}{2};\frac{1}{2},-x\right)\\\\[8.5359pt]
&\qquad\qquad\qquad=\,_{1}F_{1}\left(-\frac{a}{2},\frac{1}{2};-x\right)\,_{1}F_{1}\left(\frac{a}{2}+\frac{1}{2},\frac{3}{2};x\right)\end{split}$
(17)

It is interesting to note that these reductions demystify some quadratic
relationships for special functions studied by Mehlum and Wimp (section 5 in
[12]).

###  3.5 Generating function formulas related to the associated Meixner-
Pollaczek polynomials

Mehlum found expressions for the parameter functions of the spherical clothoid
involving associated Meixner-Pollaczek polynomials (2.38, 2.39 and 2.40 in
[9]):

$x(s)=\sum_{j=0}^{\infty}Q_{j}^{0}(\frac{1}{4\alpha};\frac{\pi}{2},\frac{1}{2})\frac{\left(\frac{-\alpha}{2}\right)^{j}s^{2j+1}}{(1)_{j}}$
(18)
$y(s)=\frac{1}{2}\sum_{j=0}^{\infty}Q_{j}^{0}(\frac{1}{4\alpha};\frac{\pi}{2},1)\frac{\left(\frac{-\alpha}{2}\right)^{j}s^{2j+2}}{\left(\frac{3}{2}\right)_{j}}$
(19)
$z(s)=\frac{\alpha}{6}\sum_{j=0}^{\infty}Q_{j}^{0}(\frac{1}{4\alpha};\frac{\pi}{2},\frac{3}{2})\frac{\left(\frac{-\alpha}{2}\right)^{j}s^{2j+3}}{(2)_{j}}$
(20)

Generating functions related to this family of orthogonal polynomials arise in
recent research [19, 20, 21]. Combining these expressions with our new
parameter functions, we obtain the following generating function results:

$\begin{split}\sum_{j=0}^{\infty}Q_{j}^{0}(x;\frac{\pi}{2},\frac{1}{2})\frac{t^{j}}{j!}=&\frac{1}{2}\Bigg{(}\,_{1}F_{1}\left(-\frac{\mathrm{i}x}{2},\frac{1}{2};\mathrm{i}t\right)\,_{1}F_{1}\left(\frac{\mathrm{i}x}{2}+\frac{1}{2},\frac{3}{2};-\mathrm{i}t\right)\\\
&+\,_{1}F_{1}\left(\frac{\mathrm{i}x}{2},\frac{1}{2};-\mathrm{i}t\right)\,_{1}F_{1}\left(-\frac{\mathrm{i}x}{2}+\frac{1}{2},\frac{3}{2};\mathrm{i}t\right)\Bigg{)}\end{split}$
(21)

$\sum_{j=0}^{\infty}Q_{j}^{0}(x;\frac{\pi}{2},1)\frac{t^{j}}{\left(\frac{3}{2}\right)_{j}}=\frac{\,{}_{1}F_{1}\left(\frac{\mathrm{i}x}{2},\frac{1}{2};-\mathrm{i}t\right)\,_{1}F_{1}\left(-\frac{\mathrm{i}x}{2},\frac{1}{2};\mathrm{i}t\right)-1}{2xt}$
(22)

$\begin{split}\sum_{j=0}^{\infty}Q_{j}^{0}(x;\frac{\pi}{2},\frac{3}{2})\frac{t^{j}}{(j+1)!}=&\frac{3\mathrm{i}}{2t}\Bigg{(}\,_{1}F_{1}\left(-\frac{\mathrm{i}x}{2},\frac{1}{2};\mathrm{i}t\right)\,_{1}F_{1}\left(\frac{\mathrm{i}x}{2}+\frac{1}{2},\frac{3}{2};-\mathrm{i}t\right)\\\
&-\,_{1}F_{1}\left(\frac{\mathrm{i}x}{2},\frac{1}{2};-\mathrm{i}t\right)\,_{1}F_{1}\left(-\frac{\mathrm{i}x}{2}+\frac{1}{2},\frac{3}{2};\mathrm{i}t\right)\Bigg{)}\end{split}$
(23)

##  4 Conclusion

We have found simple expressions for the Cartesian coordinates of the
spherical clothoid and its projection with some special function results as a
bonus. It is remarkable that tools from quantum physics elucidate a classical
problem. Suddenly this curve studied by Mehlum does not seem so exotic,
heightening its potential in the world of computer aided geometric design. The
computation of the special functions presented in this work presents an avenue
for future research.

##  5 Acknowledgments

I would like to thank Dr. Zurab Silagadze for discussions that sparked the
idea behind this hypergeometric reduction tied to the spherical clothoid. I am
grateful to Dr. Khalid Ahbli, Dr. James Hateley, Max Kölbl and Dr. Robert
Lewis for their attention and support during my research.

##  Appendix A ODE solution verification

Mathematica Session

⬇

In[1]:= x[s_]:=1/2 s Hypergeometric1F1[-(I/(8 $\alpha$)),1/2,-((I $\alpha$
s^2)/2)] Hypergeometric1F1[1/2+I/(8 $\alpha$),3/2,(I $\alpha$ s^2)/2]+1/2 s
Hypergeometric1F1[I/(8 $\alpha$),1/2,(I $\alpha$ s^2)/2]
Hypergeometric1F1[1/2-I/(8 $\alpha$),3/2,-((I $\alpha$ s^2)/2)]

In[2]:= y[s_]:=2-2 Hypergeometric1F1[-(I/(8 $\alpha$)),1/2,-((I $\alpha$
s^2)/2)] Hypergeometric1F1[I/(8 $\alpha$),1/2,(I $\alpha$ s^2)/2]

In[3]:= z[s_]:=1/(2 I) s Hypergeometric1F1[-(I/(8 $\alpha$)),1/2,-((I $\alpha$
s^2)/2)] Hypergeometric1F1[1/2+I/(8 $\alpha$),3/2,(I $\alpha$ s^2)/2]-1/(2 I)
s Hypergeometric1F1[I/(8 $\alpha$),1/2,(I $\alpha$ s^2)/2]
Hypergeometric1F1[1/2-I/(8 $\alpha$),3/2,-((I $\alpha$ s^2)/2)]

In[4]:= r[s_]:={x[s],y[s],z[s]}

In[5]:= r[0]

Out[5]= {0,0,0}

In[6]:= r’[0]

Out[6]= {1,0,0}

In[7]:= r”[0]

Out[7]= {0,1,0}

In[8]:= FullSimplify[r”’[0]]

Out[8]= {-1,0,$\alpha$}

In[9]:= FullSimplify[r””[s]+($\alpha$^2 s^2 + 1) r”[s] + 3 $\alpha$^2 s r’[s]]

Out[9]= {0,0,0}

##  Appendix B Complex differential equation system

Here we take an experimental approach and consider the following initial
conditions: $a(0)=1,b(0)=0$ (implying
$\tilde{x}(0)=0,\tilde{y}(0)=,\tilde{z}(0)=1$)

Mathematica Session

⬇

In[1]:=DSolve[{a’[s] == 1/2 I b[s] E^(1/2 (-I) $\alpha$ s^2), b’[s] == 1/2 I
a[s] E^(1/2 I $\alpha$ s^2), a[0] == 1, b[0] == 0}, {a, b}, s]

Out[1]={{a -> Function[{s}, E^(-(1/2) I s^2 $\alpha$) Hypergeometric1F1[-((-I
- 4 $\alpha$)/(8 $\alpha$)), 1/2, 1/2 I s^2 $\alpha$]], b -> Function[{s}, 1/2
s (I Hypergeometric1F1[1 - (-I - 4 $\alpha$)/(8 $\alpha$), 3/2, 1/2 I s^2
$\alpha$] + 4 $\alpha$ Hypergeometric1F1[1 - (-I - 4 $\alpha$)/(8 $\alpha$),
3/2, 1/2 I s^2 $\alpha$] - 4 $\alpha$ Hypergeometric1F1[-((-I - 4 $\alpha$)/(8
$\alpha$)) 1/2, 1/2 I s^2 $\alpha$])]}}

In[2]:=FullSimplify[E^(-(1/2) I s^2 $\alpha$) Hypergeometric1F1[-((-I - 4
$\alpha$)/(8 $\alpha$)), 1/2, 1/2 I s^2 $\alpha$]]

Out[2]=Hypergeometric1F1[-(I/(8 $\alpha$)), 1/2, -(1/2) I s^2 $\alpha$]

In[3]:=FullSimplify[1/2 s (I Hypergeometric1F1[1 - (-I - 4 $\alpha$)/(8
$\alpha$), 3/2, 1/2 I s^2 $\alpha$] + 4 $\alpha$ Hypergeometric1F1[1 - (-I - 4
$\alpha$)/(8 $\alpha$), 3/2, 1/2 I s^2 $\alpha$] - 4 $\alpha$
Hypergeometric1F1[-((-I - 4 $\alpha$)/(8 $\alpha$)), 1/2, 1/2 I s^2
$\alpha$])]

Out[3]= 1/2 I s Hypergeometric1F1[1/2 + I/(8 $\alpha$), 3/2, 1/2 I s^2
$\alpha$]

##  Appendix C Mehlum’s $x+\mathrm{i}\,z$

Combining Mehlum’s expression for $x$ and $z$ (2.65 and 2.67 in [9]) and a
Humbert series transform (2.61 and 2.62 in [9]), it is possible to obtain
expressions of this form:

$\begin{split}x(s)+\mathrm{i}\,z(s)&=s\left(u\,e^{-\frac{\mathrm{i}\,\alpha
s^{2}}{2}}\phi_{1}+v\,e^{\frac{\mathrm{i}\,\alpha
s^{2}}{2}}\phi_{1}^{*}\right)\\\
&=s\left(u\,\Xi_{1}+v\,\Xi_{1}^{*}\right)\end{split}$ (24)

$u$, $v$ do not depend on $s$ and these are the special forms of $\Xi_{1}$ we
are playing with:

$\begin{split}\Xi_{1}&=\Xi_{1}\left(\frac{\mathrm{i}}{4\,\alpha},\frac{1}{2},\frac{\mathrm{i}}{4\,\alpha}+1,\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2};\frac{1}{2},-\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\\\
&=\sum_{m=0}^{\infty}\frac{(\frac{1}{2})_{m}}{(\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2})_{m}}{}_{2}F_{1}(\frac{\mathrm{i}}{4\,\alpha},\frac{\mathrm{i}}{4\,\alpha}+1,\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2}+m;\frac{1}{2})\frac{(-\frac{\mathrm{i}\,\alpha
s^{2}}{2})^{m}}{m!}\\\
\Xi_{1}^{*}&=\Xi_{1}\left(-\frac{\mathrm{i}}{4\,\alpha},\frac{1}{2},-\frac{\mathrm{i}}{4\,\alpha}+1,-\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2};\frac{1}{2},\frac{\mathrm{i}\,\alpha
s^{2}}{2}\right)\\\
&=\sum_{m=0}^{\infty}\frac{(\frac{1}{2})_{m}}{(-\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2})_{m}}{}_{2}F_{1}(-\frac{\mathrm{i}}{4\,\alpha},-\frac{\mathrm{i}}{4\,\alpha}+1,-\frac{\mathrm{i}}{4\,\alpha}+\frac{3}{2}+m;\frac{1}{2})\frac{(\frac{\mathrm{i}\,\alpha
s^{2}}{2})^{m}}{m!}\\\ \end{split}$ (25)

Let’s examine the special forms of ${}_{2}F_{1}$ that arise. We first recall
some identities derived by Mitra (2.68 and 2.69 in [9]):

$_{2}F_{1}\left(a,a+1,a+\frac{1}{2};\frac{1}{2}\right)=\sqrt{\pi}\Gamma\left(a+\frac{1}{2}\right)\left[\frac{1}{\Gamma\left(\frac{a}{2}+\frac{1}{2}\right)^{2}}+\frac{1}{\Gamma\left(\frac{a}{2}+1\right)\Gamma\left(\frac{a}{2}\right)}\right]$
(26)
$_{2}F_{1}\left(a,a+1,a+\frac{3}{2};\frac{1}{2}\right)=2\sqrt{\pi}\Gamma\left(a+\frac{3}{2}\right)\left[\frac{1}{\Gamma\left(\frac{a}{2}+\frac{1}{2}\right)^{2}}-\frac{1}{\Gamma\left(\frac{a}{2}+1\right)\Gamma\left(\frac{a}{2}\right)}\right]$
(27)

Using the contiguous relations of ${}_{2}F_{1}$ we can deduce another
relation:

$_{2}F_{1}\left(a,a+1,a+\frac{5}{2};\frac{1}{2}\right)=\frac{4}{3}\sqrt{\pi}\Gamma\left(a+\frac{5}{2}\right)\left[\frac{1-4a}{\Gamma\left(\frac{a}{2}+\frac{1}{2}\right)^{2}}+\frac{1+4a}{\Gamma\left(\frac{a}{2}+1\right)\Gamma\left(\frac{a}{2}\right)}\right]$
(28)

Examining the first few terms in the Maclaurin series of
$s\left(u\,\Xi_{1}+v\,\Xi_{1}^{*}\right)$ and our initial conditions, we can
now find expressions for $u$ and $v$ explicitly in terms of the gamma function
and more common functions. There are no terms with even powers of $s$ in our
Maclaurin series and that satisfies the first and third initial conditions. We
examine the second and fourth:

Mathematica Session

⬇

In[1]:= u=Sqrt[Pi]Cos[Pi I/(4 $\alpha$)] Gamma[-I/(4 $\alpha$)-1/2]/(I/(4
$\alpha$)Gamma[-I/(8$\alpha$)]^2)

In[2]:= v=-Sqrt[Pi]Cos[Pi I/(4 $\alpha$)] Gamma[I/(4
$\alpha$)-1/2]/(2Gamma[I/(8$\alpha$)+1/2]^2)

In[3]:= b=2 Sqrt[Pi] Gamma[I/(4
$\alpha$)+3/2](1/Gamma[I/(8$\alpha$)+1/2]^2-1/(Gamma[I/(8$\alpha$)+1]Gamma[I/(8$\alpha$)]))

In[4]:= bstar=2 Sqrt[Pi] Gamma[-I/(4
$\alpha$)+3/2](1/Gamma[-I/(8$\alpha$)+1/2]^2-1/(Gamma[-I/(8$\alpha$)+1]Gamma[-I/(8$\alpha$)]))

In[5]:= FullSimplify[u b + v bstar]

Out[5]= 1

In[6]:= c=(1/2)/(I/(4 $\alpha$)+3/2) 4/3 Sqrt[Pi] Gamma[I/(4
$\alpha$)+5/2]((1-I/$\alpha$)/Gamma[I/(8$\alpha$)+1/2]^2+(1+I/$\alpha$)/(Gamma[I/(8$\alpha$)+1]Gamma[I/(8$\alpha$)]))
(-I $\alpha$/2)

In[7]:= cstar=(1/2)/(-I/(4 $\alpha$)+3/2) 4/3 Sqrt[Pi] Gamma[-I/(4
$\alpha$)+5/2]((1+I/$\alpha$)/Gamma[-I/(8$\alpha$)+1/2]^2+(1-I/$\alpha$)/(Gamma[-I/(8$\alpha$)+1]Gamma[-I/(8$\alpha$)]))
(I $\alpha$/2)

In[8]:= FullSimplify[Factorial[3](u c + v cstar)]

Out[8]= -1+I $\alpha$

This shows us the unique values of $u$ and $v$ that satisfy our initial
conditions.

## References

  * [1] CF Gauss.  Disquisitiones generales circa seriem infinitam…  Commentationes societatis regiae scientiarum Gottingensis recentiores, 2:1–46, 1813.
  * [2] E.E. Kummer.  De integralibus quibusdam definitis et seriebus infinitis.  Journal für die reine und angewandte Mathematik, 1837(17):228–242, 1837.
  * [3] P. Humbert.  Sur les fonctions hypercylindriques.  C. R. Acad. Sci., Paris, 171:490–492, 1920.
  * [4] Bateman Manuscript Project, H. Bateman, A. Erdélyi, and United States. Office of Naval Research.  Higher Transcendental Functions.  Number vol. 1 in Bateman Manuscript Project California Institute of Technology. McGraw-Hill, 1953.
  * [5] Milton Abramowitz and Irene A. Stegun.  Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables.  Dover, New York, ninth dover printing, tenth gpo printing edition, 1964\.
  * [6] Felix Pollaczek.  Sur une famille de polynômes orthogonaux à quatre paramètres.  C. R. Acad. Sci., Paris, 230:2254–2256, 1950.
  * [7] Min jie Luo and Ravinder Krishna Raina.  Generating functions of pollaczek polynomials: a revisit.  Integral Transforms and Special Functions, 30:893 – 919, 2019.
  * [8] Raphael Linus Levien.  From Spiral to Spline: Optimal Techniques in Interactive Curve Design.  PhD thesis, EECS Department, University of California, Berkeley, Dec 2009\.
  * [9] Even Mehlum.  Appell and the apple (nonlinear splines in space).  In M. Dæhlen, T. Lyche, and L. L. Schumaker, editors, Mathematical Methods for Curves and Surfaces: Ulvik, Norway. Vanderbilt University Press, 1994.
  * [10] Josef Stoer.  Curve fitting with clothoidal splines.  J. Res. Nat. Bur. Standards, 87(4):317–346, 1982.
  * [11] Ian D. Coope.  Curve interpolation with nonlinear spiral splines.  IMA Journal of Numerical Analysis, 13(3):327–341, 1993.
  * [12] Even Mehlum and Jet Wimp.  Spherical curves and quadratic relationships for special functions.  The Journal of the Australian Mathematical Society. Series B. Applied Mathematics, 27(1):111–124, 1985.
  * [13] Erlend Grong Mauricio Godoy Molina.  Geometric conditions for the existence of a rolling without twisting or slipping.  Communications on Pure & Applied Analysis, 13(1):435–452, 2014\.
  * [14] Ülo Lumiste.  On submanifolds with parallel higher order fundamental form in euclidean spaces.  In Dirk Ferus, Ulrich Pinkall, Udo Simon, and Berd Wegner, editors, Global Differential Geometry and Global Analysis, pages 126–137, Berlin, Heidelberg, 1991. Springer Berlin Heidelberg.
  * [15] Arkady Kholodenko and Zurab Silagadze.  When physics helps mathematics: Calculation of the sophisticated multiple integral.  Physics of Particles and Nuclei, 43, 01 2012.
  * [16] Alberto G. Rojo and Anthony M. Bloch.  The rolling sphere, the quantum spin, and a simple view of the landau–zener problem.  American Journal of Physics, 78(10):1014–1022, 2010.
  * [17] Richard P. Feynman, Frank L. Vernon, and Robert W. Hellwarth.  Geometrical representation of the schrödinger equation for solving maser problems.  Journal of Applied Physics, 28(1):49–52, 1957.
  * [18] Clarence Zener.  Non-adiabatic crossing of energy levels.  Proceedings of the Royal Society of London. Series A, Containing Papers of a Mathematical and Physical Character, 137(833):696–702, 1932.
  * [19] Min-Jie Luo, Ravinder Krishna Raina, and Shu-Han Zhao.  Certain results on generating functions related to the associated meixner-pollaczek polynomials.  Integral Transforms and Special Functions, 0(0):1–17, 2021.
  * [20] Khalid Ahbli and Zouhair Mouayn.  A generating function and formulae defining the first-associated meixner-pollaczek polynomials.  Integral Transforms and Special Functions, 29, 02 2018.
  * [21] Min-Jie Luo and Ravinder Krishna Raina.  Generating functions of pollaczek polynomials: a revisit.  Integral Transforms and Special Functions, 30(11):893–919, 2019\.

E-mail address<EMAIL_ADDRESS>


11institutetext:  Cosmic Dawn Center, University of Copenhagen, Denmark
22institutetext: Niels Bohr Institute, University of Copenhagen, Jagtvej 128,
DK-2200 Copenhagen, Denmark 33institutetext: European Space Agency, European
Space Astronomy Centre, Madrid, Spain 44institutetext: Centro de Astrobiologia
(CSIC-INTA), Departamento de Astrofisica, Madrid, Spain 55institutetext: ATG
Europe for the European Space Agency, European Space Research and Technology
Centre, Noordwijk, The Netherlands

# The Near-Infrared Spectrograph (NIRSpec) on the James Webb Space
Telescope††thanks: The eMPT software package and its associated user guide are
available for download from the ESA GitHub page: https://github.com/esdc-esac-
esa-int

V. Optimal algorithms for planning multi-object spectroscopic observations

N. Bonaventura 1122 P. Jakobsen 1122 P. Ferruit 33 S. Arribas 44 G. Giardino
55

(Received Soon 2022; accepted Later 2022)

We present an overview of the capabilities and key algorithms employed in the
so-called eMPT software suite developed for planning scientifically optimized,
multi-object spectroscopic (MOS) observations with the Micro-Shutter Array
(MSA) of the Near-Infrared Spectrograph (NIRSpec) instrument on board the
James Webb Space Telescope (JWST), the first multi-object spectrograph to
operate in space. NIRSpec MOS mode is enabled by a programmable MSA, a regular
grid of $\sim$250,000 individual apertures that projects to a static, semi-
regular pattern of available slits on the sky and makes the planning and
optimization of an MSA observation a rather complex task. As such, the eMPT
package is offered to the NIRSpec user community as a supplement to the MSA
Planning Tool (MPT) included in the STScI Astronomer’s Proposal Tool (APT) to
assist in the planning of NIRSpec MOS proposals requiring advanced
functionality to meet ambitious science goals. The eMPT produces output that
can readily be imported and incorporated into the user’s observing program
within the APT to generate a customized MPT MOS observation. Furthermore, its
novel algorithms and modular approach make it highly flexible and
customizable, providing users the option to finely control the workflow and
even insert their own software modules to tune their MSA slit masks to the
particular scientific objectives at hand.

###### Key Words.:

Instrumentation: spectrographs - Space vehicles: instruments - Techniques:
Spectroscopic

##  1 Introduction

The design of the Near-Infrared Spectrograph (NIRSpec) instrument on board the
James Webb Space Telescope (JWST) and its different observing modes are
presented in Jakobsen et al. (2022). As described in further detail by Ferruit
et al. (2021), a key capability of the instrument is the multi-object
spectroscopic (MOS) capability afforded by its novel Micro-Shutter Array
(MSA). The MSA carries a total of $4\times 365\times 171=249\,660$
individually addressable micro-shutters arranged in four quadrants spanning a
combined 3$\aas@@fstack{\prime}$6$\times$3$\aas@@fstack{\prime}$4 field of
view on the sky. The nontrivial task of matching the regular grid of MSA
shutters to a given ensemble of candidate targets on the sky in an optimal
manner requires the use of bespoke specialized software – and indeed,
comprises the NIRSpec-specific portions of the Astronomer’s Proposal Tool
(APT)111http://apt.stsci.edu in the so-called MSA Planning Tool (Karakla et
al., 2014, MPT).

However, during the development and planning of the European Space Agency
(ESA) NIRSpec Science Team’s Guaranteed Time Observer (GTO) program, a number
of ideas arose for ways to further optimize the scientific potential of the
MSA. This prompted the development of the so-called eMPT software suite, which
began as a test bed for such alternative approaches that are not currently
possible. As many of these ideas proved to be quite powerful, the eMPT has
since evolved into an alternative to the MPT and is being offered to the JWST
user community on an “as is” basis (Sect. 7.3). The purpose of this paper is
to outline the different approach taken by the eMPT in planning MSA
observations, list the unique capabilities enabled by this approach, and
document the machinery of some of the key algorithms developed for it. The
intent is not to repeat here the details of the eMPT User Guide, but to
highlight what the eMPT may have to offer NIRSpec users for their particular
MSA programs.

##  2 Architecture of the eMPT

Given a user-provided catalog listing the celestial coordinates and relative
scientific priorities of the objects to be observed with the NIRSpec MSA, the
common task of the MPT and eMPT software is to identify the precise MSA sky
pointing required, and shutters that need to be opened, to observe the optimal
number of highest-priority spectra in a single exposure, without the spectra
overlapping on the detector. For reasons explained in Sect. 7.1, this
optimization is performed at a predetermined MSA orientation, but ultimately
at the official roll angle assigned by STScI. This roll angle, the JWST
“aperture position angle”, refers to the position angle of the “science
y-axis” of, in this case, the NIRSpec MSA on-sky field of view (FOV), measured
eastward from north.

###  2.1 Modular approach

Table 1: Basic modules of the eMPT. Module | Function
---|---
ipa | Find the MSA pointings within a user-defined search box that capture the maximum number of highest priority targets
k_make | For each optimal pointing identify all targets of all priority classes that fall within viable slitlets on the MSA (the raw k_list)
k_clean | Purge the candidate list at each pointing of targets contaminated by nearby catalog entries
m_make | Identify the optimal subset of targets whose spectra fit on the detector without overlap for each pointing (the filtered m_list)
m_sort | Rank the pointings and matching target sets according to a user-defined figure of merit
m_pick | Generate the information needed to import the highest ranking MSA mask and pointing combination into the APT
m_check | Create further diagnostic files and plots for the chosen solution

The eMPT was built as a series of modules designed to be run in strict
sequence, such that each module performs a specific task on the output of the
previous module. All modules were written in standard gcc gfortran, in order
to keep the execution time associated with the most computationally intensive
modules manageable. The models and primary functions of the baseline eMPT
module suite are listed in Table 1. The eMPT is controlled by a user-edited
configuration file that simultaneously serves to set the parameters of each
step, and provides a record of the total workflow. All intermediate results
generated by each module are output as plain ASCII files that can be accessed
and optionally modified by users either manually or with their own software
(Sect. 6.1). The eMPT modular work flow can also easily be captured in simple
shell scripts (Sect. 6.6), which, together with the high speed of execution,
encourages experimentation and active exploration of a variety of “what if?”
scenarios.

###  2.2 NIRSpec instrument model

To carry out its functions, the eMPT requires a number of prerequisites, many
of which are common with the MPT; one key element, which forms the backbone of
both systems, is the NIRSpec instrument model (Dorner et al., 2016; Birkmann
et al., 2016; Giardino et al., 2016; Alves de Oliveira et al., 2022;
Lützgendorf et al., 2022). The in-flight, updated version of the NIRSpec
instrument model is capable of tracing light originating from a point on the
sky, through the telescope and instrument, and finally onto the detector in
any of the NIRSpec observing modes, to the accuracy of a fraction of a pixel
(Lützgendorf et al., 2022). Particularly relevant to the eMPT is the
polynomial fit employed by the model to capture the significant optical field
distortion that occurs in the telescope and NIRSpec foreoptics between the sky
and the MSA, along with the detailed metrology model of the MSA itself that
specifies where precisely all its shutters lie in the NIRSpec slit plane. The
NIRSpec model has been maintained and kept up-to-date by the ESA NIRSpec team
until the end of JWST commissioning; future updates will be put in place by
the STScI NIRSpec group. The eMPT and MPT use the same set of model reference
files to capture its most recent version.

###  2.3 MSA shutter operability and viable slitlet maps

Another important component of the MPT and eMPT is the MSA shutter operability
map, which keeps a tally of which shutters are fully functional, failed
closed, and failed open at a given point in time (Rawle et al., 2022). The
eMPT is presently hard-wired to assume that each target to be observed with
the MSA is assigned a three-shutter-tall slitlet, and that observations are
nodded between sub-exposures by shifting the MSA pointing up and down by one
shutter. Central to the eMPT approach is the so-called viable slitlet map, a
$4\times 365\times 171$ look-up table that identifies a given shutter
$(k,i,j)$ as capable of serving as the central shutter of a fully functioning,
three-shutter-tall slitlet. This viable slitlet map is initialized at the
start of each eMPT run and is then continuously updated as part of the
workflow, as targets and their spectra are added to the MSA and detector. The
initialization process depends on the disperser being used, and involves
identifying and excluding from use any viable slitlets whose spectra collide
with those of failed open shutters on the MSA. In the case of NIRSpec’s low-
resolution (R$\sim$100) prism disperser (PRISM), the initialization process
also includes precluding from use those slitlets that result in incomplete
spectra (Sect. 3.2).

###  2.4 Tangential coordinates

When projecting targets on the sky through the JWST telescope onto the NIRSpec
MSA, the eMPT makes use of the so-called tangential (or standard) angular
approximation throughout (Van de Kamp, 1967). In this approximation, a point
on the sky at spherical coordinates ($\alpha$,$\delta$) is, for a given MSA
pointing ($\alpha_{p}$,$\delta_{p}$), represented by the relative Cartesian
angular coordinates ($x_{\alpha}$,$y_{\delta}$), where

$x_{\alpha}=\frac{\cos\delta\sin(\alpha-\alpha_{p})}{\sin\delta\sin\delta_{p}+\cos\delta\cos\delta_{p}\cos(\alpha-\alpha_{p})}$
(1)
$y_{\delta}=\frac{\sin\delta\cos\delta_{p}-\cos\delta\sin(\alpha-\alpha_{p})}{\sin\delta\sin\delta_{p}+\cos\delta\cos\delta_{p}\cos(\alpha-\alpha_{p})}.$
(2)

Here $x_{\alpha}$ and $y_{\delta}$ respectively denote the west-to-east and
south-to-north angular distances from the point ($\alpha_{p}$,$\delta_{p}$) to
($\alpha$,$\delta$). This tangential approximation is accurate to a fraction
of a milliarcsecond (mas) over the
3$\aas@@fstack{\prime}$6$\times$3$\aas@@fstack{\prime}$4 field of view of the
MSA, well below the NIRSpec instrument model accuracy. Consequently,
$x_{\alpha}$ and $y_{\delta}$ can be rotated to the orientation of the
telescope and treated as customary planar Cartesian coordinates. When the need
arises to convert tangential coordinates into proper spherical coordinates,
the inverse expressions employed are

$\alpha=\alpha_{p}+\arctan(\frac{x_{\alpha}}{\cos\delta_{p}+y_{\delta}\sin\delta_{p}})$
(3)
$\delta=\arcsin(\frac{\sin\delta_{p}+y_{\delta}\cos\delta_{p}}{\sqrt{1+x_{\alpha}^{2}+y_{\delta}^{2}}}).$
(4)

###  2.5 Scientific prioritization of targets

Compared to the MPT, the eMPT employs a rather coarse prioritization of the
target candidates, grouping the catalog entries into only a handful of
scientific priority classes (typically fewer than 20); there are several
reasons for this choice. First and foremost, it reflects the scientific
objectives of most real-world MSA programs, that is to say, one is faced with
a small number of extremely high-priority targets for which it is vital to
obtain the greatest possible number of spectra, after which the MSA should
ideally be sequentially filled with the greatest possible number of more
abundant, but decreasingly important, targets. In fact, this means that the
algorithm employed in the eMPT to pack the largest number of non-overlapping
spectra on the NIRSpec detector array (Sect. 4) becomes more efficient with
more (lower priority) targets to consider.

The targets designated as Priority Class 1 (PC1) in the eMPT are treated in a
very different manner from the remaining targets to exploit one of the most
powerful features of the eMPT, its so-called initial pointing algorithm (IPA).
The IPA module takes as input the user-supplied catalog containing a number of
labeled PC1 targets, a nominal MSA pointing position on the sky
($\alpha_{o},\delta_{o}$), together with a specification of the size of the
maximum allowed deviations from this nominal pointing. From this input the IPA
produces, for the assigned fixed roll angle $\phi_{c}$, a list of detailed MSA
pointings ($\alpha_{p},\delta_{p},\phi_{p}$) within the specified search box
that provide the largest possible number of non-overlapping spectra of PC1
targets. The way in which the IPA module achieves this feat is described in
Sect. 5. It is important to appreciate that once the IPA module has produced
its list of PC1-maximizing pointings, these are the only pointings
subsequently considered by the following, downstream eMPT modules in Table 1.
They together endeavor to fill the MSA at each pointing identified by the IPA
with an optimal set of lower priority targets, and, in the end, identify which
of these target sets is the most scientifically preferred overall.

##  3 Avoiding spectral overlap

Another prerequisite common to the eMPT and MPT is a means of quickly
assessing whether the spectra arising from two shutters on the MSA overlap on
the NIRSpec detector array, both vertically in the spatial direction and
horizontally along the dispersion direction. As explained in Jakobsen et al.
(2022), NIRSpec grating spectra are straddled horizontally by zero- and
second-order spectra at their blue and red ends and therefore effectively span
the entire width of the detector array. Horizontal spectral separation is
therefore only of concern for the shorter, lower-resolution PRISM spectra, of
which as many as four can fit across the detector.

In an ideal instrument, the separation between two spectra from different
shutters would simply reflect the horizontal and vertical differences, $\Delta
i$ and $\Delta j$, between the two shutter locations on the MSA. However,
optical distortion in the NIRSpec collimator optics and, to a lesser extent,
small misalignments between the four MSA shutter quadrants and residual
spatial clocking differences in the mounting of the NIRSpec dispersers,
significantly complicate the situation.

###  3.1 Vertical overlap

Figure 1: Map of the angular field distortion displayed by the NIRSpec
collimator optics. The best-fit linear model is shown in red. The actual
distortion, amplified by a factor of 25 for clarity, is plotted in black.

The optical field distortion in the angular output of the NIRSpec collimator
is shown in exaggerated form in Fig. 1. In this figure, the upward curvature
of the horizontal lines, corresponding to input along a fixed MSA shutter row,
results in spectra from MSA shutters located toward the middle of the MSA to
be imaged $\simeq\\!4\\!-\\!6$ pixel rows higher on the detector relative to
spectra from shutters near the two edges. As a consequence, the vertical
separation between the spectra from any two shutters cannot be simply gauged
by the separation in shutter rows, $\Delta j$. Following a suggestion made by
the STScI NIRSpec team, this complication is handled in both the eMPT and MPT
by mapping the distortion onto a single scalar $S(k,i,j)$ assigned to each
shutter of the MSA, such that the vertical spectral separation measured in
equivalent shutter rows can instead be accurately assessed simply by
differencing the two so-called shutter values.

The dominant contribution to $S(k,i,j)$ stemming from the collimator
distortion can then be calculated as

$S_{\\!C}(k,i,j)=j+\left({f_{y}^{COL}\over
p_{y}}\right)\Delta\theta_{y}(k,i,j),$ (5)

where $\Delta\theta_{y}(k,i,j)$ is the deviation in the vertical exit angle of
the beam originating from shutter $(k,i,j)$ compared to an ideal linear
optical alignment; $f_{y}^{COL}=660$ mm is the mean focal length of the
collimator in the spatial direction; and $p_{y}=0.204$ mm is the shutter pitch
in the spatial direction.

A second, smaller contribution to $S(k,i,j)$ comes from small residual
misalignments in the MSA, which, in the worst case, amount to approximately
half a shutter pitch in the spatial direction,

$S_{\\!M}(k,i,j)=\left({1\over p_{y}}\right)\Delta y_{m}(k,i,j),$ (6)

where $\Delta y_{m}(k,i,j)$ is the spatial displacement of shutter ($k,i,j)$
with respect to the perfectly aligned MSA.

Figure 2: Schematic illustration of the vertical separation, $\Delta
S_{\\!D}$, between two spectra from two shutters separated horizontally by
$\Delta i$ when the disperser is mis-clocked by the angle $\Delta\phi_{z}$

Whereas the two above contributions to $S(k,i,j)$ are geometrical in nature,
the third contributor depends on the disperser being deployed. As illustrated
in Fig. 2, a grating or prism is rotated in its mount by an angle,
$\Delta\phi_{z}$, which leads to its dispersed spectra being tilted by the
same angle with respect to the detector pixel rows. In this case, the vertical
separation between two spectra from shutters located in the same MSA row grows
in proportion to the horizontal separation between the shutters. The
contribution to $S(k,i,j)$ from this effect can be written as

$S_{\\!D}(k,i,j)=\left(p_{x}\over p_{y}\right)\tan(\Delta\phi_{z})\thinspace
i^{\star}(k,i,j),$ (7)

where $p_{x}=0.105$ mm is the horizontal shutter pitch, and $i^{\star}(k,i,j)$
accounts for cases where the shutters lie in adjacent quadrants,

$i^{\star}(k,i,j)=\cases{i}&\text{ if $k=1$ or $2$}\\\
i+\Delta_{i}^{gap}+365\text{ if $k=3$ or $4$}{},$ (8)

where $\Delta_{i}^{gap}=85.98$ is the equivalent number of horizontal shutters
spanned by the vertical gap between shutter quadrants. Values of
$\Delta\phi_{z}$ for the seven NIRSpec dispersers are listed in Table 2. It is
seen that the six gratings are well-aligned to within approximately an
arcminute, except for the high-resolution G235H grating, which stands out at
$\Delta\phi_{z}=-350$″. The prism is mis-clocked at an even greater angle, but
since its spectra are much shorter, this is less noticeable. Nonetheless, the
differences in $\Delta\phi_{z}$ in Table 2 are still sufficient to require
that each disperser have its own separate shutter value table, formed from the
sum of the contributions of Eqs. (5) and (6) and the disperser-dependent Eq.
(7):

$S(k,i,j)=S_{\\!C}(k,i,j)+S_{\\!M}(k,i,j)+S_{\\!D}(k,i,j).$ (9)

The eMPT therefore employs seven separate shutter value tables calculated for
each disperser per the above recipe. In the interest of employing fewer such
tables, the MPT trades off accuracy by sharing tables between the dispersers
in Table 2, whose mis-clocking angles are not too dissimilar. In practice, the
vertical spectral collision algorithms employed by the MPT and eMPT are
identical.

Table 2: Disperser clocking angles. Disperser |  $\Delta\phi_{z}$ [arcsec]
---|---
G140M | +62
G235M | +82
G395M | +6
G140H | -23
G235H | -350
G395H | +30
PRISM | +1060

###  3.2 Horizontal overlap of PRISM spectra

Spectra obtained with the NIRSpec low-resolution prism disperser do not
exhibit spectral orders; these spectra extend from
$\lambda\\!\simeq\\!0.5\leavevmode\nobreak\ \mu$m up to
$\lambda\\!\simeq\\!5.5\leavevmode\nobreak\ \mu$m and have a length that,
depending on the shutter employed, varies between 172 and 184 pixels across
the face of the MSA. Consequently, up to four prism MSA spectra can fit across
the NIRSpec detector arrays without overlapping or being truncated by the gap
between the two arrays (Fig. 5). In order to quickly asses whether the PRISM
spectra from two shutters $(k,i,j)$ and $(k^{\prime},i^{\prime},j^{\prime})$
overlap horizontally, the eMPT carries two precalculated $4\times 365\times
171$ integer look-up tables that specify how far away $i^{\prime}$ must be
located respectively to the left and right of shutter $(k,i,j)$ for the red
and blue ends of the two spectra to clear each other (Fig. 3). By taking into
account the slight asymmetry in the PRISM spectra locations in this manner,
the eMPT ensures that the greatest possible number of such spectra can be
placed on the NIRSpec detector arrays. In contrast, the MPT only employs a
single minimum required horizontal shutter column separation threshold, which
of necessity is the maximum value in the two maps shown in Fig. 3. In
practice, however, this difference is insignificant except at the highest
target densities (Fig. 5), where, with all other factors being equal, it
enables the eMPT to pack $\sim$1% more non-overlapping PRISM spectra on the
detector compared to the MPT.

Figure 3: Maps of how many shutters to the left and right along an MSA row are
required for PRISM spectra to avoid overlapping horizontally.

##  4 The matrix (Arribas) algorithm

A unique core element of the eMPT is the optimal manner in which it decides
which subset of a given ensemble of targets located within viable slitlets on
the MSA produces the largest possible number of non-overlapping spectra on the
NIRSpec detector array. This critical down-selection step is carried out
throughout the eMPT by employing the so-called matrix algorithm (historically
known as the Arribas algorithm). When supplied with a list of viable slitlets
containing targets, the algorithm uses the methods outlined in the previous
Sect. 3 to quickly map which target spectra collide with others on the
detector. The algorithm then identifies which candidate target clashes with
the most competing other spectra and repeatedly eliminates the “worst
offender” from the list until no spectral clashes remain. The final surviving
set of targets is then the optimal one providing the largest possible number
of spectra that can be drawn from the input set.

The matrix algorithm is employed in both the ipa module, to eliminate spectral
collision among the PC1 targets; and also in the m_make module, where the list
of in-slit targets for each candidate pointing identified and purged of
contamination by the k_clean module (Sect. 6.4), are placed on the MSA, in the
order of increasing priority class. This approach ensures that the final set
of targets to be observed is the optimal one, providing the largest possible
number of spectra of the highest-priority PC1 targets, followed by the largest
possible number of spectra of Priority Class 2 spectra, conditional on the PC1
targets already being in place, in a successive fashion down through the
lower-priority (higher-numbered) priority classes.

An interesting aspect of the matrix algorithm is how it handles ties between
targets, that is, when two or more candidate targets conflict with the same
number of competing targets. Arriving at the absolute optimal solution would
in such cases require that all branches springing from all ties be pursued to
completion, which is computationally demanding. Moreover, experiments in which
the tied targets flagged for elimination were selected at random, do not
suggest that there is much to be gained by mapping out such branches. In any
event, since it is vital for testing purposes that the matrix algorithm not be
stochastic, but repeatable for a given input, the eMPT employs the approach of
always selecting for elimination the tied target that appears the furthest
down in the user-provided input catalog. Therefore, among the otherwise equal
targets assigned a given priority class, there is an implicit secondary
ranking of their importance hiding in the order in which the targets are
listed. With this additional constraint, the matrix algorithm is guaranteed to
arrive at the best possible solution.

In contrast to the eMPT’s grouped approach, the MPT always works in a “first
come, first served” manner by placing spectra on the detector one after the
other, in strict sequence, working its way down the input catalog. When there
are few targets available and little or no spectral overlap, all targets
falling within viable slitlets will make it onto the detector in either
approach. However, as the number of targets that need to be accommodated is
increased, and the likelihood of spectral overlap rises, the difference
becomes more and more significant. In the limit of a very high target density,
the matrix algorithm allows up to $\sim$17% more spectra to be packed onto the
detector array without overlap, compared to a single pass of the MPT approach.
However, the MPT does offer the computationally heavy option of randomly
shuffling the order of the input catalog a number of times and selecting the
best outcome amongst the trials. The matrix algorithm can therefore be thought
of as the direct path to the result of having shuffled the input catalog a
large number of times; this claim is also borne out quantitatively through
direct testing. An illustrative example of what the matrix algorithm is
capable of achieving is shown in Fig. 5

##  5 The initial pointing algorithm

Another powerful and unique feature of the eMPT is its IPA, designed to
identify the optimal set of MSA pointings on the sky that provide the highest
possible simultaneous coverage of the highest-priority PC1 targets in the
input catalog, within a user-specified search box and for the assigned roll
angle. The IPA accomplishes this by first employing an “all-seeing” formalism
that is computationally manifested as a simultaneous “mapping and stacking” of
the full projected, viable MSA shutter area accessible to all PC1 target
positions within their respective search boxes, without relying on
conventionally “blind” grid-searching or pattern-matching methods. In the
theoretical limit of infinitely precise telescope pointing accuracy and
optics, this novel algorithm for optimizing MOS configurations locates the
universal set of pointings that maximize the number of PC1 targets in a single
observation. In reality, this algorithm must be implemented digitally, with a
chosen digital sampling size that accounts for the telescope pointing accuracy
and balances computational speed with desired results222Stress tests of the
software for a variety of common use cases have thus far shown it to be a very
rare occurrence that the currently adopted IPA digital sampling size is too
coarse to locate the most optimal pointing solution. Experience has shown that
sampling the digital shift map at one seventh of the width of the Acceptance
Zone in the dispersion direction and one thirteenth of the height of the
Acceptance Zone in the spatial direction is adequate to capture the optimal
pointings. This parameter is currently hardwired in the eMPT code but is easy
to modify upon the individual user’s request. It must also be fine-tuned to
address the numerous complications arising from the specific observational
setup at hand; in this case, the possibility of spectra overlapping on the
NIRSpec detector array (Sect. 3); the differential optical field distortion
occurring in the projection between the sky and MSA; and the slight change in
MSA roll orientation that the APT imposes on each pointing shift (Sect. 7.1).
Therefore, this digitized search is followed by a more precise, individual
examination and fine-tuning of each of the possibly optimal pointings
uncovered in the first step. The resulting two-pronged approach is both highly
robust and very quick to perform.

The logic behind the first digital step of the IPA is illustrated in Fig. 4. A
target $A$ is located somewhere within the MSA FOV and a viable MSA shutter
$(k,i,j)$ is accessible within the search box centered on the target;
$\@vec{\Delta}_{A}$ denotes the shift in pitch and yaw of the MSA pointing
relative to the nominal pointing required to place target $A$ in the exact
center of shutter $(k,i,j)$. For target $A$ to be observable in shutter
$(k,i,j)$, the pointing shift need not be exactly $\@vec{\Delta}_{A}$, but
equal to any of the numerous discretized pointing shifts that place it within
the shutter’s acceptance zone.333The number of different shift vectors
available to a given target to place it within the open area of a given
shutter, grows with a decreasing digital sampling size of the shift vector
space – but at the cost of computational speed. The currently implemented size
in the IPA is sufficiently large to allow for a short code running time, but
small-enough to achieve the optimal pointing solution(s) and conveniently,
clusters of closely spaced pointings to serve as dithered pointings.
Considering now a second target $B$ located elsewhere on the MSA, requiring a
shift $\@vec{\Delta}_{B}$ to place it at the center of the viable shutter
$(k^{\prime},i^{\prime},j^{\prime})$: as is evident from Fig. 4, if the open
areas of the two shutters $(k,i,j)$ and $(k^{\prime},i^{\prime},j^{\prime})$
happen to overlap in this shift-vector space, then an MSA shift by any
compromise vector $\@vec{\Delta}_{AB}$ ending in the green overlap zone will
result in targets $A$ and $B$ being observable simultaneously, placing them
respectively in the lower-right and upper-left corners of the two shutters
$(k,i,j)$ and $(k^{\prime},i^{\prime},j^{\prime})$. The first step of the IPA
performs such a comparison between all priority class 1 targets in the input
catalog by laying down an area corresponding to the acceptance zone of all
possible target and viable shutter pairings in a digital shift map spanning
the search area. The numerical peaks in this digital map then signal the
shifted pointings that allow the greatest number of priority class 1 targets
that can be observed simultaneously in a single MSA exposure.

However, due to the numerous NIRSpec observational challenges listed above, a
local peak in the digital shift map should be considered as a necessary, but
not sufficient, indicator of a true optimal-coverage pointing providing
maximal simultaneous target coverage. The highest maxima detected in the
idealized digital shift map are therefore in the IPA followed up individually
in the second, more accurate fine-tuning step that takes into account these
complications. For each peak in the digital map, the second step of the
algorithm essentially starts from scratch, projecting the priority class 1
targets to the MSA using the initial MSA pointing $(\alpha_{p},\delta_{p})$
implied by the location of the peak in the digital shift map (and the MSA roll
angle $\phi_{p}$ given by Eq. 10 below), and performing all the steps carried
out by the full eMPT chain, including employing the matrix algorithm (Sect. 4)
to eliminate spectral overlap and identify which targets are actually covered
by the pointing. This process is then repeated iteratively until a self-
consistent solution in which the final values of $(\alpha_{p},\delta_{p})$
have the outer envelope of the superposition of the intra-shutter locations of
the covered targets perfectly centered within the imaginary common shutter.
The surviving highest coverage pointings are then purged of duplicate
pointings and, if necessary, sorted into groups according to the different
lists of priority class 1 targets that they each cover. This last step is
intended for cases where the optimal choice of two or three overlapping
“dithered” pointings are being sought (Sect. 6.2). Drawing overlapping
pointings from the same group assures that the same priority class 1 targets
are covered at all pointings.

The MPT also has the capability to search for optimal pointings, but does so
by carrying out a computationally intensive search over a grid of finite
points spanning the search area. However, as is clear from Fig. 4 since
pointings capturing a large number of targets simultaneously may extend over a
very small region in search space, the blind MPT raster search generally needs
to be performed with a very small step size to be assured of locating the
optimal pointings that the IPA algorithm is designed to instantly isolate.

Figure 4: Schematic illustrating the logic behind the digital shift-vector map
employed in the IPA. Each rectangle shown represents the acceptance zone of a
viable shutter (identified by its MSA coordinates) in shift-vector space,
accessible to the associated target (red for target A and blue for target B)
within a given search box. The (green) area of overlap of these acceptance
zone areas in shift-vector space contains the shift vector value required from
the nominal pointing position to simultaneously observe these two targets in a
single MOS observation.

##  6 Other capabilities of the eMPT

###  6.1 Allowing user customization

The modular approach of the eMPT is designed to allow users to insert their
own customized processing modules into the workflow. A prime use of this
capability is to process the list of all target candidates that project to
viable shutters at a given pointing (output by the k_make module) with the aim
of flagging and excluding from further consideration those with known redshift
or radial velocity whose spectra would be lacking coverage of certain emission
or absorption lines of interest (due to the relevant portions of those spectra
falling outside the active areas of the two NIRSpec detector arrays for the
shutters in which they happen to lie). Precalculated wavelength coverage look-
up tables for all seven NIRSpec dispersers can be provided for this purpose.

###  6.2 Optimizing multiple exposures simultaneously

The eMPT also has the ability to optimize two or three partially overlapping
MSA pointings simultaneously; this is done by examining all suitably separated
pairs or triples of pointings drawn from the list of PC1-optimized pointings
produced by the ipa module (Sect. 5). In the case of three dithered pointings,
the common list of targets covered by the triplet are sorted for each priority
class into targets that are a) common between all three pointings, b) targets
that are observed in only two of the pointings, c) and those that are only
observed in a single pointing of the triplet. Maximum commonality is then
achieved by using the matrix algorithm (Sect. 4) to, in turn, place the
thrice-covered targets on the MSA in order of increasing priority class,
followed by the twice-covered targets, and lastly, the singly covered targets.
Moreover, since the target placement sequence, and the weights that are
assigned to priority class to evaluate the figure of merit of the target set
covered by each triple, are fully under user control, the opposite goal of
covering as many different targets as possible in the three pointings (or any
intermediate case), is also possible. The opposite goal of covering as many
different targets as possible in the three pointings (or any intermediate
case), is also possible (even for PC1 targets by selecting pointings from
different groupings found by the ipa).

In the MPT Planner, by comparison, the “fixed” dither option (distinct from
nodding “dithers”) is available for MOS observations. This option translates a
planned slitlet configuration to a new location within the MSA field of view
according to the user’s specified offsets in the dispersion and/or cross-
dispersion directions in shutter units, allowing for the selection of
partially or fully observed primary sources across all dither pointings – but
not accounting for the differing positional shifts of different sources that
will inevitably result from optical distortions between the dither pointings
(thus the user-input dither offsets are considered “average” offsets between
an initial and new pointing).

###  6.3 Avoiding incomplete PRISM spectra

The utilization of a dynamically updated viable slitlet map (Sect. 2.3) in the
eMPT allows for the exclusion of MSA shutters that lead to PRISM spectra
projecting onto the $\simeq 156$ pixel-wide vertical gap between the two
NIRSpec detector arrays, at the start of each eMPT run. The MPT does not
censor such shutters and, as a result, typically 19% of all PRISM spectra in
MPT-designed MSA masks will be missing as much as half of their wavelength
range. In the eMPT, truncated spectra are instead traded off against typically
half as many complete PRISM spectra; the result of this censoring can readily
be seen in Fig. 5. This means that, for 100 PRISM spectra obtained by the MPT,
$\sim$81 would be complete versus $\sim$91 obtained by the eMPT.

###  6.4 Avoiding contaminated targets

As its name suggests, the task of the so-called k_clean module between the
k_make and m_make modules in Table 1 is to eliminate, early on in the down-
selection process, any candidate targets whose spectra are likely to be
contaminated by nearby objects, according to the contamination rules detailed
in Sect. 1.1 of the eMPT User guide. The algorithm presently employed in the
k_clean module is simplistic: for each target located within a viable slitlet,
it projects its nodded slitlet to the sky and checks and flags if any of the
five projected shutter areas contain any other catalog targets, regardless of
their brightness. By specifying a set of thresholds in the eMPT configuration
file, the user can control the overall level of such contamination that is
deemed acceptable. In the present implementation, these threshold values
merely stipulate the degree to which the centers of nearby contaminating
sources, listed in the user-supplied input catalog, are allowed to be present
in the open areas of the three shutters making up the slitlet at each of its
three nods on the sky.

This relatively crude “point source” approach to contamination elimination is
ill-suited to handling extended objects whose signal may contaminate a given
shutter even when its centroid position lies well outside of it; more
sophisticated algorithms that involve projecting the slitlets onto an existing
Hubble Space Telescope image (or eventually a JWST image) of the target field
are under development. However, the present algorithm is expected to
sufficiently eliminate the bulk of the major contamination sources in a first
pass. In the MPT, contaminated targets are only flagged after an MSA
configuration is constructed, in the list of observed targets covered by the
pointing and MSA mask; they are not eliminated.

###  6.5 Adding sky-only background spectra

At any given pointing of the MSA on the sky, there will nearly always be a
number of spare, unused slitlets available once the list of observable
candidate targets in the input catalog has been exhausted. The eMPT is capable
of exploiting this spare capacity by optionally filling the MSA with a near-
optimal number of slitlets that are absent of targets. This allows the user to
obtain as many as possible sky-only background spectra simultaneously with the
target spectra, from which a “master” background spectrum for the exposure can
be extracted and used in the reduction of the target spectra. Since faint-end
MSA observations are limited by detector noise, this approach has the
potential to notably decrease the amount of noise introduced during background
subtraction.

When instructed to do so in the configuration file, the eMPT gathers the
ensemble of spare slitlets, checks their (nodded) slitlets for the presence of
targets listed in the input catalog, and passes the set of empty slitlets to
the matrix algorithm to determine the optimal subset of sky spectra that can
still fit on the detector without overlapping with the target spectra already
in place. Figure 5 is an extreme example of this process at work.

The eMPT automates this process in an optimal way, whereas in the MPT, the
user must manually identify and select, one by one, any empty MSA shutters in
the MSA Configuration Editor to use in the calculation of a master background
sky spectrum for background subtraction.

Figure 5: Example of an MSA PRISM exposure obtained during NIRSpec
commissioning in which the matrix algorithm, provided with the bare viable
slitlet map as input, was used to produce an optimized MSA mask that yields a
total of 235 non-overlapping and non-truncated MSA and 5 fixed-slit PRISM
spectra of the diffuse interstellar medium emission during a blind pointing
toward the field near the Galactic center.

###  6.6 Scripting the work flow

The compiled eMPT modules are standard gfortran executables that read in the
name of the relevant controlling configuration file from the command line.
Once the user is comfortable with the eMPT workflow and the various parameter
choices that steer it, the entire eMPT run can easily be captured in a simple
shell script that executes the modules in the correct sequence (optionally
interlaced with the user’s own software components). Since such a scripted
eMPT run typically completes in a matter of minutes, this is a good way to
prepare and quickly process a given MSA observation once the roll angle at
which it will be executed is assigned by STScI (Sect. 7.1).

A simple Python wrapper of the Fortran modules is available for running the
eMPT in batch mode, designed primarily for experienced users of the software
who require many repeated, exploratory trials with different starting
parameters set for each.

##  7 Conforming to the Astronomer’s Proposal Tool

The eMPT software suite and the algorithms it employs are designed to produce
output in the form of MSA pointings and associated MSA masks that can readily
be imported into the STScI APT. This necessitates that the eMPT conform with a
number of conventions employed in the APT system.

###  7.1 The roll orientation of the MSA

One such aspect of the STScI APT that is inconvenient for an instrument like
NIRSpec with its unprecedented complexity, is the manner in which the APT
handles the roll angle specifying how the MSA is orientated on the sky.

The precise placement of the MSA on the sky is specified by the celestial
coordinates ($\alpha_{p},\delta_{p}$) at which the so-called MSA reference
point (nominally the geometrical center of the MSA field of view) is pointed,
together with a specification of how the MSA is rotated around this reference
position – usually quantified by the position angle, $\phi_{p}$, of the MSA
y-axis projected to the sky, measured at the MSA reference point.

NIRSpec MSA observations are, for obvious reasons, very sensitive to rotation.
The field of view spanned by the MSA measures
3$\aas@@fstack{\prime}$6$\times$3$\aas@@fstack{\prime}$4 on the sky, and the
open area of its shutters projects to 199 mas $\times$ 463 mas. It follows
that a rotation of the MSA around its center by a mere
$\Delta\phi_{p}\simeq$28″is sufficient to shift a target located within a
shutter situated in the far corner of the field of view by $\simeq$20 mas, or
one tenth of the slit width. Reflecting this sensitivity, the NIRSpec target
acquisition approach developed for MSA observations (Keyes et al., 2018)
performs an active roll correction, in addition to the more customary “pitch
and yaw” correction of the telescope pointing, to ensure that the targets to
be observed are placed within their intended respective open shutters to the
required accuracy.

At the same time, the need to keep the telescope in a perpetual shadow behind
its sunshade makes the JWST observatory itself highly roll-constrained – to
the point where JWST users are allowed to specify only in exceptional
scientifically justified circumstances the preferred roll angle of their
observations, since doing so effectively schedules when the observation can
occur. The majority of NIRSpec MSA users are therefore only assigned a final
roll angle by STScI once their observations have been placed on the
observatory timeline.

However, when STScI allocates a roll angle to a given MSA observation, it is
not the value of the angle $\phi_{p}$ of interest that is provided, but rather
the angle $\phi_{c}$, the MSA roll angle measured at the so-called catalog
reference position, defined by the median location of all objects contained in
the target input catalog entered into the APT by the user at the proposal
stage (see Fig. 6).

Fortunately, the difference between the two roll angles $\phi_{p}$ and
$\phi_{c}$ is predictable, and reflects the change in bearing toward the
north, measured along the great circle connecting the two reference points. If
$(\alpha_{c},\delta_{c})$ denotes the position of the catalog median reference
position, the relationship between the actual and assigned MSA orientation for
the MSA pointing ($\alpha_{p},\delta_{p}$) can be shown to be
$\phi_{p}=\phi_{c}+\Delta\phi$, where

$\Delta\phi=\arctan({{\sin(\alpha_{p}\\!-\\!\alpha_{c})(\sin\delta_{c}+\sin\delta_{p}})\over{\cos\delta_{c}\cos\delta_{p}+\cos(\alpha_{p}\\!-\\!\alpha_{c})(1+\sin\delta_{c}\sin\delta_{p})}}).$
(10)

It follows from this expression that the farther apart the two reference
points are from each other, and/or the closer the target field is to the
celestial poles, the greater the difference will be between the two roll
angles $\phi_{c}$ and $\phi_{p}$.

This feature of the STScI APT is not immediately visible to the user in the
MPT, as it silently orients the MSA at any given pointing to an actual roll
angle $\phi_{p}$ that differs from the officially allocated angle $\phi_{c}$
in accord with Eq. (10). Although this involuntary forced shift in roll angle
is generally small and inconsequential for an imaging instrument, it can be
quite significant for NIRSpec. Regrettably, there is no choice but to mirror
this behavior in the eMPT software in order to enable its optimized MSA mask
designs to be readily imported into the APT.

A practical example serves to illustrate the above described effect: a user
wishes to obtain NIRSpec MSA spectra of a number of remote galaxies in the
GOODS-South Legacy Field and loads the full Whitaker et al. (2019) catalog
into the eMPT or MPT. This catalog has 186 474 entries and extends over
approximately 24$\aas@@fstack{\prime}$8$\times$23$\aas@@fstack{\prime}$4 on
the sky, and its median reference position is located at
($\alpha_{c},\delta_{c}$)=(53$\aas@@fstack{\circ}$142334,-27$\aas@@fstack{\circ}$808222).
In the case where the targets of interest happen to be located in the
northeast corner of the catalog near, say,
($\alpha_{p},\delta_{p}$)=(53$\aas@@fstack{\circ}$264126,-27$\aas@@fstack{\circ}$684844),
9$\aas@@fstack{\prime}$8 away from the catalog reference position, then the
actual MSA roll angle will, per Eq. (10), deviate from the official allocated
one by $\Delta\phi=-204$″, which is substantial enough to rotate many targets
out of their intended shutters. The implication is that if the user had,
instead, first trimmed down the size of the catalog by entering into the MPT a
circular 3′ radius cut-out sub-catalog covering only the region of interest,
then $\phi_{p}$ would lie much closer to $\phi_{c}$ and a significantly
different set of targets would be observable for the exact same pointing and
assigned roll angle.

Thus, a counterintuitive situation arises where the question of which targets
are observable with the MSA at any given pointing and assigned roll angle, is
not solely determined by the availability of the scientifically interesting
targets contained within the MSA field of view, but also by all the other
catalog entries that are not being observed, even including those that are
located well outside the field of view of the MSA. Having the detailed MSA
performance tied to its full input catalog in such a fashion is undesirable
considering that the MSA is only capable of observing up to $\simeq$200
targets simultaneously in any given exposure (Ferruit et al., 2021) –
corresponding to fewer than $\simeq$0.1% of all catalog entries in the example
given above. Employing a symmetrical, trimmed-down catalog centered on the
pointing of interest may, however, not be an option in cases where several
dithered or tiled MSA exposures of the same field are planned. In these cases,
it is unavoidable that the individual dithered or tiled exposures all occur at
slightly different values of $\phi_{p}$ for the fixed assigned value of
$\phi_{c}$.

Figure 6: Schematic illustration of the difference in MSA roll angle measured
at the MSA reference point, $P$, and at the input catalog median reference
position, $C$.

NIRSpec MSA observers also need to be wary of the reverse situation where any
change made by the user to the input catalog after its entry into the MPT or
eMPT (such as eliminating superfluous targets and/or adding reference stars
needed for target acquisition), in principle shifts the catalog reference
position ($\alpha_{c},\delta_{c}$), which in turn rotates the MSA per Eq.
(10), thereby rendering the original optimized slit mask design invalid.
Fortunately, the speed of the eMPT and its easily scripted workflow (Sect.
6.6) make this obstacle easy to work around through iteration, especially if
the initial catalog is not too irregularly shaped.

###  7.2 Differential velocity aberration

The impact of the bulk velocity aberration caused by the movement of the JWST
spacecraft is an all-sky distortion effect that is handled at the spacecraft
level and is therefore invisible to the NIRSpec user. When the MSA is to be
pointed at a given position ($\alpha_{p},\delta_{p}$) on the sky, the
telescope is oriented such that the MSA reference point is placed at the
aberrated location of ($\alpha_{p},\delta_{p}$) at the time of the
observation; however, this only corrects for the velocity aberration at the
center of the MSA. To place the desired targets as accurately as possible
within their 199 mas-wide shutters necessitates that the differential velocity
aberration (DVA) over the full 3.6$\times$3.4 arcmin2 field of view of the MSA
also be considered.

The mathematics of the DVA correction are discussed by Cox & Gilliland (2003)
and Henry et al. (2010), who show that the DVA manifests itself as a simple
uniform magnification or demagnification of the view of the sky seen by the
telescope around the pointing corrected for bulk aberration. In the
nonrelativistic regime applicable here, the associated magnification factor is
simply

$M_{DVA}\simeq\frac{1}{1-(v/c)\cos\theta},$ (11)

where $v/c$ is the barycentric velocity of the JWST spacecraft relative to the
speed of light and $\theta$ is the angle between the JWST velocity vector and
the direction to the target point being observed.

Since the peculiar velocity of JWST in its slow halo orbit around L2 is
comparatively small (¡0.5 km s-1), the motion of the JWST spacecraft can, to
first order, be thought of as orbiting the Sun at a constant speed of $v\simeq
30$ km s-1, with a velocity vector trailing the Sun by $\simeq$90°in the
ecliptic plane.

It follows from Eq. (11) that the DVA field magnification is largest
($M_{DVA}\simeq 1.0001$) when looking along the velocity vector in the
ecliptic plane ($\theta\simeq$0°). Conversely, the DVA demagnification is the
greatest ($M_{DVA}\simeq 0.9999$) when looking opposite the velocity vector
($\theta\simeq$180°), and has no effect ($M_{DVA}=1.0000$) when observing
toward ether of the ecliptic poles ($\theta\simeq$90°). Thus, the, at most,
one part in 10 000 relative DVA correction has a small, but not entirely
negligible, effect on NIRSpec – in the worst case amounting to intra-shutter
displacements of $\pm 14$ mas at the extreme corners of the 3.6$\times$3.4
arcmin2 MSA field of view.

In the eMPT, the DVA correction is applied by scaling the tangential
coordinates of the targets ($x_{\alpha}$,$y_{\delta}$) calculated from Eqs.
(1) and (2), using the MSA pointing ($\alpha_{p},\delta_{p}$) as the tangent
point by the factor $M_{DVA}$ calculated from Eq. (11), for the value of
$\theta$ entered by the user and assuming a constant spacecraft velocity of
$v=30.0$ km s-1. The STScI MPT employs a more accurate velocity vector based
on the JWST spacecraft ephemerides, but calculates the angle $\theta$ with
respect to the input catalog reference position ($\alpha_{c},\delta_{c}$)
discussed above, rather than the actual MSA pointing (although the DVA
correction is correctly applied using ($\alpha_{p},\delta_{p}$) as the
origin). However, since the magnification factor $M_{DVA}$ according to Eq.
(11) is a slowly changing function of $\theta$, this inconsistent approach
does not have much of a practical impact in most circumstances.

###  7.3 Importing eMPT output into the APT/MPT

The eMPT output that can be directly imported into the APT to generate a
customized APT MOS observation includes a STScI-formatted configuration file
(shutters.csv) that describes the MSA configuration of the optimized
pointing(s), that is, which shutters are to be commanded open and which are to
remain closed; the catalog of targets observed at the optimized pointing(s)
(observed-targets.cat); along with relevant pointing summary information that
must be entered into corresponding fields of the APT (pointing-summary.txt).

General instructions for creating an APT MOS observation from a custom-made
MSA configuration without the use of the MPT Planner can be found in the JWST
online documentation on the page entitled “Custom MOS Observations using the
MSA Configuration Editor.” However, as also warned there, this can be a very
tedious process and only intended for experienced users. For this reason,
after first importing the input catalog into the APT using the MSA Source
Catalog importer, it is advised to take the simpler and quicker path of
entering all of the relevant eMPT output into the Observations pane, in the
Configurations/Pointings section, and then utilizing the “Review in MPT”
function to switch over to the MPT Planner to replan as required to match the
imported configuration. This preferred procedure for importing the eMPT output
into the APT is described in full in the eMPT User Guide.

##  8 Summary and conclusions

The eMPT software suite is offered to JWST observers as a supplement to the
STScI MPT for designing the most scientifically optimal MSA configurations for
their planned NIRSpec MOS observations. It features robust and novel
algorithms and provides great flexibility and customizability to the user due
to its modular architecture. It utilizes an up-to-date, in-flight version of
the NIRSpec instrument model, and meticulously ensures maximal scientific
return for a given observing program by carefully prioritizing targets as
desired and maximizing the number of spectra that can cleanly and safely be
dispersed together onto the detector arrays in a single exposure.

The eMPT is capable of matching the $\sim$250,000 individually addressable
micro-shutters of the NIRSpec MSA to the targets listed in a user-supplied
prioritized input catalog, producing output that can be entered directly into
the STScI APT. Compared to the MPT, the eMPT offers additional user options
for dither selection and an automatic utilization of spare, empty MSA shutters
for a master background calculation.

In its present modular form, the eMPT software suite consists of seven
independent modules that are run in strict sequence, each step of which the
user can interactively examine and approve and optionally rerun with modified
parameter settings before proceeding to the next step. Alternatively, a full
automatic run of the software can be quickly executed from the command line
when only the final output summary, diagnostic, and plot files need to be
examined. There is also a user-configurable template script available for
running the eMPT in batch mode, designed for experienced users who may need to
run many exploratory trials in succession with different starting parameters
set for each.

While the eMPT was developed to address the specific scientific needs and
concerns of the NIRSpec GTO program, it ended up growing and evolving into
something larger and more generally applicable than originally envisioned, in
the space provided by the repeated delays of the JWST launch in recent years.
Therefore, it is being shared with the JWST NIRSpec observer community at
large for all to benefit.

###### Acknowledgements.

The eMPT software suite is the result of years of discussions on how best to
optimize the use of the novel Micro-Shutter Array that have taken place within
the NIRSpec GTO Team. Special thanks are due to Diane Karakla and Gary Curtis
of STScI for their openness and patience in explaining the inner workings of
the APT/MPT and participating in many mutually beneficial exchanges, tests and
discussions. We are especially indebted to Bernd Husemann for articulating a
specialized and important user case of the eMPT that pushed us to pursue his
suggestion of modularizing the eMPT, which greatly enhanced the flexibility
and utility of the system, and made it much easier to maintain.

The Cosmic Dawn Center (DAWN) is funded by the Danish National Research
Foundation under grant No. 140

SA acknowledges AEI grant PID2021-127718-NB-I00

## References

  * Alves de Oliveira et al. (2022) Alves de Oliveira, C., Lützgendorf, N., Zeidler, P., et al. 2022, 12180, 121803S
  * Birkmann et al. (2016) Birkmann, S. M., Ferruit, P., Rawle, T., et al. 2016, Proc. SPIE, 9904, 92
  * Cox & Gilliland (2003) Cox, C. & Gilliland, R. L. 2003, in HST Calibration Workshop : Hubble after the Installation of the ACS and the NICMOS Cooling System, 58
  * Dorner et al. (2016) Dorner, B., Giardino, G., Ferruit, P., et al. 2016, A&A, 592, A113
  * Ferruit et al. (2021) Ferruit, P., Jakobsen, P., Giardino, G., et al. 2021, A&A, 661, A81
  * Giardino et al. (2016) Giardino, G., Luetzgendorf, N., Ferruit, P., et al. 2016, Proc. SPIE, 9904, 1345
  * Henry et al. (2010) Henry, R., Isaacs, J., & Kinzel, W. 2010, JWST-STScI-001888, Tech. rep., STScI
  * Jakobsen et al. (2022) Jakobsen, P., Ferruit, P., Alves de Oliveira, C., et al. 2022, A&A, 661, A80
  * Karakla et al. (2014) Karakla, D., Shyrokov, A., Pontoppidan, K., et al. 2014, Proc. SPIE, 9149, 735
  * Keyes et al. (2018) Keyes, C. D., Beck, T. L., Peña-Guerrero, M., et al. 2018, Proc. SPIE, 10704, 587
  * Lützgendorf et al. (2022) Lützgendorf, N., Giardino, G., de Oliveira, C. A., et al. 2022, Proc. SPIE, 12180, 121800Y
  * Rawle et al. (2022) Rawle, T. D., Giardino, G., Franz, D. E., et al. 2022, Proc. SPIE, 12180, 121803R
  * Van de Kamp (1967) Van de Kamp, P. 1967, Principles of Astrometry (W. H. Freeman), p75
  * Whitaker et al. (2019) Whitaker, K. E., Ashas, M., Illingworth, G., et al. 2019, ApJS, 244, 16