def test_select(self): d = Dataset(tempfile.mktemp(), 'w') tb = TargetBuffer(tags=['WI001'], name='White Island main vent', position=(177.2, -37.5, 50), position_error=(0.2, 0.2, 20), description='Main vent in January 2017') d.register_tags(['WI001', 'MD01', 'measurement']) t = d.new(tb) ib = InstrumentBuffer(tags=['MD01'], sensor_id='F00975', location='West rim', no_bits=16, type='DOAS', description='GeoNet permanent instrument') i = d.new(ib) rdtb = RawDataTypeBuffer(tags=['measurement'], name='1st round measurements', acquisition='stationary') rdt = d.new(rdtb) rb = RawDataBuffer(target=t, instrument=i, type=rdt, d_var=np.zeros((1, 2048)), ind_var=np.arange(2048), datetime=['2017-01-10T15:23:00']) r = d.new(rb) e = d.select("tags == 'MD01'") self.assertEqual(e['Target'][0], t) self.assertEqual(e['Instrument'][0], i) e = d.select("type.acquisition == 'stationary'", etype='RawData') self.assertEqual(e['RawData'][0], r)
def test_read(self): """ Test reading of HDF5 files. """ fn = tempfile.mktemp() d = Dataset(fn, 'w') tb = TargetBuffer(tags=['WI001'], name='White Island main vent', position=(177.2, -37.5, 50), position_error=(0.2, 0.2, 20), description='Main vent in January 2017') d.register_tags(['WI001', 'MD01', 'measurement']) t = d.new(tb) ib = InstrumentBuffer(tags=['MD01'], sensor_id='F00975', location='West rim', no_bits=16, type='DOAS', description='GeoNet permanent instrument') i = d.new(ib) rdtb = RawDataTypeBuffer(tags=['measurement'], name='1st round measurements', acquisition='stationary') rdt = d.new(rdtb) rb = RawDataBuffer(target=t, instrument=i, type=rdt, d_var=np.zeros((1, 2048)), ind_var=np.arange(2048), datetime=['2017-01-10T15:23:00']) d.new(rb) d.close() d1 = Dataset.open(fn) r1 = d1.elements['RawData'][0] self.assertEqual(r1.target.name, 'White Island main vent') self.assertEqual(list(r1.instrument.tags)[0], 'MD01')
def test_pedantic(self): d = Dataset(tempfile.mktemp(), 'w') rb = RawDataBuffer() with self.assertRaises(ValueError): d.new(rb, pedantic=True) d.register_tags(['WI001']) tb = TargetBuffer(tags=['WI001'], name='White Island main vent', position=(177.2, -37.5, 50), position_error=(0.2, 0.2, 20), description='Main vent in January 2017') d.new(tb) with self.assertRaises(ValueError): d.new(tb, pedantic=True)
def test_tagging(self): """ Test the tagging of data elements. """ d = Dataset(tempfile.mktemp(), 'w') d.register_tags(['measurement']) with self.assertRaises(ValueError): d.register_tags(['measurement']) tb = TargetBuffer(tags=['WI001', 'Eruption16']) with self.assertRaises(ValueError): t = d.new(tb) d.register_tags(['WI001', 'Eruption16']) t = d.new(tb) d.register_tags(['SomethingElse']) t.tags.append('SomethingElse') t.tags.remove('WI001') with warnings.catch_warnings(): warnings.simplefilter('ignore') d.remove_tags(['Eruption16', 'blub']) self.assertEqual(list(t.tags), ['SomethingElse']) # Ensure the same tag is only added once t.tags.append('SomethingElse') self.assertEqual(list(t.tags), ['SomethingElse']) self.assertEqual(len(d._f.root.tags._v_children['SomethingElse'][:]), 1)
def test_append(self): d = Dataset(tempfile.mktemp(), 'w') d.register_tags(['WI001', 'MD01', 'measurement']) tb = TargetBuffer(tags=['WI001'], name='White Island main vent', position=(177.2, -37.5, 50), position_error=(0.2, 0.2, 20), description='Main vent in January 2017') t = d.new(tb) ib = InstrumentBuffer(tags=['MD01'], sensor_id='F00975', location='West rim', no_bits=16, type='DOAS', description='GeoNet permanent instrument') i = d.new(ib) rdtb = RawDataTypeBuffer(tags=['measurement'], name='1st round measurements', acquisition='stationary') rdt = d.new(rdtb) rb = RawDataBuffer(target=t, instrument=i, type=rdt, d_var=np.zeros((1, 2048)), ind_var=np.arange(2048), datetime=['2017-01-10T15:23:00']) r = d.new(rb) rb1 = RawDataBuffer(target=t, instrument=i, type=rdt, d_var=np.ones((1, 2048)), ind_var=np.arange(2048), datetime=['2017-01-10T15:23:01']) r.append(rb1) self.assertEqual(len(r.ind_var[:]), 4096) self.assertEqual(np.array(r.ind_var[:]).size, 4096) self.assertTrue(np.alltrue(np.array(r.d_var[:]) < 2)) np.testing.assert_array_equal(np.array(r.datetime[:]).flatten(), np.array(['2017-01-10T15:23:00', '2017-01-10T15:23:01'], dtype='datetime64[ms]')) with self.assertRaises(ValueError): r.append(rb1, pedantic=True) with self.assertRaises(ValueError): r.append(rb, pedantic=True) with self.assertRaises(AttributeError): t.append(tb) d.register_tags(['WI002']) tb1 = TargetBuffer(tags=['WI002'], name='Donald Duck', position=(177.1, -37.4, 50), position_error=(0.2, 0.2, 20), description='Donald Duck vent in January 2010') t1 = d.new(tb1) rb2 = RawDataBuffer(target=t1, instrument=i, type=rdt, d_var=np.ones((1, 2048)), ind_var=np.arange(2048), datetime=['2017-01-10T15:23:02']) with self.assertRaises(AttributeError): rb.append(rb2)
def test_dtbuffer(self): """ Testing the behaviour of buffer elements. """ d = Dataset(tempfile.mktemp(), 'w') tb = TargetBuffer(tags=['WI001'], name='White Island main vent', position=(177.2, -37.5, 50), position_error=(0.2, 0.2, 20), description='Main vent in January 2017') with self.assertRaises(ValueError): t = d.new(tb) d.register_tags(['WI001', 'MD01', 'measurement']) t = d.new(tb) ib = InstrumentBuffer(tags=['MD01'], sensor_id='F00975', location='West rim', no_bits=16, type='DOAS', description='GeoNet permanent instrument') i = d.new(ib) rdtb = RawDataTypeBuffer(tags=['measurement'], name='1st round measurements', acquisition='stationary') rdt = d.new(rdtb) rb = RawDataBuffer(target=t, instrument=i, type=rdt, d_var=np.zeros((1, 2048)), ind_var=np.arange(2048), datetime=['2017-01-10T15:23:00']) r = d.new(rb) self.assertTrue(r.target == t) self.assertTrue(r.instrument == i) self.assertTrue(r.type == rdt) rb1 = RawDataBuffer() rb1.d_var = np.zeros((1, 2048)) rb1.ind_var = np.arange(2048), rb1.datetime = ['2017-01-10T15:23:00'] rb1.target = t rb1.instrument = i rb1.type = rdt d.new(rb1)