imports.gocad package¶
Submodules¶
imports.gocad.gocad_filestr_types module¶
-
class
imports.gocad.gocad_filestr_types.
GocadFileDataStrMap
[source]¶ Bases:
lib.imports.data_str_types.FileDataStructMap
-
GOCAD_HEADERS
= {'GP': ['GOCAD HETEROGENEOUSGROUP 1', 'GOCAD HOMOGENEOUSGROUP 1'], 'PL': ['GOCAD PLINE 1'], 'SG': ['GOCAD SGRID 1'], 'TS': ['GOCAD TSURF 1'], 'VO': ['GOCAD VOXET 1'], 'VS': ['GOCAD VSET 1'], 'WL': ['GOCAD WELL 1']}¶ Constant assigns possible headers to each filename extension
-
_GocadFileDataStrMap__get_ext
(filename_str)¶
-
is_borehole
(filename_str)[source]¶ Routine to recognise a borehole file
Parameters: filename_str – filename (including path) of GOCAD object file Returns: True if this file contains a borehole data structure
-
is_flat_shape
(filename_str)[source]¶ Routine to recognise a flat shape file e.g. triangles, planes in 3d
Parameters: filename_str – filename (including path) of GOCAD object file Returns: True if this file contains a flat shape data structure
-
is_mixture
(filename_str)[source]¶ Routine to recognise a file with a mixture of data structures
Parameters: filename_str – filename (including path) of GOCAD object file Returns: True if this file contains a mixture of data structures
-
imports.gocad.gocad_importer module¶
This contains the GocadImporter class, which is the main class used for parsing GOCAD object files. It also contains other functions for parsing GOCAD group files.
-
class
imports.gocad.gocad_importer.
GocadImporter
(debug_level, base_xyz=(0.0, 0.0, 0.0), group_name='', nondefault_coords=False, stop_on_exc=True, ct_file_dict={})[source]¶ Bases:
object
Class used to read GOCAD files and store their details
Initialise class
Parameters: - debug_level – debug level taken from ‘logging’ module e.g. logging.DEBUG
- base_xyz – optional (x,y,z) floating point tuple, base_xyz is added to all coordinates before they are output, default is (0.0, 0.0, 0.0)
- group_name – optional string, name of group if this gocad file is within a group, default is “”
- nondefault_coords – optional flag, supports non-default coordinates, default is False
- ct_file_dict – a dictionary of files which contain a tuple: (filename of CSV colour table, list of values to be rendered transparent) key is GOCAD filename
-
COORD_OFFSETS
= {'FROM_SHAPE': (535100.0, 0.0, 0.0)}¶ Coordinate offsets, when file contains a coordinate system that is not “DEFAULT” The named coordinate system and (X,Y,Z) offset will apply
-
SKIP_FLAGS_FILE
= True¶ Don’t read flags file
-
SUPPORTED_EXTS
= ['TS', 'VS', 'PL', 'GP', 'VO', 'WL', 'SG']¶ List of file extensions to search for
-
WELL_LINE_WIDTH
= 10¶ Line width for drawing wells
-
_GocadImporter__init_geometry
(geom_obj, local_prop_idx_list=None, prop_idx=None)¶ Convert GocadImporter to MODEL_GEOMETRY version
Parameters: - geom_obj – MODEL_GEOMETRY object where GocadImporter data is placed
- local_prop_idx_list – optional, if set, then will place multiple local property data values in object
- prop_idx – optional, if set, then will place property data in object
-
_GocadImporter__init_metadata
(meta_obj, local_prop_idx_list=None, prop_idx=None)¶ Extract metadata from GocadImporter and place in metadata object
Parameters: - meta_obj – metadata object which will hold data from GocadImporter object
- local_prop_idx_list – optional, if set, then will place multiple local property data values in object
- prop_idx – optional, if set, then will place property data in object
-
_GocadImporter__init_style
(style_obj, local_prop_idx_list=None, prop_idx=None)¶ Extract style data from GocadImporter and place in style object
Parameters: - style_obj – style object which will hold data taken from GocadImporter object
- local_prop_idx_list – optional, if set, then will place multiple local property data values in object
- prop_idx – optional, if set, then will place property data in object
-
_GocadImporter__make_vertex_dict
()¶ Make a dictionary to associate vertex insertion order with vertex sequence number Ordinarily the vertex sequence number is the same as the insertion order in the vertex array, but some GOCAD files have missing vertices etc. The first element starts at ‘1’
-
_GocadImporter__set_type
(file_ext, first_line_str)¶ Sets the type of GOCAD file: TSURF, VOXEL, PLINE etc.
Parameters: - fileExt – the file extension
- firstLineStr – first line in the file
Returns: returns True if it could determine the type of file Will return False when given the header of a GOCAD group file, since cannot create a vessel object from the group file itself, only from the group members
-
_atom_arr
= None¶ Array of named tuples ‘ATOM’ used to store atom data
-
_is_pl
= None¶ True iff it is a GOCAD PLINE file
-
_is_sg
= None¶ True iff it is a GOCAD SGRID file
-
_is_ts
= None¶ True iff it is a GOCAD TSURF file
-
_is_vo
= None¶ True iff it is a GOCAD VOXET file
-
_is_vs
= None¶ True iff it is a GOCAD VSET file
-
_is_wl
= None¶ True iff it is a GOCAD WELL file
-
_seg_arr
= None¶ Array of named tuples ‘SEG’ used to store line segment data
-
_trgl_arr
= None¶ Array of named tuples ‘TRGL’ used store triangle face data
-
_vrtx_arr
= None¶ Array of named tuples ‘VRTX’ used to store vertex data
-
axis_max
= None¶ 3 dimensional maximum point of voxet volume
-
axis_min
= None¶ 3 dimensional minimum point of voxet volume
-
axis_o
= None¶ Volume’s origin (X,Y,Z)
-
axis_u
= None¶ U-axis volume vector
-
axis_v
= None¶ V-axis volume vector
-
axis_w
= None¶ W-axis volume vector
-
calc_sg_xyz
(x_idx, y_idx, z_idx, fp_arr)¶ SGRID has coordinates in points file
-
calc_vo_xyz
(x_idx, y_idx, z_idx, mult)¶ Calculate the XYZ coords and their maxs & mins
-
coord_sys_name
= None¶ Name of the GOCAD coordinate system
-
ct_file_dict
= None¶ A dictionary of files which contain colour tables key is GOCAD filename, val is CSV file
-
flags_array_length
= None¶ Size of flags file
-
flags_bit_length
= None¶ Number of bit in use in flags file
-
flags_bit_size
= None¶ Size (number of bytes) of each element in flags file
-
flags_file
= None¶ Name of flags file associated with voxel file
-
flags_offset
= None¶ Offset within the flags file where data starts
-
flags_prop
= None¶ PROPS object used for the voxet flags file which has region data in it and for SGRID files
-
gsm_list
= None¶ List of (ModelGeometries, STYLE, METADATA)
-
handle_exc
(exc)[source]¶ If stop_on_exc is set or debug is on, print details of exception and stop
Parameters: exc – exception
-
header_name
= None¶ Contents of the name field in the header
-
invert_zaxis
= None¶ Set to true if z-axis inversion is turned on in this GOCAD file
-
local_props
= None¶ OrderedDict of PROPS objects for attached PVRTX and PATOM properties
-
meta_obj
= None¶ Seed copies of ModelGeometries, STYLE, METADATA for data gathering purposes
-
np_filename
= None¶ Filename of GOCAD file without path or extension
-
parse_axis_unit
(field)¶ Processes the AXIS_UNIT keyword :param field: array of field strings
-
parse_colour
(colour_str)¶ Parse a colour string into RGBA tuple.
Parameters: colour_str – colour can either be spaced RGBA/RGB floats, or ‘#’ + 6 digit hex string Returns: a tuple with 4 floats, (R,G,B,A)
-
parse_float
(fp_str, null_val=None)¶ Converts a string to float, handles infinite values
Parameters: - fp_str – string to convert to a float
- null_val – value representing ‘no data’
Returns: a boolean and a float If could not convert then return (False, None) else if ‘null_val’ is defined return (False, null_val)
-
parse_int
(int_str, null_val=None)¶ Converts a string to an int
Parameters: - int_str – string to convert to int
- null_val – value representing ‘no data’
Returns: a boolean and an integer If could not convert then return (False, None) else if ‘null_val’ is defined return (False, null_val)
-
parse_property_header
(prop_obj, line_str)¶ - Parses the PROPERTY header, extracting the colour table info
- and storing it in PROPS object
Params prop_obj: a PROPS object to store the data Params line_str: current line
-
parse_props
(field, coord_tup, is_patom=False)¶ This parses a line of properties associated with a PVTRX or PATOM line
Parameters: - field – array of strings representing line with properties
- coord_tup – (X,Y,Z) float tuple of the coordinates
- is_patom – optional, True if this is from a PATOM, default False
-
parse_xyz
(is_float, x_str, y_str, z_str, do_minmax=False, convert=True)¶ Helpful function to read XYZ cooordinates
Parameters: - is_float – if true parse x y z as floats else try integers
- y_str, z_str (x_str,) – X,Y,Z coordinates in string form
- do_minmax – calculate min/max of the X,Y,Z coords
- convert – convert from kms to metres if necessary
Returns: returns tuple of four parameters: success - true if could convert the strings to floats/ints x,y,z - floating point values, converted to metres if units are kms
-
points_file
= None¶ Points file (SGRID)
-
points_offset
= None¶ Offset within points file (SGRID)
-
process_ascii_well_path
(line_gen, field)¶ Process ascii well path header
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line; well_path, list of coordinates of well path; marker_list, list of markers
-
process_coord_hdr
(line_gen)¶ Process fields within coordinate header.
Parameters: line_gen – line generator Returns: two booleans, the first is True iff reached end of sequence, the second is True iff there is an unrecoverable error
-
process_gocad
(src_dir, filename_str, file_lines)[source]¶ Extracts details from gocad file. This should be called before other functions!
Parameters: - filename_str – filename of gocad file
- file_lines – array of strings of lines from gocad file
Returns: true if could process file, and a list of (geometry, style, metadata) objects
-
process_header
(line_gen)¶ Process fields in the GOCAD header
Parameters: line_gen – line generator Returns: a boolean, is True iff we are at last line
-
process_prop_class_hdr
(line_gen, field)¶ Process the property class header
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line
-
process_vol_data
(line_gen, field, field_raw, src_dir)¶ Process all the voxet and sgrid data fields
Parameters: - line_gen – line generator
- field – array of field strings
- field – array of field strings, not space separated
- src_dir – source directory of voxet file
-
process_well_binary_file
(file_name)¶
-
process_well_curve
(line_gen, field)¶ Process well curve
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line
-
process_well_info
(field, line_gen)¶ Process the information after a well marker or well zone is defined
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line and info dict
-
prop_dict
= None¶ Dictionary of PROPS objects, stores GOCAD “PROPERTY” objects from VOXET files Dictionary index is the PROPERTY number e.g. ‘1’, ‘2’, ‘3’ …
-
read_region_flags_file
(flags_array_len, flags_file, flags_bit_sz, flags_offset)¶ Reads the flags file and looks for regions for a VOXET or SGRID file.
Parameters: - flags_array_len – length of flags array
- flags_file – filename of flags file
- flags_bit_sz – mumber of bits in each element of flags array
- flags_offset – pointer to start of flags data within flags file
-
read_volume_binary_files
()¶ Open up and read binary volume file, could be from VOXET or SGRID
Returns: False upon error
-
region_colour_dict
= None¶ Region colour dict, key is region name, value is RGB (float, float, float)
-
region_dict
= None¶ Labels and bit numbers for each region in a flags file, key is number (as string), value is label
-
rock_label_idx
= None¶ Some voxet files have floats that are indexes to rock types
-
sgrid_cell_align
= None¶ Is SGRID aligned to cells or points ?
-
stop_on_exc
= True¶ Stop upon exception, regardless of debug level
-
uses_default_coords
= None¶ Uses default coordinates
-
vol_sz
= None¶ Size of voxet volume
-
xyz_mult
= None¶ Used to convert to metres if the units are in kilometres
-
xyz_unit
= None¶ Units of XYZ axes
-
imports.gocad.gocad_importer.
extract_from_grp
(src_dir, filename_str, file_lines, base_xyz, debug_lvl, nondef_coords, ct_file_dict)[source]¶ Extracts GOCAD files from a GOCAD group file
Parameters: - src_dir – source directory for GOCAD file
- filename_str – filename of GOCAD file
- file_lines – lines extracted from GOCAD group file
- base_xyz – base coordinates as (x,y,z) tuple added to all 3d coordinates
- debug_lvl – debug level for debug output e.g. logging.DEBUG
- nondefault_coords – optional flag, supports non-default coordinates, default is False
- ct_file_dict – a dictionary of files which contain a tuple: (filename of CSV colour table, list of values to be rendered transparent) key is GOCAD filename
Returns: a list of (ModelGeometries, STYLE, METADATA) objects
imports.gocad.helpers module¶
A collection GOCAD helper functions
-
imports.gocad.helpers.
check_vertex
(num, vrtx_arr)[source]¶ If vertex exists in vertex array then returns True else False
Parameters: - num – vertex number to search for
- vrtx_arr – vertex array
-
imports.gocad.helpers.
make_line_gen
(file_lines)[source]¶ - This is a Python generator function that processes lines of the GOCAD object file
- and returns each line in various forms, from quite unprocessed to fully processed
Parameters: - filename_str – filename of gocad file
- file_lines – array of strings of lines from gocad file
Returns: array of field strings in upper case with double quotes removed from strings, array of field string in original case without double quotes removed, line of GOCAD file in upper case, boolean, True iff it is the last line of the file
imports.gocad.parsers module¶
Functions that process fields in a single line of a GOCAD file
-
imports.gocad.parsers.
parse_axis_unit
(self, field)[source]¶ Processes the AXIS_UNIT keyword :param field: array of field strings
-
imports.gocad.parsers.
parse_colour
(self, colour_str)[source]¶ Parse a colour string into RGBA tuple.
Parameters: colour_str – colour can either be spaced RGBA/RGB floats, or ‘#’ + 6 digit hex string Returns: a tuple with 4 floats, (R,G,B,A)
-
imports.gocad.parsers.
parse_float
(self, fp_str, null_val=None)[source]¶ Converts a string to float, handles infinite values
Parameters: - fp_str – string to convert to a float
- null_val – value representing ‘no data’
Returns: a boolean and a float If could not convert then return (False, None) else if ‘null_val’ is defined return (False, null_val)
-
imports.gocad.parsers.
parse_int
(self, int_str, null_val=None)[source]¶ Converts a string to an int
Parameters: - int_str – string to convert to int
- null_val – value representing ‘no data’
Returns: a boolean and an integer If could not convert then return (False, None) else if ‘null_val’ is defined return (False, null_val)
-
imports.gocad.parsers.
parse_property_header
(self, prop_obj, line_str)[source]¶ - Parses the PROPERTY header, extracting the colour table info
- and storing it in PROPS object
Params prop_obj: a PROPS object to store the data Params line_str: current line
-
imports.gocad.parsers.
parse_props
(self, field, coord_tup, is_patom=False)[source]¶ This parses a line of properties associated with a PVTRX or PATOM line
Parameters: - field – array of strings representing line with properties
- coord_tup – (X,Y,Z) float tuple of the coordinates
- is_patom – optional, True if this is from a PATOM, default False
-
imports.gocad.parsers.
parse_xyz
(self, is_float, x_str, y_str, z_str, do_minmax=False, convert=True)[source]¶ Helpful function to read XYZ cooordinates
Parameters: - is_float – if true parse x y z as floats else try integers
- y_str, z_str (x_str,) – X,Y,Z coordinates in string form
- do_minmax – calculate min/max of the X,Y,Z coords
- convert – convert from kms to metres if necessary
Returns: returns tuple of four parameters: success - true if could convert the strings to floats/ints x,y,z - floating point values, converted to metres if units are kms
imports.gocad.processors module¶
Functions to process multiple lines used for specialist purposes
-
imports.gocad.processors.
process_ascii_well_path
(self, line_gen, field)[source]¶ Process ascii well path header
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line; well_path, list of coordinates of well path; marker_list, list of markers
-
imports.gocad.processors.
process_coord_hdr
(self, line_gen)[source]¶ Process fields within coordinate header.
Parameters: line_gen – line generator Returns: two booleans, the first is True iff reached end of sequence, the second is True iff there is an unrecoverable error
-
imports.gocad.processors.
process_header
(self, line_gen)[source]¶ Process fields in the GOCAD header
Parameters: line_gen – line generator Returns: a boolean, is True iff we are at last line
-
imports.gocad.processors.
process_prop_class_hdr
(self, line_gen, field)[source]¶ Process the property class header
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line
-
imports.gocad.processors.
process_vol_data
(self, line_gen, field, field_raw, src_dir)[source]¶ Process all the voxet and sgrid data fields
Parameters: - line_gen – line generator
- field – array of field strings
- field – array of field strings, not space separated
- src_dir – source directory of voxet file
-
imports.gocad.processors.
process_well_curve
(self, line_gen, field)[source]¶ Process well curve
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line
-
imports.gocad.processors.
process_well_info
(self, field, line_gen)[source]¶ Process the information after a well marker or well zone is defined
Parameters: - line_gen – line generator
- field – array of field strings from first line of prop class header
Returns: a boolean, is True iff we are at last line and info dict
-
imports.gocad.processors.
to_dia
(sdia)[source]¶ Converts a 4-tuple to 3-tuple of floats
Parameters: sdia – 4-tuple (‘STATION’, d, i, a) Returns: True/False, three float tuple
-
imports.gocad.processors.
to_xyz_min_curve
(dia1, dia2)[source]¶ Convert measured depth, inclination, azimuth to x,y,z via minimum curvature method
Parameters: - dia1 – tuple (measured depth, inclination, azimuth) measured depth, metres, float inclination, degrees, float, 0 = vertical, 90 = horizontal azimuth, degrees, float, measured from North
- dia2 – tuple (measured depth, inclination, azimuth)
imports.gocad.props module¶
Contains the PROPS class
-
class
imports.gocad.props.
PROPS
(class_name, debug_level)[source]¶ Bases:
object
This class holds generic 3d data and properties e.g. information extracted from 3d binary files (e.g. from GOCAD ‘PROP_FILE’) information attached to a set of XYZ points (e.g. from GOCAD ‘PATOM’, ‘PVRTX’)
-
_PROPS__calc_minmax
(fltp)¶ Calculates minimum & maximum of floating point value and stores result locally in ‘data_stats’ fp - floating point value (numpy or python float)
-
append_to_ijk
(ijk, val)[source]¶ Appends a value to xyz dict ijk - (I,J,K) tuple array indexes (ints) val - value to be assigned
-
append_to_xyz
(xyz, val)[source]¶ Appends a value to xyz dict xyz - (X,Y,Z) tuple array indexes (floats) val - value to be assigned
-
assign_to_3d
(x_val, y_val, z_val, fltp)[source]¶ Assigns a value to 3d array x,y,z - XYZ integer array indexes fltp - floating point value to be assigned
-
assign_to_ijk
(ijk, val)[source]¶ Assigns a value to ijk dict ijk - (I,J,K) tuple array indexes (ints) val - value to be assigned (float or tuple)
-
assign_to_xyz
(xyz, val)[source]¶ Assigns a value to xyz dict xyz - (X,Y,Z) tuple array indexes (floats) val - value to be assigned (float or tuple)
-
class_name
= None¶ Property class names
-
colour_map
= None¶ If colour map was specified, then it is stored here, integer is the key, value is (R,G,B,A) where R, G, B, A are floats
-
colourmap_name
= None¶ Name of colour map
-
data_3d
= None¶ Property data collected from binary file, value is float, stored as a 3d numpy array.
-
data_ijk
= None¶ Property data attached to XYZ points (index is IJK int indexes)
-
data_stats
= None¶ Property data statistics: min & max
-
data_sz
= None¶ Number of bytes in number in binary file, usually 1, 2 or 4
-
data_type
= None¶ Type of data in binary file e.g. ‘h’ = short 2-byte int, ‘f’ = float, ‘b’ - byte, ‘rgba’ - 4-byte RGBA
-
data_xyz
= None¶ Property data attached to XYZ points (index is XYZ coordinate)
-
file_name
= None¶ Name of binary file associated with GOCAD file
-
get_str_data_type
()[source]¶ Returns a string form of the data type of the volume data e.g. “INT_16”, “FLOAT_32”, “UINT_8”, “RGBA”
-
is_index_data
= None¶ Uses ‘data_3d’ to hold index to colour table or rock label table
-
make_numpy_dtype
()[source]¶ Returns a string that can be passed to ‘numpy’ to read a binary file It takes the ‘data_type’ of ‘f’, ‘b’, h’ & ‘rgba’
-
no_data_marker
= None¶ Value representing ‘no data’ values
-
offset
= None¶ Offset within binary file
-
read_colour_table_csv
(csv_file, transp_list)[source]¶ Reads an RGB colour table from CSV file for use in VOXET colours CSV Format: col#1: integer index, col#2: R-value, col#3: G-value, col#4: B-value csv_file - filename of CSV file to read, without path Sets the ‘colour_map’ and ‘rock_label_table’ class attibutes ‘colour_map’ is a dict, key is integer, value is (R,G,B,A) tuple of floats ‘rock_label_table’ is a dict, key is integer, value is string
-
rock_label_table
= None¶ Table specifying names of rocks , key is an integer, value is the label
-
signed_int
= None¶ Is True iff binary data is a signed integer else False
-
imports.gocad.volumes module¶
-
imports.gocad.volumes.
calc_sg_xyz
(self, x_idx, y_idx, z_idx, fp_arr)[source]¶ SGRID has coordinates in points file
-
imports.gocad.volumes.
calc_vo_xyz
(self, x_idx, y_idx, z_idx, mult)[source]¶ Calculate the XYZ coords and their maxs & mins
-
imports.gocad.volumes.
read_region_flags_file
(self, flags_array_len, flags_file, flags_bit_sz, flags_offset)[source]¶ Reads the flags file and looks for regions for a VOXET or SGRID file.
Parameters: - flags_array_len – length of flags array
- flags_file – filename of flags file
- flags_bit_sz – mumber of bits in each element of flags array
- flags_offset – pointer to start of flags data within flags file