Skip to content

Commit e4e9cd0

Browse files
Merge branch 'SC-1682' into 'develop'
SC-1682: Fix segments VS calculation See merge request SOLO-band/python-sdk!89
2 parents f4964d3 + 3b27084 commit e4e9cd0

File tree

11 files changed

+199
-156
lines changed

11 files changed

+199
-156
lines changed

src/rogii_solo/calculations/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
DELTA = 0.000001
44

5+
ANGLE_EQUALITY_PRECISION: float = 1e-10 # taken from SS source code
6+
57
ROUNDING_PRECISION = 3

src/rogii_solo/calculations/trajectory.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
)
1010
from rogii_solo.calculations.base import calc_vs as base_calc_vs
1111
from rogii_solo.calculations.base import normalize_angle
12-
from rogii_solo.calculations.constants import DELTA, FEET_TO_METERS
12+
from rogii_solo.calculations.constants import (
13+
ANGLE_EQUALITY_PRECISION,
14+
DELTA,
15+
FEET_TO_METERS,
16+
)
1317
from rogii_solo.calculations.enums import EMeasureUnits
1418
from rogii_solo.calculations.types import RawTrajectory, Trajectory, TrajectoryPoint
1519

@@ -63,12 +67,31 @@ def calculate_trajectory_point(
6367
)
6468

6569
dls = calc_dls(dog_leg, course_length, measure_units=measure_units)
66-
shape = calc_shape(dog_leg, course_length)
6770

68-
tvd = prev_point['tvd'] + shape * (curr_incl_cos + prev_incl_cos)
71+
# extracted from source/geomath/TrajectoryReconstruction.cpp:128
72+
if abs(dog_leg - pi) < ANGLE_EQUALITY_PRECISION: # vectors are opposite
73+
half_pi = pi / 2
74+
k = course_length / half_pi
75+
incl = normalize_angle(prev_point['incl'] + half_pi)
76+
77+
xd = sin(prev_point['azim']) * sin(incl)
78+
yd = cos(prev_point['azim']) * sin(incl)
79+
zd = cos(incl)
80+
81+
tvd = prev_point['tvd'] + k * zd
82+
ew = (prev_point['ew'] or 0) + k * xd
83+
ns = (prev_point['ns'] or 0) + k * yd
84+
else:
85+
shape = calc_shape(dog_leg, course_length)
6986

70-
ns = (prev_point['ns'] or 0) + shape * (prev_incl_sin * cos(prev_point['azim']) + curr_incl_sin * cos(curr_azim))
71-
ew = (prev_point['ew'] or 0) + shape * (prev_incl_sin * sin(prev_point['azim']) + curr_incl_sin * sin(curr_azim))
87+
tvd = prev_point['tvd'] + shape * (curr_incl_cos + prev_incl_cos)
88+
89+
ns = (prev_point['ns'] or 0) + shape * (
90+
prev_incl_sin * cos(prev_point['azim']) + curr_incl_sin * cos(curr_azim)
91+
)
92+
ew = (prev_point['ew'] or 0) + shape * (
93+
prev_incl_sin * sin(prev_point['azim']) + curr_incl_sin * sin(curr_azim)
94+
)
7295

7396
return TrajectoryPoint(
7497
md=curr_point['md'],

src/rogii_solo/comment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def to_dict(self, get_converted: bool = True) -> Dict[str, Any]:
5151
return {
5252
'commentbox_id': self.commentbox_id,
5353
'text': self.text,
54-
'anchor_md': self.safe_round(
55-
self.convert_z(value=self.anchor_md, measure_units=measure_units) if get_converted else self.anchor_md
56-
),
54+
'anchor_md': self.safe_round(self.convert_z(value=self.anchor_md, measure_units=measure_units))
55+
if get_converted
56+
else self.anchor_md,
5757
}
5858

5959
def to_df(self, get_converted: bool = True) -> DataFrame:

src/rogii_solo/earth_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def __init__(self, earth_model: EarthModel, **kwargs):
7272
def to_dict(self, get_converted: bool = True) -> Dict:
7373
return {
7474
'uuid': self.uuid,
75-
'md': self.safe_round(
76-
self.convert_z(self.md, measure_units=self.measure_units) if get_converted else self.md
77-
),
75+
'md': self.safe_round(self.convert_z(self.md, measure_units=self.measure_units))
76+
if get_converted
77+
else self.md,
7878
'interpretation_segment': self.interpretation_segment,
7979
}
8080

@@ -131,9 +131,9 @@ def __init__(self, earth_model_section: EarthModelSection, **kwargs):
131131

132132
def to_dict(self, get_converted: bool = True) -> Dict:
133133
return {
134-
'tvt': self.safe_round(
135-
self.convert_z(self.tvt, measure_units=self.measure_units) if get_converted else self.tvt
136-
),
134+
'tvt': self.safe_round(self.convert_z(self.tvt, measure_units=self.measure_units))
135+
if get_converted
136+
else self.tvt,
137137
'thickness': self.thickness,
138138
'resistivity_horizontal': self.resistivity_horizontal,
139139
'anisotropy': self.anisotropy,

src/rogii_solo/horizon.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ def __init__(self, measure_units: EMeasureUnits, md: float, tvd: float) -> None:
7979

8080
def to_dict(self, get_converted: bool = True) -> Dict:
8181
return {
82-
'md': self.safe_round(
83-
self.convert_z(self.md, measure_units=self.measure_units) if get_converted else self.md
84-
),
85-
'tvd': self.safe_round(
86-
self.convert_z(self.tvd, measure_units=self.measure_units) if get_converted else self.tvd
87-
),
82+
'md': self.safe_round(self.convert_z(self.md, measure_units=self.measure_units))
83+
if get_converted
84+
else self.md,
85+
'tvd': self.safe_round(self.convert_z(self.tvd, measure_units=self.measure_units))
86+
if get_converted
87+
else self.tvd,
8888
}
8989

9090
def to_df(self, get_converted: bool = True) -> DataFrame:

src/rogii_solo/interpretation.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
)
2525
from rogii_solo.types import DataList
2626
from rogii_solo.types import Interpretation as InterpretationType
27-
from rogii_solo.utils.constants import ENDLESS_INTERPRETATION_VERSION
2827

2928
TVT_DATA_MAX_MD_STEP = 100000
3029

@@ -74,23 +73,22 @@ def assembled_segments(self):
7473
interpretation_id=self.uuid
7574
)
7675

77-
if self.format == ENDLESS_INTERPRETATION_VERSION:
78-
try:
79-
well_data = self.well.to_dict(get_converted=False)
80-
calculated_trajectory = calculate_trajectory(
81-
raw_trajectory=self.well.trajectory.to_dict(get_converted=False),
82-
well=well_data,
83-
measure_units=self.well.project.measure_unit,
84-
)
85-
self._assembled_segments_data['segments'] = self._get_fitted_segments(
86-
calculated_trajectory=calculated_trajectory,
87-
well=well_data,
88-
measure_units=self.well.project.measure_unit,
89-
)
90-
except InterpretationOutOfTrajectoryException:
91-
self._assembled_segments_data = None
76+
try:
77+
well_data = self.well.to_dict(get_converted=False)
78+
calculated_trajectory = calculate_trajectory(
79+
raw_trajectory=self.well.trajectory.to_dict(get_converted=False),
80+
well=well_data,
81+
measure_units=self.well.project.measure_unit,
82+
)
83+
self._assembled_segments_data['segments'] = self._get_fitted_segments(
84+
calculated_trajectory=calculated_trajectory,
85+
well=well_data,
86+
measure_units=self.well.project.measure_unit,
87+
)
88+
except InterpretationOutOfTrajectoryException:
89+
self._assembled_segments_data = None
9290

93-
return {'horizons': None, 'segments': None}
91+
return {'horizons': None, 'segments': None}
9492

9593
assembled_horizons_data = self._assembled_segments_data['horizons']
9694
measure_units = self.well.project.measure_unit
@@ -215,6 +213,17 @@ def _get_fitted_segments(
215213
)
216214
)
217215
else:
216+
nearest_left_point, nearest_right_point = get_nearest_values(
217+
value=left_segment['md'], input_list=calculated_trajectory, key=lambda it: it['md']
218+
)
219+
interpolated_point = interpolate_trajectory_point(
220+
left_point=nearest_left_point,
221+
right_point=nearest_right_point,
222+
md=left_segment['md'],
223+
well=well,
224+
measure_units=measure_units,
225+
)
226+
left_segment['vs'] = interpolated_point['vs']
218227
fitted_segments.append(left_segment)
219228

220229
return fitted_segments

src/rogii_solo/log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def __init__(self, measure_units: EMeasureUnits, md: float, value: float):
7575

7676
def to_dict(self, get_converted: bool = True) -> Dict:
7777
return {
78-
'md': self.safe_round(
79-
self.convert_z(value=self.md, measure_units=self.measure_units) if get_converted else self.md
80-
),
78+
'md': self.safe_round(self.convert_z(value=self.md, measure_units=self.measure_units))
79+
if get_converted
80+
else self.md,
8181
'value': self.value,
8282
}
8383

src/rogii_solo/target_line.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,36 @@ def to_dict(self, get_converted: bool = True) -> Dict[str, Any]:
3838
return {
3939
'uuid': self.uuid,
4040
'name': self.name,
41-
'azimuth': self.safe_round(self.azimuth),
42-
'delta_tvd': self.safe_round(self.delta_tvd),
43-
'delta_vs': self.safe_round(self.delta_vs),
44-
'inclination': self.safe_round(self.inclination),
45-
'length': self.safe_round(self.length),
46-
'origin_base_corridor_tvd': self.safe_round(self.origin_base_corridor_tvd),
47-
'origin_md': self.safe_round(self.origin_md),
48-
'origin_top_corridor_tvd': self.safe_round(self.origin_top_corridor_tvd),
49-
'origin_tvd': self.safe_round(self.origin_tvd),
50-
'origin_vs': self.safe_round(self.origin_vs),
51-
'origin_x': self.safe_round(self.origin_x),
52-
'origin_y': self.safe_round(self.origin_y),
53-
'origin_z': self.safe_round(self.origin_z),
54-
'target_base_corridor_tvd': self.safe_round(self.target_base_corridor_tvd),
55-
'target_md': self.safe_round(self.target_md),
56-
'target_top_corridor_tvd': self.safe_round(self.target_top_corridor_tvd),
57-
'target_tvd': self.safe_round(self.target_tvd),
58-
'target_vs': self.safe_round(self.target_vs),
59-
'target_x': self.safe_round(self.target_x),
60-
'target_y': self.safe_round(self.target_y),
61-
'target_z': self.safe_round(self.target_z),
62-
'tvd_vs': self.safe_round(self.tvd_vs),
41+
'azimuth': self.safe_round(self.azimuth) if get_converted else self.azimuth,
42+
'delta_tvd': self.safe_round(self.delta_tvd) if get_converted else self.delta_tvd,
43+
'delta_vs': self.safe_round(self.delta_vs) if get_converted else self.delta_vs,
44+
'inclination': self.safe_round(self.inclination) if get_converted else self.inclination,
45+
'length': self.safe_round(self.length) if get_converted else self.length,
46+
'origin_base_corridor_tvd': self.safe_round(self.origin_base_corridor_tvd)
47+
if get_converted
48+
else self.origin_base_corridor_tvd,
49+
'origin_md': self.safe_round(self.origin_md) if get_converted else self.origin_md,
50+
'origin_top_corridor_tvd': self.safe_round(self.origin_top_corridor_tvd)
51+
if get_converted
52+
else self.origin_top_corridor_tvd,
53+
'origin_tvd': self.safe_round(self.origin_tvd) if get_converted else self.origin_tvd,
54+
'origin_vs': self.safe_round(self.origin_vs) if get_converted else self.origin_vs,
55+
'origin_x': self.safe_round(self.origin_x) if get_converted else self.origin_x,
56+
'origin_y': self.safe_round(self.origin_y) if get_converted else self.origin_y,
57+
'origin_z': self.safe_round(self.origin_z) if get_converted else self.origin_z,
58+
'target_base_corridor_tvd': self.safe_round(self.target_base_corridor_tvd)
59+
if get_converted
60+
else self.target_base_corridor_tvd,
61+
'target_md': self.safe_round(self.target_md) if get_converted else self.target_md,
62+
'target_top_corridor_tvd': self.safe_round(self.target_top_corridor_tvd)
63+
if get_converted
64+
else self.target_top_corridor_tvd,
65+
'target_tvd': self.safe_round(self.target_tvd) if get_converted else self.target_tvd,
66+
'target_vs': self.safe_round(self.target_vs) if get_converted else self.target_vs,
67+
'target_x': self.safe_round(self.target_x) if get_converted else self.target_x,
68+
'target_y': self.safe_round(self.target_y) if get_converted else self.target_y,
69+
'target_z': self.safe_round(self.target_z) if get_converted else self.target_z,
70+
'tvd_vs': self.safe_round(self.tvd_vs) if get_converted else self.tvd_vs,
6371
}
6472

6573
def to_df(self, get_converted: bool = True) -> DataFrame:

src/rogii_solo/trajectory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def __init__(self, measure_units: EMeasureUnits, **kwargs):
1919

2020
def to_dict(self, get_converted: bool = True) -> Dict[str, Any]:
2121
return {
22-
'md': self.safe_round(
23-
self.convert_z(self.md, measure_units=self.measure_units) if get_converted else self.md
24-
),
25-
'incl': self.safe_round(self.convert_angle(self.incl) if get_converted else self.incl),
26-
'azim': self.safe_round(self.convert_angle(self.azim) if get_converted else self.azim),
22+
'md': self.safe_round(self.convert_z(self.md, measure_units=self.measure_units))
23+
if get_converted
24+
else self.md,
25+
'incl': self.safe_round(self.convert_angle(self.incl)) if get_converted else self.incl,
26+
'azim': self.safe_round(self.convert_angle(self.azim)) if get_converted else self.azim,
2727
}
2828

2929
def to_df(self, get_converted: bool = True) -> DataFrame:

0 commit comments

Comments
 (0)