Skip to content

Commit

Permalink
Merge branch 'synthetics2021' of https://github.com/hyperiongeo/welly
Browse files Browse the repository at this point in the history
…into synthetics2021
  • Loading branch information
hyperiongeo committed Dec 15, 2024
2 parents 3edcb3a + 2c7aac4 commit b98864b
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 105 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
branches: [ develop, main ]
pull_request:
branches: [ develop ]
branches: [ develop, main ]

jobs:
build:
Expand All @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
Expand All @@ -29,5 +29,4 @@ jobs:
python -m pip install --upgrade pip
python -m pip install .[test]
- name: Test with pytest
run: |
python run_tests.py
run: pytest
63 changes: 57 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
[build-system]
requires = [
"setuptools>=48",
"setuptools_scm[toml] >= 4, <6",
"setuptools_scm_git_archive",
"wheel >= 0.29.0",
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "welly"
dynamic = ["version"]
authors = [{ name = "The Welly Authors", email = "[email protected]" }]
description = "Tools for making and managing well data."
readme = "README.md"
readme-content-type = "text/markdown"
homepage = "https://github.com/agilescientific/welly"
classifiers = [
"Intended Audience :: Science/Research",
"Development Status :: 4 - Beta",
"Natural Language :: English",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent"
]
dependencies = [
"numpy",
"scipy",
"pandas",
"matplotlib",
"lasio",
"striplog",
"tqdm",
"wellpathpy",
"requests"
]

[project.optional-dependencies]
docs = ["sphinx", "sphinxcontrib-apidoc", "myst_nb", "furo"]
test = ["pytest", "pytest-cov", "pytest-mpl"]
dev = ["build", "pytest", "pytest-cov", "pytest-mpl", "sphinx", "sphinxcontrib-apidoc", "myst_nb", "furo"]

[tool.hatch.metadata]
packages = ["welly"]

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "_version.py"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [
"--cov=welly",
"--cov-config=pyproject.toml",
"--mpl",
"--mpl-baseline-path=tests/baseline",
]
build-backend = "setuptools.build_meta"
testpaths = ["tests"]

[tool.setuptools_scm]
write_to = "welly/_version.py"
Expand Down
20 changes: 0 additions & 20 deletions run_tests.py

This file was deleted.

39 changes: 0 additions & 39 deletions setup.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions setup.py

This file was deleted.

Binary file modified tests/baseline/test_curve_2d_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tests/test_well.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
from pathlib import Path

import pandas as pd

import welly
from welly import Well

Expand Down Expand Up @@ -148,3 +150,11 @@ def test_iter_well(well):
for curve in well:
assert curve == well.data['CALI']
break

def test_df_object_cols(df):

df["Test object"] = "54"
df["test_str"] = '1z'
well = Well.from_df(df)
assert all(well.df()["Test object"] == 54)
assert all(well.df()["test_str"] == "1z")
23 changes: 9 additions & 14 deletions welly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
welly
==================
"""
import sys

from .project import Project
from .well import Well
from .header import Header
Expand Down Expand Up @@ -67,17 +69,10 @@ def read_df(df, **kwargs):
]


from pkg_resources import get_distribution, DistributionNotFound

try:
VERSION = get_distribution(__name__).version
except DistributionNotFound:
try:
from ._version import version as VERSION
except ImportError:
raise ImportError(
"Failed to find (autogenerated) _version.py. "
"This might be because you are installing from GitHub's tarballs, "
"use the PyPI ones."
)
__version__ = VERSION
if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata

__version__ = metadata.version(__name__)

12 changes: 7 additions & 5 deletions welly/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_any_real_numeric_dtype
from pandas.api.types import is_numeric_dtype
from scipy.interpolate import interp1d

from welly.plot import plot_2d_curve, plot_curve, plot_kde_curve
Expand Down Expand Up @@ -367,15 +369,15 @@ def _repr_html_(self):
# Curve preview.
s = '<tr><th style="border-top: 2px solid #000;">Depth</th><th style="border-top: 2px solid #000;">Value</th></tr>'
rows += s.format(self.start, self.df.values[0][0])
if self.dtypes[0] == float:
if self.dtypes.iloc[0] == float:
s = '<tr><td>{:.4f}</td><td>{:.4f}</td></tr>'
else:
s = '<tr><td>{}</td><td>{}</td></tr>'
for depth, value in self.df.iloc[:3].iterrows():
rows += s.format(depth, value[0])
rows += s.format(depth, value.iloc[0])
rows += '<tr><td>⋮</td><td>⋮</td></tr>'
for depth, value in self.df.iloc[-3:].iterrows():
rows += s.format(depth, value[0])
rows += s.format(depth, value.iloc[0])

# Footer.
# ...
Expand Down Expand Up @@ -509,7 +511,7 @@ def step(self):
0. If the index is numeric and not equally sampled
None. If the index is not numeric
"""
if self.df.index.is_numeric() and not self.df.index.empty:
if is_any_real_numeric_dtype(self.df.index) and not self.df.index.empty:
return get_step_from_array(self.df.index.values)
else:
return None
Expand Down Expand Up @@ -969,7 +971,7 @@ def to_basis(self,
Curve. The current instance in the new basis.
"""
# category data type or a string in data defaults to 'nearest'
if pd.api.types.is_categorical_dtype(self.df.iloc[:, 0]) or pd.api.types.is_string_dtype(self.df.iloc[:, 0]):
if not is_numeric_dtype(self.df.iloc[:, 0]):
interp_kind = 'nearest'

new_curve = copy.deepcopy(self)
Expand Down
4 changes: 2 additions & 2 deletions welly/las.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def to_lasio(well,
if basis:
df_merged = df_merged.reindex(basis)
try:
l.add_curve('DEPT', df_merged.index.values)
l.append_curve('DEPT', df_merged.index.values)
except:
raise Exception("Please provide an index.")

Expand Down Expand Up @@ -452,7 +452,7 @@ def to_lasio(well,
# take the series, reindex it and transform to np.array
new_data = curve.df[col].reindex(basis).values
descr = getattr(curve, 'description', '')
l.add_curve(mnemonic=key_,
l.append_curve(mnemonic=key_,
data=new_data,
unit=curve.units,
descr=descr)
Expand Down
7 changes: 6 additions & 1 deletion welly/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,14 @@ def plot_2d_curve(curve,
x2=np.nanmin(curve_data),
facecolor='none',
**kwargs)

# Combine the paths into a single Path object
vertices = np.concatenate([p.vertices for p in paths._paths])
codes = np.concatenate([p.codes for p in paths._paths])
merged_paths = mpl.path.Path(vertices, codes)

# Make the 'fill' mask and clip the background image with it.
patch = PathPatch(paths._paths[0], visible=False)
patch = PathPatch(merged_paths, visible=False)
ax.add_artist(patch)
im.set_clip_path(patch)
else:
Expand Down
27 changes: 19 additions & 8 deletions welly/well.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,28 @@ def df(self,
# swap MultiIndex levels
df = df.swaplevel()

# I think this is the wrong place to do this.
# Anyway, use i not name just in case there are duplicate names.
for i, (_, column) in enumerate(df.iteritems()):
if is_object_dtype(column.dtype):
try:
df.iloc[:, i] = column.astype(float)
except ValueError:
pass
df = self._convert_object_cols_to_numeric(df)

return df

def _convert_object_cols_to_numeric(self, df):
"""
Convert object columns into numeric columns, if possible.
Args:
df (pd.DataFrame): dataframe to work
Returns:
pd.DataFrame. Whole dataframe with conversions
"""
df_nonobject = df.select_dtypes(exclude="object")
df_object = df.select_dtypes(include="object")
for col in df_object.columns:
try:
df_object[col] = pd.to_numeric(df_object[col])
except ValueError:
pass
return pd.concat([df_nonobject, df_object], axis=1)

def add_curves_from_las(self, fname, remap=None, funcs=None):
"""
Given a LAS file, add curves from it to the current well instance.
Expand Down

0 comments on commit b98864b

Please sign in to comment.