Commit b5197359 authored by Niall McDaid's avatar Niall McDaid
Browse files

Initial solution - not working

URL is wrong
parent 6a7fa42a
......@@ -49,6 +49,9 @@ class LasCommandLoader(CLICommandsLoader):
group.command('welllog', 'welllog')
group.command('curves', 'welllog_data')
with CommandGroup(self, 'update', 'lasloader.commands.update#{}') as group:
group.command('welllog', 'welllog')
with CommandGroup(self, 'download', 'lasloader.commands.download#{}') as group:
group.command('welllog', 'download_las')
......@@ -61,6 +64,7 @@ class LasCommandLoader(CLICommandsLoader):
arg_context.argument('config_path', type=str, options_list=('-c', '--config_path'),
help='The path and filename of the configuration file.')
# 'fileload'
with ArgumentsContext(self, 'fileload') as arg_context:
arg_context.argument('input_path', type=str, options_list=('-p', '--path'),
help='Path to a file or folder containing LAS file(s) to upload.')
......@@ -69,6 +73,7 @@ class LasCommandLoader(CLICommandsLoader):
arg_context.argument('wellbore_id', type=str, options_list=('--wellbore_id'),
help='The wellbore id to use when printing to file.')
# 'ingest'
with ArgumentsContext(self, 'ingest') as arg_context:
arg_context.argument('input_path', type=str, options_list=('-p', '--path'),
help='Path to a file or folder containing LAS file(s) to upload.')
......@@ -89,6 +94,7 @@ class LasCommandLoader(CLICommandsLoader):
arg_context.argument('welllog_id', options_list=('--welllog_id'),
help='The welllog id of the record into which to write the data.')
# 'list'
with ArgumentsContext(self, 'list') as arg_context:
arg_context.argument('url', type=str, options_list=('-u', '--url'),
help='Url for the OSDU instance.')
......@@ -117,6 +123,24 @@ class LasCommandLoader(CLICommandsLoader):
arg_context.argument('curves', type=str, options_list=('--curves'), nargs='*',
help='The list of curves to retrieve (space separated list), returns all curves if not specified.')
# 'update'
with ArgumentsContext(self, 'update') as arg_context:
arg_context.argument('url', type=str, options_list=('-u', '--url'),
help='Url for the OSDU instance.')
with ArgumentsContext(self, 'update') as arg_context:
arg_context.argument('token', type=str, options_list=('-t', '--token'),
help='A valid bearer token used to authenticate with the OSDU instance.')
with ArgumentsContext(self, 'update welllog') as arg_context:
arg_context.argument('welllog_id', type=str, options_list=('--welllog_id'),
help='The welllog ID of the record to updated.')
with ArgumentsContext(self, 'update welllog') as arg_context:
arg_context.argument('curve_families', options_list=('--curvefamilies'), action='store_true',
help='If specified or set to True LASCLI will attempt to recognize and update the curve families.')
# 'download'
with ArgumentsContext(self, 'download') as arg_context:
arg_context.argument('url', type=str, options_list=('-u', '--url'),
help='Url for the OSDU instance.')
......
from knack.log import get_logger
from lasloader.configuration import Configuration
from lasloader.file_loader import LocalFileLoader
from lasloader.osdu_client import OsduClient
from lasloader.well_service import WellLogService
logger = get_logger(__name__)
def welllog(welllog_id: str, url: str, token: str, config_path: str, curve_families: bool = True):
"""
Update an existing well log record.
:param str welllog_id: ID of the well log to be updated.
:param str url: The base URL of the OSDU instance to which the well log was ingested.
:param str token: A valid bearer token that is used to authenticate the update request.
:param str config_path: Path to the LAS metadata file.
:param str curve_families: If true, recognize and update the curve families, otherwise don't.
"""
# This command currently only containes functionality to update the curve families of a well log.
# It is set up in such a way that it should be possible to extend to include other update operations in future if needed.
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
service = WellLogService(client)
if curve_families:
logger.info("Recognizing curve families and updating well log record.")
service.update_log_family(welllog_id, config.data_partition_id)
logger.warning("Curve families recognized and updated.")
else:
logger.warning("No updates made - set command option 'curve_families' to True to update curve families.")
......@@ -65,13 +65,25 @@ class OsduClient:
"""
Make a post request to OSDU to create a new well log record.
:param Record welllog_record: The welllog record to be uploaded
:param Union[Record, WellLogRecord] welllog_record: The welllog record to be uploaded
:return: the id of the new well log
:rtype: list[any]
"""
record = welllog_record.to_record() if isinstance(welllog_record, WellLogRecord) else welllog_record
return self._post_data_with_id_response("/api/os-wellbore-ddms/ddms/v3/welllogs", record)
def update_welllog(self, welllog_id: str, welllog_record: Union[Record, WellLogRecord]) -> list[any]:
"""
Make a post request to OSDU to update an existing well log record.
:param str welllog_id: The ID of the well log to be updated
:param Union[Record, WellLogRecord] welllog_record: The welllog record to overwrite the existing one
:return: The ID of the well log
:rtype: list[any]
"""
record = welllog_record.to_record() if isinstance(welllog_record, WellLogRecord) else welllog_record
return self._post_data_with_id_response(f"/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}", record)
def get_wellbore_record(self, wellbore_id: str) -> WellboreRecord:
"""
Make a get request to OSDU to retreive an existing wellbore record.
......
......@@ -78,6 +78,21 @@ class WellLogService:
return f"{data_partition_id}:reference-data--LogCurveFamily:{family_id}:"
def update_log_family(self, welllog_id: str, data_partition_id: str) -> None:
"""
Update the recognized curve families for an existing well log record.
:param str welllog_id: ID of the well log record to be updated.
:param str data_partition_id: The data partition ID.
"""
logger.info("Retrieving existing well log record.")
welllog_record = self._client.get_welllog_record(welllog_id)
logger.info("Beginning recognition of curve families.")
enriched_welllog_record = self.recognize_log_family(welllog_record.to_record(), data_partition_id)
logger.info("Updating existing well log record with recognized curve families.")
self._client.update_welllog(welllog_id, enriched_welllog_record)
def ingest_welllog_data(self, input_path: str, welllog_id: str) -> None:
"""
Write data from a LAS file to an existing well log. First the LAS file is validated against the
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment