<jupyter_start><jupyter_text>Example notebook: Creating an LRS2 TSL file for a list of stars- Assumes you want to do both LRS2-R and LRS2-B exposures of the same exposure time (see TSL file at the end)- Reads in stars from a .csv file- Queries SIMBAD for fluxes and proper motions- Accounts for proper motions at a given epoch- Creates FinderCharts that the Resident Astronomers / Telescope Operators like<jupyter_code>from __future__ import print_function
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import astropy
import sys
%matplotlib inline

sys.path.append("../src/")

import het_helper_functions
import het_obs
import astropy.units as u
from astropy.coordinates import SkyCoord<jupyter_output>WARNING: OldEarthOrientationDataWarning: Your version of the IERS Bulletin A is 18.1 days old. For best precision (on the order of arcseconds), you must download an up-to-date IERS Bulletin A table. To do so, run:

>>> from astroplan import download_IERS_A
>>> download_IERS_A()
 [astroplan.utils]<jupyter_text>Read in data- Main columns are columns that contain the name, RA and DEC<jupyter_code>df = pd.read_csv("../data/lrs2/targets/kdwarfs.csv")
df<jupyter_output><empty_output><jupyter_text>Query Simbad- We are interested in getting the fluxes (V mag), and the proper motions - Proper motions are important, as HET requires the RA/DEC coordinates to be given in the current epoch, e.g., 2018.1<jupyter_code>dataframes = []
for i, name in enumerate(df.name.values):
    #name = name.split(";")[0]
    print(i,name)
    table = het_helper_functions.get_ra_dec_pmra_pmdec(name).to_pandas()
    dataframes.append(table)
    table["VMAG"] = het_helper_functions.get_simbad_fluxes(name)["FLUX_V"].values[0]
    table["RMAG"] = het_helper_functions.get_simbad_fluxes(name)["FLUX_R"].values[0]
    table["IMAG"] = het_helper_functions.get_simbad_fluxes(name)["FLUX_I"].values[0]
    table["JMAG"] = het_helper_functions.get_simbad_fluxes(name)["FLUX_J"].values[0]
    table["SIMBADNAME"] = name
df_all = pd.concat(dataframes)
df_all = df_all.fillna(0.)
df_all
df["PMRA"]        = df_all["PMRA"].values
df["PMDEC"]       = df_all["PMDEC"].values
df["RA_SIMBAD"]   = het_helper_functions.raHMS2deg(df_all["RA"].values)
df["DEC_SIMBAD"]  = het_helper_functions.decDeg2deg(df_all["DEC"].values)
df["MAIN_ID"]     = [het_helper_functions.compactString(i) for i in df_all["SIMBADNAME"].values]
df["VMAG"]        = df_all["VMAG"].values
df["RMAG"]        = df_all["RMAG"].values
df["IMAG"]        = df_all["IMAG"].values
df["JMAG"]        = df_all["JMAG"].values

# Remove nans
#df = df.fillna(0) 

# Reject too bright stars
df_cut = df[(df.VMAG>8.) & (df.JMAG >8.)]
df_cut<jupyter_output><empty_output><jupyter_text>Check magnitudes<jupyter_code>fig, ax = plt.subplots()
for i in range(len(df_cut)):
    d = [df_cut.VMAG.values[i],
         df_cut.RMAG.values[i],
         df_cut.IMAG.values[i],
         df_cut.JMAG.values[i]]
    ax.plot(d)
ax.set_ylabel("Magnitude")
ax.set_xticks([0,1,2,3])
ax.set_xticklabels(["V","R","I","J"])<jupyter_output><empty_output><jupyter_text>Checking that the arrays are the same<jupyter_code>print(np.allclose(df_cut["RAJ2000"],df_cut["RA_SIMBAD"],0.001))
print(np.allclose(df_cut["DECJ2000"],df_cut["DEC_SIMBAD"],0.001))<jupyter_output>True
True<jupyter_text>Check which targets are observable<jupyter_code># It can take a while to initialize this class, does a few calculations
HTO = het_obs.HETObservability('2018-03-20 05:00:00','2018-04-01 05:00:00')
# Epoch for March 25th, 2018
EPOCH   = 2018. + (31. + 28. + 25.)/365.245
A = het_helper_functions.AngleWithProperMotion(epoch=EPOCH)
cc_new = [A.radec_with_proper_motion(df_cut["RA_SIMBAD"].values[i],
                                     df_cut["DEC_SIMBAD"].values[i],
                                     df_cut["PMRA"].values[i],
                                     df_cut["PMDEC"].values[i],verbose=True) for i in range(len(df_cut))]
# We want the number of observable days
observable_days = [len(HTO.get_observable_days(c,verbose=True)) for c in cc_new] 
df_obs = df_cut[np.array(observable_days)>0]
# check which targets are not observable
zip(df_cut.name.values,observable_days)<jupyter_output><empty_output><jupyter_text>Create Finder Charts<jupyter_code># Start finderchart maker
FM = het_obs.FinderChartMaker()
# Make finder charts
for i in range(len(df_obs)):
    print(i,
          df_obs.MAIN_ID.values[i],
          df_obs.RA_SIMBAD.values[i],
          df_obs.DEC_SIMBAD.values[i])
    FM.make_chart_shift(ra=df_obs["RA_SIMBAD"].values[i],
                        de=df_obs["DEC_SIMBAD"].values[i],
                        pmra=df_obs["PMRA"].values[i],
                        pmde=df_obs["PMDEC"].values[i],
                        name=df_obs["MAIN_ID"].values[i],
                        outdir="../data/lrs2/findercharts/")<jupyter_output>0 NLTT_15974 90.81024166666666 19.359644444444445
1 NLTT_33176 197.8435 9.603666666666665
2 NLTT_39942 230.11791666666664 0.19080555555555553<jupyter_text>Create TSL file<jupyter_code>vmag = df_obs["VMAG"].values
exptime = [het_helper_functions.lrs2_scale_exptime_from_mags(mag,MINLIM=10.) for mag in vmag]
repeat_exp = 2.*np.ones(len(df_obs))
het_helper_functions.print_TSL(names=df_obs["MAIN_ID"].values,
                               vmag=vmag,
                               priority=4*np.ones(len(df_obs)),
                               ra=df_obs["RA_SIMBAD"].values,
                               dec=df_obs["DEC_SIMBAD"].values,
                               pmra=df_obs["PMRA"].values,
                               pmdec=df_obs["PMDEC"].values,
                               exptime=exptime,
                               outputname="../data/lrs2/tsl/lrs2_submission_kdwarfs.tsl",
                               epoch=EPOCH,
                               repeat_exposures=repeat_exp,
                               program="PSU18-1-XXX",
                               instrument="LRS2",
                               visits=1)
# Would suggest to take a close look at the file, and cross check that things look ok before submitting !
# - Especially RAs and DECs, and exposure times
cat "../data/lrs2/tsl/lrs2_submission_kdwarfs.tsl"<jupyter_output>COMMON
   PROGRAM PSU18-1-XXX
   SEEING 3.0
   SKYTRANS S
   NUMEXP 1
   VISITS 1
   STDCALS Y
   SNWAVE 6000
   SNGOAL 200
   SKYBRIGHT 18
   SKYCALS Y
   TELL Y
GROUP
   GNAME NLTT_15974
   GTYPE SEQ
TRACK
   OBJECT NLTT_15974
   MAG 14
   PRI 4
   RA 6:03:15.32
   DEC 19:21:23.42
ACTION_LIST
   INSTRUMENT      EXP
      LRS2-R 169
      LRS2-R 169
      LRS2-B 169
      LRS2-B 169
GROUP
   GNAME NLTT_33176
   GTYPE SEQ
TRACK
   OBJECT NLTT_33176
   MAG 12
   PRI 4
   RA 13:11:21.80
   DEC 9:36:18.10
ACTION_LIST
   INSTRUMENT      EXP
      LRS2-R 43
      LRS2-R 43
      LRS2-B 43
      LRS2-B 43
GROUP
   GNAME NLTT_39942
   GTYPE SEQ
TRACK
   OBJECT NLTT_39942
   MAG 12
   PRI 4
   RA 15:20:28.47
   DEC 0:11:22.42
ACTION_LIST
   INSTRUMENT      EXP
      LRS2-R 36
      LRS2-R 36
      LRS2-B 36
      LRS2-B 36
{'fraction_non_alphanumeric': 0.11253161000280978, 'fraction_numerical': 0.050295026692891265, 'mean_word_length': 2.9266409266409266, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 5, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '199944', 'license': 'MIT', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2536, 'n_words': 525, 'path': 'notebooks/Example -- Creating LRS2 TSL File from a list of stars.ipynb', 'repo_name': 'gummiks/HET-Observing', 'size': '7118'}