TrajectoryInput¶
- class geodetic_engine.welltrajectory.TrajectoryInput[source]¶
Bases:
objectEverything a well trajectory is computed from.
Four settings are required: the
survey, thewellhead, thecrsand thenorth_reference. The others have defaults. Build an input with the constructor for the form the survey is in:from_arrays(): one array or list per quantity.from_records(): one row per station, as tuples, lists or mappings.from_dataframe(): a pandas DataFrame, with any column names.from_csv(): a CSV survey file, its settings in a header and its columns under any names.from_osdu_payload(): an OSDUconvertTrajectoryrequest body.
or directly, from a
Surveyand aWellhead. Thencompute()gives theWellTrajectory.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 byfrom_osdu_payload()to check a body’sunitXY. 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:
xandyin the CRS, andz, its elevation, inz_unit.
- crs¶
The trajectory CRS: anything
from_user_input()accepts, such as"EPSG:23031", WKT, an OSDUpersistableReferenceor 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,ENUorLMP.
- z_unit¶
Unit of the wellhead elevation and of every depth, elevation and offset reported.
- md_step¶
Also a point every
md_stepof 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 fromnorth_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 aWellhead.north_reference (
NorthReference|str) –"GN"or"TN".options (
Unpack[TrajectoryOptions]) – The optional settings; seeTrajectoryOptions.
- Raises:
InvalidInputError – If 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:
>>> 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:
records (
Iterable[Sequence[float] |Mapping[str,Any]]) – The stations, each(md, inclination, azimuth), or(md, inclination)for an inclination-only survey, or a mapping with the keys"md","inclination"and"azimuth". Every row has the same form.wellhead (
Wellhead|Sequence[float]) –(x, y)or(x, y, z)in the CRS, or aWellhead.north_reference (
NorthReference|str) –"GN"or"TN".options (
Unpack[TrajectoryOptions]) – The optional settings; seeTrajectoryOptions.
- 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:
>>> 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 aWellhead.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; seeTrajectoryOptions.
- Raises:
InvalidInputError – If a column is missing, 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:
>>> 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: valuestates 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 Xiswellhead_x, and a trailingsis dropped.crs, required: the trajectory CRS, as forcrs, on one line. Alsocoordinate_system.The wellhead, required, in the CRS’s own units, either on one line,
wellhead: x, yorwellhead: x, y, z(alsoorigin), or one value a line:wellhead_x(alsox,easting,origin_x),wellhead_y(alsoy,northing,origin_y) andwellhead_z(alsoz,elevation,kb,rkb), the elevation inz_unit, 0 if left out.north_reference, required:GNorTN, orgridortrue north. Alsonorthandazimuth_reference.md_unit,angle_unit,z_unit,method,md_stepandname: the optional settings ofTrajectoryOptions, with the same defaults. Alsodepth_unitformd_unitandwellorwell_nameforname.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, asmd_untiis: that is refused.Other lines above the table are free text, and skipped, except a line
key: valuegiving the name or the north reference, such asNorth 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;delimiternames another. The measured depth, inclination and azimuth columns are found by their usual names, in any case:MD,Measured DepthorDepth;Inclination,IncorIncl;Azimuth,Azior any name startingAz.md_column,inclination_columnandazimuth_columnname 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)orInc [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 inm 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, replacingcrs.north_reference (
NorthReference|str|None, default:None) –"GN"or"TN", replacingnorth_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; seeTrajectoryOptions.
- 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:
- classmethod from_osdu_payload(payload)[source]¶
An input from an OSDU
convertTrajectoryrequest body.The body’s fields map onto the input one for one:
inputStationsonto the survey, withinputKind"MD_Incl"for an inclination-only one, whose stations give no azimuth;referencePointonto the wellhead,trajectoryCRSonto the CRS andazimuthReferenceonto the north reference, also read as"GRID_NORTH"or"TRUE_NORTH";unitMDonto the MD unit,unitZif it is left out, andunitZontoz_unit; angles are in degrees;methodontomethod, where"GNL"isGridNorthLocaland"LeesModifiedProposal"isLMP;interpolateontomd_step: true, also when it is left out, as the service takes it, asks for a point every 100 of the MD unit;MD_iontomd_points:md_ias listed, or a point everymd_intervalfrom the first station, and the last, as the service expands it.
unitXYis 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 incompute().The service returned the points
MD_iasked for apart from the stations, asstations_i. Here they are among the stations, in MD order, withWellTrajectory.is_survey_stationFalse.- 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,
inputKindis not"MD_Incl_Azim"or"MD_Incl", an"MD_Incl"station gives an azimuth,interpolateis not a boolean,methodnames no known method,MD_igives bothmd_iandmd_interval, ormd_intervalis 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
unitXYis 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:
- compute()[source]¶
The trajectory: positions, angles and dogleg severity at every point.
- Raises:
UnresolvableCRSError – If the CRS cannot be resolved.
geodetic_engine.geodesy.UnsupportedCRSError – If the CRS has no geographic or projected horizontal part, grid azimuths are given in a geographic CRS or in one whose projection does not preserve angles at the wellhead, or
GridNorthLocalis asked for there.DegenerateSurveyError – If two consecutive stations point in opposite directions.
- Return type:
- 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)¶