jonnymaserati / welleng

A collection of Wells/Drilling Engineering tools, focused on well trajectory planning for the time being.
Apache License 2.0
119 stars 32 forks source link

Inconsistent units in `_interpolate_survey` #191

Open srivatsamr opened 4 weeks ago

srivatsamr commented 4 weeks ago

Firstly, thanks for creating and sharing this awesome project!

Description

I believe there is a bug in the _interpolate_survey function in the survey module while handling the units. When working in the units of feet, this function throws the following error: AssertionError: inconsistent units with header.

Here is a minimal reproducer:

import welleng as we

header = we.survey.SurveyHeader(deg=True, depth_unit='feet', surface_unit='feet')
sections = []
sections.append(
    we.connector.Connector(
        pos1=[0., 0., 0.],
        inc1=0.,
        azi1=0.,
        md1=0.,
        md2=100.,
        dls_design=3.0,
        degrees=True,
        unit='feet',
    )
)
survey = we.survey.from_connections(sections,
                                    step=30, 
                                    survey_header=header,
                                    radius=10, 
                                    deg=True,
                                    depth_unit='feet', 
                                    surface_unit='feet'
                                   )
node = survey.interpolate_md(50)

Bug

In the _interpolate_survey function, a new instance of Survey is created: https://github.com/jonnymaserati/welleng/blob/bc20a3b90fbfb30ed5da3a3cf64e611713150cc7/welleng/survey.py#L1624

While the header having units of feet is passed into the argument , the unit argument is left to default which is meters, causing this AssertionError. I guess setting unit=sh.depth_unit would resolve this.

Thanks!

jonnymaserati commented 4 weeks ago

Thanks for the feedback @srivatsamr!

I'll take a closer look when I get time, but I don't doubt there's issues as the whole units part was not well implemented. Longer term I want to make the engine dimensionless and then call stuff like dls as a method that checks dimensions.

In the meantime, I would suggest assuming that the survey module works in meters and transform your input into meters (using the units module for example, which is just a wrapper on the pint library) and then converting back to your unit of choice after.