Beispiel #1
0
 def parse(self, sineslist):
     doc = DataObjectCollection()
     for sines in sineslist:
         do = DataObject()
         for key, sine in sines.items():
            ts = TimeSeries(sine)
            ts.sample_rate = 1
            do[key] = ts
         doc.append(do)
     return doc
Beispiel #2
0
 def parse(self, sineslist):
     doc = DataObjectCollection()
     for sines in sineslist:
         do = DataObject()
         for key, sine in sines.items():
             ts = TimeSeries(sine)
             ts.sample_rate = 1
             do[key] = ts
         doc.append(do)
     return doc
Beispiel #3
0
    def parse(self, sines):
        doc = DataObjectCollection()
        do = DataObject()
        for key, sine in sines.items():
           ts = TimeSeries(sine)
           ts.sample_rate = 1
#            ts.rangex = (-1,1)
           do[key] = ts
        doc.append(do)
        return doc
Beispiel #4
0
 def parse(self, sines):
     doc = DataObjectCollection()
     do = DataObject()
     for key, sine in sines.items():
         ts = TimeSeries(sine)
         ts.sample_rate = 1
         #            ts.rangex = (-1,1)
         do[key] = ts
     doc.append(do)
     return doc
Beispiel #5
0
    def parse(self, stations, years, fields):
        ''' Pass in some stations and years. For convenience (and to match CRN's data output)
        we'll only deal with data in complete years. '''
        # First make sure we've got the data locally:
        self._download(stations, years)

        doc = DataObjectCollection()
        for station in stations:
            do = DataObject()
            for field in self.fields:
                # Skip some fields we know we don't care about
                useless_fields = [
                    'WBANNO', 'UTC_DATE', 'UTC_TIME', 'LST_DATE', 'LST_TIME',
                    'CRX_VN', 'SUR_TEMP_TYPE'
                ]
                if (fields and field not in fields) or (not fields and field
                                                        in useless_fields):
                    continue
                do[field] = TimeSeries([])

            for year in years:
                f = open(self.storage_dir + self._filename(station, year))
                for line in f:
                    values = line.split()
                    do.append(values, self.fields)
            for ts in do.values():
                ts.replace_data(
                    interpolate_forward_backward(ts, missing_values))
            doc.append(do)
        return doc
Beispiel #6
0
 def parse(self):
     d = eval(self.file.readline().strip())
     doc = DataObjectCollection(sample_rate=1 / 3.0)
     for i, octant in enumerate(d):
         do = DataObject()
         for varname, values in octant.items():
             ts = TimeSeries(values)
             do[varname] = ts
         doc.append(do)
     return doc
Beispiel #7
0
def test_do_imposes_sample_rate():
    # create a TimeSeries
    ts1 = TimeSeries(['datapoint'])

    # create a DO and put the TS in it
    do1 = DataObject(sample_rate=60)
    do1['somed'] = ts1

    # test the sample_rate of the TimeSeries (which it should derive from the DO)
    assert(do1['somed'].sample_rate == 60)

    # while we're at it, make sure that it percolates up to the DOC
    doc = DataObjectCollection([do1])
    assert doc.sample_rate == 60, str(doc.sample_rate) + ' is not 60.'
Beispiel #8
0
def test_datamapper_1():
    # create a TimeSeries and stick something in it
    ts1 = TimeSeries(['datapoint'], sample_rate=60)

    # create a DO and put the TS in it
    do1 = DataObject()
    do1['somedata'] = ts1
    assert do1.keys() == ['somedata']

    # create a DOC and put the DO in it
    doc = DataObjectCollection()
    doc.append(do1)

    # dig down through the levels and get the datapoint we originally inserted
    timeseries = doc[0]['somedata']
    datapoint = timeseries[0]
    assert(datapoint == 'datapoint')
Beispiel #9
0
def test_combine_range():
    ''' Make some sines, modify them to have different ranges, and combine the ranges. '''
    parser = MultiSineDictParser()
    sinelist = []
    for i in range(3):
        sines = generate_sines(3, 3)
        sinelist.append(sines)
    doc = parser.parse(sinelist)
    for i, do in enumerate(doc):
        do[0] = TimeSeries([(i + 1) * v for v in do[0]])
    old_ranges = [do[0].ts_range for do in doc]
    assert old_ranges[0] == (0.2871614310423001, 0.4665948234153722), old_ranges[0]
    assert len(set(old_ranges)) == 3 # All identical
    doc.combine_range(0)
    new_ranges = [do[0].ts_range for do in doc]
    assert new_ranges[0] == (0.2871614310423001, 1.3997844702461166), new_ranges[0]
    assert len(set(new_ranges)) == 1 # All identical
Beispiel #10
0
 def _getDataObject():
     ''' Convenience method to return a DataObject initialized to fit the buoy data. '''
     do = DataObject(metadata={'buoy_id': id})
     for key in ['LAT', 'LON', 'TEMP']:
         do[key] = TimeSeries([])
     return do
Beispiel #11
0
def test_remap_range():
    inlist = TimeSeries([0, .5, 1])
#    original_range = (0, 1)
    desired_range = (0, 10)
    outlist = inlist.remap_range(desired_range)
    assert outlist == TimeSeries([0.0, 5.0, 10.0]), 'outlist is ' + str(outlist) + ': ' + str(type(outlist))

    inlist = TimeSeries([1.0, 1.5, 2])
    original_range = (1, 2)
    desired_range = (100, 110)
    outlist = inlist.remap_range(desired_range)
    assert outlist == TimeSeries([100.0, 105.0, 110.0]), 'outlist is ' + str(outlist)

    # same thing without explicitly setting the original range
    inlist = TimeSeries([1.0, 1.5, 2])
    desired_range = (100, 110)
    outlist = inlist.remap_range(desired_range)
    assert outlist == TimeSeries([100.0, 105.0, 110.0]), 'outlist is ' + str(outlist)
Beispiel #12
0
def test_resample():
    ts = TimeSeries([0, 1, 2, 3, 4, 5, 6])
    ts.resample(.4)
    assert str(ts) == 'TimeSeries([0.0, 0.4, 0.8, 1.2000000000000002, 1.6, 2.0, 2.4000000000000004, 2.8000000000000003, 3.2, 3.6, 4.0, 4.4, 4.800000000000001, 5.2, 5.6000000000000005], sample_rate=None, ts_range=(0.0, 5.6000000000000005))'
    ts.resample(1 / .4) # Reversible? Should be except that we lose some off the end (we have to)
    assert str(ts) == 'TimeSeries([0.0, 1.0, 2.0, 3.0, 4.0, 5.0], sample_rate=None, ts_range=(0.0, 5.0))'
Beispiel #13
0
def test_ts_range():
    ts = TimeSeries([2, 3, 1, 5, 4], ts_range=(0, 5))
    assert(ts.ts_range == (0, 5))

    ts = TimeSeries([2, 3, 1, 5, 4])
    assert(ts.ts_range == (1, 5))