\section{How to}
\label{sec:how_to}

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to log into a UdeM Machine}
\label{sec:how_to:log_in}
% ---------------------------------------------------------------------------------

First you need to log on to venus.astro.umontreal with your personal account. 

For example: 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
ssh -XY -oport=5822 cook@venus.astro.umontreal
\end{lstlisting}
\end{codebox}

Then login to the “nirp-client” account (please ask for password) on rail. 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
ssh nirps-client@rali
\end{lstlisting}
\end{codebox}

Note please do not use the rali.astro.umontreal.ca machine for non-babysitter activities . 

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to activate the environment}
\label{sec:how_to:activate_environment}
% ---------------------------------------------------------------------------------

Currently we are using APERO version 7 so we activate this conda environment as follows: 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
conda deactivate 
conda deactivate 
conda deactivate 
conda activate apero-env-07 
\end{lstlisting}
\end{codebox}

This loads all python modules required to run various apero and apero affiliated recipes. 

Note you need to deactivate as many times as required until there is no longer the word (base) in the command prompt (or until you see no * next to any profile when using `conda env list'. 

\subsubsection{How to check your conda environment}

You can check you conda environment by using the command: 
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
conda env list 
\end{lstlisting}
\end{codebox}

There will be an asterisk (\*) by the conda environment you are currently in. 

\subsubsection{Note that you may already be in the correct environment}

If you use \lstcode{conda env list} and see you are already in `apero-env-07' you don’t need to deactivate and re-activate as said above (unless you want to be extra safe). 


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to load an apero profile}
\label{sec:how_to:load_apero_profile}
% ---------------------------------------------------------------------------------

\subsubsection{Introduction}

An `apero profile' is a specific setup for a specific instrument, mode and reduction. 

Note there is no way to `deactivate' an apero profile – you just load a new one over an old one. 

\subsubsection{Step 1/3}

\hyperref[sec:how_to:log_in]{Log on to the correct machine}.

\subsubsection{Step 2/3}

\hyperref[sec:how_to:activate_environment]{Activate the conda environment}.

\subsubsection{Step 3/3}

Load the correct APERO profile 

The following is for NIRPS-HE (online): 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
nirps_he_online 
\end{lstlisting}
\end{codebox}

And the following for NIRPS-HA (offline): 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
nirps_ha_online 
\end{lstlisting}
\end{codebox}

If done correctly, you should see something similar to the following:  

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=\textwidth]{images/apero_splash.png}
    \caption{APERO validation - this appears when you correctly activate an apero profile}
    \label{fig:enter-label}
\end{figure}

\subsubsection{How to check you are in the correct apero profile}

You'll know if you are in a current apero profile in two ways: 

\begin{itemize}
    \item The command prompt should start with something like \lstcode{nirps_he_online} in yellow followed by the date and then user@machine and then your current path. 

    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    nirps_he_online Fri Jan 31 10:24:16 /your/path/here
    \end{lstlisting}
    \end{codebox}

    \item You can check the \lstcode{DRS_UCONFIG} environmental variable. This is done by typing the command: \lstcode{echo $DRS_UCONFIG$} 

    And you should see the path linking to the APERO you want e.g. for NIRPS-HE online the path should be \lstpath{/cosmos99/nirps/apero-settings/nirps_he_online}
\end{itemize}

There is no way to deactivate another APERO profile so you just activate a new one on top of an old one.

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to re-run an apero check}
\label{sec:how_to:re_run}
% ---------------------------------------------------------------------------------

\subsubsection{Step 1/4}

\hyperref[sec:how_to:log_in]{Log on to the correct machine}.

\subsubsection{Step 2/4}

\hyperref[sec:how_to:activate_environment]{Activate the conda environment}.

\subsubsection{Step 3/4}

Type the following in the command line to change to the correct directory

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_checks
\end{lstlisting}
\end{codebox}

\subsubsection{Step 4/4}

You need to decide:

\begin{itemize}
    \item Whether you want to Run a `raw check' or a `reduced check'
    \item Which yaml you want to check (linked to a specific apero profile) 
    \item Which observation date you want to check 
    \item What kind of test you want to run 
\end{itemize}

\subsubsection{Which check?}

If you are looking at the `raw checks' (e.g. RAW-NIRPS-HE or RAW-NIRPS-HA) then the code you need to run is \lstcode{apero_raw_check.py}. 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_raw_check.py {yaml name} {obs dir} {test} 
\end{lstlisting}
\end{codebox}

If you are looking at the `reduced checks' (e.g. RED-ONLINE-NIRPS-HE or RED-ONLINE-NIRPS-HA) then the code you need to run is \lstcode{apero_red_check.py}. 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_red_check.py {yaml name} {obs dir} {test} 
\end{lstlisting}
\end{codebox}

\subsubsection{Which YAML name}

The yaml files are in the directory you changed to with the \lstcode{apero_checks} command. 

Currently, they are: 
\begin{itemize}
    \item \lstcode{nirps_he_online_udem}
    \item \lstcode{nirps_he_offline_udem}
    \item \lstcode{nirps_ha_online_udem}
    \item \lstcode{nirps_ha_offline_udem} 
\end{itemize}

In the commands below we refer to this as `yaml name': 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_raw_check.py {yaml name} 
\end{lstlisting}
\end{codebox}


\subsubsection{Which observation date(s)}

You  can choose from: 
\begin{itemize}
    \item any observation night in format \lstpath{YYYY-MM-DD} or observation nights (as a comma-separated list)
    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    apero_raw_check.py {yaml name} --obsdir=YYYY-MM-DD 
    apero_raw_check.py {yaml name} --obsdir=YYYY-MM-DD,YYYY-MM-DD 
    \end{lstlisting}
    \end{codebox}
    \item today
    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    apero_raw_check.py {yaml name} --today 
    \end{lstlisting}
    \end{codebox}
    \item yesterday
    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    apero_raw_check.py {yaml name} --yesterday 
    \end{lstlisting}
    \end{codebox}
\end{itemize}

You can also leave out this argument to run all nights (though this will take a long time, so think carefully about \hyperref[sec:how_to:re_run:kind_of_test]{what kind of test you want to run}. 

\subsubsection{What kind of test you want to run}
\label{sec:how_to:re_run:kind_of_test}

You have a choice: 

\begin{enumerate}
    \item re-run all tests for the observation date (in this case no \lstcode{test} argument is required):
    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    apero_raw_check.py {yaml name} --obsdir={obs dir}  
    apero_red_check.py {yaml name} --obsdir={obs dir}  
    \end{lstlisting}
    \end{codebox}

    \item re-run a specific test or set of tests for the observation 
    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    apero_raw_check.py {yaml name} --obsdir={obs dir} --testfilter={TEST1},{TEST2} 
    apero_red_check.py {yaml name} --obsdir={obs dir} --testfilter={TEST1},{TEST2}  
    \end{lstlisting}
    \end{codebox}

    \item run in test mode to display a report of a specific test failure 
    \begin{codebox}[]{Bash}
    \begin{lstlisting}[language=Bash]
    apero_raw_check.py {yaml name} --obsdir={obs dir} --test={TEST1} 
    apero_red_check.py {yaml name} --obsdir={obs dir} --test={TEST1}  
    \end{lstlisting}
    \end{codebox}    
\end{enumerate}

Where \lstcode{TEST1, TEST2, ..., TESTN} are the raw or reduced test column names. 

 
% ---------------------------------------------------------------------------------
\newpage
\subsection{How to override a check}
\label{sec:how_to:override_check}
% ---------------------------------------------------------------------------------

For some checks we require you to override a FALSE value with a TRUE value manually.
This is normally when a FALSE has been triggered correctly but the reason for the FALSE is okay.

This can only be done on certain raw checks:
\begin{itemize}
    \item \hyperref[sec:raw_checks:crit_sci]{CRIT\_SCI}
    \item \hyperref[sec:raw_checks:no_sci]{NO\_SCI}
\end{itemize}

and certain red checks:
\begin{itemize}
    \item \hyperref[sec:raw_checks:crit_sci]{HAS\_OBSDIR} (Though please do not use this without verifying with Neil first).
    \item \hyperref[sec:raw_checks:no_sci]{LOW\_SNR}
\end{itemize}

To override a FALSE first run \hyperref[sec:how_to:re_run]{steps 1 to 3 of re-running a check}

Then run the following command:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
python apero_check_override.py {yaml name} --test={TEST NAME} --obsdir=XXXX
\end{lstlisting}
\end{codebox}

Where `XXXX` is the observation directory for the override required and \lstcode{TEST NAME} is the test you wish to override. 

Make sure to add your name and a good reason why there were no observations (i.e. don't just write things like ``no data'' please try to explain why there was no data. 

You may need to \hyperref[sec:how_to:re_run]{re-run the apero checks} for this night again if it doesn't update from FALSE to TRUE. 


% ---------------------------------------------------------------------------------
\newpage
\subsection{How do I know which data are which?}
\label{sec:how_to:identify_data}
% ---------------------------------------------------------------------------------

Unless you are Etienne, most of us can't identify a calibration from science data without a lot of hard work looking at images along (and this isn't practical when wanting to know this about many files).

The headers of fits files are your friend and reading fits file headers is a must.

You can of course open up files in python but it is must faster (and convienient) to do so from the command line.


\subsubsection{Opening a fits header from the command line}

We use two commands which are installed on the servers \lstcode{dfits} and \lstcode{fitsort}, we don't use them separately but together to give us a table like result.


\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
dfits {filename} | fitsort {header_key_1} {header_key_2}
\end{lstlisting}
\end{codebox}

Where \lstcode{filename} can have unix wildcards such as \lstcode{*}, \lstcode{?}, \lstcode{[]} etc,
and \lstcode{header_key_1} and \lstcode{header_key_2} are a list of header keys separated by whitespace (you can use as many as you need, though for readability avoid too many).

An example is the following on NIRPS HE data:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
cd /nirps_raw/nirps/raw-data/nirps_he/
dfits 2025-10-1[0-9]/*.fits | fitsort OBJECT dpr.type
\end{lstlisting}
\end{codebox}

This will display all fits files from 2025-10-10 to 2025-10-19 and give the header keys OBJECT and dpr.type (see section \ref{sec:which_data:useful_headers}). The \lstcode{[]} gives all permutations between 0 and 9, the \lstcode{*} gets everything with this prefix (followed by .fits).


\subsubsection{Opening a fits header in python}

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=python]
# import astropy 
from astropy.io import fits
# read the header
hdr = fits.getheader(filename)
# access a header key
print(hdr['OBJECT'])
\end{lstlisting}
\end{codebox}

\subsubsection{Useful header keys}
\label{sec:which_data:useful_headers}

There are some extremely useful header keys in the raw and reduced data.

\begin{gentable}
\hline
Header key & what files & Data Type & Comment \\
\hline
OBJECT & raw+reduced & STRING & Observation type (from telescope) \\
obs.targ.name &  raw+reduced & STRING & Observation Block target name (usually what was set by scheduler/observer) \\
dpr.type &  raw+reduced & STRING & The ESO data type (see below) \\
DPRTYPE & reduced [APERO] & STRING & The APERO data type \\
dpr.catg & raw+reduced & STRING & The ESO data catagory \\
\hline
\end{gentable}

Note that more information on data types can be found here, how we define the APERO DPRTYPE based on the ESO keywords.

\begin{itemize}
    \item \href{https://apero.exoplanets.ca/auto/file_definitions/nirps_he/files.html}{NIRPS HE}
    \item \href{https://apero.exoplanets.ca/auto/file_definitions/nirps_ha/files.html}{NIRPS HA}
\end{itemize}


Note that:
\begin{itemize}
    \item a calibration is one that has a DARK, LED, LAMP, FP, UN1, UN2, in the science fiber (we can never have science in the reference fiber).
    \item a telluric or hot star is a bright, fast rotating, hot star (spectral type A or F) which we use for telluric correction these are denoted by \lstcode{TELLURIC,SKY} in multiple header keys (including \lstcode{dpr.type} and \lstcode{OBJECT})
    \item a science observation will be either \lstcode{OBJECT,SKY} or \lstcode{OBJECT,FP} in \lstcode{dpr.type}
\end{itemize}


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to find and read a log file}
\label{sec:how_to:find_log}
% ---------------------------------------------------------------------------------

Log files are an important way (the only way sometimes) to diagnose a problem. 

They come in different flavours depending on what has been run. 

We document the following below: 

\begin{itemize}
    \item \hyperref[sec:how_to:override_check:recipes]{apero recipes}
    \item \hyperref[sec:how_to:override_check:checks]{apero check scripts}
    \item \hyperref[sec:how_to:override_check:manual_trigger]{manual trigger}
\end{itemize}

\subsubsection{APERO recipes}
\label{sec:how_to:override_check:recipes}

This includes: 

\begin{itemize}
    \item \lstcode{apero_processing.py}
    \begin{itemize}
        \item all apero recipes run inside \lstcode{apero_processing.py}
    \end{itemize}

    \item apero tools: 
    \begin{itemize}
        \item \lstcode{apero_ri.py} [ARI] 
        \item \lstcode{apero_reject.py} 
        \item \lstcode{apero_remove.py} 
        \item \lstcode{apero_get.py} 
    \end{itemize}
\end{itemize}

Note that the manual trigger runs \lstcode{apero_processing}, \lstcode{apero_ri}, \lstcode{apero_get}

The place to look for these log messages is here: 

\begin{itemize}
    \item NIRPS-HE (online): \lstpath{/cosmos99/nirps/apero-data/nirps_he_online/msg}
    \item NIRPS-HA (online): \lstpath{/cosmos99/nirps/apero-data/nirps_ha_online/msg}
\end{itemize}

\note{Logging style}

All APERO logs are separated into 3 bits: 

\begin{itemize}
    \item Splash: the “start of the apero recipe” – contains inputs etc 
    \begin{itemize}
        \item Starting with \lstcode{NIRPS_HE @PID-XXXXXXXXXXXXX}
        \item Stating the version, git branch, config and run arguments used 
    \end{itemize}

    \item What was run in the recipe 

    \item A statement saying the recipe finished successfully or did not (had a caught error). Start with:
    \begin{itemize}
        \item \lstcode{I[40-003-00001]: Recipe {recipe_name} has been successfully completed}
        \item \lstcode{W[40-003-00005]: Recipe {recipe_name} has NOT been successfully completed}
    \end{itemize}
\end{itemize}

If you do not see one of these lines at the end the APERO recipe crashed unexpectedly and needs reporting! 

\note{apero processing logs}

\lstcode{apero_processing} logs will be stored in the sub-directory \lstpath{/tool/other} there will be one per run (or per manual trigger run). 

Note that the `what was run in the recipe section' can be separated into three important bits: 
\begin{itemize}
    \item Verification and skipping – contains what was planned to be run 
    \item What was run (the run string for each command that was run) 
    \item What finished + errors for individual recipes 
\end{itemize}

Also note that the name of the log has a long PID code which is used as the APERO group for recipes run inside \lstcode{apero_processing}.

\note{APERO recipe run inside apero processing}

These are stored in the \lstpath{/processing/\{APERO_GROUP\}/\{obsdir\}} directory.  

Where APERO\_GROUP comes from the \lstcode{apero_processing} run (see above section) followed by \lstcode{_group}

There will be one log for each recipe run. 

Note that any recipes that don't have a group wont go into \lstpath{YYYY-MM-DD} but an `other' directory e.g. for template creation or any LBL step.

Note there is also a `sub-recipe'  directory in the log directory – this is for recipes run inside other recipes and works similarly with the group being the parent recipe pid followed by \lstcode{_group}

\note{Hint for locating the correct recipe log}

You need to first find the APERO group directory inside the \lstpath{msg/processing/} directory (this will most likely be the most recent APERO group) you can then change into the observation directory, then there may be a log of logs so using a grep works well to locate the log file: 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
grep -n {file identifier} *recipe*
\end{lstlisting}
\end{codebox}

Where \lstcode{{file identifier}} is the \lstpath{NIRPS-YYYY-MM-DDThh_mm_ss_sss} part of the filename (without \lstpath{_pp... .fits}). 

After re-running the manual trigger, running the dfits command and finding the recipe log file for this file/ these files. Please email the list of files (and the log from the reduced check) to the following people: 

\begin{contacttable}
    \ccNeil{1} & \eeNeil \\
    \ccEtienne{} & \eeEtienne \\
    \ccLison{} & \eeLison \\
    \hline
\end{contacttable}

\note{APERO recipes that are run on their own}

These will be in a \lstpath{/recipes/ sub-directory} (or \lstpath{/sub-recipes/} sub-directory) and are in the same format as those run inside \lstcode{apero_processing}.

\note{APERO tools}

These include: 
\begin{itemize}
    \item \lstcode{apero_ri.py} [ARI]
    \item \lstcode{apero_reject.py}
    \item \lstcode{apero_remove.py}
    \item \lstcode{apero_get.py}
\end{itemize}

They can be found in either the \lstpath{nolog-tool/other} or \lstpath{tool/other} sub-directory. 


\subsubsection{APERO checks}
\label{sec:how_to:override_check:checks}

The APERO checks dump all log messages into: \lstpath{HOMEDIR/apero_check.log} this file can be long if it has not been cleaned out properly, so we advise using a command like: 

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
tail -n 200 HOMEDIR/apero_check.log
\end{lstlisting}
\end{codebox}

Where the `-n` is the number of lines at the end of the file to look at. 

The log format is as follows: 
\begin{itemize}
    \item A splash
    \begin{itemize}
        \item starting with `APERO Raw data checks'
        \item which has the version and date last updated
    \end{itemize}
    \item A part showing what was run
    \item A line saying `Code finished successfully'
\end{itemize}


\subsubsection{Manual trigger}
\label{sec:how_to:override_check:manual_trigger}

The manual trigger log file is a lot more basic than the others. It stores one log per yaml file. 

They are stored in \lstpath{HOMEDIR/.apero/manual_trigger/} and the name of the file is the yaml file name with the \lstpath{.yaml} replaced with \lstpath{.log}. 

These logs are a big csv file with no header. 

The format of each file is as follows:

\begin{bcodebox}[]{Bash}
\begin{lstlisting}[language=Bash, style=nonumbering]
YYYY-MM-DD hh:mm:ss.sss, {apero profile}, {step}, {obsdir}, {comment}
\end{lstlisting}
\end{bcodebox}

where:

\note{apero\_profile}

The apero profile that was used (e.g. \lstcode{nirps ha online})

\note{step}

One of the steps that was run in the manual trigger, and is only added once that step is complete.
Possible steps are as follows:
\begin{itemize}
    \item MANUAL\_START
    \item MANUAL\_END
    \item APERO\_START
    \item APERO\_END
    \item ARI\_START
    \item ARI\_END
\end{itemize}

Please refer to the reduced checks section for details on these.

\note{obsdir}

is a \lstcode{|} separated list of observation nights that were asked for in the call to manual trigger

\note{comment}

Is a possible comment (but most the time is `None')

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to find the observer, observation log, and schedule}
\label{sec:how_to:find_observer}
% ---------------------------------------------------------------------------------

Open the link to the correct semester.

\begin{itemize}
    \item Scheduling tab
    \item Find the row with the date of observations
    \item Last columns have observer contact information
\end{itemize}

%%%%
% Important note: when adding links you need to escape "#" character otherwise you'll get an error
%%%
\begin{gentable}
    \hline
    Semester name & Start & End & Link \\
    \hline
    P111 & April 2023 & Sept 2023 & \href{https://docs.google.com/spreadsheets/d/1INui54LLIFjoWdcyrO93h7VlVofMV4OS2QNI04wDo_s/edit?gid=0\#gid=0}{Here}  \\
    P112 & Oct 2023 & March 2024 & \href{https://docs.google.com/spreadsheets/d/1DOd6UPPR7nqK1-DkCtr1ZyVSTyNG3rGfGd-OjCGw0_Q/edit?gid=0\#gid=0}{Here}  \\
    P113 & April 2024 & Sept 2024 & \href{https://docs.google.com/spreadsheets/d/1WCbENLb2Bhlpzr7AfmeQg4WgHOo7YperjPUutbf1vak/edit\#gid=0}{Here}  \\
    P114 & Oct 2024 & March 2025 & \href{https://docs.google.com/spreadsheets/d/1Fl4OaJcVgGs4nWeVZyDu6fDJpjXpWZPKcQysYS3sDVQ/edit?gid=0\#gid=0}{Here}  \\
    P115 & April 2025 & Sept 2025 &  \href{https://docs.google.com/spreadsheets/d/1UKGzSaYR_t6U-mbKywy818hwIiDSaEPas8eZWDi-s1E/edit?gid=0\#gid=0}{Here} \\
    P116 & Oct 2025 & April 2026 & 	\href{https://docs.google.com/spreadsheets/d/1rkHwgIEMDccyTTj9V5pGzNjOpr0E5DGHh2Zlf_sH6ec/edit?gid=0\#gid=0}{Here}  \\
    P117 &  May 2026 & April 2027 & \href{https://docs.google.com/spreadsheets/d/1cjSOJ3qnf7NILSCWVu4ca39PyKl_7H6oTEg2QgZza0E/edit?gid=0#gid=0}{Here} \\
    P118 &  &  & \\
    P119 &  &  & \\
    P120 &  &  & \\
    \hline
\end{gentable}


Note all semesters will be available on the \href{https://unigech.sharepoint.com/teams/NIRPS/Documents%20partages/Forms/AllItems.aspx?id=%2Fteams%2FNIRPS%2FDocuments%20partages%2FScience%20Team%2FObservations%2FTime%20Share&viewid=2f190b75%2D4180%2D41fc%2D983f%2D9cae3d9af119}{Geneva share point} \lstcode{Documents>Science Team>Observations>Time Share}. Look for the \lstcode{PXXX-TimeShare.url}

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to find information on a observation}
\label{sec:how_to:observation_schedule}
% ---------------------------------------------------------------------------------

The NIRPS observation schedules are given in the following table, you can check here which work packages targets belonged to, various astrophysical parameters and other requested observation conditions.

%%%%
% Important note: when adding links you need to escape "#" character otherwise you'll get an error
%%%
\begin{gentable}
    \hline
    Semester name & Start & End & Link \\
    \hline
    P111 & April 2023 & Sept 2023 & \href{https://docs.google.com/spreadsheets/d/1d9ggnYzHMK_8CQiH2en20FIST0XcWqWlfD44_WCYJmU/edit?gid=1813284249\#gid=1813284249}{Here}  \\
    P112 & Oct 2023 & March 2024 & \href{https://docs.google.com/spreadsheets/d/1d9ggnYzHMK_8CQiH2en20FIST0XcWqWlfD44_WCYJmU/edit?gid=1813284249\#gid=1813284249}{Here}  \\
    P113 & April 2024 & Sept 2024 & \href{https://docs.google.com/spreadsheets/d/1T9wMdy1lKM_H8pEgfQq-v3axBKvClktZhXpeP7WtN2Y/edit?gid=1813284249\#gid=1813284249}{Here}  \\
    P114 & Oct 2024 & March 2025 & \href{https://docs.google.com/spreadsheets/d/1J_vAlWSPODs4GkxnjDmlD6kF6rAwO304mK7EOvsyDYo/edit?gid=1813284249\#gid=1813284249}{Here}  \\
    P115 & April 2025 & Sept 2025 & \href{https://docs.google.com/spreadsheets/d/1EAejMz_j_4guuFadV1cUyvHtMDAOk9cVAaWcNM44VnY/edit?gid=1813284249\#gid=1813284249}{Here} \\
    P116 & Oct 2025 & March 2026 & \href{https://docs.google.com/spreadsheets/d/1-H0Rgas-YLEHVAUb8q1LBr5Rmday49SAfXGEsYI8hfM/edit?gid=1813284249\#gid=1813284249}{Here} \\
    P117 &  &  & \\
    P118 &  &  & \\
    \hline
\end{gentable}


Note all semesters will be available on the \href{https://unigech.sharepoint.com/teams/NIRPS/Documents%20partages/Forms/AllItems.aspx?id=%2Fteams%2FNIRPS%2FDocuments%20partages%2FScience%20Team%2FObservations%2FTime%20Share&viewid=2f190b75%2D4180%2D41fc%2D983f%2D9cae3d9af119}{Geneva share point} \lstcode{Documents>Science Team>Observations>Time Share}. Look for the \lstcode{PXXX-Instructions.url}


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to check for data on the ESO Archives}
\label{sec:how_to:eso_archives}
% ---------------------------------------------------------------------------------

There are various times when you may need to look on the ESO archives for data, mostly when we don't seem to have data on our machines.

The following steps show you how to check for data on the archives:

\subsubsection{Step 1/3}

Go to \href{http://archive.eso.org/eso/eso_archive_main.html}{here}. The page should look like figure \ref{fig:eso_archive_page} (or for GTO data go to \href{https://archive.eso.org/wdb/forms/cas/eso_archive_main.html}{the special access archive} - note that you will need to create and log in to an ESO account. For the GTO observations you should use the \lstcode{NIRPSteam} account).

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=\textwidth]{images/eso_archive_whole_page.png}
    \caption{The ESO archive page}
    \label{fig:eso_archive_page}
\end{figure}

\subsubsection{Step 2/3}

Enter the night (or Start and End nights) in the box in figure \ref{fig:eso_archive_night_box}.

If you want to filter out sun observations, add ``not SUN'' under ``Target Name'' and change the drop-down to ``OBJECT - FITS keyword''.

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=0.5\textwidth]{images/eso_archive_night_box.png}
    \caption{ESO Archive night(s) information}
    \label{fig:eso_archive_night_box}
\end{figure}

\subsubsection{Step 3/3}

Check the NIRPS/LaSilla box as in Figure \ref{fig:eso_archive_inst_box}

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=0.5\textwidth]{images/eso_archive_inst_box.png}
    \caption{ESO Archive instrument selection}
    \label{fig:eso_archive_inst_box}
\end{figure}

Then click the green "search" button to show all observations for your criteria.

\subsubsection{Notes on the ESO archive}

\note{Note 1}

It may also be useful for some checks to set the OB Name and the Category (i.e. to SCIENCE or CALIB) in the box shown in figure \ref{fig:eso_archive_data_info}.

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=0.5\textwidth]{images/eso_archive_data_info.png}
    \caption{ESO Archive data product selection}
    \label{fig:eso_archive_data_info}
\end{figure}

\note{Note 2}

If you are searching for something specific by default it returns 200 rows. You can increase the number of rows in this box as in figure \ref{fig:eso_archive_nrows}.

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=\textwidth]{images/eso_archive_nrows.png}
    \caption{ESO archive number of rows}
    \label{fig:eso_archive_nrows}
\end{figure}



% ---------------------------------------------------------------------------------
\newpage
\clearpage
\subsection{How to figure out when observations should happen}
\label{sec:how_to:observation_times}
% ---------------------------------------------------------------------------------

For good operations observations should happen at particular times:

\begin{dgentable}
\hline
What & UTC & Chile summer & Chile winter & MTL summer & MTL winter \\
     &     & UTC-4        & UTC-3        & UTC-4      & MTL-5  \\
\hline
HELIOS observations & 9:00-12:00 & 5:00–8:00 & 6:00-9:00 & 5:00-8:00 & 4:00-7:00 \\ 
Daily-Calibrations Full-Set [start] & 12:00 & 8:00 & 9:00 & 8:00 & 7:00  \\
Daily-Calibrations Full-Set [end] & 14:00 & 10:00 & 11:00 & 10:00 & 9:00  \\
Daily-Calibrations Full-Set [in MTL] & 16:00 & 12:00 & 13:00 & 12:00 & 11:00  \\
HELIOS observations & 14:00-19:00 & 10:00-15:00 & 11:00-16:00 & 10:00-15:00 & 9:00-14:00  \\
Afternoon-Calibrations [start] & 20:00-21:00 & 16:00-17:00 & 17:00-18:00 & 16:00-17:00 & 15:00-16:00  \\
Afternoon-Calibrations [end] & 21:00-22:00 & 17:00-18:00 & 18:00-19:00 & 17:00-18:00 & 16:00-17:00  \\
Afternoon-Calibrations [in MTL] & 22:00-23:00 & 18:00-19:00 & 19:00-20:00 & 18:00-19:00 & 17:00-18:00  \\
Telluric stars & 21:00-22:00 & 17:00-18:00 & 18:00-19:00 & 17:00-18:00 & 16:00-17:00  \\
Night time observations & 22:00-9:00$\bigstar$ & 18:00-5:00$\bigstar$ & 19:00-6:00$\bigstar$ & 18:00-5:00$\bigstar$ & 17:00-4:00$\bigstar$  \\
\hline
\end{dgentable}

Where $^\bigstar$ means next day in the daily cycle


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to report a FALSE on the check spreadsheet}
\label{sec:how_to:false_check}
% ---------------------------------------------------------------------------------

If and only if you were asked to ignore a check should you fill out the comments section on the APERO NIRPS UdeM checks google sheet. 

Please make sure there is one entry per observation night – do not stack multiple even if everything else is the same. 

You do not need multiple entries per observation night (even if more than one thing is still FALSE) 

\subsubsection{Location of comment pages}

\begin{itemize}
    \item \href{https://docs.google.com/spreadsheets/d/1zvU_XFA1ZOJE111qZKiav7v6ptYveWpDkMHjdhiN06M/edit?gid=68390787#gid=68390787}{Comments-NIRPS-HE}
    \item \href{https://docs.google.com/spreadsheets/d/1zvU_XFA1ZOJE111qZKiav7v6ptYveWpDkMHjdhiN06M/edit?gid=346030560#gid=346030560}{Comments-NIRPS-HA}
\end{itemize}

\subsubsection{Comment page columns}

\note{obsdir}

The observation directory that has the FALSE (please make sure there is one entry per observation directory). 

\note{date}

The date you filled out this comment. 

\note{Name}

First and last name of the person filling this out. 

\note{Comments}

A good comment on what is FALSE for that night. 

This should include:
\begin{itemize}
    \item The test(s) that failed.
    \item Who said you could ignore this test/these tests?
    \item Any other relevant information.
\end{itemize}

Please don’t just write vague statements like `telescope was broken' or `got a weird message.' 

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to use a screen on the UdeM machines}
\label{sec:how_to:use_screen}
% ---------------------------------------------------------------------------------

The screen command is a useful way of running a script in the background (so that when you log out or close your ssh session it continues running). 

This means that you can go back to it later. 

It also means that the previous babysitter may have a screen that you can use. 

It also means that someone else might be using a specific screen when you try to connect to it (i.e. it is “attached”) 

If the screen is attached please contact: 

\begin{contacttable}
    \ccNeil{1} & \eeNeil \\
    \ccEtienne{} & \eeEtienne \\
    \ccLison{} & \eeLison \\
    \hline
\end{contacttable}


\subsubsection{Screen that are usually on rali}

Screen that are usually on \lstpath{rali.astro.umontreal.ca} are:

\begin{itemize}
    \item \texttt{nirps\_he\_online} - this is the online reduction screen for NIRPS-HE.
    \item \texttt{nirps\_ha\_online} - this is the online reduction screen for NIRPS-HA.
    \item \texttt{nirps\_he\_offline} - this is the offline reduction screen for NIRPS-HE.
    \item \texttt{nirps\_ha\_offline} - this is the offline reduction screen for NIRPS-HA.
\end{itemize}

These screens can be used to avoid having to load the conda environment and apero profiles over and over again, but be warned you should check that the conda environment and check that the apero profile is correct.

\newpage
\subsubsection{Useful screen commands}

Here are some useful screen commands/keyboard control shortcuts:

\note{List the available screens}

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
screen -list
\end{lstlisting}
\end{codebox}


\note{Join the screen}
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
screen -r {screen name}
\end{lstlisting}
\end{codebox}

\note{Make a new screen}
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
screen -R {screen name}
\end{lstlisting}
\end{codebox}

\note{Leave a screen (but do not terminate it)}
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
Ctrl+A+D
\end{lstlisting}
\end{codebox}

\note{Leave a screen and terminate it}
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
Ctrl+D
\end{lstlisting}
\end{codebox}

\note{Scroll up (but not infinitely)}
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
Ctrl+A+Esc
\end{lstlisting}
\end{codebox}

\note{Attach to an already attached screen}
\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
screen -x {screen_name}
\end{lstlisting}
\end{codebox}

When using the \lstcode{-x} option please do not type commands while someone else is connected but it is a good way to screen what’s happening without detaching someone else’s screen.


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to re-run apero with a custom run file}
\label{sec:how_to:custom_run_file}
% ---------------------------------------------------------------------------------

\subsubsection{Introduction}

Sometimes, things go wrong in the manual trigger and you need to re-run specific steps of the reduction or all steps for specific objects. 

One example where this is required is if an object fell through the cracks of the `ASTROM\_TEST' and it wasn’t checked (or the files didn’t exist on disk at the time the reduction was run). 

This will usually be done by forcing \lstcode{apero_processing} to use a different run file as an argument. 

This can be done one of two ways: 
\begin{itemize}
    \item directly with \lstcode{apero_processing}
    \item using the \lstcode{manual_trigger}
\end{itemize}

The advantages of using the \lstcode{manual_trigger} are that object sym-links are updated and ARI is also run after \lstcode{apero_processing} making sure everything is up-to-date. 

However you may want to run \lstcode{apero_processing} in test mode first to check any changes you made to a run file worked as expected. 

\subsubsection{Modifying a run file}
\label{sec:how_to:custom_run_file:modifying}

Run files are stored in the APERO profile data directory:
\begin{itemize}
    \item For NIRPS-HE online, this is located at:  
    \texttt{/cosmos99/nirps/apero-data/nirps\_he\_online/run/}
    \item For NIRPS-HA online, this is located at:  
    \texttt{/cosmos99/nirps/apero-data/nirps\_ha\_online/run/}
\end{itemize}

There are different types of run files depending on the task.  

\important{Please do not edit default run files themselves—always create new ones with a sensible name (e.g., including your name and the date).}

Default run files are:
\begin{itemize}
    \item \texttt{complete\_run.ini} -- Used to run all recipes
    \item \texttt{ref\_calib\_run.ini} -- Used to run the reference night calibrations
    \item \texttt{calib\_run.ini} -- Used to run nightly calibration recipes
    \item \texttt{science\_run.ini} -- Used to run nightly science observation recipes
    \item \texttt{lbl\_run.ini} -- Used to run the LBL recipes
    \item \texttt{other\_run.ini} -- Used for engineering/diagnostic work
    \item \texttt{online\_run.ini} -- Used by the \texttt{manual\_trigger} for online runs
    \item \texttt{offline\_run.ini} -- Used by the \texttt{manual\_trigger} for offline runs
\end{itemize}

Each run file uses one or multiple "APERO sequences" to run different recipes in a reduction:
\begin{itemize}
    \item \texttt{pp\_seq}, \texttt{pp\_seq\_opt}
    \item \texttt{full\_seq}, \texttt{limited\_seq}
    \item \texttt{ref\_seq}, \texttt{calib\_seq}, \texttt{tellu\_seq}
    \item \texttt{science\_seq}
    \item \texttt{quick\_seq}, \texttt{eng\_seq}, \texttt{lbl\_seq}
\end{itemize}

Documentation on these can be found here:
\begin{itemize}
    \item \href{http://apero.exoplanets.ca/auto/recipe_sequences/nirps_he/sequences.html}
    {NIRPS-HE sequences}
    \item \href{http://apero.exoplanets.ca/auto/recipe_sequences/nirps_ha/sequences.html}
    {NIRPS-HA sequences}
\end{itemize}

These allow us to use certain recipes which can be turned on and off with the 
\lstcode{RUN_{SHORTNAME}} parameter in the run files (where \lstcode{{SHORTNAME}} is the name of a recipe).  
See the recipe definitions here:
\begin{itemize}
    \item \href{http://apero.exoplanets.ca/auto/recipe_definitions/nirps_he/recipes.html}
    {NIRPS-HE recipes}
    \item \href{http://apero.exoplanets.ca/auto/recipe_definitions/nirps_ha/recipes.html}
    {NIRPS-HA recipes}
\end{itemize}

For most babysitting purposes, the \texttt{science\_run.ini} file can be copied and modified.  
This is useful when needing to re-process one or more science observations 
for a night (or completely). 

\subsubsection{Key parameters in the run files}

\href{http://apero.exoplanets.ca/auto/tool_definitions/default/rdefinition_PROC.html}{All parameters can be found here}, but a few are 
important for babysitters:

\note{RUN\_OBS\_DIR}  

Whether to limit processing to a single observation directory.
    
\note{INCLUDE\_OBS\_DIRS}  

Whether to limit processing to a set of observation directories.
    
\note{CORES}  

The number of cores to use (should never be more than 20 in total for 
APERO on one machine). You should consider whether other 
\texttt{manual\_trigger} processes (e.g., NIRPS-HE and NIRPS-HA) 
 are already running.
    
\note{TEST\_RUN} 

Set this to \texttt{True} to test your run file without running any 
recipes—recommended to verify everything works before running the 
wrong thing!
    
\note{UPDATE\_OBJ\_DATABASE}  

Required if a manual change to the astrometric database has been made.
    
\note{RUN\_XXX}  

These should be \texttt{True} for the steps you want to run.
    
\note{SKIP\_XXX}  

These should be \texttt{False} for the steps you want to override.
    
\note{SCIENCE\_TARGETS} 

This specifies which targets APERO should reduce. Use the name 
from the \href{https://docs.google.com/spreadsheets/d/1dOogfEwC7wAagjVFdouB1Y1JdF9Eva4uDW6CTZ8x2FM/edit?gid=0\#gid=0}{astrometric database}.

\subsubsection{Using apero processing}

\important{Either use these four steps or the manual trigger steps in the next session. Do not use both!}

The \href{http://apero.exoplanets.ca/auto/tool_definitions/default/rdefinition_PROC.html }{full documentation for \lstcode{apero_processing} can be found here}.

This assumes you have already \hyperref[sec:how_to:custom_run_file:modifying]{modified a run file}.

\note{Step 1/4}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} you want to reduce from 

\note{Step 2/4}

Run the following command (to test your run file):

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_processing.py {run file} --test=True
\end{lstlisting}
\end{codebox}

\note{Step 3/4}

Run the following command (to run the reduction):

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_processing.py {run file}
\end{lstlisting}
\end{codebox}


\note{Step 4/4}

Re-run the manual trigger for updating the `objects` directory and ARI:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
manual_trigger
python manual_trigger.py {yaml file} --links=False --apero_process=False --get=True --ari=True

\end{lstlisting}
\end{codebox}

You will want to use the \lstcode{--obsdir} argument if running for a specific set of days (or the \lstcode{--since} argument if running for a large set of days since a certain date).

\subsubsection{Using the manual trigger directly}

\important{We highly recommend running} \lstcode{apero_processing} \important{steps 1 and 2 before running this (to test your run file)}

\note{Step 1/2}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} you want to reduce from 

\note{Step 2/2}

Re-run the manual trigger for updating the “objects” directory and ARI:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
manual_trigger
python manual_trigger.py {yaml file} --run={run_file}
\end{lstlisting}
\end{codebox}


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to run APERO astrometrics}
\label{sec:how_to:apero_astrometrics}
% ---------------------------------------------------------------------------------

\subsubsection{Adding an object}
You can add an object to the astrometric database as follows:

\note{Step 1/2}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} 

\note{Step 2/2}

Run apero astrometrics:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_astrometrics.py {objname}
\end{lstlisting}
\end{codebox}

Where \lstcode{objname} is any alias of the object you wish to add (or a comma-separated list of objects)

Then follow the options on the screen and answer all the questions.

\newpage
\subsubsection{Please think about aliases of the object}

It is important to think about all possible names (aliases for each object) people can name the same object many things and we want all possible names to be caught by APERO and merged into the same object.

APERO does some cleaning of objects to allow them to be proper filenames:

\begin{itemize}
    \item White spaces will be replaced with ``\_'' (underscore).
    \item All punctuation except ``-'' and ``+'' will be replaced with ``\_'' (underscore).
    \item ``-'' will be replaced with ``M'' and ``+'' will be replaced with ``P''.
    \item All characters will be converted to uppercase.
\end{itemize}

For example, the following transformations occur:
\begin{itemize}
    \item \texttt{TRAPPIST 1} $\rightarrow$ \texttt{TRAPPIST\_1}
    \item \texttt{TRAPPIST1} $\rightarrow$ \texttt{TRAPPIST1}
    \item \texttt{TRAPPIST-1} $\rightarrow$ \texttt{TRAPPISTM1}
    \item \texttt{Trappist1} $\rightarrow$ \texttt{TRAPPIST1}
\end{itemize}

Thus, at least the first three variations should be included in the aliases.

\subsubsection{Solar system objects and objects without proper motion}

APERO astrometrics required a match to a proper motion catalog. 

Solar system objects and objects without proper motion might not get resolved with APERO astrometrics. 

Please contact the following people stating that you need an object manually added to the astrometric database. 

Please also remind those people that they will have to update the local astrometric databases themselves (or you could run \lstcode{apero_astrometrics} to do it).

\begin{contacttable}
    \ccNeil{1} & \eeNeil \\
    \ccEtienne{} & \eeEtienne \\
    \ccLison{} & \eeLison \\
    \hline
\end{contacttable}

\subsubsection{What if apero astrometrics can not find my target?}

Sometimes APERO astrometrics can not find your object name. This can happen, especially for newer TOI objects. APERO astrometric first scans for the name in SIMBAD, then checks several proper motion catalogues for a match to the ID. 

Therefore if APERO astrometrics can't find your object, first see if you can find another name for the object that works in SIMBAD (these include many aliases including in many cases Gaia IDs) and worst case choose an ID that will be found in one of the proper motion catalogues below (hint the Gaia ID is always a safe bet):

\begin{itemize}
    \item Gaia DR3
    \item Gaia EDR3
    \item Gaia DR2
    \item Gaia DR1
    \item UCAC4
    \item HIP
\end{itemize}

You can also look at the following for information on the targets:
\begin{itemize}
    \item For TESS candidates:  
    \href{https://exofop.ipac.caltech.edu/tess/}{https://exofop.ipac.caltech.edu/tess/}
    \item For exoplanet hosts:  
    \href{https://exoplanetarchive.ipac.caltech.edu/}{https://exoplanetarchive.ipac.caltech.edu/}
\end{itemize}

\important{Please make sure you add all variants of the original name and the name in the header to the alias list, otherwise your target will not be found by APERO and linked to this other name.}

\subsubsection{What if I don't have a Teff}

A Teff is optional for most of APERO but mandatory for LBL, therefore you will get an error in LBL if an object has no Teff in the astrometrics database.

If your object is resolved in SIMBAD, the astrometrics code will provide a 
list of \texttt{T\textsubscript{eff}} values (from SIMBAD). However, some 
objects may not resolve in SIMBAD (especially TOI objects), or even if they 
do, they may not have a \texttt{T\textsubscript{eff}} value.

The best places to look are as follows:
\begin{itemize}
    \item For TESS candidates:  
    \href{https://exofop.ipac.caltech.edu/tess/}{https://exofop.ipac.caltech.edu/tess/}
    \item For exoplanet hosts:  
    \href{https://exoplanetarchive.ipac.caltech.edu/}{https://exoplanetarchive.ipac.caltech.edu/}
\end{itemize}

If you still can’t find an entry, you can always use an estimate from the 
spectral type of the object.  

One such site that provides this conversion is:  \href{https://sites.uni.edu/morgans/astro/course/Notes/section2/spectraltemps.html}
{provides this conversion is here}. 

In the source, include a note like: `\texttt{T\textsubscript{eff}} estimated from Spectral type'. 

Note keep the source column short it must be able to fit in $\sim$60 characters.


\newpage
\subsubsection{What if I can't find my object anywhere?}


There are some cases where the name given to a target is not helpful at all in knowing what the object is (i.e. you have tried apero astrometrics and simbad cannot resolve the object).
apero astrometrics has another option

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_astrometrics.py Unknown --fileoption={ABSOLUTE PATH}
\end{lstlisting}
\end{codebox}

This should look up the file, find the RA and Dec and then give you a list of the 10 brightest objects within an arc-minute. This can be used to select the target (which is probably the brightest one in this list) however please be sure this is actually the correct object by continuing and looking carefully at the retrieved SIMBAD information.

\begin{itemize}
\item Step 1/4: Find the file you need the observation directory (if you are running from a check the check should give you the last night this object was found).

\item Step 2/4: then you can go to:

\begin{itemize}
    \item NIRPS HE: \lstcode{/cosmos99/nirps/apero-data/nirps_he_online/raw}
    \item NIRPS HA: \lstcode{/cosmos99/nirps/apero-data/nirps_ha_online/raw}
\end{itemize}

and open the observation directory you file is in.

\item Step 3/4: Run the following command to find your filename

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
dfits * | fitsort OBJECT obs.targ.name
\end{lstlisting}
\end{codebox}

This will give you several names for each file in that directory.

\item Step 4/4: Run apero astrometrics with the \lstcode{--fileoption} argument being the full path to the file (e.g. \lstcode{/cosmos99/nirps/apero-data/nirps_he_online/raw/2025-11-01/NIRPS_2025-11-02T00_27_21_546.fits})

\end{itemize}

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to run APERO reject}
\label{sec:how_to:apero_reject}
% ---------------------------------------------------------------------------------

\subsubsection{Introduction}

At some points, we need to reject an object (from the astrometric database), 
a file or set of files (from being reduced). For this, we use \lstcode{apero_reject.py}.  

Below are three ways to use \texttt{apero\_reject.py}:
\begin{itemize}
    \item \hyperref[sec:how_to:apero_reject:non_astrophysical]{Rejecting an astrophysical object}
    \item \hyperref[sec:how_to:apero_reject:file]{Rejecting a specific file or set of files}
    \item \hyperref[sec:how_to:apero_reject:night]{Rejecting a whole observation night}
\end{itemize}

\subsubsection{Rejecting a non-astrophysical object}
\label{sec:how_to:apero_reject:non_astrophysical}

\note{Step 1/2}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} 

\note{Step 2/2}

Run apero reject:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_reject.py --objname={objname}
\end{lstlisting}
\end{codebox}

where \lstcode{objname} is any alias of the object you wish to add (or a comma-separated list of objects) 

Only reject objects that are truly non-astrophysical. 

You’ll be asked some questions:

\begin{itemize}
    \item Where to reject from [PP, TEL, RV] (to which in most cases you should say yes)
    \item To give a comment (Please make sure the comment is descriptive)
\end{itemize}

You can skip these questions by adding an argument:

\lstcode{--autofill="1,1,1,my comment"}

Again, make sure the `my comment` is descriptive.

\subsubsection{Rejecting a specific file or set of files}
\label{sec:how_to:apero_reject:file}

You can reject a specific file or set of files using the “identifier” argument:

\note{Step 1/2}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} 

\note{Step 2/2}

Run apero reject:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_reject.py --identifier=file1,file2,file3
\end{lstlisting}
\end{codebox}

Where file1, file2, file3 are filenames 

You’ll be asked some questions:

\begin{itemize}
    \item To give any aliases for a target
    \item To give a comment (Please make sure the comment is descriptive)
\end{itemize}

You can skip these questions by adding an argument: 

\lstcode{--autofill="alias1|alias2|alias3,my comment"}

Again, make sure the `my comment` is descriptive.

\note{Filenames for reject script}
\begin{itemize}
    \item Please do not include the path
    \item Please only include the raw file name (i.e. the characters before the \lstcode{_pp} suffix in any reduced files) 
    \item Please use the \important{APERO filename} not the ESO filename i.e. the file format should be:
    \begin{itemize}
        \item \lstcode{NIRPS_YYYY-mm-ddTHH_MM_SS_sss}
    \end{itemize}
\end{itemize}


\subsubsection{Rejecting a whole observation}
\label{sec:how_to:apero_reject:night}

Sometimes you'll have to reject a whole night as the telescope or instrument means all data is unusable.
\important{You must have all data on disk, so make sure all data is downloaded - otherwise you may only reject some data.}

\note{Step 1/2}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} 

\note{Step 2/2}

Run apero reject:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_reject.py --obsdir=NIGHT1
\end{lstlisting}
\end{codebox}

Note this overrides the use of \lstcode{--identifier}.


You’ll be asked some questions:

\begin{itemize}
    \item Where to reject from [PP, TEL, RV] (to which in most cases you should say yes)
    \item To give a comment (Please make sure the comment is descriptive)
\end{itemize}

You can skip these questions by adding an argument:

\lstcode{--autofill="1,1,1,my comment"}

Again, make sure the `my comment` is descriptive.

\subsubsection{APERO reject can't find the raw directory}

You cannot reject data on a night where the raw sym-links have not been created.

If this is the case you need to run the manual trigger (\hyperref[sec:manual_trigger]{See this section}) 
as you normally would do but add the argument \lstcode{--only_links=True}

This will generate the links and then allow you to run \lstcode{apero_reject} without problem (assuming the data is actually on our disks in the first place).

You can check for raw data in the following directories:
\begin{itemize}
    \item NIRPS-HE: \lstpath{/nirps_raw/nirps/raw-data/nirps_he}
    \item NIRPS-HA: \lstpath{/nirps_raw/nirps/raw-data/nirps_ha}
\end{itemize}

Note that the symbolic links should be created in the following directories:
\begin{itemize}
    \item NIRPS-HE: \lstpath{/cosmos99/nirps/apero-data/nirps_he_online/raw}
    \item NIRPS-HA: \lstpath{/cosmos99/nirps/apero-data/nirps_ha_online/raw}
\end{itemize}

Also note that the directories should be symbolic links, not the files themselves.

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to run APERO remove}
\label{sec:how_to:apero_remove}
% ---------------------------------------------------------------------------------

Some times the manual trigger is run and there is a problem that is not known about. 

For example, a binary was aliased to the same name in the astrometric database. 

In this case (or other cases) we need to remove all traces of data from the disk/databases of APERO, 
and then (normally) re-reduced the data. To do this we use \lstcode{apero_remove.py}.

\note{Step 1/2}

\hyperref[sec:how_to:load_apero_profile]{Activate the apero profile} 

\note{Step 2/2}

Run apero remove:

\begin{codebox}[]{Bash}
\begin{lstlisting}[language=Bash]
apero_remove.py {args}
\end{lstlisting}
\end{codebox}

\important{Please note that this is permanent we cannot undo this, all files you ask to be removed will be removed, please test before running properly (using --test=True)}

Note that we never remove raw data - so we can always reprocess.

In some cases (i.e. for astrometric database corrections) you will need to remove entries from the raw database (with the \lstcode{--rawdb} argument)

\newpage
\subsubsection{APERO remove arguments}

Below we list some useful arguments

\note{obsdir}  

Delete all instances of a certain observation directory from disk and databases.

\note{blocks}  

Delete all instances of a block from disk and database (multiple blocks should be separated by a comma).  
The blocks are as follows:
\begin{itemize}
    \item \texttt{tmp} \quad (preprocessed files)
    \item \texttt{red} \quad (reduced files after preprocessing, not including post-processed files or LBL)
    \item \texttt{out} \quad (post-processed files)
    \item \texttt{calib} \quad (reduced calibrations that passed all QC)
    \item \texttt{tellu} \quad (reduced telluric hot stars and science files that passed all QC)
\end{itemize}

\note{file\_prefix}  

Delete all instances of a certain file prefix from disk and databases.

\note{file\_suffix}  

Delete all instances of a certain file suffix from disk and databases.

\note{objnames}  

Delete all instances of a certain object name (\texttt{DRSOBJN}) from disk and databases.

\note{test}  

Whether to run in test mode (recommended first time).

\note{rawdb}  

Whether to remove raw database entries.


% ---------------------------------------------------------------------------------
\newpage
\subsection{How to add a new reduction product to the objects directory}
\label{sec:how_to:add_to_objects_dir}
% ---------------------------------------------------------------------------------

The \texttt{objects} directory is a directory of symbolic links sorted by target.  

For the online reductions, these are located here:
\begin{itemize}
    \item NIRPS-HE: \lstpath{/cosmos99/nirps/apero-data/nirps_he_online/objects}
    \item NIRPS-HA: \lstpath{/cosmos99/nirps/apero-data/nirps_ha_online/objects}
\end{itemize}

Currently, we do not copy every product here.  
If you decide that a product that is not included is worth having for everyone,  
you can add the product using the following steps:

\begin{enumerate}
    \item Go to the \lstcode{manual_trigger} directory (on \texttt{nirps\_he} / \texttt{nirps\_ha})  
    - usually, you just type \lstcode{manual_trigger}.
    \item Open the \texttt{nirps\_he} and \texttt{nirps\_ha} YAML files.
    \item Find the section: \lstcode{get: science out types:}
    \item Add the required new product (a list of products can be found here, use the ``name'' column):
    \begin{itemize}
        \item \href{http://apero.exoplanets.ca/auto/file_definitions/nirps_he/files.html\#reduced-files}{NIRPS-HE reduced products}
        \item \href{http://apero.exoplanets.ca/auto/file_definitions/nirps_he/files.html\#post-processed-files}{NIRPS-HE post-processing products}
        \item \href{http://apero.exoplanets.ca/auto/file_definitions/nirps_ha/files.html\#reduced-files}{NIRPS-HA reduced products}
        \item \href{http://apero.exoplanets.ca/auto/file_definitions/nirps_ha/files.html\#post-processed-files}{NIRPS-HA post-processing products}
    \end{itemize}
    \item Run \lstcode{manual_trigger} with the argument \lstcode{--only_aperoget} and no \texttt{obsdir}.
\end{enumerate}

This should update all objects (to be consistent, we should do this for both  
\texttt{nirps-he} and \texttt{nirps-ha}) and keep the offline and online YAML files the same.  
(Hence, in step 2, both YAML files should be opened.)

% ---------------------------------------------------------------------------------
\newpage
\subsection{How to find whether there should be science data}
\label{sec:how_to:find_science}
% ---------------------------------------------------------------------------------

With NIRPS we have two modes (HE and HA) often only HE is used so there may genuinely be no data for HA (or in some cases for HE, if only HA was used). It is ambiguous whether we have no data due to technical issues or because there was genuinely no data taken.

Note science files will appear after a night has been completed. The way the observation directories are set up means you have to wait until the next calendar day to do this test. 

Even if science data is taken we may not have access to it, therefore you need to find out if there should have been data we should have access to.

\hyperref[sec:how_to:observation_times]{Please check whether we expect data on our disks based on the time it is now}.

Next \hyperref[sec:how_to:find_observer]{check the observation log} to see if there was a good reason for no science files.

If not mentioned in the observation log follow the `special archive` steps in section \ref{sec:how_to:eso_archives}. Please note if you are specifically looking to see whether there is no HA data or no HE data (as the other does have data) you must click the tick for `Orig Name` column in the `Data Product Info' (yellow) section before searching - this will give you the original file name which does start with either `NIRPS\_HE' or `NIRPS\_HA'. Please also note that by default results are trucated to 200 rows so you may need to increase the `Return max' rows value to a higher number (before searching).


If there are no `NIRPS\_HA' data here but we have `NIRPS\_HE' data then you can safely assume that no `NIRPS\_HA' data was observed (and vice-versa).

If there are no data for either `NIRPS\_HA' or `NIRPS\_HE' or there are data for both you need to go to \href{https://www.eso.org/LPOschedule/public} and set:

\begin{itemize}
    \item filter by Instrument to `NIRPS'
    \item filter by Telescope to `3P6'
    \item set a loose schedule time interval (a few days before to a few days after the night you are investigating)
\end{itemize}

This will give you the program ids which you can match to the `Instructions' page of the observation log (Section \ref{sec:how_to:find_observer}). Note you should only assume we have access to NIRPS GTO programs - PI `BOUCHY').

\clearpage
\newpage 

Good reasons for no science data include:
\begin{itemize}
    \item No GTO data for that night
    \item Bad weather
    \item Technical problems
    \item HARPS only run
\end{itemize}

You will have to look in the “Obs time” sheet and look for the date of observations row and the columns marked GTO-WP3, GTO-WP1, GTO-WP2, GTO-OS2

If any of these have non-zero values science data should have been taken, it may be the observer hasn't filled out the time, so also check the comment for that night for information on whether science was observed.