<jupyter_start><jupyter_text>UKIRT Hemisphere Survey (UHS)This notebook takes in the downloaded survey and filters it per field creating new fits files for each field.<jupyter_code>import subprocess

from astropy.table import Table
from astropy import units as u

import numpy as np

from pymoc import MOC

from herschelhelp_internal.utils import inMoc
#TODO: Maybe check for edge effects and add add extra leeway
fields= [
# Field                RAtyp    DECtyp   RAmin   RAmax   DECmin  DECmax
['AKARI-NEP',          274.65,  65.796,  263.6,  266.5,  68.48,  69.51 ],
['AKARI-SEP',          72.231, -54.380,   66.1,  75.5,  -55.96, -51.61 ],
['Bootes',             216.43,  32.401,  215.7,  220.7,  32.12,  36.18 ],
['CDFS-SWIRE',         51.022, -29.818,   50.7,  55.5,  -30.50, -25.92 ],
['COSMOS',             149.29,  1.0821,  148.6,  151.6,  0.72,   3.71  ],
['EGS',                217.27,  53.644,  212.3,  217.6,  51.08,  54.31 ],
['ELAIS-N1',           247.09,  55.175,  237.9,  247.9,  52.37,  57.59 ],
['ELAIS-N2',           248.42,  39.127,  246.1,  252.3,  39.02,  43.02 ],
['ELAIS-S1',           7.1062, -43.863,    6.3,  11.3,  -45.60, -41.53 ],
['GAMA-09',            129.07, -2.2317,  127.1,  142.2, -2.53,   3.55  ],
['GAMA-12',            172.84,  -0.482,  172.2,  187.4, -3.54,   2.59  ],
['GAMA-15',            211.75, -2.2857,  209.9,  225.3, -2.57,   3.5   ],
['HDF-N',              190.25,  62.205,  188.0,  190.4,  61.69,  62.78 ],
['Herschel-Stripe-82', 353.75, -7.1089,  348.3,  19.1,  -9.5,    9.25  ],
['Lockman-SWIRE',      161.94,  59.056,  154.7,  167.8,  54.95,  60.89 ],
['NGP',                192.89,  22.099,  189.8,  209.3,  21.62,  36.16 ],
['SA13',               197.89,  42.440,  197.5,  198.6,  42.34,  43.09 ],
['SGP',                334.29, -34.503,  333.5,  28.2,  -37.1,  -26.0  ],
['SPIRE-NEP',          266.33,  68.790,  264.6,  275.4,  64.41,  68.63 ],
['SSDF',               341.57, -59.186,  340.5,  2.8,   -61.2,  -48.6  ],
['xFLS',               261.38,  58.018,  255.6,  262.5,  57.85,  60.84 ],
['XMM-13hr',           203.31,  37.474,  202.8,  204.4,  37.31,  38.52 ],
['XMM-LSS',            32.941, -6.0229,   32.1,  38.2,  -7.53,  -1.52  ]]
   
    
#Has a field been removed?  ( RA BETWEEN 13.4 AND 36.3 AND DEC BETWEEN -2.32 AND 2.49 )

uhs = Table.read("data/UHS-DR1_HELP.fits")
uhs["RA"].unit = u.rad
uhs["DEC"].unit = u.rad
uhs["RA"].convert_unit_to(u.deg)
uhs["DEC"].convert_unit_to(u.deg)
uhs[:10].show_in_notebook()
log_file = open('log.txt', 'a')
for field in fields:
    field_moc = MOC(filename="../../dmu2/dmu2_field_coverages/{}_MOC.fits".format(field[0]))
    field_mask= inMoc(uhs["RA"],uhs["DEC"],field_moc)
    if not np.all( np.logical_not(field_mask)):
        uhs[field_mask].write("data/UHS-DR1_{}.fits".format(field[0]), overwrite=True)
    
        subprocess.call(["stilts", 
                 "pixfoot", 
                 "in=./data/UHS-DR1_{}.fits".format(field[0]), 
                 "out=./data/UHS-DR1_{}_MOC.fits".format(field[0]),
                 "ra=RA",
                 "dec=DEC",
                 "order=10"], 
                    stdout=log_file)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20006311139160618, 'fraction_numerical': 0.19154307352477123, 'mean_word_length': 1.863595302619693, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '45138', 'license': 'MIT', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1397, 'n_words': 275, 'path': 'dmu0/dmu0_UHS/UHS-DR1_processing.ipynb', 'repo_name': 'djbsmith/dmu_products', 'size': '3169'}