Exemplo n.º 1
0
def test_upcasing():
    meta = MetaDict({'wibble': 1, 'WOBBLE': 2})
    # __getitem__
    assert meta['wibble'] == meta['WIBBLE']
    # get
    assert meta.get('wibble') == meta.get('WIBBLE')
    # has_key
    assert ('wibble' in meta) == ('WIBBLE' in meta)
    # Copy
    meta2 = meta.copy()
    assert meta2 == meta
    # pop
    assert meta.pop('wibble') == meta2.pop('WIBBLE')
    # update
    meta.update({'spam': 'eggs'})
    meta2.update({'SPAM': 'eggs'})
    assert meta == meta2
    # setdefault
    meta.setdefault('dave', 3)
    meta2.setdefault('DAVE', 3)
    assert meta.get('DAVE') == meta2.get('dave')
    # __setitem__
    meta['wibble'] = 10
    assert meta['wibble'] == 10
    meta['WIBBLE'] = 20
    assert meta['wibble'] == 20
    # __contains__
    assert 'wibble' in meta
    assert 'WIBBLE' in meta
Exemplo n.º 2
0
def test_upcasing():
    meta = MetaDict({'wibble':1, 'WOBBLE':2})
    #__getitem__
    assert meta['wibble'] == meta['WIBBLE']
    #get
    assert meta.get('wibble') == meta.get('WIBBLE')
    #has_key
    assert ('wibble' in meta) == ('WIBBLE' in meta)
    #Copy
    meta2 = meta.copy()
    assert meta2 == meta
    #pop
    assert meta.pop('wibble') == meta2.pop('WIBBLE')
    #update
    meta.update({'spam':'eggs'})
    meta2.update({'SPAM':'eggs'})
    assert meta == meta2
    #setdefault
    meta.setdefault('dave',3)
    meta2.setdefault('DAVE',3)
    assert meta.get('DAVE') == meta2.get('dave')
    #__setitem__
    meta['wibble'] = 10
    assert meta['wibble'] == 10
    meta['WIBBLE'] = 20
    assert meta['wibble'] == 20
    #__contains__
    assert 'wibble' in meta
    assert 'WIBBLE' in meta
Exemplo n.º 3
0
    def _parse_hdus(cls, hdulist):
        """Parses LYRA HDU list from a FITS file"""
        # Open file with PyFITS
        fits_record = hdulist[1].data
        # secondary_header = hdulist[1].header

        # Start and end dates.  Different LYRA FITS files have
        # different tags for the date obs.
        """
        print(hdulist[0].header)
        if 'date-obs' in hdulist[0].header:
            start_str = hdulist[0].header['date-obs']
        elif 'date_obs' in hdulist[0].header:
            start_str = hdulist[0].header['date_obs']
        # end_str = hdulist[0].header['date-end']
        """
        metadata = MetaDict(OrderedDict(hdulist[0].header))
        start_str = metadata.get('date-obs', metadata.get('date_obs', ''))

        # start = datetime.datetime.strptime(start_str, '%Y-%m-%dT%H:%M:%S.%f')
        start = parse_time(start_str)
        # end = datetime.datetime.strptime(end_str, '%Y-%m-%dT%H:%M:%S.%f')

        # First column are times.  For level 2 data, the units are [s].
        # For level 3 data, the units are [min]
        if hdulist[1].header['TUNIT1'] == 's':
            times = start + TimeDelta(fits_record.field(0) * u.second)
        elif hdulist[1].header['TUNIT1'] == 'MIN':
            td = [int(n) for n in fits_record.field(0)]
            times = start + TimeDelta(td * u.minute)
        else:
            raise ValueError("Time unit in LYRA fits file not recognised.  "
                             "Value = {0}".format(hdulist[1].header['TUNIT1']))

        # Rest of columns are the data
        table = {}

        for i, col in enumerate(fits_record.columns[1:-1]):
            # temporary patch for big-endian data bug on pandas 0.13
            if fits_record.field(
                    i +
                    1).dtype.byteorder == '>' and sys.byteorder == 'little':
                table[col.name] = fits_record.field(
                    i + 1).byteswap().newbyteorder()
            else:
                table[col.name] = fits_record.field(i + 1)

        # Return the header and the data
        times.precision = 9
        data = pandas.DataFrame(table, index=times.isot.astype('datetime64'))
        data.sort_index(inplace=True)

        # Add the units data
        units = OrderedDict([('CHANNEL1', u.W / u.m**2),
                             ('CHANNEL2', u.W / u.m**2),
                             ('CHANNEL3', u.W / u.m**2),
                             ('CHANNEL4', u.W / u.m**2)])
        # ToDo: check: http://www.wmo-sat.info/oscar/instruments/view/733
        return data, metadata, units
Exemplo n.º 4
0
    def _parse_hdus(cls, hdulist):
        """Parses LYRA HDU list from a FITS file"""
        # Open file with PyFITS
        fits_record = hdulist[1].data
        # secondary_header = hdulist[1].header

        # Start and end dates.  Different LYRA FITS files have
        # different tags for the date obs.
        """
        print(hdulist[0].header)
        if 'date-obs' in hdulist[0].header:
            start_str = hdulist[0].header['date-obs']
        elif 'date_obs' in hdulist[0].header:
            start_str = hdulist[0].header['date_obs']
        # end_str = hdulist[0].header['date-end']
        """
        metadata = MetaDict(OrderedDict(hdulist[0].header))
        start_str = metadata.get('date-obs', metadata.get('date_obs', ''))

        # start = datetime.datetime.strptime(start_str, '%Y-%m-%dT%H:%M:%S.%f')
        start = parse_time(start_str)
        # end = datetime.datetime.strptime(end_str, '%Y-%m-%dT%H:%M:%S.%f')

        # First column are times.  For level 2 data, the units are [s].
        # For level 3 data, the units are [min]
        if hdulist[1].header['TUNIT1'] == 's':
            times = start + TimeDelta(fits_record.field(0)*u.second)
        elif hdulist[1].header['TUNIT1'] == 'MIN':
            td = [int(n) for n in fits_record.field(0)]
            times = start + TimeDelta(td*u.minute)
        else:
            raise ValueError("Time unit in LYRA fits file not recognised.  "
                             "Value = {0}".format(hdulist[1].header['TUNIT1']))

        # Rest of columns are the data
        table = {}

        for i, col in enumerate(fits_record.columns[1:-1]):
            # temporary patch for big-endian data bug on pandas 0.13
            if fits_record.field(i+1).dtype.byteorder == '>' and sys.byteorder =='little':
                table[col.name] = fits_record.field(i + 1).byteswap().newbyteorder()
            else:
                table[col.name] = fits_record.field(i + 1)

        # Return the header and the data
        times.precision = 9
        data = pandas.DataFrame(table, index=times.isot.astype('datetime64'))
        data.sort_index(inplace=True)

        # Add the units data
        units = OrderedDict([('CHANNEL1', u.W/u.m**2),
                             ('CHANNEL2', u.W/u.m**2),
                             ('CHANNEL3', u.W/u.m**2),
                             ('CHANNEL4', u.W/u.m**2)])
        # ToDo: check: http://www.wmo-sat.info/oscar/instruments/view/733
        return data, metadata, units