Ejemplo n.º 1
0
def main_map(fn='all_fields.npy'):
    nside = 1024
    m = np.zeros(hp.nside2npix(nside))

    # opsim log
    log = np.load(fn)
    mjd_min = DateTimeFrom('2022-01-01').mjd
    mjd_max = DateTimeFrom('2023-01-01').mjd
    idx = (log['band'] == 'LSSTPG::i')
    idx &= (log['mjd'] >= mjd_min)
    idx &= (log['mjd'] <= mjd_max)
    log = log[idx]
    coords = np.vstack(
        (log['Ra'] * DEGREE_PER_RADIAN, log['Dec'] * DEGREE_PER_RADIAN)).T
    print coords.shape

    f = FocalPlane()
    p = f.pixellize(1, 1)

    for i, (r, d) in enumerate(coords):
        if i % 100 == 0:
            print i, r, d
        cells = p.copy()
        f.to_uv(cells, (r, d))

        for c in cells:
            poly = np.vstack([c['p0'], c['p1'], c['p2'], c['p3']])
            ipix = hp.query_polygon(nside, poly, nest=True)
            m[ipix] += 1.

    return m, p
Ejemplo n.º 2
0
def testObjects(store):
    import mx
    from mx.DateTime import DateTimeFrom, TimeFrom
    print 'Testing with DateTime module.'

    d = DateTimeFrom('2001-06-07')
    t = TimeFrom('12:42')
    dt = DateTimeFrom('2001-06-07 12:42')

    f = Foo()
    f.setD(d)
    f.setT(t)
    f.setDt(dt)

    storeFoo(store, f)

    d = DateTimeFrom('2002-11-11')
    t = TimeFrom('16:04')
    dt = DateTimeFrom('2002-11-11 16:04')

    f.setD(d)
    f.setT(t)
    f.setDt(dt)

    store.saveChanges()
Ejemplo n.º 3
0
 def valueForRawValue(self, rawValue):
     """ The rawValue is typically a string or value already of the appropriate type. TableRecord invokes this method to ensure that values (especially strings that come from files) are the correct types (e.g., ints are ints and floats are floats). """
     # @@ 2000-07-23 ce: an if-else ladder? perhaps these should be dispatched messages or a class hier
     if self._type is StringType:
         value = str(rawValue)
     elif self._type is IntType:
         if rawValue == '':
             value = 0
         else:
             value = int(rawValue)
     elif self._type is LongType:
         if rawValue == '':
             value = 0
         else:
             value = long(rawValue)
     elif self._type is FloatType:
         if rawValue == '':
             value = 0.0
         else:
             value = float(rawValue)
     elif self._type is DateTimeType:
         value = DateTimeFrom(rawValue)
     elif self._type is ObjectType:
         value = rawValue
     else:
         raise DataTableError, 'Unknown column type "%s"' % self._type
     return value
Ejemplo n.º 4
0
 def testRefresh(self):
     for entry, value in (("otherParty", Person(name="Jose", surname="Perez")),
                          ("amount", 123.98), ("detail", "whatever"),
                          ("actualDate", "12/03/2005")):
         getattr(self.widget, entry).commitValue(value)
         if entry == "actualDate":
             """
             Ugly fix so the Date in entry can be compared with the one commited
             """
             self.assertEqual(self.widget.value.getattr(entry), DateTimeFrom(value))
         else:
             self.assertEqual(self.widget.value.getattr(entry), value)
Ejemplo n.º 5
0
def test(store):
    from Foo import Foo

    f = store.fetchObjectsOfClass(Foo)[0]

    d = '2000-01-01'
    t = '13:01'
    dt = '2000-01-01 13:01'
    try:
        try:
            from mx.DateTime import DateTimeFrom, DateTimeDeltaFrom
        except ImportError:
            from DateTime import DateTimeFrom, DateTimeDeltaFrom
        print 'Testing with DateTime module.'
        d = DateTimeFrom(d)
        t = DateTimeDeltaFrom(t)
        dt = DateTimeFrom(dt)
    except ImportError:
        print 'Testing with strings.'
    assert f.d() == d, 'f.d()=%s, d=%s' % (f.d(), d)
    assert f.t() == t, 'f.t()=%s, t=%s' % (f.t(), t)
    assert f.dt() == dt, 'f.dt()=%s, dt=%s' % (f.dt(), dt)
Ejemplo n.º 6
0
def get_tasks_mjd(cadences, mjd, bands, nside, standards):
    mjds = [
        DateTimeFrom(str(yr) + '-01-01').mjd for yr in xrange(2022, 2033, 1)
    ]
    seasons = np.repeat(mjds, 2)[1:-1].reshape((-1, 2))
    print seasons

    ret = []
    for c in cadences:
        for begin, end in seasons:
            for b in bands:
                ret.append((c, begin, end, b, nside, standards))
    return ret
Ejemplo n.º 7
0
def main_observe(nside=1024,
                 refpixs=None,
                 fn=None,
                 dither=False,
                 mjd_range=None,
                 band='LSSTPG::i'):
    """
    Build the observation NTuple
    (each measurement associates a focal plane cell to a sky pixel)
    """
    m = np.zeros(hp.nside2npix(nside))

    # opsim log
    log = np.load(fn)
    if mjd_range is None:
        mjd_min = DateTimeFrom('2023-01-01').mjd
        mjd_max = DateTimeFrom('2024-01-01').mjd
    else:
        mjd_min, mjd_max = mjd_range
    idx = (log['band'] == band)
    idx &= (log['mjd'] >= mjd_min)
    idx &= (log['mjd'] <= mjd_max)
    log = log[idx]
    iexp = np.arange(len(log))
    n_exp = len(log)
    if dither:
        d_ra = np.random.uniform(-1. * RADIAN_PER_DEGREE,
                                 1. * RADIAN_PER_DEGREE, n_exp)
        d_dec = np.random.uniform(1. * RADIAN_PER_DEGREE,
                                  1. * RADIAN_PER_DEGREE, n_exp)
    else:
        d_ra = np.zeros(n_exp)
        d_dec = np.zeros(n_exp)

    coords = np.vstack(
        (log['Ra'] * DEGREE_PER_RADIAN, log['Dec'] * DEGREE_PER_RADIAN,
         log['mjd'], iexp, log['gridobs'], log['rotation'])).T
    dtype = np.dtype([
        ('expnum', 'i4'),
        ('cell', 'i2'),
        # ('ichip', 'i4'),
        # ('iraft', 'i4'),
        ('pixel', 'i4'),
        ('mjd', 'f8'),
        ('refstar', 'i2'),
        ('refcell', 'i2'),
        ('gridobs', 'i2')
    ])

    f = FocalPlane()
    p = f.pixellize(1, 1)
    l = []

    for i, (r, d, mjd, iexp, gridobs, rotation) in enumerate(coords):
        if i % 100 == 0:
            logging.info('exposure: % 6d  [RA=% 6.6f DEC=% +6.5f]' % (i, r, d))
        cells = p.copy()
        if np.abs(rotation) > 0.:
            cells = f.rotate(cells, theta=rotation * 180. / np.pi)
        f.to_uv(cells, (r, d))

        for c in cells:
            poly = np.vstack([c['p0'], c['p1'], c['p2'], c['p3']])
            try:
                ipix = hp.query_polygon(nside,
                                        poly,
                                        nest=True,
                                        inclusive=False)
            except:
                continue
            m[ipix] += 1
            N = len(ipix)
            z = np.zeros(N, dtype=dtype)
            z['expnum'] = iexp
            z['cell'] = c['icell']
            z['pixel'] = ipix
            z['mjd'] = mjd
            z['gridobs'] = gridobs
            l.append(z)

    # reference objects (well, here, we have reference pixels)
    if refpixs is not None:
        N = len(refpixs)
        z = np.zeros(N, dtype=dtype)
        z['pixel'] = refpixs
        z['refstar'] = 1
        l.append(z)

    return m, np.hstack(l)