-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparseSplice.py
48 lines (35 loc) · 1.58 KB
/
sparseSplice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Created on Apr 20, 2017
@author: bgrivna
'''
import math
import os
import unittest
from tabular.csvio import createWithCSV
from tabular.columns import TabularDatatype, TabularFormat, ColumnIdentity
from .columns import namesToIds, CoreIdentityCols
Gap = ColumnIdentity("Gap", desc="Space added before an APPEND of the next interval", datatype=TabularDatatype.NUMERIC, unit='m', optional=True)
SpliceType = ColumnIdentity("SpliceType", desc="Type of splice operation: TIE or APPEND")
SparseSpliceColumns = CoreIdentityCols + namesToIds(['TopSection', 'TopOffset', 'BottomSection', "BottomOffset"]) + [SpliceType, Gap] + namesToIds(['DataUsed', 'Comment'])
SparseSpliceFormat = TabularFormat("Sparse Splice", SparseSpliceColumns)
class SparseSplice:
def __init__(self, name, dataframe):
self.name = name
self.dataframe = dataframe
@classmethod
def createWithFile(cls, filepath):
dataframe = createWithCSV(filepath, SparseSpliceFormat)
return cls(os.path.basename(filepath), dataframe)
def getSites(self):
return list(set(self.dataframe['Site']))
def getHoles(self):
return list(set(self.dataframe['Hole']))
class Tests(unittest.TestCase):
def test_create(self):
ss = SparseSplice.createWithFile("../testdata/GLAD9_Site1_SparseSplice.csv")
self.assertTrue(len(ss.dataframe) == 58)
self.assertTrue(math.isnan(ss.dataframe['Gap'].iloc[0]))
self.assertTrue('1' in ss.getSites())
self.assertTrue(len(ss.getHoles()) == 3)
if __name__ == "__main__":
unittest.main()