예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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.)
예제 #4
0
 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.)
예제 #5
0
    def to_boreholes(self, fieldnames, extra_fields=None):
        fieldnames = self.FieldNames(**fieldnames)
        extra_fields = extra_fields or {}
        borehole_fields = extra_fields.get('borehole') or []
        segment_fields = extra_fields.get('segments') or []

        log.debug('reading {s.file.name:}'.format(s=self))
        with open(self.file, 'r') as f:
            reader = csv.DictReader(f, delimiter=self.delimiter)
            bycode = lambda r: r[fieldnames.code]
            for code, rows in groupby(reader, key=bycode):
                if code in {None, ''}:
                    continue

                # materialize rows
                rows = [r for r in rows]

                # code
                code = str(code)

                # segments as list
                segments = [
                    s for s in self.read_segments(rows,
                        decimal=self.decimal,
                        fieldnames=fieldnames,
                        fields=segment_fields,
                        )
                    ]

                # depth
                if fieldnames.depth in rows[0]:
                    depth = self.safe_float(rows[0][fieldnames.depth],
                        self.decimal)
                else:
                    depth = self.depth_from_segments(segments)

                # x, y, z
                x = self.safe_float(rows[0][fieldnames.x], self.decimal)
                y = self.safe_float(rows[0][fieldnames.y], self.decimal)
                z = self.safe_float(rows[0][fieldnames.z], self.decimal)

                # extra fields
                for field in borehole_fields:
                    value = rows[0].get(field['fieldname'])
                    if value is not None:
                        self.attrs[field['name']] = self.cast(value,
                            dtype=field['dtype'],
                            decimal=self.decimal,
                            )

                yield Borehole(code, depth,
                    x=x, y=y, z=z,
                    segments=segments,
                    **self.attrs,
                    )
예제 #6
0
    def to_borehole(self, extra_fields=None):
        '''read Dinoloket XML file and return Borehole'''
        # extra fields
        extra_fields = extra_fields or {}
        borehole_fields = extra_fields.get('borehole') or None
        segment_fields = extra_fields.get('segments') or None

        # code
        survey = self.root.find('pointSurvey')
        code = survey.find('identification').attrib.get('id')

        # timestamp of borehole
        date = survey.find('borehole/date')
        try:
            year = self.safe_int(date.attrib.get('startYear'))
            month = self.safe_int(date.attrib.get('startMonth'))
            day = self.safe_int(date.attrib.get('startDay'))
            if year and month and day:
                timestamp = datetime.datetime(year, month, day).isoformat()
            elif year and month:
                timestamp = datetime.datetime(year, month, 1).isoformat()
            elif year:
                timestamp = datetime.datetime(year, 1, 1).isoformat()
            else:
                timestamp = None
        except AttributeError:
            timestamp = None
        self.attrs['timestamp'] = timestamp

        # segments as list
        segments = [s for s in self.read_segments(survey, segment_fields)]

        # final depth of borehole in m
        basedepth = survey.find('borehole').attrib.get('baseDepth')
        depth = self.safe_float(basedepth)
        try:
            depth *= 1e-2  # to m
        except TypeError:
            depth = self.depth_from_segments(segments)

        # x,y coordinates
        coordinates = survey.find('surveyLocation/coordinates')
        x = self.safe_float(coordinates.find('coordinateX').text)
        y = self.safe_float(coordinates.find('coordinateY').text)

        # elevation in m
        elevation = survey.find('surfaceElevation/elevation')
        if not elevation is None:
            z = self.safe_float(elevation.attrib.get('levelValue'))
            try:
                z *= 1e-2  # to m
            except TypeError:
                z = None
        else:
            z = None

        return Borehole(
            code,
            depth,
            x=x,
            y=y,
            z=z,
            segments=segments,
            **self.attrs,
        )
예제 #7
0
 def test_borehole_depth(self):
     b = Borehole(code='b', depth=1.2)
     assert np.isclose(b.depth, 1.2)
예제 #8
0
    def to_borehole(self):
        log.debug('reading {file:}'.format(file=os.path.basename(self.file)))

        with open(self.file) as f:
            lines = (l.rstrip('\n') for l in f if len(l.strip()) > 0)
            header = self.read_header(lines)

            # column separator
            if self.fieldnames.columnsep in header:
                columnsep, *_ = header[self.fieldnames.columnsep]
            else:
                columnsep = None

            # record separator
            if self.fieldnames.recordsep in header:
                recordsep, *_ = header[self.fieldnames.recordsep]
            else:
                recordsep = None

            # segments
            segments = [
                s for s in self.read_segments(lines, columnsep, recordsep)
                ]
            # classify lithology and admix
            if self.classifier is not None:
                for segment in segments:
                    segment.update(self.classifier.classify(segment.lithology))
        # code
        try:
            code = header[self.fieldnames.code][0].strip()

        except KeyError:
            log.warning(
                (
                    'no value for \'{s.fieldnames.code:}\' in {s.file.name:},\n'
                    'skipping this file'
                    ).format(s=self))
            return

        # depth
        try:
            depth = header['MEASUREMENTVAR'][self.measurementvars.depth].value
        except KeyError:
            depth = self.depth_from_segments(segments)

        # x, y
        _, x, y, *_ = header[self.fieldnames.xy]
        x = self.safe_float(x)
        y = self.safe_float(y)

        # z
        if self.fieldnames.z in header:
            _, z, *_ = header[self.fieldnames.z]
            z = self.safe_float(z)
        else:
            z = None

        return Borehole(code, depth,
            x=x, y=y, z=z,
            segments=segments,
            **self.attrs,
            )