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

Some changes necessary for subsurface #118

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions striplog/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def __init__(self, properties=None):
# Cope with a boolean...
setattr(self, k, v)
else:
try: # To treat as number...
setattr(self, k, float(v))
except ValueError: # Just add it.
try:
setattr(self, k, v)
except TypeError: # It's probably None.
continue
Expand Down Expand Up @@ -106,8 +104,8 @@ def __eq__(self, other):
s = {k.lower(): v.lower() for k, v in ds if v}
o = {k.lower(): v.lower() for k, v in do if v}
except (AttributeError, ValueError): # Dealing with numbers.
s = {k.lower(): v for k, v in ds if isinstance(v, strobj) or isinstance(v, bool)}
o = {k.lower(): v for k, v in do if isinstance(v, strobj) or isinstance(v, bool)}
s = {k.lower(): v for k, v in ds if isinstance(v, strobj) or isinstance(v, bool) or isinstance(v, int)}
o = {k.lower(): v for k, v in do if isinstance(v, strobj) or isinstance(v, bool) or isinstance(v, int)}

# Compare.
if s == o:
Expand Down
68 changes: 62 additions & 6 deletions striplog/striplog.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,62 @@ def from_csv(cls, filename=None,

f.close()

remap = remap or {}
for k, v in remap.items():
reorg[v] = reorg.pop(k)

data = cls._clean_longitudinal_data(reorg, null=null)

list_of_Intervals = cls._build_list_of_Intervals(data,
points=points,
lexicon=lexicon,
include=include,
exclude=exclude,
ignore=ignore,
stop=stop)

return cls(list_of_Intervals, source=source)

@classmethod
def from_dict_advanced(cls, dict,
lexicon=None,
points=False,
include=None,
exclude=None,
remap=None,
function=None,
null=None,
ignore=None,
source=None,
stop=None,
):
"""
Load from a dictionary reusing `from_csv` post processing.

Args
dict (dict): python dict containing the data.
lexicon (Lexicon): The lexicon to use, optional. Only needed if \
parsing descriptions (e.g. cuttings).
points (bool): Whether to make a point dataset (as opposed to \
ordinary intervals with top and base. Default is False.
include: Default is None.
exclude: Default is None.
remap: Default is None.
function: Default is None.
null: Default is None.
ignore: Default is None.
source: Default is None.
stop: Default is None.
fieldnames: Default is None.

Returns
Striplog. A new instance.
"""

# Reorganize the data to make fixing it easier.
reorg = dict


remap = remap or {}
for k, v in remap.items():
reorg[v] = reorg.pop(k)
Expand Down Expand Up @@ -1095,7 +1151,7 @@ def copy(self):
order=self.order,
source=self.source)





Expand Down Expand Up @@ -1230,7 +1286,7 @@ def to_log(self,
you are asking for. It's up to you to make sure the function
does what you want.
bins (bool): Whether to return the index of the items from the
lookup table. If False, then the item itself will be returned.
lookup table. If False, then the item itself will be returned.
dtype (str): The NumPy dtype string for the output log.
table (list): Provide a look-up table of values if you want. If you
don't, then it will be constructed from the data.
Expand Down Expand Up @@ -2623,7 +2679,7 @@ def from_macrostrat(cls, lng, lat, buffer_size=0.2):
This is simply a helper function to make things easier, but it
works because we know what our data looks like in advance.

Note: In order to plot this, you will need to add space for text and
Note: In order to plot this, you will need to add space for text and
other decoration. This simply gives a Striplog back which _can_
be plotted.

Expand All @@ -2640,8 +2696,8 @@ def from_macrostrat(cls, lng, lat, buffer_size=0.2):
lat = 44.4454632
buffer_size = 0.3
striplog.striplog.from_macrostrat(lng, lat, buffer_size)
{'top': Position({'middle': 358.9, 'units': 'm'}),
'base': Position({'middle': 419.2, 'units': 'm'}),
{'top': Position({'middle': 358.9, 'units': 'm'}),
'base': Position({'middle': 419.2, 'units': 'm'}),
'description': '', 'data': {}, 'components': [Component({
'map_id': 948660.0, 'scale': 'small', 'source_id': 7.0,
'name': 'Devonian plutonic: undivided granitic rocks',
Expand All @@ -2665,7 +2721,7 @@ def from_macrostrat(cls, lng, lat, buffer_size=0.2):
't_int': 112.0, 'b_int': 122.0, 'color': '#409963',
'source': 'MacroStrat.org (CC-BY)})]}
"""
# Get the
# Get the
features = utils.geology_from_macrostrat(lng=lng, lat=lat,
buffer_size=buffer_size)

Expand Down
5 changes: 5 additions & 0 deletions tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ def test_from_text():
assert rock3 == rock4
rock5 = Component.from_text(s, lexicon, required='not there')
assert not rock5 # Should be None

def test_integer_comparison():
formations = range(1, 3)
table = [Component({'lith': l}) for l in formations]
assert (table[0] == table[1]) is False