def load_strat_definition(datadir, stratdeffile, verbose=False): """ :param datadir: :param stratdeffile: :param verbose: """ print('Opening stratigraphy definition file:') stratargs = { 'datadir': datadir, 'filename_in': stratdeffile, 'headerlines_in': 1, 'columns_in': (1, 2) } try: Stratigraphy.STRAT = dict() Stratigraphy.STRAT['NONE'] = 'None' Stratigraphy.STRAT['REF'] = 'Reference Level' stratdefreader = fileio.BHReaderWriter(**stratargs) lines = stratdefreader.read_data() for line in lines: if len(line) == 2: Stratigraphy.STRAT[line[0]] = line[1] if verbose: print(Stratigraphy.STRAT) except FileNotFoundError: print( 'Exception: File not found during loading of stratigraphy definition data' ) sys.exit(1) print('Stratigraphy definition updated')
def load_strat_order(datadir, stratorder_file, verbose=False): """ :param datadir: :param stratorder_file: :param verbose: """ print('Opening stratigraphy order/selection file:') stratargs = { 'datadir': datadir, 'filename_in': stratorder_file, 'headerlines_in': 1, 'columns_in': (1, ) } try: stratorderreader = fileio.BHReaderWriter(**stratargs) lines = stratorderreader.read_data() seen = {'REF': 1} result = ['REF'] for line in lines: if len(line) == 1: if line[0] in seen: continue seen[line[0]] = 1 result.append(line[0]) Stratigraphy.STRATORDER = result if verbose: print(Stratigraphy.STRATORDER) except FileNotFoundError: print( 'Exception: File not found during loading of stratigraphy order data' ) sys.exit(1) print('Stratigraphy order/selection updated')
def __init__(self, **kwargs): """ sets class parameters based on external keywords and / or robust defaults :param kwargs: unpacked keyword dictionary """ print(kwargs) # ###########defaults kwargs.setdefault('datadir', 'data') kwargs.setdefault('verbose', False) kwargs.setdefault('depthunit', 'ft') kwargs.setdefault('surfaceunits', 'ft') kwargs.setdefault('filename_in', 'sample-wellheads.txt') # default well head file # default values for header file shape kwargs.setdefault('headerlines_in', 1) kwargs.setdefault('columns_in', (1, 2, 3, 4, 5)) # default values for survey handling kwargs.setdefault('mode', 0) kwargs.setdefault('interval', 50) # ###########variables self.wells = dict() self.verbose = kwargs['verbose'] if self.verbose: Well.switch_verbose() print('Opening well head file:') # create dictionary based on kwargs and load well head spreadsheet welldbinargs = { 'datadir': kwargs['datadir'], 'filename_in': kwargs['filename_in'], 'headerlines_in': kwargs['headerlines_in'], 'columns_in': kwargs['columns_in'] } headreader = fileio.BHReaderWriter(**welldbinargs) lines = headreader.read_data() if kwargs['depthunit'] == 'm': Well.depth_to_metric() if kwargs['surfaceunits'] == 'm': Well.surf_to_metric() for line in lines: try: # convert spreadsheet data to proper type and check for depth-sorting wname = line[0] # str: WELLNAME # 3 x flt: ORIGIN X, Y, Z(KB) wcoordinates = tuple([float(i) for i in line[1:4]]) wfname = line[4] # str: DEVIATION FILENAME # create dictionary based on info in well head file wellinargs = { 'datadir': kwargs['datadir'], 'wellname': wname, 'origin': wcoordinates, 'filename_in': wfname, 'mode': kwargs['mode'], 'interval': kwargs['interval'] } # do not allow duplicates and instantiate new well if wname not in self.wells: self.wells[wname] = Well(**wellinargs) else: print( 'Warning: Double occurrence of name in well head file, keeping first instance' ) except ValueError: print('Exception: Error during conversion of well head data') sys.exit(1) if self.verbose: print( 'Input Name: {0:s}, X: {1:10.1f}, Y: {2:10.1f}, KB: {3:6.1f}' .format(wname, *wcoordinates)) print(str(self.wells[wname]))
def load_strat_markers(self, markerfile, headerlines=1, columns=(1, 2, 3, 4, 5)): """ :param markerfile: :param headerlines: :param columns: """ print('Opening marker file:') mfargs = { 'datadir': self.datadir, 'filename_in': markerfile, 'headerlines_in': headerlines, 'columns_in': columns } if (len(columns)) not in (3, 5): print( 'Error: Column specification in marker file requires three or five rows to be supplied\n\tformat:\ WELL NAME, MARKER CODE, DEPTH MD [length], DIP(opt) [deg], DAZIM(opt) [deg]' ) sys.exit() try: # build dictionary of relevant markers validmarkers = dict() for item in markermath.Stratigraphy.STRATORDER: validmarkers[item] = 1 # read marker table markerreader = fileio.BHReaderWriter(**mfargs) lines = markerreader.read_data() for line in lines: # find corresponding well print(line) wellin = line[0] markerin = line[1] if len(line) in (3, 5): if len(line) == 3: wmargs = { 'wellname': wellin, 'wmtype': 'STRAT', 'strat': markerin, 'md': float(line[2]) } elif line[3] == '' or line[4] == '': wmargs = { 'wellname': wellin, 'wmtype': 'STRAT', 'strat': markerin, 'md': float(line[2]) } else: wmargs = { 'wellname': wellin, 'wmtype': 'STRAT', 'strat': markerin, 'md': float(line[2]), 'dip': float(line[3]), 'dazim': float(line[4]) } if self.verbose: print('Line: {0:s}'.format(str(line))) print('Inargs: {0:s}'.format(str(wmargs))) if wellin in self.welldb.wells and markerin in validmarkers: # add marker to well wmargs['wellgeometry'] = self.welldb.wells[ wellin].geometry # array solution # self.welldb.wells[wellin].markers.append(WellMarker(**wmargs)) # dict solution self.welldb.wells[wellin].markers[ markerin] = markermath.WellMarker(**wmargs) if self.verbose: print( 'Class Well: Adding stratigraphy well marker to {0} using arguments:' .format(wellin)) print(wmargs) else: print( 'Stratigraphy marker {0} in well {1} discarded'.format( markerin, wellin)) except TypeError: print('Exception: Type error during conversion of marker file') sys.exit(1) except ValueError: print('Exception: Value error during conversion of marker file') sys.exit(1) print('Well markers successfully loaded to well database') if self.verbose: self.print_strat_markers()
def generate_output(self, mode=0): """ :param mode: """ if 0 < mode < 4: # generate Cartesian coordinate file from original curvelinear coordinate file pointlist = [] outheader = '' wellnote = 'Well: ' + self.wellname filename_out = 'out_' + self.wellname if mode == 1: self.cartesian_points = [] self.build_cartesian_points() filename_out += '_borehole_cart_orig.txt' if self.relativeCoords: outheader = (wellnote, 'dX(N) ['+self.surfunit+']', 'dY(E) ['+self.surfunit+']', 'dZ(TVD) ['+self.depthunit+']') else: outheader = (wellnote, 'X(N) ['+self.surfunit+']', 'Y(E) ['+self.surfunit+']', 'Z(TVD) ['+self.depthunit+']') pointlist = self.cartesian_points # for row in self.cartesian_points: # print(row) # generate interpolation points and output curvelinear coordinate file elif mode == 2: self.interpolation_points = [] self.setup_cl_points() self.interpolate_cl_points() filename_out += '_borehole_curve_inter.txt' outheader = (wellnote, 'MD ['+self.depthunit+']', 'INCL [deg]', 'AZIM [deg]') pointlist = self.interpolation_points # generate and output Cartesian coordinate file from interpolated data elif mode == 3: self.interpolation_points = [] self.setup_cl_points() self.interpolate_cl_points() self.curve_pairs = [] self.setup_min_curv_pairs(self.interpolation_points) self.cartesian_points = [] self.build_cartesian_points() filename_out += '_borehole_cart_inter.txt' if self.relativeCoords: outheader = (wellnote, 'dX(N) ['+self.surfunit+']', 'dY(E) ['+self.surfunit+']', 'dZ(TVD) ['+self.depthunit+']') else: outheader = (wellnote, 'X(N) ['+self.surfunit+']', 'Y(E) ['+self.surfunit+']', 'Z(TVD) ['+self.depthunit+']') pointlist = self.cartesian_points # for row in self.cartesian_points: # print(row) outdata = [] for item in pointlist: outdata.append(item.output_list()) outargs = {'datadir': self.datadir, 'filename_out': filename_out, 'header_out': outheader, 'data_out': outdata, 'verbose': self.verbose} writer = fileio.BHReaderWriter(**outargs) writer.write_data() else: print('No output file generated')
def __init__(self, **kwargs): """ sets class parameters based on external keywords and / or robust defaults :param kwargs: unpacked keyword dictionary """ kwargs.setdefault('wellname', 'UNKNOWN') kwargs.setdefault('datadir', 'data') kwargs.setdefault('filename_in', 'sample-borehole.txt') kwargs.setdefault('headerlines_in', 1) kwargs.setdefault('columns_in', (1, 2, 3)) kwargs.setdefault('mode', 0) kwargs.setdefault('depthunit', 'ft') kwargs.setdefault('surfaceunit', 'ft') kwargs.setdefault('interval', 50.0) kwargs.setdefault('relativeCoords', True) kwargs.setdefault('origin', (0.0, 0.0, 0.0)) kwargs.setdefault('verbose', False) # ###########Variables self.wellname = kwargs['wellname'] self.datadir = kwargs['datadir'] # catching an empty input survey filename if kwargs['filename_in'] == 'sample-borehole.txt': print('Warning: Using default deviation survey') self.filename_in = kwargs['filename_in'] # interpolate in different modes self.mode = kwargs['mode'] if kwargs['depthunit'] in ('ft', 'm'): self.depthunit = kwargs['depthunit'] else: print('Warning: Using default vertical unit [ft]') self.depthunit = 'ft' if kwargs['surfaceunit'] in ('ft', 'm'): self.surfunit = kwargs['surfaceunit'] else: print('Warning: Using default surface unit [ft]') self.surfunit = 'ft' self.interpolation_interval = kwargs['interval'] self.verbose = kwargs['verbose'] # MD/INCL/AZIM columns in input file try: # generate reader object and check file for existence self.reader = fileio.BHReaderWriter(**kwargs) self.reader.read_head() except FileNotFoundError: print('Exception: Deviation survey file not found - using default deviation survey') kwargs['filename_in'] = 'sample-borehole.txt' self.reader = fileio.BHReaderWriter(**kwargs) # for blank wells try parsing well name from deviation file header if self.wellname == 'UNKNOWN': # join the original list of strings back together and match by regular expression lines = self.reader.read_head() for line in lines: res_match = match(r"(?i)well:\s*(\S*?),", line) if res_match: self.wellname = res_match.group(1) print('Reading well name from file successful: {0:s}'.format(self.wellname)) # output absolute or relative Cartesian coordinates if not kwargs['relativeCoords']: self.relativeCoords = False self.origin = kwargs['origin'] if len(self.origin) != 3: raise ValueError('Exception: Borehole origin in wrong format - needs to be (X(N), Y(E), Z(TVD))') else: self.relativeCoords = True self.origin = (0.0, 0.0, 0.0) # ###########Main self.survey_points = [] self.curve_pairs = [] self.interpolation_points = [] self.cartesian_points = [] # load, convert, setup data for calculations lines = self.reader.read_data() try: first = float(lines[0][0]) # check first depth value to be non-negative if first < 0.0: raise ValueError('Exception: first MD value is negative') # check first depth value to be at KB or add surface point elif first >= 0.0001: self.survey_points.append(CLPoint(0.0, 0.0, 0.0)) print('Warning: Adding surface point to survey data') except ValueError as err: print('Exception: Error during conversion of survey data\n', err.args) sys.exit(1) prev = -1 for line in lines: try: # convert data to numbers and check for depth-sorting line = [float(i) for i in line] md = line[0] if md < prev: raise ValueError('Exception: MD values are not ascending') prev = md self.survey_points.append(CLPoint(*line)) except ValueError as err: print('Exception: Error during conversion of survey data\n', err.args) sys.exit(1) self.setup_min_curv_pairs(self.survey_points) # calculate and optionally output self.generate_output(self.mode)
mode=0, relativeCoords=True, verbose=False) # correct one marker by extracting corresponding horehole inclination/azim print('Apply correction on one DipMarker point:') dmarker = DipMarker(5000, 45, 10, wellgeometry, verbose=True) print(dmarker) # repeat the same for data read from a file print('Opening dipmarker file:') inargs = { 'datadir': '..\\data', 'filename_in': 'sample-dipmarker.txt', 'headerlines_in': 1, 'columns_in': (1, 2, 3) } reader = fileio.BHReaderWriter(**inargs) lines = reader.read_data() result = [] for line in lines: try: # convert data to numbers and check for depth-sorting line = [float(i) for i in line] result.append(DipMarker(*line, wellgeometry, verbose=False)) except ValueError: print('Exception: Error during conversion of survey data') sys.exit() print('Before - MD: {0:8.3f}, Dip: {1:8.3f}, Azimuth: {2:8.3f}'.format( *line)) print('After - ' + str(result[-1])) print('Writing dipmarker file:') # mode = basic(0) or detailed(1) output