\documentclass{article}
\pagestyle{empty}
\usepackage[ps2pdf,colorlinks=true]{hyperref}
\usepackage{html}
\setlength{\textwidth}{415pt}
\setlength{\textheight}{610pt}
\setlength{\hoffset}{-40pt}
\setlength{\parindent}{0cm}
\newcommand{\AWE}{\texttt{awe}}
\newcommand{\dpu}{\texttt{DPU}}


\title{Astrometry exercises}
\begin{document}
\maketitle

\section*{Find Astrometric Solution}

{\it Question 1:} In a previous exercise, a \texttt{ReducedScienceFrame} was
created with the \texttt{ScienceTask}.  Construct a list of these frames.

\vspace{0.3cm}
\noindent
Instruction: Use information in the 
\htmladdnormallink{Python database querying HOW-TO}{http://www.astro-wise.org/portal/howtos/man\_howto\_queries/man\_howto\_queries.shtml} 
at the ASTRO-WISE portal (http://portal.astro-wise.org/) to construct a query 
that contains your and only your \texttt{ReducedScienceFrames}.

\begin{verbatim}
Answer:
awe> date = DateTime.DateTimeFrom('2001-01-01')
awe> q  = (ReducedScienceFrame.DATE_OBS == date)
awe> q &= (ReducedScienceFrame.instrument.name == 'WFI') 
awe> q &= (ReducedScienceFrame.filter.name == '#877'))
awe> q &= (ReducedScienceFrame.OBJECT.like('Science*'))
awe> len(q)
<some number of frames>
awe> for f in q: print f.filename, f.DATE_OBS, f.filter.name, f.OBJECT
.
.
.
\end{verbatim}

\noindent
A more direct way would be to use the select method:

\begin{verbatim}
Answer:
awe> q = ReducedScienceFrame.select(date=<date>, instrument='WFI', filter='#877',
         object='Science*')
awe> len(q)
<some number of frames>
awe> for f in q: print f.filename, f.DATE_OBS, f.filter.name, f.OBJECT
.
.
.
\end{verbatim}

{\it Question 2:} In a previous exercise, \texttt{ReducedScienceFrames} were
created with the \texttt{ScienceTask}.  Determine if the astrometric solutions
were created for these frames.

\vspace{0.3cm}
\noindent
Instruction: Use information in the 
\htmladdnormallink{Astrometry check HOW-TO}{http://www.astro-wise.org/portal/howtos/man\_howto\_qcastrom/man\_howto\_qcastrom.shtml} 
at the ASTRO-WISE portal (http://portal.astro-wise.org/) to query the database
for the existance of an \texttt{AstrometricParameters} object for one of your
\texttt{ReducedScienceFrames}.

\begin{verbatim}
Answer:
awe> apq = AstrometricParameters.reduced == q[0]
awe> len(apq)
1
\end{verbatim}

{\it Question 3:} Create \texttt{AstrometricParameters} for 
\texttt{ReducedScienceFrames}.

\vspace{0.3cm}
\noindent
Instruction: Use information in the 
\htmladdnormallink{Astrometry check HOW-TO}{http://www.astro-wise.org/portal/howtos/man\_howto\_astrometry/man\_howto\_astrometry.shtml} 
at the ASTRO-WISE portal (http://portal.astro-wise.org/) to re-derive the \texttt{AstrometricParameters} for your \texttt{ReducedScienceFrames}.

\begin{verbatim}
Answer:
awe> list = [name.filename for name in q]
awe> dpu.run('Astrom', i='WFI', l=list, C=1)
\end{verbatim}

{\it Question 4:} Examine the attributes of an \texttt{AstrometricParameters} object.

\vspace{0.3cm}
\noindent
Instruction: Use the \texttt{dir()} method to see the attributes of interest (usually in all capital letters).

\begin{verbatim}
Answer:
awe> apq = AstrometricParameters.reduced.filename == q[0].filename
awe> dir(apq[0])
['CD1_1', 'CD1_2', 'CD2_1', 'CD2_2', 'CRPIX1', 'CRPIX2', 'CRVAL1', 'CRVAL2',
'CTYPE1', 'CTYPE2', 'FITERRS', 'FITPARMS', 'Flagged', 'MEAN_DDEC', 'MEAN_DRA',
'NFITPARM', 'NREF', . . .
awe> print ap.CD1_1
-6.613638e-05
awe> print ap.CD1_2
3.554581e-07
.
.
.
\end{verbatim}


\section*{Create a \texttt{RegriddedFrame}}

{\it Question 5:} In order to visually inspect an astrometric solution, the \texttt{ReducedScienceFrame} must first be converted into a \texttt{RegriddedFrame}.

\vspace{0.3cm}
\noindent
Instruction: Follow the instructions in the 
\htmladdnormallink{\texttt{ScienceTask} HOW-TO}{http://www.astro-wise.org/portal/howtos/man\_howto\_qcastrom/man\_howto\_qcastrom.shtml} 
at the ASTRO-WISE portal (http://portal.astro-wise.org/) to process your \texttt{ReducedScienceFrames} into \texttt{RegriddedFrames}.

\begin{verbatim}
Answer:
awe> dpu.run('Regrid', i='WFI', d='2001-01-01', f='#877', o='Science*', C=1)
\end{verbatim}


\section*{Visually Inspect Astrometry}

{\it Question 6:} Inspect the astrometric solution for the regridded frames 
just crearted.

\vspace{0.3cm}
\noindent
Instruction: Follow the instructions in the 
\htmladdnormallink{\texttt{ScienceTask} HOW-TO}{http://www.astro-wise.org/portal/howtos/man\_howto\_qcastrom/man\_howto\_qcastrom.shtml} 
at the ASTRO-WISE portal (http://portal.astro-wise.org/) to inspect the astrometric solution for one of your regridded frames.

\begin{verbatim}
awe> rq = RegriddedFrame.reduced == q[0]
awe> os.system('skycat %s' % (rq[0].filename))
\end{verbatim}


\end{document}
