TrajectoryInput

class geodetic_engine.welltrajectory.TrajectoryInput[source]

Bases: object

Everything a well trajectory is computed from.

Four settings are required: the survey, the wellhead, the crs and the north_reference. The others have defaults. Build an input with the constructor for the form the survey is in:

or directly, from a Survey and a Wellhead. Then compute() gives the WellTrajectory.

Everything that can be checked without the CRS is checked when the input is made: the units, the settings, and that the survey describes a wellbore. The CRS is resolved by compute(), or already by from_osdu_payload() to check a body’s unitXY. An input is frozen; dataclasses.replace() gives a copy with some settings changed, and checks it again.

survey

The stations: measured depth, inclination and azimuth, with the units they are stated in.

wellhead

The position of the first station, which TVD and the offsets count from: x and y in the CRS, and z, its elevation, in z_unit.

crs

The trajectory CRS: anything from_user_input() accepts, such as "EPSG:23031", WKT, an OSDU persistableReference or a bound CRS.

north_reference

What the azimuths are measured from: grid north, "GN", or true north, "TN".

method

How the offsets are georeferenced in the CRS, a Method: AZIMUTHAL_EQUIDISTANT, the default, GRID_NORTH_LOCAL, ENU or LMP.

z_unit

Unit of the wellhead elevation and of every depth, elevation and offset reported.

md_step

Also a point every md_step of MD between the stations, in the survey’s MD unit; None for none.

md_points

Also a point at each of these measured depths, in the survey’s MD unit; empty for none.

name

The well’s name, carried to the trajectory and its plots.

Example

>>> well = TrajectoryInput.from_arrays(
...     md=[0, 1000, 2000],
...     inclination=[0, 30, 60],
...     azimuth=[45, 45, 45],
...     wellhead=(500000.0, 6600000.0, 25.0),
...     crs="EPSG:32631",
...     north_reference="GN",
... )
>>> well.compute().tvd.round(1).tolist()
[0.0, 954.9, 1654.0]
classmethod from_arrays(md, inclination, azimuth=None, *, wellhead, crs, north_reference, **options)[source]

An input from one array per quantity.

Numpy arrays, lists, tuples and pandas Series all work.

Parameters:
  • md (ArrayLike) – Measured depth of each station.

  • inclination (ArrayLike) – Inclination of each station, from vertical.

  • azimuth (ArrayLike | None, default: None) – Azimuth of each station, clockwise from north_reference; None for an inclination-only survey, which is then taken to head north throughout.

  • wellhead (Wellhead | Sequence[float]) – (x, y) or (x, y, z) in the CRS, or a Wellhead.

  • crs (Any) – The trajectory CRS; see crs.

  • north_reference (NorthReference | str) – "GN" or "TN".

  • options (Unpack[TrajectoryOptions]) – The optional settings; see TrajectoryOptions.

Raises:

Example

Return type:

TrajectoryInput

>>> well = TrajectoryInput.from_arrays(
...     np.array([0.0, 500.0, 1500.0]),
...     np.array([0.0, 20.0, 60.0]),
...     np.array([0.0, 30.0, 45.0]),
...     wellhead=(500000.0, 6600000.0),
...     crs="EPSG:32631",
...     north_reference="TN",
...     md_unit="ft",
... )
>>> well.survey.md_metres.round(3).tolist()
[0.0, 152.4, 457.2]
classmethod from_records(records, *, wellhead, crs, north_reference, **options)[source]

An input from one row per station.

Parameters:
Raises:
  • InvalidInputError – If the rows differ in form, a mapping lacks a key, or a setting is missing or has a value it cannot take.

  • InvalidSurveyError – If the stations cannot describe a wellbore.

  • UnitError – If a unit is not recognised.

Example

Return type:

TrajectoryInput

>>> well = TrajectoryInput.from_records(
...     [(0, 0, 0), (500, 20, 30), (1500, 60, 45)],
...     wellhead=(500000.0, 6600000.0),
...     crs="EPSG:32631",
...     north_reference="GN",
... )
>>> well.survey.inclination.tolist()
[0.0, 20.0, 60.0]
classmethod from_dataframe(frame, *, wellhead, crs, north_reference, md_column='md', inclination_column='inclination', azimuth_column='azimuth', **options)[source]

An input from a pandas DataFrame, one row per station.

Other columns are ignored, so a table exported with TVD, offsets or tool readings can be passed as it is.

Parameters:
  • frame (DataFrame) – The stations.

  • wellhead (Wellhead | Sequence[float]) – (x, y) or (x, y, z) in the CRS, or a Wellhead.

  • crs (Any) – The trajectory CRS; see crs.

  • north_reference (NorthReference | str) – "GN" or "TN".

  • md_column (str, default: "md") – The column holding measured depths.

  • inclination_column (str, default: "inclination") – The column holding inclinations.

  • azimuth_column (str | None, default: "azimuth") – The column holding azimuths; None for an inclination-only survey.

  • options (Unpack[TrajectoryOptions]) – The optional settings; see TrajectoryOptions.

Raises:

Example

Return type:

TrajectoryInput

>>> import pandas as pd
>>> table = pd.DataFrame(
...     {"MD": [0, 500, 1500], "INC": [0, 20, 60], "AZI": [0, 30, 45]}
... )
>>> well = TrajectoryInput.from_dataframe(
...     table,
...     md_column="MD",
...     inclination_column="INC",
...     azimuth_column="AZI",
...     wellhead=(500000.0, 6600000.0),
...     crs="EPSG:32631",
...     north_reference="GN",
... )
>>> well.survey.azimuth.tolist()
[0.0, 30.0, 45.0]
classmethod from_csv(source, *, wellhead=None, crs=None, north_reference=None, md_column=None, inclination_column=None, azimuth_column=None, delimiter=None, **options)[source]

An input from a survey file: settings in a header, then a table.

A CSV file reads, for instance:

# A synthetic well, not a real one. This line is a comment.
# name: Synthetic-1
# crs: EPSG:23031
# wellhead: 455000.0, 6785000.0, 32.0
# north_reference: GN
MD (m),Inclination,Azimuth,TVD
0.0,0.0,0.0,0.0
30.0,0.31,210.01,30.0
...

and a survey report, as older software writes, is read as it is:

WELL NAME: F-1
North Reference: Grid
SURVEY LIST
MD        Inc       Azim      TVD       UTM E/W
m RKB     deg       deg       m RKB     m
145.90    0.00      0.00      145.90    435046.488
...

The text is UTF-8, or else read as Latin-1.

Header. Above the table, lines starting with #. A line # key: value states a setting, and the value runs to the end of the line, colons and all. Keys are read in any case, with spaces, hyphens or underscores between their words: Wellhead X is wellhead_x, and a trailing s is dropped.

  • crs, required: the trajectory CRS, as for crs, on one line. Also coordinate_system.

  • The wellhead, required, in the CRS’s own units, either on one line, wellhead: x, y or wellhead: x, y, z (also origin), or one value a line: wellhead_x (also x, easting, origin_x), wellhead_y (also y, northing, origin_y) and wellhead_z (also z, elevation, kb, rkb), the elevation in z_unit, 0 if left out.

  • north_reference, required: GN or TN, or grid or true north. Also north and azimuth_reference.

  • md_unit, angle_unit, z_unit, method, md_step and name: the optional settings of TrajectoryOptions, with the same defaults. Also depth_unit for md_unit and well or well_name for name.

  • md_points: depths separated by commas.

Any other line starting with # is a comment, such as # Created by: Petrel, unless its key is so close to a known one that it is likely misspelt, as md_unti is: that is refused.

Other lines above the table are free text, and skipped, except a line key: value giving the name or the north reference, such as North Reference: Grid, when its value reads as that setting: the first of each states it, unless a # line does. Nothing else is read from free text, which may give positions and elevations of more than the wellhead.

Table. It starts at the first line naming the measured depth and inclination columns, or else at the first line that is not a header line. The columns are separated by commas, semicolons or tabs, whichever that line uses, or else lined up with spaces, two or more ending a name such as UTM E/W; delimiter names another. The measured depth, inclination and azimuth columns are found by their usual names, in any case: MD, Measured Depth or Depth; Inclination, Inc or Incl; Azimuth, Azi or any name starting Az. md_column, inclination_column and azimuth_column name them instead. A table without an azimuth column is an inclination-only survey. Other columns are ignored.

A unit in brackets after a column’s name, as in MD (ft) or Inc [deg], is its unit, and so is one in a line of units right below the names, which holds no number, and may follow a unit with a word, as in m RKB. Given both ways, the units must agree, and so must one given as an argument or in the header: a column’s own unit is never overridden.

Every further line is one station: plain numbers, with . as the decimal point and no thousands separator. Blank lines are skipped.

The keyword arguments fill in what the header leaves out, and take precedence over what it states, so one file can be computed with other settings. to_csv() writes this format.

Parameters:
  • source (str | PathLike[str] | Traversable | TextIO) – The file: a path, or an open text stream.

  • wellhead (Wellhead | Sequence[float] | None, default: None) – The wellhead, replacing the header’s.

  • crs (Any, default: None) – The trajectory CRS, replacing crs.

  • north_reference (NorthReference | str | None, default: None) – "GN" or "TN", replacing north_reference.

  • md_column (str | None, default: None) – The column holding measured depths, by its name in the file, with or without the unit; found by its usual names if left out.

  • inclination_column (str | None, default: None) – The column holding inclinations, likewise.

  • azimuth_column (str | None, default: None) – The column holding azimuths, likewise.

  • delimiter (str | None, default: None) – The character separating the values, " " for columns lined up with spaces; found from the line naming the columns if left out.

  • options (Unpack[TrajectoryOptions]) – The optional settings, each replacing the header’s; see TrajectoryOptions.

Raises:
  • InvalidInputError – If the file does not follow the format, a column cannot be found or is found twice, or a required setting is in neither the header nor the arguments. The message names the line at fault.

  • InvalidSurveyError – If the stations cannot describe a wellbore.

  • UnitError – If a unit is not recognised, a line of units included.

  • OSError – If the file cannot be read.

Return type:

TrajectoryInput

classmethod from_osdu_payload(payload)[source]

An input from an OSDU convertTrajectory request body.

The body’s fields map onto the input one for one:

  • inputStations onto the survey, with inputKind "MD_Incl" for an inclination-only one, whose stations give no azimuth;

  • referencePoint onto the wellhead, trajectoryCRS onto the CRS and azimuthReference onto the north reference, also read as "GRID_NORTH" or "TRUE_NORTH";

  • unitMD onto the MD unit, unitZ if it is left out, and unitZ onto z_unit; angles are in degrees;

  • method onto method, where "GNL" is GridNorthLocal and "LeesModifiedProposal" is LMP;

  • interpolate onto md_step: true, also when it is left out, as the service takes it, asks for a point every 100 of the MD unit;

  • MD_i onto md_points: md_i as listed, or a point every md_interval from the first station, and the last, as the service expands it.

unitXY is checked against the CRS and not stored: the wellhead is read in the CRS’s own unit, never rescaled. Checking it resolves the CRS here, rather than in compute().

The service returned the points MD_i asked for apart from the stations, as stations_i. Here they are among the stations, in MD order, with WellTrajectory.is_survey_station False.

Parameters:

payload (Mapping[str, Any] | str) – The request body, as a mapping or as JSON text.

Raises:
  • InvalidInputError – If the payload is not a JSON object, a required field is missing or has the wrong shape, inputKind is not "MD_Incl_Azim" or "MD_Incl", an "MD_Incl" station gives an azimuth, interpolate is not a boolean, method names no known method, MD_i gives both md_i and md_interval, or md_interval is not a positive length or gives more than a million points.

  • InvalidSurveyError – If the stations cannot describe a wellbore.

  • UnitError – If a unit is not recognised, or unitXY is not the CRS’s own unit.

  • UnresolvableCRSError – With unitXY, if the CRS cannot be resolved.

  • geodetic_engine.geodesy.UnsupportedCRSError – With unitXY, if the CRS has no geographic or projected horizontal part.

  • TransformationFailedError – With unitXY, if the wellhead is outside the CRS’s range.

Return type:

TrajectoryInput

compute()[source]

The trajectory: positions, angles and dogleg severity at every point.

Raises:
Return type:

WellTrajectory

to_dataframe()[source]

The stations, one row each, in the units they are stated in.

Return type:

DataFrame

to_csv(target=None)[source]

Write the input as a survey file, in the format from_csv() reads.

Overloads:
  • self, target (None) → str

  • self, target (str | os.PathLike[str]) → None

Every setting goes in the header, defaults included, so the file states everything the trajectory is computed with. Numbers are written in full, so from_csv() reads back exactly the same values. A CRS that is not already one line of text is written as WKT.

Parameters:

target (str | PathLike[str] | None, default: None) – The file to write; with None the text is returned instead.

Returns:

The text, if no target was given.

Raises:

InvalidInputError – If the name or a unit runs over more than one line.

__init__(*, survey, wellhead, crs, north_reference, method=Method.AZIMUTHAL_EQUIDISTANT, z_unit='m', md_step=None, md_points=<factory>, name=None)