# Optimizing Telescope Time¶

## 1. Introduction¶

One issue that astronomers comes across in their research is trying to get telescope time for their projects. For a lot of telescopes, a researcher will submit an observation proposal and then a committee will decide which observations to make. A problem with this method is that biases can be introduced on the side of the committee. So I propose to simply let the computer decide which proposals to take on. Using optimization, one can go through all given proposals and determine the maximum number of proposals they can perform and which ones those should be for a given telescope. This method takes out the need for a committee to meet up (which can be a challenge in itself) and more importantly, gets rid of any bias that committee members may have towards a given proposal.

With the launch of the Hubble Space Telescope back in 1990, scientists from around the world were eager to see what the new telescope could do. In order to weed through all of the proposals, the people at the Space Telescope Science Institute (STScI) came up with a review committee that is "made up of experts from the astronomical community" who determine "which proposed observations address pressing scientific questions and make the best use of the telescope's capabilities" (Team Hubble). Now I can see why this method is used a lot. There is a lot of important astronomy research to be done and the committee simply wants to see every area of research, from exoplanets to quasars, studied. The problem with basing it mainly on what the committee believes to be scientifically important is that there is a possibility that the maximum number of proposals that the telescope can actually take on will not be reached. "Each year more than 1,000 proposals are reviewed and approximately 200 are selected" (Team Hubble).

The James Webb Space Telescope, which will be launched in 2018 and in essence replace the outdated Hubble, is one such telescope that we can optimize proposals for. JWST has four instruments on board: NIRCam, MIRI, NIRSpec, and NIRISS, each one having their own field of view (James Webb Telescope Design). It will be at the second Lagrange point which means it will have a stable orbit relative to the Earth and Sun; it will stay in line with the Earth as it orbits the Sun. The following diagram represents where JWST will reside and how it will orbit:

For this project, I will synthetically generate a list of proposals (for JWST) that would be theoretically submitted to STScI for approval. Each proposal will have a number identifying it, how long the exposure time needs to be, where the celestial object is in the sky, how far away the object is, and which instrument on JWST it needs to use. I will then use Julia in order to create four schedules (one for each instrument) that will optimize JWST's observing time.

##### Citations:¶

Team Hubble. (n.d.). Retrieved April 25, 2016, from http://hubblesite.org/the_telescope/team_hubble/

James Webb Space Telescope Design. (n.d.). Retrieved April 25, 2016, from http://www.stsci.edu/jwst/overview/design/

## 2. Mathematical Model¶

### 2.A. Physics Equations and Assumptions¶

We will need to make a fair amount of assumptions in order to make this astrophysics problem easier to handle. Since James Webb will orbit the Sun and come back to the same point in space in one year, I will attempt to make an observing schedule for one year. (Usually Hubble takes observation proposals in one year chunks anyway.) From there, I will try and submit 1000 proposals.

Our first calculation is it determine how fast James Webb will be orbiting the Sun - which will affect how fast its field of view will be changing. We can use the following equation in order to determine the radial velocity:

$$(Eq. ~1): ~ V = \frac{2 * \pi * a }{T}$$

For this equation $a$ is the length of the semimajor axis and $T$ is the period of the orbit. We already know that the orbit is 365 days (the same as Earth). We also know that the Earth is 150 million km from the Sun and that L2 lies about 1.5 million km from the Earth. Therefore $a$ will be 151.1 million km. This calculation then yields a radial velocity of 30.18 $\frac{km}{sec}$. We calculated this because in order to take an observation, the celestial body must be in the field of view for the entire duration of the observation. This will then be a constraint in our mathematical model.

In terms of whether or not the instrument can actually see a given object, we need to take into account the field of view for each instrument:
*the units are in arc minutes
NIRCam = 2.2' x 2.2'
MIRI = 1.88' x 1.27'
NIRSpec = 3.4' x 3.4'
NIRISS = 2.2' x 2.2'

Now with the following equation (which is physically represented by the diagram below), we can determine how big the field of view would be for a given object (using its distance from James Webb) and the instrument we are trying to analyze it with ($\theta$ is the angle given in the previous list of angles):

$$(Eq.~2): ~ d = 2 * D * \tan(\frac{\theta}{2})$$

After calculating the size of the chunk of sky that we are looking at for a given object, we can then determine how long the telescope has to look at that area in the sky before the telescope moves to far away in its orbit (which we already know from our pervious calculation). This will be an important constraint in our model because the telescope must be pointing at the correct point in the sky for the whole duration of the observation (exposure time).

$$(Eq.~3): ~ Time = \frac{d}{30.18\frac{km}{sec}}$$

Also, to make it easier, for each proposal I will give the position in the sky for a given object in terms of the angle it makes with the Sun. The diagram below showcases two celestial bodies and the angle that will be given for each proposal (these angles will be randomly picked from 0 to 2$\pi$):

We can also calculate when JWST will be in line with the Sun and object we are trying to take an observation of. By calculating this number, it will make scheduling a time to observe an object a lot easier because we will know roughly when JWST (in its 365 days of orbiting) would be able to take an observation of that given body. In order to do this, all we have to do is use the following equation for every $\theta$:

$$(Eq.~4): ~ t = \frac{\theta * T}{2\pi}$$

For this equation $t$ is the time when JWST will be in line with the object, $T$ is the period (365 days), and $\theta$ is the angle between the object and the Sun.

Now that we understand the math behind the problem, we can start talking about the variables, constraints, objective function, and model type.

### 2.B. The Optimization Problem¶

We will be modeling this as a Traveling Salesman Problem, where we try and "visit" as many of the objects as we can in the 365 days. We will make a schedule for each instrument. Each one will have a 2d array (250 by 250) of binary numbers. (For example, if the variable at [78,93] is 1, we would be making an observation of object 78 followed by object 93.) Therefore we will technically have 25000 variables for the entire project. In terms of constraints, we will have a constraint that says the sum of the exposure times for the objects must not exceed the 365 days. Also, there will have to be a constraint that says that the exposure time for one object cannot overlap with another object - we can only "visit" one object at time. We will then have an objective function that will attempt to maximize the total number of objects that we can take observations of. The following represents the optimization problem in standard form:

\begin{aligned} \underset{z}{\text{maximize}}\qquad& \sum_{i=1}^{250} \sum_{j=1}^{250} z_{ij} \\ \text{subject to:}\qquad& exposureTime[i] \times z_{ij} \le totalTime[i] && i=1,\dots,250 && j=1,\dots,250 \\ & (startTime[i]+exposureTime[i]) \times z_{ij} \le startTime[j] && i=1,\dots,250 && j=1,\dots,250 \\ & [\sum_{i=1}^{250} z_{ij}] \le 1 && j=1,\dots,250 \\ & [\sum_{j=1}^{250} z_{ij}] \le 1 && i=1,\dots,250 \\ & [\sum_{i=1}^{250} \sum_{j=1}^{250} z_{ij} \times exposureTime[i]] \le 8760 \\ & z_{ij} \in \{0,1\} ~ binary \end{aligned}

The first listed constraint states that the exposure time (which is given to us in the proposal) must be within the amount of time we have to look at the object, which is based on intrinsic properties of the telescope (given to us in Eq. 3).

The next constraint states that the time when we can start looking at an object (given to us in Eq. 4) plus the total time we need to take the observation (given to us in the proposal) must be less than or equal to the start time of the next object (using Eq. 4 again). This will ensure that we finish an observation of an object before we start the next one.

The next two constraints simply make it that we can only, at max, look at one object at a time.

The final constraint is a really important constraint. This is the one that states we only have 8760 hours (365 days) for all of the observations that we want to make. Therefore the sum of all the exposures must be less than or equal to the total time we have to make observations.

## 3. Solution¶

We will start by reading in the data for all four instruemts and then put them into arrays to make it easier to work with the data.

In [1]:
# DATA
# We first need to read in the proposals - they are in a csv file
# The first 250 entries are for NIRCam, the next 250 for MIRI, the next 250 for NIRSpec, and the last 250
# are for NIRISS

raw = readdlm("Witt_Data.csv",',');

# NIRCam's Data
NIRCamNames = raw[2:251,1];
NIRCamPositions = raw[2:251,2];
NIRCamExposures = raw[2:251,3];
NIRCamDistances = raw[2:251,4];

# MIRI's Data
MIRINames = raw[252:501,1];
MIRIPositions = raw[252:501,2];
MIRIExposures = raw[252:501,3];
MIRIDistances = raw[252:501,4];

# NIRSpec's Data
NIRSpecNames = raw[502:751,1];
NIRSpecPositions = raw[502:751,2];
NIRSpecExposures = raw[502:751,3];
NIRSpecDistances = raw[502:751,4];

# NIRISS's Data
NIRISSNames = raw[752:1001,1];
NIRISSPositions = raw[752:1001,2];
NIRISSExposures = raw[752:1001,3];
NIRISSDistances = raw[752:1001,4];


The next few blocks of code will run through the math equations that we oulined in section 2.A.

In [2]:
# TOTAL TIME - This section is where we will calculate the maximum amount of time that we will have to make each observation
# We will start by figuring out d (which is the distance across the field of view)
# Side Note - since these angles are in arcminutes, I will times the number by pi/10800 (which will give us radians)
# Side Note 2 - there are 9.461*10^12 km in one light year
# NIRCam = 2.2' x 2.2'
# MIRI = 1.88' x 1.27' - I'll just use the first angle to make it easier
# NIRSpec = 3.4' x 3.4'
# NIRISS = 2.2' x 2.2'

# These distances will be in light years
NIRCam_Distances = []
MIRI_Distances = []
NIRSpec_Distances = []
NIRISS_Distances = []

NIRCam_Times = []
MIRI_Times = []
NIRSpec_Times = []
NIRISS_Times = []

for n = 1:250
push!(NIRCam_Distances,(2*NIRCamDistances[n]*tan((2.2*(pi/10800)/2))))
push!(MIRI_Distances,(2*MIRIDistances[n]*tan((1.88*(pi/10800)/2))))
push!(NIRSpec_Distances,(2*NIRSpecDistances[n]*tan((3.44*(pi/10800)/2))))
push!(NIRISS_Distances,(2*NIRISSDistances[n]*tan((2.2*(pi/10800)/2))))

push!(NIRCam_Times, ((9.461*10^(12)*NIRCam_Distances[n])/30.18)*0.000277778)
push!(MIRI_Times, ((9.461*10^(12)*MIRI_Distances[n])/30.18)*0.000277778)
push!(NIRSpec_Times, ((9.461*10^(12)*NIRSpec_Distances[n])/30.18)*0.000277778)
push!(NIRISS_Times, ((9.461*10^(12)*NIRISS_Distances[n])/30.18)*0.000277778)
end

In [3]:
# START TIME - This section will determine how early we can start taking an observation for each object
NIRCam_StartTime = []
MIRI_StartTime = []
NIRSpec_StartTime = []
NIRISS_StartTime = []

for n = 1:250
push!(NIRCam_StartTime,((NIRCamPositions[n]*8760))/(2*pi))
push!(MIRI_StartTime,((MIRIPositions[n]*8760))/(2*pi))
push!(NIRSpec_StartTime,((NIRSpecPositions[n]*8760))/(2*pi))
push!(NIRISS_StartTime,((NIRISSPositions[n]*8760))/(2*pi))
end

In [4]:
# Our version of distances for TSP - which will be in times
# These arrays will be the times in between all of the objects
NIRCamTimes = zeros(250,250)
MIRITimes = zeros(250,250)
NIRSpecTimes = zeros(250,250)
NIRISSTimes = zeros(250,250)

for row = 1:250
for col = 1:250
NIRCamTimes[row,col]=(NIRCam_StartTime[row]) -  (NIRCam_StartTime[col])
MIRITimes[row,col] = (MIRI_StartTime[row]) - (MIRI_StartTime[col])
NIRSpecTimes[row,col] = (NIRSpec_StartTime[row]) - (NIRSpec_StartTime[col])
NIRISSTimes[row,col] = (NIRISS_StartTime[row]) - (NIRISS_StartTime[col])
end
end


Now that we have the data from our proposals, we will model the problem in Julia.

*** As a side note, it takes a few minutes to run through the code for each instrument.

In [12]:
# SCHEDULE 1 - NIRCam

using JuMP
m1 = Model()

@variable(m1, NIRCamObjects[1:250,1:250], Bin)

for row = 1:250
for col = 1:250
# The telescope must be able to have enough time for each exposure
@constraint(m1, (NIRCamExposures[row])*NIRCamObjects[row,col] <= NIRCam_Times[row])
# There also must be no overlap - the exposure for one object must end before we start the next one
@constraint(m1, (NIRCam_StartTime[row] + NIRCamExposures[row])*NIRCamObjects[row,col] <= NIRCam_StartTime[col])
end
end

for n = 1:250 # This will also make sure that there are no overlaps
@constraint(m1, sum(NIRCamObjects[:,n]) <= 1)
@constraint(m1, sum(NIRCamObjects[n,:]) <= 1)
end

# We also have to make sure that the observation times do not exceed our 365 days (8760 Hours)
@constraint(m1, sum{(NIRCamObjects[k,n].*NIRCamExposures[k]), k = 1:250, n = 1:250} <= 8760)

# Our objective is to maximize the number of objects we can observe
@objective(m1, Max, sum(NIRCamObjects))
solve(m1)
println(getObjectiveValue(m1))

205.99999999999991

In [13]:
# SCHEDULE 2 - MIRI

using JuMP
m2 = Model()

@variable(m2, MIRIObjects[1:250,1:250], Bin)

for row = 1:250
for col = 1:250
# The telescope must be able to have enough time for each exposure
@constraint(m2, (MIRIExposures[row])*MIRIObjects[row,col] <= MIRI_Times[row])
# There also must be no overlap - the exposure for one object must end before we start the next one
@constraint(m2, (MIRI_StartTime[row] + MIRIExposures[row])*MIRIObjects[row,col] <= MIRI_StartTime[col])
end
end

for n = 1:250 # This will also make sure that there are no overlaps
@constraint(m2, sum(MIRIObjects[:,n]) <= 1)
@constraint(m2, sum(MIRIObjects[n,:]) <= 1)
end

# We also have to make sure that the observation times do not exceed our 365 days (8760 Hours)
@constraint(m2, sum{(MIRIObjects[k,n].*MIRIExposures[k]), k = 1:250, n = 1:250} <= 8760)

# Our objective is to maximize the number of objects we can observe
@objective(m2, Max, sum(MIRIObjects))
solve(m2)
println(getObjectiveValue(m2))

207.0

In [14]:
# SCHEDULE 3 - NIRSpec

using JuMP
m3 = Model()

@variable(m3, NIRSpecObjects[1:250,1:250], Bin)

for row = 1:250
for col = 1:250
# The telescope must be able to have enough time for each exposure
@constraint(m3, (NIRSpecExposures[row])*NIRSpecObjects[row,col] <= NIRSpec_Times[row])
# There also must be no overlap - the exposure for one object must end before we start the next one
@constraint(m3, (NIRSpec_StartTime[row] + NIRSpecExposures[row])*NIRSpecObjects[row,col] <= NIRSpec_StartTime[col])
end
end

for n = 1:250 # This will also make sure that there are no overlaps
@constraint(m3, sum(NIRSpecObjects[:,n]) <= 1)
@constraint(m3, sum(NIRSpecObjects[n,:]) <= 1)
end

# We also have to make sure that the observation times do not exceed our 365 days (8760 Hours)
@constraint(m3, sum{(NIRSpecObjects[k,n].*NIRSpecExposures[k]), k = 1:250, n = 1:250} <= 8760)

# Our objective is to maximize the number of objects we can observe
@objective(m3, Max, sum(NIRSpecObjects))
solve(m3)
println(getObjectiveValue(m3))

205.0

In [15]:
# SCHEDULE 4 - NIRISS

using JuMP
m4 = Model()

@variable(m4, NIRISSObjects[1:250,1:250], Bin)

for row = 1:250
for col = 1:250
# The telescope must be able to have enough time for each exposure
@constraint(m4, (NIRISSExposures[row])*NIRISSObjects[row,col] <= NIRISS_Times[row])
# There also must be no overlap - the exposure for one object must end before we start the next one
@constraint(m4, (NIRISS_StartTime[row] + NIRISSExposures[row])*NIRISSObjects[row,col] <= NIRISS_StartTime[col])
end
end

for n = 1:250 # This will also make sure that there are no overlaps
@constraint(m4, sum(NIRISSObjects[:,n]) <= 1)
@constraint(m4, sum(NIRISSObjects[n,:]) <= 1)
end

# We also have to make sure that the observation times do not exceed our 365 days (8760 Hours)
@constraint(m4, sum{(NIRISSObjects[k,n].*NIRISSExposures[k]), k = 1:250, n=1:250} <= 8760)

# Our objective is to maximize the number of objects we can observe
@objective(m4, Max, sum(NIRISSObjects))
solve(m4)
println(getObjectiveValue(m4))

206.00000000000014


## 4. Results and Discussion¶

### 4.A. Results¶

So it looks like each instrument had roughly the same amount of proposals it could accept: NIRCam could take 206, MIRI could take 207, MIRSpec could take 205, and MIRISS could take 206. Therefore, out of 1000 proposals for a given year, JWST could accept a maximum of 824. I am not too surprised that all four instruments were able to take roughly the same amount of proposals. Each one had a very similar field of view. Now if we had an instrument with a very small field of view, we would expect it to not be able to meet the exposure requirement for certain objects.

Now, I am not going to print out the schedule for each one because that would take up a lot of space, but we know that JWST would be making observations of objects in the order that it is orbiting around the Sun. In other words objects with a small position angle come before ones with a high position angle. As demonstrated in the diagram below, JWST would, as expected make observations at the first object, then the second and on and on but once it gets to the forth object it would make a decision of whether or not to take on four or five:

By doing observations in this way, and not basing it on whether a committee finds a proposal "scientifically significant" we can get more observations in for a given proposal year.

### 4.B. Sensitivity and Assumptions¶

So it seems that since the objects that I supplied for this optimization were so far away that there was no real problem with JWST moving too fast to complete an observation. In other words, the field of view is very large for all four instruments for every object, which causes the amount of time that the telescope is pointing at a certain chunk of the sky to be large. I had made the distances anywhere from 1 to 100 light years. Now if I had made the objects a lot closer there could have been the chance that JWST moved too fast in its orbit and wouldn't be able to make the entire exposure time.

Also, I had made all of the objects point sources. In reality though, some objects can be much bigger than others and would move out of the field of view faster than smaller objects. Therefore, bigger objects might not have as much of a chance of being chosen.

## 5. Conclusion¶

So in conclusion it seems that making a schedule for a telescope is a lot harder than I thought it would be. Since we only looked at the maximum number of observations we could take on, with respect to their exposure times, we were able to make a far amount of observations. We simply minimized the amount of time between observations as we orbited around the Sun. Whether or not these would be as "scientifically important" as ones we didn't pick is hard to say. In other words, I can see why these proposals go through a committee.

There are a lot of things to take into account that I wasn't even able to touch on in this project. For instance, JWST will actually be orbiting around the second Lagrange point. So one possible direction that I could go in would be to work this extra orbital constraint into the problem.

Another possible follow up would be to make the project even more generic, so it can work for other telescopes as well.