===Procedure for METIS_img_n_cal_flat_twilight ===

For the twilight flat field calibration observations, the telescope is pointed at a location in the sky, opposite of the sun and at a given airmass. The telescope is put in no-tracking mode so that the sky drifts over METIS. This logic is encoded in the template.

The template cycles through a selectable series of filters to determine the best DIT and NDIT for the actual twilight flat observation in order to obtain a high initial count level on the frames (~50% of the full-well capacity). After this, exposures are taken cycling through these filters obtaining frames with fixed DIT and NDIT (and decreasing or increasing count levels during evening or morning twilight, respectively). The sequence can be repeated at different illumination levels, i.e. different airmasses.

++++
Preset telescope|
  * send target coordinates to TCS
  * [comment] Since twilight flats will be taken at sky positions preferably without stars, and since image quality does not matter for twilight flats, no AO guiding is necessary or possible in this mode.
  * wait for signal “arrived at position”
++++
++++
Configure CFO |
  * CFO can be configured while the telescope is presetting
  * ''CFO PP1'': select cold stop PPS-CFO1
  * Set de-rotator initial angle and start derotator. Options:
    * Field tracking (pupil rotates) [default]
    * Pupil tracking (field rotates; by default used for both HCI and (on-axis) regular imaging)
    * No tracking (stopped). For engineering purposes.
  * Chopper to home position
  * ''CFO FP2'' to N Field Stop
  * LMS pick-off to open
++++
++++
Setup imager|
  * Set ''IMG-LM PP1'' to CLOSED (no light on IMG-LM system)
  * Move ''IMG-N PP1 MASK/GRISM'' to selected pupil mask (pupil stop PPS-N for field-tracking observations, spider mask SPM-N for pupil-tracking observations)
  * Move ''IMG-N PP1 FILT'' to selected science filter 
  * Move ''IMG-N PP1 ND'' to selected neutral-density filter (for acquisition of very bright targets)
  * Pupil imaging lens to open
  * Set detector parameters (DIT, NDIT, readout mode)
++++
++++
Start exposures|
  * Start science exposures with specified DIT/NDIT and perform ''Nexp'' number of exposures.
++++
++++
End exposures|
  * Collect headers
  * Send file to ESO Archive
  * Select "DARK" position in CFO-PP1
  * [comment] as per recommendation by ELT WG on persistence (May 2022)
  * Stop derotator
  * Handover to telescope
    * Telescope gets ready for next preset
++++




===Parameters for METIS_img_n_cal_flat_twilight ===

^Parameter             ^Hidden     ^Range (default)            ^Label^
|DPR CATG              |yes        |CALIB TEST (CALIB) |Data product category|
|DPR TECH              |yes        |IMAGE IMAGE,CVC (NODEFAULT)    |Data product technique|
|DPR TYPE              |yes        |FLAT,SKY (FLAT,SKY)|Data product type| 
|DET2 DIT               |yes         |0..TBD (NODEFAULT)         |IMG-N Detector integration time (DIT)|
|DET2 NDIT              |yes         |1..TBD (NODEFAULT)         |IMG-N Number of Integrations (NDIT)|
|DET2 NCORRS NAME       |no         |TBD                         |IMG-N Readout mode|
|SEQ TIME              |no         |0..TBD (NODEFAULT)         |Total integration time (sec)|
|SEQ NEXPO             |no         |0..TBD (1)                 |Number of exposures|
|SEQ NCYCLES            |no         |1..TBD (1)                 |Number of cycles|
|SEQ DIT FILT LIST     |no         |(NODEFAULT)                 |Filter list|
|SEQ PRESET            |yes        |T F (T)                    |Preset telescope?|
|INS OPTI1 NAME         |yes        | PPS-CFO1 RAP-LM (PPS-CFO1)                |CFO-PP1 mask wheel|
|INS OPTI2 NAME         |yes        | TBD (TBD)                |CFO-PP1 ADC wheel|
|INS OPTI3 NAME   	|yes        | FIELD-11 FIELD-14 FIELD-3 SLIT-A SLIT-B SLIT-C SLIT-D SLIT-E VPM-L VPM-M PI-MASK PNH-1 (FIELD-11)                              |CFO FP2 mask/slit wheel |
|INS OPTI4 NAME         |yes        |OUT IN (OUT)                  |LMS beamsplitter pickoff wheel|
|INS OPTI12 NAME         |no         |open PPS-N SPM-N CLS-N (SPM-N)                  |IMG-N Mask/Grism name|
|INS OPTI13 NAME         |no         |N1 N2 PAH8.6 PAH8.6_ref PAH11.25 PAH11.25_ref [NeII] [NeII]_ref [SIV] [SIV]_ref N3 (N1)                |IMG-N Filter name|
|INS OPTI14 NAME         |no         |OPEN ND1 ND2 ND3 ND4 (NODEFAULT)                  |IMG-N Neutral density filter|
|INS OPTI16 NAME         |yes        |OUT IN (OUT)                    |IMG-N pupil imaging lens|
|INS OPTI17 NAME         |yes        |OUT (OUT)                    | WCU periscope arm|
