Building the input¶
TrajectoryInput holds everything a
trajectory is computed from: the survey, the wellhead, the CRS, what the
azimuths are measured from, and the optional settings.
compute() turns it into
a WellTrajectory. Build one from the
form your survey is in; each form has its own constructor:
Constructor |
The survey as |
|---|---|
One array or list per quantity: numpy arrays, lists, tuples or pandas Series. |
|
One row per station: tuples, lists, or mappings with the keys |
|
A pandas DataFrame, with any column names. |
|
A CSV survey file: settings in a header, then a table with any column names; see the format. |
|
An OSDU |
What an input holds¶
Four settings are required. The others have defaults.
Setting |
Required |
Default |
Meaning |
|---|---|---|---|
|
yes |
The stations: measured depth, inclination and azimuth, with their units. A |
|
|
yes |
The position of the first station, which TVD and the offsets count from: |
|
|
yes |
The trajectory CRS: an EPSG code, WKT, PROJJSON, an OSDU |
|
|
yes |
What the azimuths are measured from: |
|
|
|
Unit of the measured depths. |
|
|
|
Unit of the inclinations and azimuths. |
|
|
|
How the offsets are georeferenced in the CRS; see Georeferencing methods. |
|
|
|
Unit of the wellhead elevation and of every depth, elevation and offset reported. |
|
|
None |
Also a point every |
|
|
none |
Also a point at each of these measured depths, in |
|
|
None |
The well’s name, carried to the trajectory and used as its label in plots. |
Every constructor takes wellhead, crs and north_reference as keyword
arguments, and the optional settings as further keyword arguments, listed in
TrajectoryOptions. Units are given as
Surveys and units describes: symbols, OSDU unit ids or OSDU unit
persistableReferences.
From arrays¶
import numpy as np
from geodetic_engine.welltrajectory import TrajectoryInput
well = TrajectoryInput.from_arrays(
md=np.array([0.0, 500.0, 1500.0, 2500.0]),
inclination=np.array([0.0, 20.0, 60.0, 70.0]),
azimuth=np.array([10.0, 30.0, 45.0, 50.0]),
wellhead=(500000.0, 6600000.0, 25.0),
crs="EPSG:32631",
north_reference="GN",
name="Well A",
)
well.compute().to_dataframe()
| md | inclination | azimuth_true | azimuth_grid | east | north | tvd | x | y | z | dls | is_survey_station | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 10 | 10 | 0 | 0 | 0 | 500000 | 6600000 | 25 | 0 | True |
| 1 | 500 | 20 | 30 | 30 | 43.191979 | 74.810702 | 489.907768 | 500043.174702 | 6600074.780777 | -464.907768 | 1.2 | True |
| 2 | 1500 | 60 | 45 | 45 | 452.401845 | 549.414152 | 1241.949611 | 500452.220884 | 6600549.194387 | -1216.949611 | 1.226742 | True |
| 3 | 2500 | 70 | 50 | 50 | 1120.555349 | 1159.47817 | 1664.251663 | 501120.107127 | 6601159.014391 | -1639.251663 | 0.329244 | True |
Lists work as well as numpy arrays. Leave azimuth out for an
inclination-only survey, which is then taken to head north throughout.
From rows¶
One row per station, as a tuple or list, (md, inclination, azimuth):
rows = [(0, 0, 10), (500, 20, 30), (1500, 60, 45), (2500, 70, 50)]
by_rows = TrajectoryInput.from_records(
rows, wellhead=(500000.0, 6600000.0, 25.0), crs="EPSG:32631", north_reference="GN"
)
by_rows.survey.md, by_rows.survey.azimuth
(array([ 0., 500., 1500., 2500.]), array([10., 30., 45., 50.]))
or as a mapping, which is how JSON usually holds stations:
stations = [
{"md": 0, "inclination": 0, "azimuth": 10},
{"md": 500, "inclination": 20, "azimuth": 30},
{"md": 1500, "inclination": 60, "azimuth": 45},
]
TrajectoryInput.from_records(
stations, wellhead=(500000.0, 6600000.0), crs="EPSG:32631", north_reference="GN"
).survey.inclination
array([ 0., 20., 60.])
Rows of two values, (md, inclination), are an inclination-only survey. Every
row must have the same form.
From a DataFrame¶
Name the columns to read. Other columns are ignored, so a table exported with TVD, offsets or tool readings can be passed as it is:
import pandas as pd
exported = pd.DataFrame(
{
"MD": [0.0, 500.0, 1500.0, 2500.0],
"INC": [0.0, 20.0, 60.0, 70.0],
"AZI": [10.0, 30.0, 45.0, 50.0],
"TVD": [0.0, 489.9, 1241.9, 1664.3],
}
)
from_table = TrajectoryInput.from_dataframe(
exported,
md_column="MD",
inclination_column="INC",
azimuth_column="AZI",
wellhead=(500000.0, 6600000.0, 25.0),
crs="EPSG:32631",
north_reference="GN",
)
from_table.to_dataframe()
| md | inclination | azimuth | |
|---|---|---|---|
| 0 | 0 | 0 | 10 |
| 1 | 500 | 20 | 30 |
| 2 | 1500 | 60 | 45 |
| 3 | 2500 | 70 | 50 |
azimuth_column=None reads an inclination-only survey. A column that is not
there is named, with the columns that are:
TrajectoryInput.from_dataframe(
exported, wellhead=(500000.0, 6600000.0), crs="EPSG:32631", north_reference="GN"
)
InvalidInputError: the DataFrame has no column 'md', 'inclination', 'azimuth'; its columns are ['MD', 'INC', 'AZI', 'TVD']. Name the ones to read with md_column, inclination_column and azimuth_column
From a survey file¶
A survey file holds a whole input: the settings in a header, then the
stations in a table. The package ships a synthetic one in its
example_data folder:
from importlib.resources import files
EXAMPLE = files("geodetic_engine.welltrajectory") / "example_data" / "synthetic_well.csv"
print(*EXAMPLE.read_text(encoding="utf-8").splitlines()[:17], "...", sep="\n")
# Synthetic survey for the geodetic-engine examples. Not a real well.
# Read it with TrajectoryInput.from_csv, which documents the format.
# name: Synthetic-1
# crs: EPSG:23031
# wellhead_x: 455000.0
# wellhead_y: 6785000.0
# wellhead_z: 32.0
# north_reference: GN
# md_unit: m
# angle_unit: degree
# z_unit: m
# method: AzimuthalEquidistant
md,inclination,azimuth
0.0,0.0,0.0
30.0,0.31,210.01
60.0,0.3,206.73
90.0,0.33,201.27
...
synthetic = TrajectoryInput.from_csv(EXAMPLE)
print(synthetic.name, "|", synthetic.crs, "|", synthetic.wellhead, "|", synthetic.north_reference)
trajectory = synthetic.compute()
print(f"{len(trajectory)} stations to TD at MD {trajectory.md[-1]:g} m, TVD {trajectory.tvd[-1]:.1f} m")
Synthetic-1 | EPSG:23031 | Wellhead(x=455000.0, y=6785000.0, z=32.0) | GN
122 stations to TD at MD 3612 m, TVD 2780.1 m
The survey file format¶
The file is UTF-8 text. A byte order mark, as spreadsheet programs write, is skipped, and text that is not UTF-8 is read as Latin-1, as older software writes it.
Header. Lines starting with #, above the table. A line # key: value
states one 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, or none: Wellhead X, wellhead-x and WellheadX are all
wellhead_x. A trailing s is dropped, so Depth units is depth_unit.
Each setting is given at most once, under whichever name.
Key |
Also |
Required |
Value |
|---|---|---|---|
|
|
yes |
The trajectory CRS, on one line: |
|
|
yes, or |
The wellhead on one line: |
|
|
yes, or |
The wellhead in the CRS, in its own units: easting and northing, or longitude and latitude. |
|
|
no, 0 |
The wellhead’s elevation, in |
|
|
yes |
|
|
|
no, |
Unit of the measured depths. |
|
|
no, |
Unit of the inclinations and azimuths. |
|
|
no, |
Unit of the wellhead elevation and of every depth and elevation reported. |
|
no, |
|
|
|
|
no |
Also a point every this much MD. |
|
no |
Also a point at each of these measured depths, separated by commas. |
|
|
|
no |
The well’s name. |
Any other line starting with # is a comment, # Created by: Petrel
included. A key within a letter or two of a known one, such as md_unti, is
refused as a likely misspelling rather than skipped; so is Units, which
could be either unit.
Free text. Other lines above the table are free text, as a survey
report’s header is, and skipped, except a line key: value that gives the
name or the north reference under one of their keys above, such as
WELL NAME: F-1 or North Reference: Grid. The first of each states that
setting, unless a # line states it, and only if its value reads as the
setting: North: 6478566.7 is skipped. Nothing else is read from free text,
which may give the positions and elevations of more than the wellhead; give
those in # lines or as arguments. A line of free text is never refused.
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, where two or more spaces end a name, so
UTM E/W is one; delimiter= names another.
The three the survey needs are found by their names, in any case and with
any punctuation, or named with an argument:
Column |
Found by the names |
Or named with |
|---|---|---|
Measured depth |
|
|
Inclination |
|
|
Azimuth |
|
|
A table without an azimuth column is an inclination-only survey. Other
columns, such as TVD, coordinates or remarks, are ignored. Two columns that
could both be one quantity, such as AZIM_GN and AZIM_TN, are refused:
name the one to read.
A unit in brackets after a column’s name, as in MD (ft) or Inc [deg], is
that column’s unit. So is one in a line of units right below the names, a
line holding no number, as in m RKB deg deg; a word after the unit, such
as the datum RKB, is ignored. A unit given both ways must agree, and so must
one given as an argument or in the header: a column’s own unit is never
overridden. Annotated units must be recognized and measure the correct
quantity. An unsupported annotation never becomes a default.
Every further line is one station: plain numbers, with . as the decimal
point and no thousands separator. Blank lines are skipped; header and comment
lines may not appear inside the table.
A file from other software¶
A file exported by another program is read as it is, when its names are among those above:
import io
exported = io.StringIO(
"# Exported by: SurveyTool 4.2\n"
"# Well name: A-10\n"
"# Coordinate system: EPSG:32631\n"
"# Origin: 500000; 6600000; 25\n"
"# Azimuth reference: Grid north\n"
"Measured Depth (ft);INCL;AZIM_GN;TVD (ft);Remark\n"
"0;0;10;0;tie-in\n"
"1500;20;30;1469.6;\n"
"4500;60;45;3664.1;TD\n"
)
other = TrajectoryInput.from_csv(exported)
print(other.name, "|", other.wellhead, "|", other.north_reference, "|", other.survey.md_unit)
other.to_dataframe()
A-10 | Wellhead(x=500000.0, y=6600000.0, z=25.0) | GN | ft
| md | inclination | azimuth | |
|---|---|---|---|
| 0 | 0 | 0 | 10 |
| 1 | 1500 | 20 | 30 |
| 2 | 4500 | 60 | 45 |
Columns under other names are named with md_column, inclination_column
and azimuth_column, with or without the unit in brackets:
plan = io.StringIO("DEPTH_M,I,A,X,Y\n0,0,10,500000,6600000\n500,20,30,500043,6600074\n")
TrajectoryInput.from_csv(
plan,
md_column="DEPTH_M",
inclination_column="I",
azimuth_column="A",
wellhead=(500000.0, 6600000.0),
crs="EPSG:32631",
north_reference="GN",
).to_dataframe()
| md | inclination | azimuth | |
|---|---|---|---|
| 0 | 0 | 0 | 10 |
| 1 | 500 | 20 | 30 |
A survey report¶
A survey report, as a well database exports it, is read as it is too. The package ships the report of Volve F-1, a real well, from the Volve field data set. Below its free text, the columns are lined up with spaces, with their units underneath:
REPORT = files("geodetic_engine.welltrajectory") / "example_data" / "volve_f1_survey.txt"
print(*REPORT.read_text(encoding="latin-1").splitlines()[37:48], "...", sep="\n")
Map-Zone: Zone 31N (0 E to 6 E)
North Reference: Grid
Geo Datum: European 1950 - Mean
Vertical Section Direction: 302.24deg
----------------------------------------------------------------
SURVEY LIST
MD Inc Azim TVD X-Offset (E/W) Y-Offset (N/S) UTM E/W UTM N/S DLS
m RKB deg deg m RKB m m m m deg/30m
145.90 0.00 0.00 145.90 -3.534 3.165 435046.488 6478566.687 0.00
150.15 0.00 0.00 150.15 -3.534 3.165 435046.488 6478566.687 0.00
160.45 0.00 0.00 160.45 -3.534 3.165 435046.488 6478566.687 0.00
...
The free text gives the name and the north reference, and the line of units the units. The report names its CRS only in words, ED50 and UTM zone 31N, and its survey starts at the wellhead on the seabed, 91 m below sea level, so those two are passed:
volve = TrajectoryInput.from_csv(
REPORT, wellhead=(435046.488, 6478566.687, -91.0), crs="EPSG:23031"
)
print(volve.name, "|", volve.north_reference, "|", volve.survey.md_unit, "|", len(volve.survey.md), "stations")
F-1 | GN | m | 100 stations
Arguments fill in and take precedence¶
Keyword arguments fill in what the header leaves out, so a bare table works:
bare = io.StringIO("md,inclination,azimuth\n0,0,10\n500,20,30\n1500,60,45\n")
TrajectoryInput.from_csv(
bare, wellhead=(500000.0, 6600000.0), crs="EPSG:32631", north_reference="GN"
).to_dataframe()
| md | inclination | azimuth | |
|---|---|---|---|
| 0 | 0 | 0 | 10 |
| 1 | 500 | 20 | 30 |
| 2 | 1500 | 60 | 45 |
and they take precedence over what the header states, so one file can be computed with other settings:
lmp = TrajectoryInput.from_csv(EXAMPLE, method="LMP", z_unit="ft")
lmp.method, lmp.z_unit, lmp.wellhead
(<Method.LMP: 'LMP'>, 'ft', Wellhead(x=455000.0, y=6785000.0, z=32.0))
wellhead= replaces the header’s wellhead, however it is stated.
Files out of format¶
A key that looks misspelt is refused, with the line at fault:
TrajectoryInput.from_csv(
io.StringIO(
"# crs: EPSG:32631\n# wellhead: 500000, 6600000\n"
"# north_refrence: GN\nmd,inclination,azimuth\n0,0,0\n500,20,30\n"
)
)
InvalidInputError: the survey file, line 3: 'north_refrence' is not a header key; did you mean north_reference?
and so is a table in which two columns could be the azimuths:
TrajectoryInput.from_csv(
io.StringIO("MD,INCL,AZIM_GN,AZIM_TN\n0,0,0,0\n500,20,30,29.2\n"),
wellhead=(500000.0, 6600000.0),
crs="EPSG:32631",
north_reference="GN",
)
InvalidInputError: the survey file, line 1: 'AZIM_GN', 'AZIM_TN' could each be the azimuth column; name the one to read with azimuth_column
and so is one that leaves out a required setting, which the arguments do not give either:
TrajectoryInput.from_csv(io.StringIO("md,inclination\n0,0\n500,5\n"), crs="EPSG:32631")
InvalidInputError: the survey file states no wellhead, north_reference: add each to the header, as in '# crs: EPSG:23031' or '# wellhead: 455000, 6785000, 32', or pass it as an argument
From an OSDU request body¶
from_osdu_payload() reads
the body of an OSDU convertTrajectory request, as a mapping or as JSON text.
Its fields map onto the input one for one:
Body field |
Input setting |
|---|---|
|
|
|
|
|
|
|
|
|
An inclination-only survey, whose stations give no azimuth. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Checked to be the CRS’s own unit, which resolves the CRS when the input is made, and not stored: the wellhead is never rescaled. |
body = {
"trajectoryCRS": "EPSG:32631",
"azimuthReference": "GN",
"unitZ": "ft",
"unitMD": "m",
"referencePoint": {"x": 500000.0, "y": 6600000.0, "z": 82.0},
"inputStations": [
{"md": 0, "inclination": 0, "azimuth": 10},
{"md": 500, "inclination": 20, "azimuth": 30},
{"md": 1500, "inclination": 60, "azimuth": 45},
],
"method": "GNL",
"interpolate": False,
"MD_i": {"md_i": [1000.0]},
}
from_body = TrajectoryInput.from_osdu_payload(body)
print(from_body.method, from_body.survey.md_unit, from_body.z_unit, from_body.md_points)
from_body.compute().to_dataframe()[["md", "tvd", "z", "is_survey_station"]]
GridNorthLocal m ft [1000.]
| md | tvd | z | is_survey_station | |
|---|---|---|---|---|
| 0 | 0 | 0 | 82 | True |
| 1 | 500 | 1607.30895 | -1525.30895 | True |
| 2 | 1000 | 3023.231681 | -2941.231681 | False |
| 3 | 1500 | 4074.637832 | -3992.637832 | True |
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
is_survey_station False.
Checked when it is made¶
Everything that can be checked without the CRS is checked when the input is
made, before anything is computed: 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.
TrajectoryInput.from_arrays(
[0, 500, 400], [0, 10, 20], [0, 0, 0],
wellhead=(500000.0, 6600000.0), crs="EPSG:32631", north_reference="GN",
)
InvalidSurveyError: MD must strictly increase; it does not at 400
TrajectoryInput.from_arrays(
[0, 500, 1500], [0, 10, 20], [0, 0, 0],
wellhead=(500000.0, 6600000.0), crs="EPSG:32631", north_reference="magnetic",
)
InvalidInputError: north_reference must be one of GN, TN, not 'magnetic'
A missing setting raises
InvalidInputError, a survey that
cannot describe a wellbore
InvalidSurveyError, and a unit that
is not recognised UnitError.
Changing a setting¶
An input is frozen. dataclasses.replace() gives a copy with some
settings changed, and checks it again:
import dataclasses
every_100 = dataclasses.replace(synthetic, md_step=100, method="ENU")
every_100.method, every_100.md_step, len(every_100.compute())
(<Method.ENU: 'ENU'>, 100.0, 146)
That is also how one survey is compared across methods, CRSs or north references; Georeferencing methods does so.
Writing a survey file¶
to_csv() writes an input
in the survey file format: to a file when given a path, or else as text.
Every setting goes in the header, defaults included, so the file states
everything the trajectory is computed with, and
from_csv() reads it back
exactly:
text = every_100.to_csv()
print(*text.splitlines()[:15], "...", sep="\n")
again = TrajectoryInput.from_csv(io.StringIO(text))
print("\nthe same input:", again.md_step == every_100.md_step and np.array_equal(again.survey.md, every_100.survey.md))
# name: Synthetic-1
# crs: EPSG:23031
# wellhead_x: 455000.0
# wellhead_y: 6785000.0
# wellhead_z: 32.0
# north_reference: GN
# md_unit: m
# angle_unit: degree
# z_unit: m
# method: ENU
# md_step: 100.0
md,inclination,azimuth
0.0,0.0,0.0
30.0,0.31,210.01
60.0,0.3,206.73
...
the same input: True
A CRS given as something other than one line of text, such as a
pyproj.CRS or a bound CRS, is written as WKT.
to_dataframe() gives the
stations as a table, in the units they are stated in.