<jupyter_start><jupyter_text>Using MOC files of the VAST Pilot SurveyThis notebook gives an example of how to use vast-tools in a notebook environment to interact with the MOC, or STMOC, files of the VAST Pilot survey.MOC stands for `Multi-Order Coverage map` as is a standard in astronomy for showing survey coverage, see this link for a tutorial on HiPS and MOCS:* http://cds.unistra.fr/adass2018/I also recommened looking at the mocpy docs, as all interaction with the mocs here is performed using mocpy:* https://cds-astro.github.io/mocpy/Below are the imports required for this example. The main import required from vast-tools is the VASTMOCS class. Astropy objects are also imported, as well as `matplotlib.pyplot`. Also imported is `World2ScreenMPL` from mocpy which allows us to create `wcs` objects on which we can plot MOC coverages (see https://cds-astro.github.io/mocpy/examples/examples.html).<jupyter_code>from vasttools.moc import VASTMOCS
from astropy.time import Time
from mocpy import World2ScreenMPL
import matplotlib.pyplot as plt
from astropy import units as u
from astropy.coordinates import Angle, SkyCoord<jupyter_output><empty_output><jupyter_text>Included in VASTMOCS are:* A MOC file for each pilot survey tile (sometimes called 'field').* A MOC file for each pilot survey defined field (a collection of tiles).* A MOC file for each pilot survey epoch.* A STMOC for the current VAST Pilot Survey (this is a MOC file with observation time information attached).The first task is to initialise a VASTMOCS object:<jupyter_code>vast_mocs = VASTMOCS()<jupyter_output><empty_output><jupyter_text>Tile MOCSLet's start by loading and plotting a MOC of a tile, which is loaded as below. We will load both the `TILES` and `COMBINED` version and plot both to see the difference between the two.<jupyter_code>field_moc = vast_mocs.load_pilot_tile_moc('VAST_0012-06A', itype='tiles')
field_moc_comb = vast_mocs.load_pilot_tile_moc('VAST_0012-06A', itype='combined')<jupyter_output><empty_output><jupyter_text>As stated in the mocpy documentation, in order to plot a MOC file we need to use `World2ScreenMPL`. This is done below. For convenience we also load a dataframe containing tile/field centres which is available in vast-tools.<jupyter_code>from vasttools.survey import load_field_centres
FIELD_CENTRES = load_field_centres()
# set the field name as the index for convenience
FIELD_CENTRES = FIELD_CENTRES.set_index('field')

fig = plt.figure(figsize=(10,10))

with World2ScreenMPL(
    fig,
    fov=15 * u.deg,
    center=SkyCoord(
        FIELD_CENTRES.loc['VAST_0012-06A']['centre-ra'], 
        FIELD_CENTRES.loc['VAST_0012-06A']['centre-dec'], unit='deg', frame='icrs'
    ),
    coordsys="icrs",
    rotation=Angle(0, u.degree),
) as wcs:
    ax = fig.add_subplot(111, projection=wcs)
    ax.set_title("VAST Pilot Field 0012-06A Area")
    ax.grid(color="black", linestyle="dotted")
    field_moc_comb.fill(ax=ax, wcs=wcs, alpha=0.7, fill=True, linewidth=0, color="C1", label='COMBINED')
    field_moc_comb.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
    field_moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="#00bb00", label='TILE')
    field_moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
        
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>You can also combine MOC files to create a new MOC, below I load the field to the North and add it to the already loaded field above.<jupyter_code># Load moc to the north
north_field_moc = vast_mocs.load_pilot_tile_moc('VAST_0012+00A', itype='tiles')

# Add the mocs together
sum_moc = field_moc.union(north_field_moc)

fig = plt.figure(figsize=(10,10))

with World2ScreenMPL(
    fig,
    fov=20. * u.deg,
    center=SkyCoord(
        FIELD_CENTRES.loc['VAST_0012-06A']['centre-ra'], 
        FIELD_CENTRES.loc['VAST_0012-06A']['centre-dec'] + 3, unit='deg', frame='icrs'
    ),
    coordsys="icrs",
    rotation=Angle(0, u.degree),
) as wcs:
    ax = fig.add_subplot(111, projection=wcs)
    ax.set_title("Combined VAST Pilot Field 0012-06A and 0012+00A Area")
    ax.grid(color="black", linestyle="dotted")
    sum_moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="#00bb00")
    sum_moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
        
plt.show()<jupyter_output><empty_output><jupyter_text>VAST Pilot Field MOCSYou can also load MOCS of each of the defined VAST Pilot fields as defined on this wiki page: https://github.com/askap-vast/vast-project/wiki/Pilot-Survey-Planning.<jupyter_code># First we load the ellipical frame from astropy to make the sky plot look nicer
from astropy.visualization.wcsaxes.frame import EllipticalFrame

vast_pilot_field_1_moc = vast_mocs.load_pilot_field_moc('1')

fig = plt.figure(figsize=(12, 6))

with World2ScreenMPL(
    fig,
    fov=320 * u.deg,
    center=SkyCoord(0, 0., unit='deg', frame='icrs'),
    coordsys="icrs",
    rotation=Angle(0, u.degree),
) as wcs:
    ax = fig.add_subplot(111, projection=wcs, frame_class=EllipticalFrame)
    ax.set_title("VAST Pilot Survey Field 1")
    ax.grid(color="black", linestyle="dotted")
    vast_pilot_field_1_moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="#00bb00")
    vast_pilot_field_1_moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
        
plt.show()<jupyter_output><empty_output><jupyter_text>We can add another field to the MOC.<jupyter_code>vast_pilot_field_4_moc = vast_mocs.load_pilot_field_moc('4')

fig = plt.figure(figsize=(12, 6))

with World2ScreenMPL(
    fig,
    fov=320 * u.deg,
    center=SkyCoord(0, 0., unit='deg', frame='icrs'),
    coordsys="icrs",
    rotation=Angle(0, u.degree),
) as wcs:
    ax = fig.add_subplot(111, projection=wcs, frame_class=EllipticalFrame)
    ax.set_title("VAST Pilot Survey Fields 1 and 4")
    ax.grid(color="black", linestyle="dotted")
    vast_pilot_field_1_moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="#00bb00")
    vast_pilot_field_1_moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
    vast_pilot_field_4_moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="C1")
    vast_pilot_field_4_moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
    
plt.show()<jupyter_output><empty_output><jupyter_text>Epoch MOCSEpoch MOCS are loaded and manipulated in the same way.<jupyter_code># Load the epoch one MOC
epoch1_moc = vast_mocs.load_pilot_epoch_moc('1')

fig = plt.figure(figsize=(12, 6))

with World2ScreenMPL(
    fig,
    fov=320 * u.deg,
    center=SkyCoord(0, 0., unit='deg', frame='icrs'),
    coordsys="icrs",
    rotation=Angle(0, u.degree),
) as wcs:
    ax = fig.add_subplot(111, projection=wcs, frame_class=EllipticalFrame)
    ax.set_title("VAST Pilot Survey Epoch 1")
    ax.grid(color="black", linestyle="dotted")
    epoch1_moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="#00bb00")
    epoch1_moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black")
        
plt.show()<jupyter_output><empty_output><jupyter_text>VAST Pilot STMOCThe STMOC (a Space-Time MOC) file is a MOC file containing the current entire VAST Pilot survey with time information attached. You can use it to match survey areas that are time sensitive. In the example below we query 4 time ranges and plot the coverage of the Pilot survey within these time ranges, example taken from the mocpy example notebook (https://github.com/cds-astro/mocpy/blob/master/notebooks/Space%20%26%20Time%20coverages.ipynb).<jupyter_code># load the stmoc
vast_stmoc = vast_mocs.load_pilot_stmoc()

def add_to_plot(fig, id, wcs, title, moc):
    ax = fig.add_subplot(id, projection=wcs, frame_class=EllipticalFrame)

    ax.grid(color="black", linestyle="dotted")
    ax.set_title(title)
    ax.set_xlabel('lon')
    ax.set_ylabel('lat')

    moc.fill(ax=ax, wcs=wcs, alpha=0.9, fill=True, linewidth=0, color="#00bb00")
    moc.border(ax=ax, wcs=wcs, linewidth=1, color="black")

fig = plt.figure(figsize=(18, 9))
plt.subplots_adjust(hspace=0.3)

time_ranges = Time([
        [["2019-10-29", "2019-10-30"]],
        [["2019-12-19", "2019-12-20"]],
        [["2020-01-16", "2020-01-18"]],
        [["2020-02-01", "2020-08-01"]]
    ], format='iso', scale='tdb', out_subfmt="date")
with World2ScreenMPL(fig, 
         fov=320 * u.deg,
         center=SkyCoord(0, 0, unit='deg', frame='icrs'),
         coordsys="icrs",
         rotation=Angle(0, u.degree),
         projection="AIT") as wcs:

    for i in range(0, 4):
        moc_vast = vast_stmoc.query_by_time(time_ranges[i])
        title = "VAST Pilot observations between \n{0} and {1}".format(time_ranges[i][0, 0].iso, time_ranges[i][0, 1].iso)
        id_subplot = int("22" + str(i+1))
        add_to_plot(fig, id_subplot, wcs, title, moc_vast)

plt.show()<jupyter_output>/Users/adam/GitHub/vast-tools/vasttools/moc.py:66: ResourceWarning: unclosed file <_io.FileIO name='/Users/adam/GitHub/vast-tools/vasttools/./data/mocs/VAST_PILOT.stmoc.fits' mode='rb' closefd=True>
  stmoc = STMOC.from_fits(stmoc_path)
{'fraction_non_alphanumeric': 0.12934770530058895, 'fraction_numerical': 0.03444827203022558, 'mean_word_length': 4.840363400389357, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '283122', 'license': 'MIT', 'n_tokens_mistral': 3578, 'n_tokens_neox': 3334, 'n_words': 798, 'path': 'docs/notebook-examples/using-vast-mocs-example.ipynb', 'repo_name': 'askap-vast/vast-tools', 'size': '8999'}