<jupyter_start><jupyter_text>Calculate Well TrajectoryCalculate the well trajectory points from a json document with only wellname, md, inc, azim, and surface latitude and longitude or surface x and y.Directional surveys come in a variety of formats, these formats are often missing critical information the user needs for their analysis. The welltrajconvert package allows the user to take the bare minimum required wellbore survey information and convert that into its latitude and longitude points along the wellbore and a host of other common parameters.welltrajconvert requires the wellId, measured depth, inclination angle, azimuth degrees, surface_latitude, and surface_longitude points or surface x and y points to calculate various points along the wellbore using a minimum curvature algorithm.**welltrajconvert calculates the following:*** **tvd:**    * true vertical depth from surface to the survey point.* **n_s_deviation:**    * north south deviation for each point in the wellbore path.* **e_w_deviation:**    * east west deviation for each point in the wellbore path.* **dls:**    * Dogleg severity is a measure of the change in direction of a wellbore over a defined length, measured in degrees per 100 feet of length.* **surface_x:**    * Surface Easting component of the UTM coordinate* **surface_y:**    * Surface Northing component of the UTM coordinate* **x_points:**    * Easting component of the UTM coordinate* **y_points:**    * Northing component of the UTM coordinate* **zone_number:**    * Zone number of the UTM coordinate* **zone_letter:**    * Zone letter of the UTM coordinate* **latitude_points:**    * The latitude value of a location in the borehole. A positive value denotes north. Angle subtended with equatorial plane by a perpendicular from a point on the surface of a spheriod.* **longitude_points:**    * The longitude value of a location in a borehole. A positive value denotes east. Angle measured about the spheroid axis from a local prime meridian to the meridian through the point.* **isHorizontal:**    * Array of strings, Vertical Or Horizontal depending on Inclination angle point.<jupyter_code>from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
# ONLY RUN ONCE, must restart notebook otherwise
import os
from pathlib import Path
import matplotlib.pyplot as plt
current_dir = Path.cwd()
path = current_dir.parent
print(path)
#change directory to get src class data
os.chdir(path)
current_dir = Path.cwd()
path = current_dir.parent

os.chdir(path)
current_dir = Path.cwd()
path = current_dir.parent

os.chdir(path)
current_dir = Path.cwd()
path = current_dir.parent
#from welltrajconvert.wellbore_trajectory import *
from welltrajconvert.wellbore_trajectory import *<jupyter_output><empty_output><jupyter_text>Get Wellbore Trajectory object get the path to the json file<jupyter_code>json_path = './data/wellbore_survey.json'
json_path<jupyter_output><empty_output><jupyter_text>Open the json, just to take a look at it. the `from_json()` takes care of this<jupyter_code>with open(json_path) as json_file:
    json_obj = json.load(json_file)
json_file.close()
# take a look at the json
#print(json.dumps(json_obj, indent=4))<jupyter_output><empty_output><jupyter_text>using the WellboreTrajectory class, use `from_json` to take the path and convert it to a deviation survey object. This step will validate if the json contains the correct data for the minimum curvature calculation.**Create Wellbore_Survey_Object:**<jupyter_code># create a wellbore deviation object from the json path
dev_obj = WellboreTrajectory.from_json(json_path)
# take a look at the data
dev_obj.deviation_survey_obj<jupyter_output><empty_output><jupyter_text>As you can see above, there is only input data for wellId, md, inc, azim, and surface latitude and longitude.The rest of the data is missing and needs to be calculated.**Calculate Survey Points:**<jupyter_code># now you can calculate the survey points using a minimum curvature algorithm
dev_obj.calculate_survey_points()
# take a look at the data that was just calculated
dev_obj.deviation_survey_obj<jupyter_output><empty_output><jupyter_text>As you can see above, the data for latitude, longitude points and various other points along the wellbore have been calculated. **Serialize Dict:**<jupyter_code># finally, you can serialize the data object back to a json string to export or be used in a other applications.
json_ds = dev_obj.serialize()
json_ds<jupyter_output><empty_output><jupyter_text>Now you have done it, you can check out your calculated points in a dataframe for easy viewing.<jupyter_code>json_ds_obj = json.loads(json_ds)
df = pd.DataFrame(json_ds_obj)
df.head()
df.plot(kind="scatter", x="longitude_points", y="latitude_points", alpha=0.4)
plt.show()
fig = pyplot.figure()
ax = Axes3D(fig)
ax.scatter(df['longitude_points'].values, df['latitude_points'].values, df['tvd'].values*-1)
pyplot.show()
# Finished<jupyter_output><empty_output><jupyter_text>Calculate From WellId, MD, INC, AZIM and Suface X,YSometimes the latitue and longitude coordinates are not provided.In the case that only X,Y surface coordinates are provided you can still calculate the survey points withone additional step. The user must find the CRS coordinate system and provide that in the calculation.* **Transformation Tested with latitude and longitude points error less than 0.001%**<jupyter_code># get data that has only surface x and y, wellid, md, inc, azim
json_path = 'C:/Users/BpAmos/Documents/repos/directional-survey-converter/docs/source/notebook/data/well_export.json'
with open(json_path) as json_file:
    json_obj = json.load(json_file)
json_file.close()
#create a dict that has only the surface x and y
well_dict = {'wellId':json_obj['wellId'],
             'md':json_obj['md'],
            'inc':json_obj['inc'],
            'azim':json_obj['azim'],
            'surface_x':json_obj['surface_x'],
            'surface_y':json_obj['surface_y']}
#well_dict<jupyter_output><empty_output><jupyter_text>Since we already have a dictionary created, we do not need the `from_json`Enter the dict into the `WellboreTrajectory(data)`<jupyter_code># import dict data
well_obj = WellboreTrajectory(data = well_dict)
well_obj.deviation_survey_obj<jupyter_output><empty_output><jupyter_text>As you can see above, no surface latitude and longitude are provided. Only the surface X and Y.**CRS Transformation:**Since we are only given surface x and y we must translate this to the WGS:84 projection system.To do this use `crs_transform()` and enter in the EPSG coordinate system.Find your CRS here: https://epsg.io/<jupyter_code># must import crs transform string
well_obj.crs_transform(crs_in='epsg:32638')<jupyter_output><empty_output><jupyter_text>**Calculate Survey Points:**<jupyter_code>well_obj.calculate_survey_points()
# check out object
well_obj.deviation_survey_obj<jupyter_output><empty_output><jupyter_text>As you can see above, all the survey points have been calculated.**Deserialize Dict:**<jupyter_code># serialize
json_ds = well_obj.serialize()
json_ds<jupyter_output><empty_output><jupyter_text>Now you have done it, you can check out your calculated points in a dataframe for easy viewing.<jupyter_code>json_ds_obj = json.loads(json_ds)
dfXY = pd.DataFrame(json_ds_obj)
dfXY.head()
dfXY.plot(kind="scatter", x="longitude_points", y="latitude_points", alpha=0.4)
plt.show()
fig = pyplot.figure()
ax = Axes3D(fig)
ax.scatter(dfXY['longitude_points'].values, dfXY['latitude_points'].values, dfXY['tvd'].values*-1)
pyplot.show()
# Finished<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08584992746933931, 'fraction_numerical': 0.0032968482131082687, 'mean_word_length': 5.983425414364641, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '537015', 'license': 'MIT', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2260, 'n_words': 819, 'path': 'docs/source/notebook/Getting Started-Copy1.ipynb', 'repo_name': 'bpamos/welltrajconvert', 'size': '7583'}