BHP input data is one of the most important attribute of a well. The bhp input model essentially encapsulates the wellbore data and plays a key role in bottom hole pressure calculations.
fromtypingimportOptional,ListimportosimportrequestsACCESS_TOKEN=os.environ["WHITSON_API_TOKEN"]CLIENT_NAME=os.environ["CLIENT_NAME"]defget_well(project_id:Optional[int]=None,name:Optional[str]=None,uwi_api:Optional[str]=None,):""" Get a list of wells. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells"response=requests.get(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},params={"project_id":project_id,"name":name,"uwi_api":uwi_api},)res=response.json()ifnotres:raiseException("no existing wells")returnresdefget_bhp_input(well_id:int):""" get bhp input data of the well specified by well_id """base_url=(f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input")response=requests.get(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},)ifnotresponse.json():raiseException("no existing wells")returnresponse.json()defupload_well_data_to_well(well_id:int,payload:List[dict]):""" Upload a well data to a well. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_data"response=requests.post(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},json=payload,)ifresponse.status_code>=200andresponse.status_code<300:print(f"success on well_id {well_id}")else:print(response.text)defget_well_data(well_id:int,use_from_date:Optional[str]=None):""" Get well data based on well_id and use_from_date. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_data"response=requests.get(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},params={"use_from_date":use_from_date},)ifnotresponse.json():raiseException("no existing wells")returnresponse.json()
fromtypingimportOptional,ListimportosimportrequestsACCESS_TOKEN=os.environ["WHITSON_API_TOKEN"]CLIENT_NAME=os.environ["CLIENT_NAME"]defedit_well_deviation_data(well_id:int,bhp_input_id:int,payload:List[dict]):""" Edit well deviation data of a well in the database """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_deviation_survey"response=requests.put(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},json=payload,)ifresponse.status_code>=200andresponse.status_code<300:print(f"changed well deivation survey on well_id {well_id}")else:print(response.text)if__name__=="__main__":well_json=get_well(project_id=1,name="SPE-DATA-REPOSITORY-DATASET-1-WELL-1-OSPREY")[0]well_id=well_json["id"]well_name=well_json["name"]#bhp_input_id = get_bhp_input(well_id)["id"]deviation_survey_payload=[{"md":0,"tvd":0},{"md":5000,"tvd":5000},{"md":7000,"tvd":7000},{"md":12000,"tvd":7000},]print(f"Changing well deviation data for well_id {well_id} ")edit_well_deviation_data(well_id,deviation_survey_payload)
fromtypingimportOptional,ListimportosimportrequestsACCESS_TOKEN=os.environ["WHITSON_API_TOKEN"]CLIENT_NAME=os.environ["CLIENT_NAME"]defedit_well_data(well_data_id:int,payload:dict):""" Edit well data of a well in the database """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/bhp_input/well_data/{well_data_id}"response=requests.put(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},json=payload,)ifresponse.status_code>=200andresponse.status_code<300:print(f"success on well_data_id {well_data_id}")else:print(response.text)if__name__=="__main__":well_name="SPE-DATA-REPOSITORY-DATASET-1-WELL-1-OSPREY"well_json=get_well(project_id=1,name=well_name)[0]well_id=well_json["id"]use_from_date="2022-01-01"well_data_payload=[{"use_from_date":use_from_date,"flow_path":"casing","gas_lift_config":"poorboy","lift_method":"none","well_data_casing":[{"bottom_md":7029,"d_casing_inner":6.276,"k_casing":0.0006,"pipe_number":1,"top_md":0,}],}]print("uploading well_data to well: ",well_id,", well name",well_name)upload_well_data_to_well(well_id,well_data_payload)new_well_data_payload={"well_data_casing":[{"bottom_md":7029,"d_casing_inner":6.276,"k_casing":0.0006,"pipe_number":1,"top_md":0,},{"bottom_md":11900,"d_casing_inner":4.0,"k_casing":0.0006,"pipe_number":2,"top_md":6936,},],"well_data_tubing":[{"bottom_md":7000,"d_tubing_inner":2.441,"d_tubing_outer":2.875,"k_tubing":0.0006,"pipe_number":1,}],}well_data_json=get_well_data(well_id,use_from_date=use_from_date)[0]well_data_id=well_data_json["id"]print(f"Edit well_data {well_data_id} for well: ",well_id,", well name",well_name)edit_well_data(well_data_id,new_well_data_payload)
Overwrite Well Data
Another way to alter Well Data is to overwrite the existing WellData. The Well Data object is primary keyed on well_id and use_from_date, so new payload will overwrite the existing WellData when user POST a payload that includes the same well_id and use_from_date as a WellData that already exists in whitson+.
Note: the database only overwrite fields that are included in the payload sent through the API. The following example shows how to erase the tubing data of the initial wellbore configuration, but leaving other part of the wellbore configuration untouched.
defupload_well_data_to_well(well_id:int,payload:List[dict]):""" Upload a well data to a well. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_data"response=requests.post(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},json=payload,)ifresponse.status_code>=200andresponse.status_code<300:print(f"success on well_id {well_id}")else:print(response.text)if__name__=="__main__":well_data_payload=[{"use_from_date":None,"well_data_tubing":[],}]print("uploading well_data to well: ",well_id,", well name",well_name)upload_well_data_to_well(well_id,well_data_payload)
fromtypingimportOptional,ListimportosimportrequestsACCESS_TOKEN=os.environ["WHITSON_API_TOKEN"]CLIENT_NAME=os.environ["CLIENT_NAME"]defget_well_data_casing(well_id:int,use_from_date:Optional[str]=None):""" Get well data casing based on well_id and use_from_date. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_data/well_data_casing"response=requests.get(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},params={"use_from_date":use_from_date},)ifnotresponse.json():raiseException("no existing wells")returnresponse.json()defupload_well_data_casing_to_well(well_id:int,payload:List[dict],use_from_date:Optional[str]=None):""" Upload a well data casing to a well. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_data/well_data_casing"response=requests.post(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},json=payload,params={"use_from_date":use_from_date},)ifresponse.status_code>=200andresponse.status_code<300:print(f"success on well_id {well_id}")else:print(response.text)defedit_well_data_casing(well_data_id:int,pipe_number:int,payload:dict):""" Edit a well data casing to a well data. """base_url=f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/bhp_input/well_data/{well_data_id}/well_data_casing/{pipe_number}"response=requests.put(base_url,headers={"content-type":"application/json","Authorization":f"Bearer {ACCESS_TOKEN}",},json=payload,)ifresponse.status_code>=200andresponse.status_code<300:print(f"success on well_id {well_id}")else:print(response.text)if__name__=="__main__":# First get the well idwell_name="SPE-DATA-REPOSITORY-DATASET-1-WELL-1-OSPREY"well_json=get_well(project_id=1,name=well_name)[0]well_id=well_json["id"]# Create a new well datause_from_date="2022-03-01"well_data_payload=[{"use_from_date":use_from_date,"flow_path":"casing","gas_lift_config":"poorboy","lift_method":"none","well_data_casing":[{"bottom_md":7029,"d_casing_inner":6.276,"k_casing":0.0006,"pipe_number":1,"top_md":0,}],}]print("uploading well_data to well: ",well_id,", well name",well_name)upload_well_data_to_well(well_id,well_data_payload)# Upload a new casing pipe to the well datawell_data_casing_payload=[{"bottom_md":11900,"d_casing_inner":4.0,"k_casing":0.0006,"pipe_number":2,"top_md":6936,}]print("uploading well_data_casing to well: ",well_id,", well name",well_name)upload_well_data_casing_to_well(well_id,well_data_casing_payload,use_from_date)# Get the well data id for the new well data we createdwell_data_json=get_well_data(well_id,use_from_date=use_from_date)[0]well_data_id=well_data_json["id"]# Alter well data casing dataprint(f"Edit well_data_casing to well data {well_data_id}")edit_well_data_casing(well_data_id=well_data_id,pipe_number=2,payload={"bottom_md":11999,},)# Last query the casing dataprint(f"Get well_data_casing to well {well_name}")well_data_casing_res=get_well_data_casing(well_id,use_from_date)print(well_data_casing_res)
FAQ
What is the use_from_date of the initial wellbore configuration (WellData)?
The use_from_date of the initial wellbore configuration is null.