Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove first xml bore parser #265

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pygef/bore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import annotations
from dataclasses import dataclass
from datetime import date
from typing import Any
import copy
import pprint

from pygef.broxml import Location
import polars as pl

Expand All @@ -18,3 +22,24 @@ class BoreData:
final_sample_depth: float | None
bore_hole_completed: bool
data: pl.DataFrame

@property
def columns(self) -> list[str]:
return self.data.columns

def __str__(self):
return f"BoreData: {self.display_attributes()}"

def attributes(self) -> dict[str, Any]:
"""
Get the attributes
"""
attribs = copy.copy(self.__dict__)
attribs["data"] = attribs["data"].shape
return attribs

def display_attributes(self) -> str:
"""
Get pretty formatted string representation of `CPTData.attributes``
"""
return pprint.pformat(self.attributes())
2 changes: 0 additions & 2 deletions pygef/broxml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .bore import _BroXmlBore
from pygef.cpt import CPTData, QualityClass, Location
from pygef.bore import BoreData
from pygef.broxml.parse_cpt import read_cpt
Expand All @@ -12,5 +11,4 @@
"read_bore",
"QualityClass",
"Location",
"_BroXmlBore",
]
204 changes: 0 additions & 204 deletions pygef/broxml/bore.py

This file was deleted.

2 changes: 1 addition & 1 deletion pygef/cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def columns(self) -> list[str]:
return self.data.columns

def __str__(self):
return f"CPTData: {self.bro_id}"
return f"CPTData: {self.display_attributes()}"

def attributes(self) -> dict[str, Any]:
"""
Expand Down
7 changes: 2 additions & 5 deletions pygef/gef/bore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pygef.gef.plot_utils as plot
from pygef.gef.base import Base
from pygef.broxml import _BroXmlBore
from pygef.gef.gef import _GefBore


Expand Down Expand Up @@ -60,8 +59,6 @@ def __init__(self, path=None, content: dict | None = None):
"""
super().__init__()

parsed: Union[_BroXmlBore, _GefBore]

self.nen_version = None

if content is not None:
Expand All @@ -72,13 +69,13 @@ def __init__(self, path=None, content: dict | None = None):
if content["file_type"] == "gef":
parsed = _GefBore(string=content["string"])
elif content["file_type"] == "xml":
parsed = _BroXmlBore(string=content["string"])
raise ValueError("xml not supported by this parser")

elif path is not None:
if path.lower().endswith("gef"):
parsed = _GefBore(path)
elif path.lower().endswith("xml"):
parsed = _BroXmlBore(path)
raise ValueError("xml not supported by this parser")
else:
raise ValueError("One of [path, (string, file_type)] should be not None.")

Expand Down
51 changes: 0 additions & 51 deletions pygef/tests/gef/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,54 +1153,3 @@ def test_plot_cpt(self):
def test_plot_bore(self):
gef = Bore("./pygef/test_files/example_bore.gef")
gef.plot(show=False, figsize=(4, 12))


class TestBoreXml(unittest.TestCase):
def setUp(self):
self.bore = Bore("./pygef/test_files/bore_xml/DP65+005_HB_VL.xml")

def test_bore_main_attributes(self):
assert np.isclose(self.bore.zid, 4.49)
assert np.isclose(self.bore.x, 154154.0)
assert np.isclose(self.bore.y, 443248.0)
assert self.bore.file_date == datetime(2021, 10, 5).date()
assert self.bore.test_id == "78379_HB423"

def test_df_bore(self):

assert self.bore.df.columns == [
"depth_top",
"depth_bottom",
"soil_name",
"gravel_component",
"sand_component",
"clay_component",
"loam_component",
"peat_component",
"silt_component",
]

def test_all_xml(self):
path_folder = "./pygef/test_files/bore_xml/"
for file in os.listdir(path_folder):
if file.lower().endswith("xml"):
bore = Bore(f"{path_folder}/{file}")

assert {
"gravel_component",
"sand_component",
"clay_component",
"loam_component",
"peat_component",
"silt_component",
}.issubset(set(bore.df.columns))
bore.plot()

def test_read_as_string(self):
path = "./pygef/test_files/bore_xml/DP65+005_HB_VL.xml"
with open(path, encoding="utf-8", errors="ignore") as f:
string = f.read()

bore = Bore(content=dict(string=string, file_type="xml"))
assert type(bore.s_bin) == bytes
assert type(bore.s) == str