コード例 #1
0
def using_gtvt(ra,
               dec,
               instrument,
               targetName='noName',
               ephFileName=None,
               output='bokeh'):
    """Plot the visibility (at a range of position angles) against time.

    Parameters
    ----------
    ra : str
        The RA of the target (in degrees) hh:mm:ss.s or dd:mm:ss.s or representing a float
    dec : str
        The Dec of the target (in degrees) hh:mm:ss.s or dd:mm:ss.s or representing a float
    instrument : str
        Name of the instrument. Can either be (case-sensitive):
        'NIRISS', 'NIRCam', 'MIRI', 'FGS', or 'NIRSpec'
    ephFileName : str
        The filename of the ephemeris file.
    output : str
        Switches on plotting with Bokeh. Parameter value must be 'bokeh'.

    Returns
    -------
    paGood : float
        The good position angle.
    paBad : float
        The bad position angle.
    gd : matplotlib.dates object
       The gregorian date.
    fig : bokeh.plotting.figure object
        The plotted figure.

    """
    # Getting calculations from GTVT (General Target Visibility Tool)
    tab = get_table(ra, dec)

    gd = tab['Date']
    paMin = tab[str(instrument) + ' min']
    paMax = tab[str(instrument) + ' max']
    paNom = tab[str(instrument) + ' nom']
    v3min = tab['V3PA min']
    v3max = tab['V3PA max']

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NOTE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Addressing NIRSpec issue*
    # *the issue that NIRSpec's angle goes beyond 360 degrees with some targs,
    # thus resetting back to 0 degrees, which can make the plot look weird
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    index = np.arange(0, len(paNom), 1)

    for idx in index:

        try:
            a1 = paNom[idx]
            b1 = paNom[idx + 1]

            if (np.isfinite(a1)) & (np.isfinite(b1)):
                delta = np.abs(a1 - b1)

                if delta > 250:

                    gd = np.insert(gd, idx + 1, np.nan)
                    paMin = np.insert(paMin, idx + 1, np.nan)
                    paMax = np.insert(paMax, idx + 1, np.nan)
                    paNom = np.insert(paNom, idx + 1, np.nan)
                    v3min = np.insert(v3min, idx + 1, np.nan)
                    v3max = np.insert(v3min, idx + 1, np.nan)
        except BaseException:
            pass

    # Setting up HoverTool parameters & other variables
    COLOR = 'green'
    TOOLS = 'pan, wheel_zoom, box_zoom, reset, save'
    SOURCE = ColumnDataSource(
        data=dict(pamin=paMin, panom=paNom, pamax=paMax, date=gd))
    TOOLTIPS = [('Date', '@date{%F}'), ('Maximum Aperture PA', '@pamax'),
                ('Nominal Aperture PA', '@panom'),
                ('Minimum Aperture PA', '@pamin')]

    # Time to plot
    if output == 'bokeh':
        fig = figure(tools=TOOLS,
                     plot_width=800,
                     plot_height=400,
                     x_axis_type='datetime',
                     title='{} Visibility with {}'.format(
                         targetName, instrument))

    # Draw the curve and PA min/max circles
    try:
        nom = fig.line('date',
                       'panom',
                       line_color=COLOR,
                       legend_label='Nominal Aperture PA',
                       alpha=.5,
                       source=SOURCE)
    except AttributeError:
        nom = fig.line('date',
                       'panom',
                       line_color=COLOR,
                       legend='Nominal Aperture PA',
                       alpha=.5,
                       source=SOURCE)

    fig.circle('date', 'pamin', color=COLOR, size=1, source=SOURCE)
    fig.circle('date', 'pamax', color=COLOR, size=1, source=SOURCE)

    # Adding HoverTool
    fig.add_tools(
        HoverTool(renderers=[nom],
                  tooltips=TOOLTIPS,
                  formatters={'date': 'datetime'},
                  mode='vline'))

    # Plot formatting
    fig.xaxis.axis_label = 'Date'
    fig.yaxis.axis_label = 'Aperture Position Angle (degrees)'
    fig.y_range = ranges.Range1d(0, 360)

    # Making the output table
    # Creating new lists w/o the NaN values
    v3minnan, v3maxnan, paNomnan, paMinnan, paMaxnan, gdnan, mjds = \
        [], [], [], [], [], [], []

    for vmin, vmax, pnom, pmin, pmax, date in zip(v3min, v3max, paNom, paMin,
                                                  paMax, gd):
        if np.isfinite(pmin):
            v3minnan.append(vmin)
            v3maxnan.append(vmax)
            paNomnan.append(pnom)
            paMinnan.append(pmin)
            paMaxnan.append(pmax)
            gdnan.append(date)

    # Adding MJD column
    mjdnan = []
    for date in gdnan:
        t = Time(str(date), format='iso')
        mjd = t.mjd
        mjdnan.append(mjd)

    # Adding lists to a table object
    table = Table(
        [v3minnan, v3maxnan, paMinnan, paMaxnan, paNomnan, gdnan, mjdnan],
        names=('min_V3_PA', 'max_V3_PA', 'min_Aperture_PA', 'max_Aperture_PA',
               'nom_Aperture_PA', 'Gregorian', 'MJD'))

    # Getting bad PAs
    allPAs = np.arange(0, 360, 1)
    badPAs = []

    for pa in allPAs:
        if (pa not in np.round(paMinnan)) & \
           (pa not in np.round(paMaxnan)) & \
           (pa not in np.round(paNomnan)):

            badPAs.append(pa)

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NOTE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # This addresses a bokeh shading issue that accidentally shades
    # accessible PAs (e.g: trappist-1b)
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    remove_pa = []
    for badpa in badPAs:

        for panom in paNomnan:
            diff = np.abs(badpa - panom)
            if diff < 7:
                remove_pa.append(badpa)

    for pa in np.unique(remove_pa):
        badPAs.remove(pa)
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NOTE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Grouping the bad PAs into lists within the badPAs list.
    # This will make bad PA shading easier in the contamination Bokeh plot
    # (sossContamFig.py)
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    badPAs = np.sort(badPAs)

    if len(badPAs > 0):
        grouped_badPAs = [[badPAs[0]]]

        for idx in range(1, len(badPAs)):

            if ((badPAs[idx - 1] + 1) == badPAs[idx]):

                grouped_badPAs[len(grouped_badPAs) - 1].append(badPAs[idx])

            elif ((badPAs[idx - 1] + 1) < badPAs[idx]):
                grouped_badPAs.append([badPAs[idx]])

        grouped_badPAs = np.asarray(grouped_badPAs)

    else:  # Accounting for targets with 100% visibility
        grouped_badPAs = np.asarray([])

    return paMin, paMax, gd, fig, table, grouped_badPAs
コード例 #2
0
def using_gtvt(ra, dec, instrument, ephFileName=None, output='bokeh'):
    """Plot the visibility (at a range of position angles) against time.

    Parameters
    ----------
    ra : float
        The RA of the target.
    dec : float
        The Dec of the target.
    instrument : str
        Name of the instrument. Can either be (case-sensitive):
        'NIRISS', 'NIRCam', 'MIRI', 'FGS', or 'NIRSpec'
    ephFileName : str
        The filename of the ephemeris file.
    output : str
        Switches on plotting with Bokeh. Parameter value must be 'bokeh'.

    Returns
    -------
    paGood : float
        The good position angle.
    paBad : float
        The bad position angle.
    gd : matplotlib.dates object
       The gregorian date.
    fig : bokeh.plotting.figure object
        The plotted figure.

    """
    # getting calculations from GTVT (General Target Visibility Tool)
    tab = get_table(ra, dec)

    gd = tab['Date']
    paMin = tab[str(instrument) + ' min']
    paMax = tab[str(instrument) + ' max']
    paNom = tab[str(instrument) + ' nom']
    v3min = tab['V3PA min']
    v3max = tab['V3PA max']

    # addressing NIRSpec issue*
    # *the issue that NIRSpec's angle goes beyond 360 degrees with some targs,
    # thus resetting back to 0 degrees, which can make the plot look weird
    index = np.arange(0, len(paNom), 1)

    for idx in index:

        try:
            a1 = paNom[idx]
            b1 = paNom[idx + 1]

            if (np.isfinite(a1) == True) & (np.isfinite(b1) == True):
                delta = np.abs(a1 - b1)

                if delta > 250:
                    print(a1, b1, delta)
                    gd = np.insert(gd, idx + 1, np.nan)
                    paMin = np.insert(paMin, idx + 1, np.nan)
                    paMax = np.insert(paMax, idx + 1, np.nan)
                    paNom = np.insert(paNom, idx + 1, np.nan)
                    v3min = np.insert(v3min, idx + 1, np.nan)
                    v3max = np.insert(v3min, idx + 1, np.nan)
        except:
            pass

    # Setting up HoverTool parameters & other variables
    COLOR = 'green'
    TOOLS = 'pan, wheel_zoom, box_zoom, reset, save'
    SOURCE = ColumnDataSource(data=dict(pamin=paMin,\
                                        panom=paNom,\
                                        pamax=paMax,\
                                        date=gd))
    TOOLTIPS = [('Date','@date{%F}'),\
                ('Maximum Aperture PA', '@pamax'),\
                ('Nominal Aperture PA', '@panom'),\
                ('Minimum Aperture PA', '@pamin')]

    # Time to plot
    if output == 'bokeh':
        fig = figure(tools=TOOLS,\
                     plot_width=800,\
                     plot_height=400,\
                     x_axis_type='datetime',\
                     title='Target Visibility with '+str(instrument))

    # Draw the curve and PA min/max patch
    fig.circle('date', 'panom', color=COLOR, size=1, legend='Nominal Aperture PA',\
               source=SOURCE, alpha=.5)
    fig.circle('date', 'pamin', color=COLOR, size=1, source=SOURCE)
    fig.circle('date', 'pamax', color=COLOR, size=1, source=SOURCE)

    # Adding HoverTool
    fig.add_tools(HoverTool(tooltips=TOOLTIPS,\
                            formatters={'date':'datetime'},\
                            mode='vline'))

    # Plot formatting
    fig.xaxis.axis_label = 'Date'
    fig.yaxis.axis_label = 'Position Angle (degrees)'
    fig.y_range = ranges.Range1d(0, 360)

    # Making the output table
    # Creating new lists w/o the NaN values
    v3minnan, v3maxnan, paNomnan, paMinnan, paMaxnan, gdnan, mjds = \
    [], [], [], [], [], [], []

    for vmin, vmax, pnom, pmin, pmax, date in zip(v3min, v3max, paNom, paMin,
                                                  paMax, gd):
        if np.isfinite(pmin) == True:
            v3minnan.append(vmin)
            v3maxnan.append(vmax)
            paNomnan.append(pnom)
            paMinnan.append(pmin)
            paMaxnan.append(pmax)
            gdnan.append(date)

    # Adding MJD column
    mjdnan = []
    for date in gdnan:
        t = Time(str(date), format='iso')
        mjd = t.mjd
        mjdnan.append(mjd)

    # Adding lists to a table object
    table = Table([v3minnan, v3maxnan, paMinnan, paMaxnan, paNomnan, gdnan, mjdnan],\
                  names=('#min_V3_PA', 'max_V3_PA','min_Aperture_PA',\
                         'max_Aperture_PA', 'nom_Aperture_PA', 'Gregorian', 'MJD'))

    return paMin, paMax, gd, fig, table