def test_borehole_iter(self): s_iter = (s for s in [ Segment(top=0., base=0.5, lithology='Z'), Segment(top=0.5, base=3.0, lithology='K'), Segment(top=3.0, base=20., lithology='Z'), ]) b = Borehole(code='b', depth=20., segments=s_iter) b.materialize() assert len(b) == 3
def test_simplify_min_thickness(self): segments = [ Segment(top=0., base=0.5, lithology='Z'), Segment(top=0.5, base=3.0, lithology='Z'), Segment(top=3.0, base=3.1, lithology='K'), Segment(top=10.0, base=20., lithology='Z'), ] b = Borehole(code='b', depth=20., segments=segments) b.simplify(min_thickness=0.5) assert len(b) == 1 assert b.segments[0].lithology == 'Z' assert np.isclose(b.segments[0].thickness, 20.)
def classify_lithology(self, classifier, admixclassifier=None): if self.complete: self.segments = [] top = 0. for row in self.rows: base = row.depth lithology = classifier.classify( row.friction_ratio, row.cone_resistance, ) segment = Segment(top, base, lithology) segment.update(admixclassifier.classify(segment.lithology)) self.segments.append(segment) top = base
def read_segments(cls, lines, columnsep, recordsep): for line in lines: line = line.rstrip(recordsep) attrs = {} top, base, *remainder = line.split(columnsep) try: lithologycolor = remainder[0].replace('\'', '').strip() or None except IndexError: lithologycolor = None try: sandmedianclass = remainder[1].replace('\'', '').strip() or None except IndexError: sandmedianclass = None try: comment = remainder[2].replace('\'', '').strip() or None except IndexError: comment = None top = cls.safe_float(top) base = cls.safe_float(base) if lithologycolor is not None: lithology, *color = lithologycolor.split(maxsplit=1) attrs['color'] = color else: lithology = None if sandmedianclass is not None: sandmedianclass, *_ = sandmedianclass.split(maxsplit=1) if comment is not None: attrs['comment'] = comment yield Segment(top, base, lithology, sandmedianclass, **attrs)
def classify_lithology(self, classifier, admixclassifier=None): if self.complete: self.segments = [] for i, row in enumerate(self.rows): base = row.depth if i == 0: top = 0. blind_segment = Segment(top, base, "O") self.segments.append(blind_segment) top = base continue lithology = classifier.classify( row.friction_ratio, row.cone_resistance, ) segment = Segment(top, base, lithology) segment.update(admixclassifier.classify(segment.lithology)) self.segments.append(segment) top = base
def read_segments(cls, survey, fields=None): '''read segments from XML and yield as Segment''' fields = fields or {} intervals = survey.findall('borehole/lithoDescr/lithoInterval') for interval in intervals: # top and base top = cls.safe_float( interval.attrib.get('topDepth')) * 1e-2 # to m base = cls.safe_float( interval.attrib.get('baseDepth')) * 1e-2 # to m # attrs attrs = {} # lithology lithology = interval.find('lithology').attrib.get('code') # sandmedianclass try: sandmedianclass = interval.find('sandMedianClass').attrib.get( 'code')[:3] except AttributeError: sandmedianclass = None # sand median try: attrs['sandmedian'] = cls.safe_float( interval.find('sandMedian').attrib.get('median')) except AttributeError: attrs['sandmedian'] = None for field in fields: path, attrib = field['match'].split('@') element = interval.find(path.rstrip('/')) if element is None: continue value = element.attrib.get(attrib) if value is None: continue attrs[field['name']] = cls.cast(value, field['dtype']) # yield segment yield Segment(top, base, lithology, sandmedianclass, **attrs)
def read_segments(cls, rows, decimal, fieldnames, fields=None): fields = fields or {} top = 0. for row in rows: base = cls.safe_float(row[fieldnames.base], decimal) lithology = row.get(fieldnames.lithology) sandmedianclass = row.get(fieldnames.sandmedianclass) attrs = {} for field in fields: value = row.get(field['fieldname']) if value is not None: attrs[field['name']] = cls.cast(value, dtype=field['dtype'], decimal=decimal, ) yield Segment(top, base, lithology, sandmedianclass, **attrs) # base to next top top = base
def test_segment_lithology(self): s = Segment(top=0., base=10., lithology='Z') assert s.lithology == 'Z'
def test_segment_relative_to(self): z = 13. s = Segment(top=5., base=7., lithology='Z') ref_top, ref_base = s.relative_to(z) assert np.isclose(ref_top, 8.) assert np.isclose(ref_base, 6.)
def test_segment_add_lithology(self): s1 = Segment(top=0., base=10., lithology='Z') s2 = Segment(top=10., base=12., lithology='K') s1 += s2 assert s1.lithology == 'Z'
def test_segment_add_base(self): s1 = Segment(top=0., base=10., lithology='Z') s2 = Segment(top=10., base=12., lithology='K') s1 += s2 assert np.isclose(s1.base, 12.)
def test_segment_thickness(self): s = Segment(top=0., base=10., lithology='Z') assert np.isclose(s.base, 10.)