コード例 #1
0
ファイル: test_date.py プロジェクト: mcnanna/obztak
def test_datestring():
    string = '2016/02/14 01:30:00.0000'
    dt = dateutil.parser.parse(string)
    eph = ephem.Date(string)

    for d in [dt, eph, string]:
        np.testing.assert_equal(datestring(d), string)
        for i, j in [(4, None), (3, -1), (2, -2), (1, -3), (0, -5)]:
            np.testing.assert_equal(datestring(d, i), string[slice(j)])
コード例 #2
0
ファイル: survey.py プロジェクト: kadrlica/obztak
    def prepare_windows(self, nights, horizon=-14., standards=False, outfile=None):
        """Create a list of observation windows consisting of start-stop
        times for all dates of observation.

        Parameters:
        -----------
        nights   : A list of the nights and modes ('full','first','second').
        horizon  : Sun altitude at the start of observing.
        standards: Add time for taking standards
        outfile  : Output file of observing windows.

        Returns:
        --------
        observation_windows : Record array of observation windows.
        """
        observatory = obztak.ctio.CTIO()
        observatory.horizon = str(horizon)

        sun = ephem.Sun()

        observation_windows = []
        for date, mode in nights:
            mode = mode.lower().strip()
            # Afternoon
            observatory.date = '%s 03:00'%(date)
            observatory.date = observatory.date + 24. * ephem.hour

            time_setting = ephem.Date(observatory.previous_setting(sun))
            time_rising = ephem.Date(observatory.next_rising(sun))
            time_midpoint = ephem.Date(0.5*(time_setting + time_rising))

            if mode == 'full':
                window = [time_setting, time_rising]
            elif mode == 'first':
                # Don't do midpoint standards
                if standards:
                    time_midpoint = time_midpoint - STANDARDS
                window = [time_setting, time_midpoint]
            elif mode == 'second':
                # Don't do midpoint standards
                if standards:
                    time_midpoint = time_midpoint + STANDARDS
                window = [time_midpoint, time_rising]
            else:
                msg = "Unrecognized mode: '%s'"%mode
                raise ValueError(msg)

            window = [datestring(w,0) for w in window]
            observation_windows.append(window)

        #dtype=[('UTC_START','S28'),('UTC_END','S28')]
        #observation_windows = np.rec.fromrecords(observation_windows,dtype=dtype)
        names=['UTC_START','UTC_END']
        observation_windows = np.rec.fromrecords(observation_windows,names=names)

        if outfile:
            logging.debug("Writing %s..."%outfile)
            fileio.rec2csv(outfile,observation_windows)

        return observation_windows
コード例 #3
0
ファイル: fileio.py プロジェクト: kadrlica/obztak
def header():
    import ephem
    from obztak.utils.date import datestring
    now = ephem.now()
    header = "# author: %s@%s\n" % (get_username(), get_hostname())
    header += "# date: %s UTC\n" % (datestring(ephem.now(), 0))
    header += "# version: obztak v%s\n" % (__version__)
    return header
コード例 #4
0
 def set_date(self, date):
     if date is None:
         #NOOP (consistent with Tactician)
         return
     elif date == 'now':
         self.date = dateutil.parser.parse(datestring(ephem.now()))
     else:
         self.date = dateutil.parser.parse(date)
コード例 #5
0
ファイル: test_date.py プロジェクト: mcnanna/obztak
def test_datestr():
    string = '2016/02/14 01:30:00.0000'
    dt = dateutil.parser.parse(string)
    eph = ephem.Date(string)

    for d in [dt, eph, string]:
        np.testing.assert_equal(datestr(d), string[:-5])
        for i, j in [(0, -5), (3, -1), (2, -2), (1, -3), (0, -5)]:
            np.testing.assert_equal(datestring(d, i),
                                    string[slice(j)],
                                    err_msg="i=%s, j=%s" % (i, j))
コード例 #6
0
ファイル: test_tactician.py プロジェクト: mcnanna/obztak
def test_calculate_slew():
    tac = create_tactician()

    # Use a previously completed field
    completed_fields = FieldArray(1)
    completed_fields[0]['RA'] = 137
    completed_fields[0]['DEC'] = -43
    completed_fields[0]['DATE'] = datestring(tac.date)

    #test_slew = np.array([47., 66.6686451, 72.6195061, 103.43996017, 149.98635165, 122.82243022, 61.24007137, 38.8279613, 86.08700171, 122.10797116])
    test_slew = np.array([
        47.6988041, 51.8633918, 37.6586078, 18.1169301, 39.2690875, 78.3913867,
        118.9542319, 153.814957, 153.7471813, 133.7394395
    ])
    zero_slew = np.zeros(len(tac.fields))

    tac.set_completed_fields(completed_fields)
    np.testing.assert_almost_equal(tac.slew,
                                   test_slew,
                                   err_msg='slew from previous field')

    # Set previous field to be < 30 min before date
    completed_fields[0]['DATE'] = datestring(tac.date - 29 * ephem.minute)
    tac.set_completed_fields(completed_fields)
    np.testing.assert_almost_equal(
        tac.slew, test_slew, err_msg='slew not calculated for <30 min gap')

    # Set previous field to be > 30 min before date
    completed_fields[0]['DATE'] = datestring(tac.date - 31 * ephem.minute)
    tac.set_completed_fields(completed_fields)
    np.testing.assert_equal(tac.slew,
                            zero_slew,
                            err_msg='non-zero slew for >30 min gap')

    # Set previous field to None
    tac.set_completed_fields(None)
    np.testing.assert_equal(tac.slew,
                            zero_slew,
                            err_msg='non-zero slew without previous field')
コード例 #7
0
def makePlot(date=None,
             name=None,
             figsize=(10.5, 8.5),
             dpi=80,
             s=50,
             center=None,
             airmass=True,
             moon=True,
             des=True,
             smash=False,
             maglites=None,
             bliss=None,
             galaxy=True):
    """
    Create map in orthographic projection
    """
    if date is None: date = ephem.now()
    if type(date) != ephem.Date:
        date = ephem.Date(date)

    survey = get_survey()
    if survey == 'maglites':
        if maglites is None: maglites = True
        if airmass is True: airmass = 2.0
    if survey == 'bliss':
        if bliss is None: bliss = True
        if airmass is True: airmass = 1.4
    if des:
        if airmass is True: airmass = 1.4

    fig = plt.figure(name, figsize=figsize, dpi=dpi)
    plt.cla()

    proj_kwargs = dict()
    if center: proj_kwargs.update(lon_0=center[0], lat_0=center[1])
    basemap = DECamOrtho(date=date, **proj_kwargs)
    observatory = basemap.observatory

    if des: basemap.draw_des()
    if smash: basemap.draw_smash(s=s)
    if maglites: basemap.draw_maglites()
    if bliss: basemap.draw_bliss()
    if airmass:
        airmass = 2.0 if isinstance(airmass, bool) else airmass
        basemap.draw_airmass(observatory, airmass)
    if moon: basemap.draw_moon(date)
    if galaxy: basemap.draw_galaxy()

    plt.title('%s UTC' % (datestring(date)))

    return fig, basemap
コード例 #8
0
def plotField(field,
              target_fields=None,
              completed_fields=None,
              options_basemap={},
              **kwargs):
    """
    Plot a specific target field.

    Parameters:
    -----------
    field            : The specific field of interest.
    target_fields    : The fields that will be observed
    completed_fields : The fields that have been observed
    options_basemap  : Keyword arguments to the basemap constructor
    kwargs           : Keyword arguments to the matplotlib.scatter function

    Returns:
    --------
    basemap : The basemap object
    """
    if isinstance(field, np.core.records.record):
        tmp = FieldArray(1)
        tmp[0] = field
        field = tmp
    band = field[0]['FILTER']
    cmap = matplotlib.cm.get_cmap(CMAPS[band])
    defaults = dict(marker='H',
                    s=100,
                    edgecolor='',
                    vmin=-1,
                    vmax=4,
                    cmap=cmap)
    #defaults = dict(edgecolor='none', s=50, vmin=0, vmax=4, cmap='summer_r')
    #defaults = dict(edgecolor='none', s=50, vmin=0, vmax=4, cmap='gray_r')
    setdefaults(kwargs, defaults)

    msg = "%s: id=%10s, " % (datestring(field['DATE'][0], 0), field['ID'][0])
    msg += "ra=%(RA)-6.2f, dec=%(DEC)-6.2f, secz=%(AIRMASS)-4.2f" % field[0]
    logging.info(msg)

    defaults = dict(date=field['DATE'][0], name='ortho')
    options_basemap = dict(options_basemap)
    setdefaults(options_basemap, defaults)
    fig, basemap = makePlot(**options_basemap)
    plt.subplots_adjust(left=0.03, right=0.97, bottom=0.03, top=0.97)

    # Plot target fields
    if target_fields is not None and len(target_fields):
        sel = target_fields['FILTER'] == band
        x, y = basemap.proj(target_fields['RA'], target_fields['DEC'])
        kw = dict(kwargs, c='w', edgecolor='0.6', s=0.8 * kwargs['s'])
        basemap.scatter(x[sel], y[sel], **kw)
        kw = dict(kwargs, c='w', edgecolor='0.8', s=0.8 * kwargs['s'])
        basemap.scatter(x[~sel], y[~sel], **kw)

    # Plot completed fields
    if completed_fields is not None and len(completed_fields):
        sel = completed_fields['FILTER'] == band
        x, y = basemap.proj(completed_fields['RA'], completed_fields['DEC'])
        kw = dict(kwargs)
        basemap.scatter(x[~sel], y[~sel], c='0.6', **kw)
        basemap.scatter(x[sel],
                        y[sel],
                        c=completed_fields['TILING'][sel],
                        **kw)

    # Try to draw the colorbar
    try:
        if len(fig.axes) == 2:
            # Draw colorbar in existing axis
            colorbar = plt.colorbar(cax=fig.axes[-1])
        else:
            colorbar = plt.colorbar()
        colorbar.set_label('Tiling (%s-band)' % band)
    except TypeError:
        pass
    plt.sca(fig.axes[0])

    # Show the selected field
    x, y = basemap.proj(field['RA'], field['DEC'])
    kw = dict(kwargs, edgecolor='k')
    basemap.scatter(x, y, c=COLORS[band], **kw)

    return basemap