Skip to content

Commit

Permalink
Merge pull request #43 from Zabamund/drop-pandas
Browse files Browse the repository at this point in the history
Drop pandas
  • Loading branch information
Zabamund authored Mar 16, 2021
2 parents 92322cb + c8b594a commit bec5f3a
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 124 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# README

[wellpathpy/master](https://github.com/Zabamund/wellpathpy/tree/master):[![Build Status](https://travis-ci.com/Zabamund/wellpathpy.svg?branch=master)](https://travis-ci.com/Zabamund/wellpathpy)
[wellpathpy/api_models](https://github.com/Zabamund/wellpathpy/tree/api_models):[![Build Status](https://travis-ci.com/Zabamund/wellpathpy.svg?branch=api_models)](https://travis-ci.com/Zabamund/wellpathpy)
[wellpathpy/master](https://github.com/Zabamund/wellpathpy/tree/master):
[![Build Status](https://travis-ci.com/Zabamund/wellpathpy.svg?branch=master)](https://travis-ci.com/Zabamund/wellpathpy)

## Contributors:

Expand All @@ -18,16 +18,16 @@
- load well deviation in (md, inc, azi) format:
* meta data (header, rkb, dfe, rt)
* md, incl, azi
- interpolate survey using one of these methods:
- calculate position log survey using one of these methods:
* minimum curvature method
* radius of curvature method
* tangential method
- calculate dog-leg severity
* tangential methods
- calculate dog-leg severity from minimum curvature
- calculate depth references using header data if available: MD, TVD, TVDSS
- return interpolated deviation in (tvd, northing, easting) format
- move surface location to (0, 0, 0) or to (kb, mE, mN)
- convert to tvdss based on kb elevation
- resample deviation on regular steps
- resample deviation on regular steps with minimum curvature only

## Installation

Expand All @@ -39,14 +39,12 @@ From [pypi](https://pypi.org/project/wellpathpy/) with:

## Requirements

- [pandas](https://pandas.pydata.org/) version 0.24.2 or greater
- [numpy](https://numpy.org/) version 1.16.2 or greater
- [pytest](https://pytest.org/) version 4.3.1 or greater
- [pint](https://github.com/hgrecco/pint) version 0.9 or greater

## Tutorials

Currently work-in-progress in [branch:api_models](https://github.com/Zabamund/wellpathpy/tree/api_models).
A tutorial is available on [wellpathpy.readthedocs.io](https://wellpathpy.readthedocs.io/en/latest/tutorial.html)

## Contributing

Expand Down
36 changes: 29 additions & 7 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,35 @@ A valid input file must be a CSV file containing the columns: md, inc, azi in th
150,78.5,254
252.5,90,359.9
- column headers are **required**
- column headers are generally expected but will be skipped when the file is read
- if no headers are provided, the ``skiprows`` argument can be set to ``0``
- md must increase monotonically
- as inc and azi cannot be distinguished numerically it is the user's responsibility to ensure the data are passed in this order
- inc must be in range 0-180 (to allow for horizontal wells to climb)
- azi must be in range 0-360
- inc must be in range 0 <= inc < 180 (to allow for horizontal wells to climb)
- azi must be in range 0 <= azi < 360

You can then load them into wellpathpy using:

.. code-block:: python
md, inc, azi = wp.read_csv(fname)
``wp.read_csv`` simply calls ``np.loadtxt`` with ``delimiter=','`` and ``skiprows=1``.
These can be changed if required; for example the ``delimiter`` and ``skiprows`` can be changed with:

.. code-block:: python
md, inc, azi = wp.read_csv(fname, delimiter='\t', skiprows=0)
Additional ``kwargs`` accepted by ``np.loadtxt`` can also be passed in, for example:

.. code-block:: python
md, inc, azi = wp.read_csv(fname, comments='$')
**Notes**:

Some simple sanity checks are performed to reject bad CSVs. ``wp.read_csv`` supports all options ``pd.read_csv``
Some simple sanity checks are performed to reject bad CSVs. ``wp.read_csv`` supports all options ``np.loadtxt``
supports. Only those columns named md, inc, azi will be read.

If the deviation survey is not in CSV, is generated in a different place in your
Expand Down Expand Up @@ -105,7 +119,7 @@ With this, it is then possible to resample the depths using the ``minimum_curvat
step = 30
depths = list(range(0, int(dev.md[-1]) + 1, step))
pos = dev.mininum_curvature().resample(depths = depths)
pos = dev.minimum_curvature().resample(depths = depths)
dev2 = pos.deviation()
**Notes**:
Expand Down Expand Up @@ -370,8 +384,9 @@ Exporting results
#################

The two main ``wellpathpy`` objects; ``deviation`` and ``position`` logs can be written to CSV via
object methods as shown below. These simply use ``pd.DataFrame.to_csv`` under the hood with the
``pandas`` ``kwarg`` ``index`` set to ``False`` so that the index is not written out.
object methods as shown below. These both call ``np.savetxt`` with ``fmt='%.3f'`` and ``delimiter=','``.
The ``deviation`` also has ``header='md,inc,azi'`` and the ``postition`` has ``header='easting,northing,depth'``.
Other ``kwargs`` accepted by ``np.savetxt`` are also accepted.

- for a deviation survey:

Expand All @@ -385,5 +400,12 @@ object methods as shown below. These simply use ``pd.DataFrame.to_csv`` under th
pos.to_csv('./position.csv')
Additional ``kwargs`` can be passed like:

.. code-block:: python
dev.to_csv('./deviation.csv', fmt='%.2e')
pos.to_csv('./position.csv', header='X,Y,Z', comments='$')
This is a pretty straight-forward function convenient CSV writing. If you need
more control, or more sophisticated output, you must implement your own writer.
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest
pandas
numpy
pint
setuptools-scm
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pandas
numpy
pint
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
packages=['wellpathpy'],
license='LGPL-3.0',
platforms='any',
install_requires=['numpy >=1.10', 'pandas', 'pint'],
install_requires=['numpy >=1.10', 'pint'],
setup_requires=['setuptools >=28', 'setuptools_scm', 'pytest-runner'],
tests_require=['pytest', 'hypothesis'],
use_scm_version=True,
Expand Down
8 changes: 4 additions & 4 deletions wellpathpy/position_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def tan_method(self, choice = 'avg'):
)
return tan_method(self, tvd, n, e)

def to_csv(self, fname):
def to_csv(self, fname, **kwargs):
"""This function calls write.deviation_to_csv with self
Notes
-----
You can access help with `wp.write.deviation_to_csv?`
in `ipython`
"""
return deviation_to_csv(fname, self.md, self.inc, self.azi)
return deviation_to_csv(fname, self.md, self.inc, self.azi, **kwargs)

class position_log:
"""Position log
Expand Down Expand Up @@ -207,15 +207,15 @@ def resample(self, *args, **kwargs):
def deviation(self, *args, **kwargs):
raise NotImplementedError

def to_csv(self, fname):
def to_csv(self, fname, **kwargs):
"""This function calls write.position_to_csv with self
Notes
-----
You can access help with `wp.write.position_to_csv?`
in `ipython`
"""
return position_to_csv(fname, self.depth, self.northing, self.easting)
return position_to_csv(fname, self.depth, self.northing, self.easting, **kwargs)

def spherical_interpolate(p0, p1, t, omega):
"""
Expand Down
40 changes: 26 additions & 14 deletions wellpathpy/read.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import pandas as pd
import numpy as np

from .checkarrays import checkarrays

def read_csv(fname, md = 'md', inc = 'inc', azi = 'azi', **kwargs):
def read_csv(fname, delimiter=',', skiprows=1, **kwargs):
"""Read a deviation file in CSV format
Read a deviation survey from a CSV file. Columns can be specified with the
md, inc, and azi parameters.
A header row containing the column names `md`, `inc`, `azi` in
that order is generally expected to be included as the first row
in the file. By default, this header is skipped with the `skiprows`
argument set to `1` but this can be changed to `0` if no header is
inclduded.
The data must be ordered as `md`, `inc`, `azi` as the data cannot
be distinguished numerically.
Parameters
----------
fname : str
path to a CSV file with this format:
md : str
measured depth column name
inc : str
inclination column name
azi : str
azimuth column name
```md,inc,azi
0,0,244
10,11,220
50,43,254
150,78.5,254
252.5,90,359.9```
delimiter: str
the character used as a delimiter in the CSV
skiprows : int
number of rows to skip, normally the header row
Other Parameters
----------------
**kwargs : All other keyword arguments are passed to `np.loadtxt`
Returns
-------
Expand All @@ -31,11 +44,10 @@ def read_csv(fname, md = 'md', inc = 'inc', azi = 'azi', **kwargs):
inc : float
well inclination in degrees from vertical
azi : float
well azimuth in degrees from North
well azimuth in degrees from Grid North
"""
df = pd.read_csv(fname, header=0, **kwargs)

md, inc, azi = df[md].values, df[inc].values, df[azi].values
dev = np.loadtxt(fname, delimiter=delimiter, skiprows=skiprows, **kwargs)
md, inc, azi = np.split(dev[:,0:3], 3, 1)
md, inc, azi = checkarrays(md, inc, azi)

return md, inc, azi
34 changes: 16 additions & 18 deletions wellpathpy/test/test_calculations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import pandas as pd
import numpy as np

import hypothesis
Expand All @@ -11,28 +10,27 @@
from ..position_log import deviation, position_log as mc

# import test well data
well9 = pd.read_csv('./wellpathpy/test/fixtures/well9.csv', sep=",")
well10 = pd.read_csv('./wellpathpy/test/fixtures/well10.csv', sep=",")

well9 = np.loadtxt('./wellpathpy/test/fixtures/well9.csv', delimiter=",", skiprows=1)
well10 = np.loadtxt('./wellpathpy/test/fixtures/well10.csv', delimiter=",", skiprows=1)
# get data series
well9_true_md_m = well9['Measured Depth ( ft )'].values * 0.3048 # converting feet to meters
well9_true_inc = well9['Inclination ( deg )'].values
well9_true_azi = well9['Azimuth Grid ( deg )'].values
well9_true_tvd_m = well9['TVD ( ft )'].values * 0.3048 # converting feet to meters
well9_true_northing = well9['Northing ( m )'].values
well9_true_easting = well9['Easting ( m )'].values
well9_true_dls = well9['DLS ( deg/100 ft )'].values
well9_true_md_m = well9[:,0] * 0.3048 # converting feet to meters
well9_true_inc = well9[:,1]
well9_true_azi = well9[:,2]
well9_true_tvd_m = well9[:,3] * 0.3048 # converting feet to meters
well9_true_northing = well9[:,5]
well9_true_easting = well9[:,6]
well9_true_dls = well9[:,4]
well9_true_surface_northing = 39998.454
well9_true_surface_easting = 655701.278
well9_true_datum_elevation = 100 * 0.3048 # converting feet to meters

well10_true_md_m = well10['Measured Depth ( ft )'].values * 0.3048 # converting feet to meters
well10_true_inc = well10['Inclination ( deg )'].values
well10_true_azi = well10['Azimuth Grid ( deg )'].values
well10_true_tvd_m = well10['TVD ( ft )'].values * 0.3048 # converting feet to meters
well10_true_northing = well10['Northing ( m )'].values
well10_true_easting = well10['Easting ( m )'].values
well10_true_dls = well10['DLS ( deg/100 ft )'].values
well10_true_md_m = well10[:,0] * 0.3048 # converting feet to meters
well10_true_inc = well10[:,1]
well10_true_azi = well10[:,2]
well10_true_tvd_m = well10[:,3] * 0.3048 # converting feet to meters
well10_true_northing = well10[:,5]
well10_true_easting = well10[:,6]
well10_true_dls = well10[:,4]
well10_true_surface_northing = 40004.564
well10_true_surface_easting = 655701.377
well10_true_datum_elevation = 100 * 0.3048 # converting feet to meters
Expand Down
31 changes: 16 additions & 15 deletions wellpathpy/test/test_location.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import pytest
import numpy as np
import pandas as pd

from ..mincurve import minimum_curvature
from ..location import loc_to_wellhead, loc_to_zero, loc_to_tvdss

# import test well data
well9 = pd.read_csv('./wellpathpy/test/fixtures/well9.csv', sep=",")
well10 = pd.read_csv('./wellpathpy/test/fixtures/well10.csv', sep=",")
well9 = np.loadtxt('./wellpathpy/test/fixtures/well9.csv', delimiter=",", skiprows=1)
well10 = np.loadtxt('./wellpathpy/test/fixtures/well10.csv', delimiter=",", skiprows=1)

# get data series
well9_true_md_m = well9['Measured Depth ( ft )'].values * 0.3048 # converting feet to meters
well9_true_inc = well9['Inclination ( deg )'].values
well9_true_azi = well9['Azimuth Grid ( deg )'].values
well9_true_tvd_m = well9['TVD ( ft )'].values * 0.3048 # converting feet to meters
well9_true_northing = well9['Northing ( m )'].values
well9_true_easting = well9['Easting ( m )'].values
well9_true_md_m = well9[:,0] * 0.3048 # converting feet to meters
well9_true_inc = well9[:,1]
well9_true_azi = well9[:,2]
well9_true_tvd_m = well9[:,3] * 0.3048 # converting feet to meters
well9_true_northing = well9[:,5]
well9_true_easting = well9[:,6]
well9_true_dls = well9[:,4]
well9_true_surface_northing = 39998.454
well9_true_surface_easting = 655701.278
well9_true_datum_elevation = 100 * 0.3048 # converting feet to meters

well10_true_md_m = well10['Measured Depth ( ft )'].values * 0.3048 # converting feet to meters
well10_true_inc = well10['Inclination ( deg )'].values
well10_true_azi = well10['Azimuth Grid ( deg )'].values
well10_true_tvd_m = well10['TVD ( ft )'].values * 0.3048 # converting feet to meters
well10_true_northing = well10['Northing ( m )'].values
well10_true_easting = well10['Easting ( m )'].values
well10_true_md_m = well10[:,0] * 0.3048 # converting feet to meters
well10_true_inc = well10[:,1]
well10_true_azi = well10[:,2]
well10_true_tvd_m = well10[:,3] * 0.3048 # converting feet to meters
well10_true_northing = well10[:,5]
well10_true_easting = well10[:,6]
well10_true_dls = well10[:,4]
well10_true_surface_northing = 40004.564
well10_true_surface_easting = 655701.377
well10_true_datum_elevation = 100 * 0.3048 # converting feet to meters
Expand Down
Loading

0 comments on commit bec5f3a

Please sign in to comment.