Пример #1
0
def test_compute_cdftt2000(dtime):
    random_time = [dtime.year, dtime.month, dtime.day,
                   dtime.hour, dtime.minute, dtime.second,
                   dtime.microsecond // 1000,  # Millisecond
                   randint(0, 999),     # Microsecond
                   randint(0, 999),     # Nanosecond
                   ]
    x = cdfepoch.breakdown(cdfepoch.compute(random_time))
    for i, t in enumerate(x):
        assert t == random_time[i], f'Time {random_time} was not equal to {x}'
Пример #2
0
def test_breakdown_cdftt2000():
    x = cdfepoch.breakdown(123456789101112131)
    assert x[0] == 2003
    assert x[1] == 11
    assert x[2] == 30
    assert x[3] == 9
    assert x[4] == 32
    assert x[5] == 4
    assert x[6] == 917
    assert x[7] == 112
    assert x[8] == 131
Пример #3
0
def test_compute_cdfepoch(dtime):
    '''
    Using random numbers for the compute tests
    '''
    random_time = [dtime.year, dtime.month, dtime.day,
                   dtime.hour, dtime.minute, dtime.second,
                   dtime.microsecond // 1000]
    x = cdfepoch.breakdown(cdfepoch.compute(random_time))
    i = 0
    for t in x:
        assert t == random_time[i], f'Time {random_time} was not equal to {x}'
        i += 1
Пример #4
0
def test_breakdown_cdfepoch16():
    x = cdfepoch.breakdown(np.complex128(63300946758.000000 + 176214648000.00000j))
    assert x[0] == 2005
    assert x[1] == 12
    assert x[2] == 4
    assert x[3] == 20
    assert x[4] == 19
    assert x[5] == 18
    assert x[6] == 176
    assert x[7] == 214
    assert x[8] == 648
    assert x[9] == 000
Пример #5
0
def test_compute_cdfepoch16(dtime):
    random_time = [dtime.year, dtime.month, dtime.day,
                   dtime.hour, dtime.minute, dtime.second,
                   dtime.microsecond // 1000,  # Millisecond
                   randint(0, 999),     # Microsecond
                   randint(0, 999),     # Nanosecond
                   randint(0, 999),     # Picosecond
                   ]
    x = cdfepoch.breakdown(cdfepoch.compute(random_time))
    i = 0
    for t in x:
        assert t == random_time[i], f'Time {random_time} was not equal to {x}'
        i += 1
Пример #6
0
def test_compute_cdftt2000():
    random_time = []
    random_time.append(randint(0, 2018))  # Year
    random_time.append(randint(1, 12))  # Month
    random_time.append(randint(1, 28))  # Date
    random_time.append(randint(0, 23))  # Hour
    random_time.append(randint(0, 59))  # Minute
    random_time.append(randint(0, 59))  # Second
    random_time.append(randint(0, 999))  # Millisecond
    random_time.append(randint(0, 999))  # Microsecond
    random_time.append(randint(0, 999))  # Nanosecond
    x = cdfepoch.breakdown(cdfepoch.compute(random_time))
    i = 0
    for t in x:
        assert t == random_time[i], 'Time {} was not equal to {}'.format(
            random_time, x)
        i += 1
Пример #7
0
 def get_dataset_raw(self, keys, WFR_file_id=0):
     """ Convert the raw data to dict format """
     self.epoch = None
     o = {"Epoch": []}
     for f in self.files["file_objects"]:
         dates = [
             dt.datetime(i[0], i[1], i[2], i[3], i[4], i[5])
             for i in CDFepoch.breakdown(f.varget("Epoch"))
         ]
         o["Epoch"].extend(dates)
         if self.verbose: print(f.cdf_info())
         for key in keys:
             if key not in o.keys(): o[key] = f.varget(key)[:]
             else: o[key] = np.concatenate(o[key], f.varget(key)[:])
     if WFR_file_id is not None: o["WFR"] = self.get_WFR_info(WFR_file_id)
     self.epoch = o["Epoch"]
     return o
Пример #8
0
def test_breakdown_cdfepoch():
    x = cdfepoch.breakdown([62285326000000.0, 62985326000000.0])
    # First in the array
    assert x[0][0] == 1973
    assert x[0][1] == 9
    assert x[0][2] == 28
    assert x[0][3] == 23
    assert x[0][4] == 26
    assert x[0][5] == 40
    assert x[0][6] == 0
    # Second in the array
    assert x[1][0] == 1995
    assert x[1][1] == 12
    assert x[1][2] == 4
    assert x[1][3] == 19
    assert x[1][4] == 53
    assert x[1][5] == 20
    assert x[1][6] == 0
Пример #9
0
def test_compute_cdftt2000():
    random_time = []
    # These are the supported years for CDF files; see
    # https://spdf.gsfc.nasa.gov/pub/software/cdf/doc/cdf371/cdf371ug.pdf
    # page 55
    random_time.append(randint(1709, 2292))  # Year
    random_time.append(randint(1, 12))  # Month
    random_time.append(randint(1, 28))  # Date
    random_time.append(randint(0, 23))  # Hour
    random_time.append(randint(0, 59))  # Minute
    random_time.append(randint(0, 59))  # Second
    random_time.append(randint(0, 999))  # Millisecond
    random_time.append(randint(0, 999))  # Microsecond
    random_time.append(randint(0, 999))  # Nanosecond
    x = cdfepoch.breakdown(cdfepoch.compute(random_time))
    i = 0
    for t in x:
        assert t == random_time[i], 'Time {} was not equal to {}'.format(
            random_time, x)
        i += 1
Пример #10
0
def _convert_cdf_time_types(data,
                            atts,
                            properties,
                            to_datetime=False,
                            to_unixtime=False):
    '''
    # Converts CDF time types into either datetime objects, unixtime, or nothing
    # If nothing, ALL CDF_EPOCH16 types are converted to CDF_EPOCH, because xarray can't handle int64s
    '''

    if not hasattr(data, '__len__'):
        data = [data]

    if to_datetime and to_unixtime:
        print(
            "Cannot convert to both unixtime and datetime.  Continuing with conversion to unixtime."
        )
        to_datetime = False

    # Convert all data in the "data" variable to unixtime or datetime if needed
    data_type = properties['Data_Type_Description']
    if len(data) == 0 or data_type not in ('CDF_EPOCH', 'CDF_EPOCH16',
                                           'CDF_TIME_TT2000'):
        new_data = data
    else:
        if to_datetime:
            new_data = cdfepoch.to_datetime(data)
            if 'UNITS' in atts:
                atts['UNITS']['Data'] = 'Datetime (UTC)'
        elif to_unixtime:
            new_data = cdfepoch.unixtime(data)
            if 'UNITS' in atts:
                atts['UNITS']['Data'] = 'seconds'
        else:
            if data_type == 'CDF_EPOCH16':
                new_data = cdfepoch.compute(cdfepoch.breakdown(data)[0:7])
            else:
                new_data = data

    # Convert all the attributes in the "atts" dictionary to unixtime or datetime if needed
    new_atts = {}
    for att in atts:
        data_type = atts[att]['Data_Type']
        data = atts[att]['Data']
        if not hasattr(data, '__len__'):
            data = [data]
        if len(data) == 0 or data_type not in ('CDF_EPOCH', 'CDF_EPOCH16',
                                               'CDF_TIME_TT2000'):
            new_atts[att] = data
        else:
            if to_datetime:
                new_atts[att] = cdfepoch.to_datetime(data)
            elif to_unixtime:
                new_atts[att] = cdfepoch.unixtime(data)
            else:
                if data_type == 'CDF_EPOCH16':
                    new_atts[att] = cdfepoch.compute(
                        cdfepoch.breakdown(data)[0:7])
                else:
                    new_atts[att] = data

    return new_data, new_atts