exports package

Submodules

exports.assimp_kit module

Contains the AssimpKit class

class exports.assimp_kit.AssimpKit(debug_level)[source]

Bases: lib.exports.export_kit.ExportKit

Class used to export geometries to assimp lib

Initialise class

Parameters:debug_level – debug level taken from python’s ‘logging’ module
EXPORT_TYPE = 'gltf2'

Export type for assimp API

FILE_EXT = '.gltf'

Extension of file

add_geom(geom_obj, style_obj, meta_obj)[source]

Add a geometry to the scene. It only does triangular meshes for the moment. Will be expanded to include other types.

Parameters:
  • geom_obj – ModelGeometries object
  • style_obj – STYLE object
  • meta_obj – METADATA object
add_vertices_to_mesh(mesh, vertex_list)[source]

Adds the vertices to a mesh

Parameters:
  • mesh – pyassimp ‘Mesh’ object
  • vertex_list – list of floats, (x,y,z) coords of vertices
end_scene(out_filename)[source]

Called after geometries have all been added to scene and a file or blob should be created

Parameters:out_filename – filename and path of output file, without file extension if an empty string, then a blob is returned and a file is not created
Returns:True if file was written out, else returns the GLTF as an assimp blob object
end_write()

Generic routine to write out the accumulated GSM objects

make_a_mesh(mesh_name, index_list, material_index)[source]

Creates a mesh object

Parameters:
  • mesh_name – name of mesh object, bytes object
  • index_list – list of integers, indexes into a vertex list
  • material_index – index into scene’s array of materials
Returns:

pyassimp ‘Mesh’ object

make_colour(key, r_val, g_val, b_val, a_val)[source]

Makes a pyassimp ‘MaterialProperty’ object for colour

Parameters:
  • key – bytes object with name of key
  • r,g,b,a – floating point values of RGBA colours
make_empty_node(node_name)[source]

Makes an empty node with a supplied name

Parameters:node_name – name of node to be created
Returns:pyassimp ‘Node’ object
make_material(diffuse_colour, two_sided=False)[source]

Makes a material object with a certain diffuse colour

Parameters:
  • diffuse_colour – A tuple of floating point values (R,G,B,A)
  • two_sided – Boolean, optional, default False, make a double-sided material
Returns:

pyassimp ‘Material’ object

make_nodes(root_node_name, child_node_name, num_meshes)[source]

Make the scene’s root node and a child node

Parameters:
  • root_node_name – bytes object, name of root node
  • child_node_name – bytes object, name of child of root node
make_two_sided()[source]

Makes a two-sided ‘MaterialProperty’ object

Parameters:two_sided – boolean value of two sided property
Returns:A ‘MaterialProperty’ object with two-sided set to 1
scn = None

Assimp scene object

start_scene()[source]

Initiate scene creation, only one scene can be created at a time

start_write()

Generic routine to start the process write out multiple GSM objects

write(geom_obj, style_obj, meta_obj, file_name)

Generic routine to write out a single GSM object

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename file to output
write_borehole(base_vrtx, borehole_name, colour_info_dict, height_reso, out_filename='')[source]
Write out a file or blob of a borehole stick
if ‘out_filename’ is supplied then writes a file and returns True/False else returns a pointer to a ‘structs.ExportDataBlob’ object
Parameters:
  • base_vrtx – base vertex, position of the object within the model [x,y,z]
  • borehole_name – name of borehole
  • colour_info_dict – dict of colour info; key - depth, float, val {‘colour’:(R,B,G,A), ‘classText’: mineral name }, where R,G,B,A are floats
  • height_reso – height resolution for colour info dict
  • out_filename – optional destination directory+file (without extension), where file is written

exports.bh_utils module

A collection of Python functions used to create clean, consistent borehole labels and filenames

exports.bh_utils.clean(borehole_name)[source]

Returns a clean version of the borehole name or id

Parameters:borehole_name – borehole identifier or name
exports.bh_utils.make_borehole_filename(borehole_name)[source]

Returns a string, formatted borehole file name with no filename extension

Parameters:borehole_name – borehole identifier used to make file name
exports.bh_utils.make_borehole_label(borehole_name, depth)[source]

Makes a consistent and space-free label for borehole sections :param borehole_name: name of borehole :param depth: depth of section :returns: byte string label

exports.collada2gltf module

Converts files from collada to GLTF v2 by calling ‘COLLADA2GLTF-bin’ which is assumed to be available locally See https://github.com/KhronosGroup/COLLADA2GLTF/ for more information

exports.collada2gltf.REMOVE_COLLADA = True

Removes COLLADA file after conversion

exports.collada2gltf.convert_dir(src_dir, file_mask='*.dae')[source]

Converts a directory of files from COLLADA to GLTF

Parameters:
  • src_dir – directory of COLLADA files to be converted
  • file_mask – optional file mask of files
exports.collada2gltf.convert_file(daefile_str)[source]
Converts a COLLADA file to GLTF
will convert <file>_0 <file>_1 etc. if <file> does not exist
Parameters:daefile_str – filename to be converted
exports.collada2gltf.convert_one_file(daefile_str)[source]

Converts a COLLADA file to GLTF

Parameters:daefile_str – filename to be converted

exports.collada_kit module

Contains the ColladaKit class

class exports.collada_kit.ColladaKit(debug_level)[source]

Bases: lib.exports.export_kit.ExportKit

Class used to output COLLADA files, given geometry, style and metadata data structures

Initialise class

Parameters:debug_level – debug level taken from python’s ‘logging’ module
AMBIENT = (0, 0, 0, 1)

Ambient parameter for pycollada material effect

EMISSION = (0, 0, 0, 1)

Emission parameter for pycollada material effect

MAX_COLOURS = 256.0

Maximum number of colours displayed in one COLLADA file

POINT_SIZE = 300

Size of object used to represent point data

SHADING = 'phong'

Shading parameter for pycollada material effect

SHININESS = 50.0

Shininess parameter for pycollada material effect

SPECULAR = (0.7, 0.7, 0.7, 1)

Specular parameter for pycollada material effect

add_geom(geom_obj, style_obj, meta_obj)

Generic routine to add GSM objects to be written out in future

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
add_geom_to_collada(geom_obj, style_obj, meta_obj)[source]
Adds a vessel object to the pycollada mesh object
NB: Does not accept GOCAD vertex or volume files as they usually have (too) many node objects
Parameters:
  • geom_obj – MODEL_GEOMETRY object
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object
Returns:

a popup info dict or exits if you try to add a GOCAD VS (vertex) or VO (volume) file popup info dict format: { object_name: { ‘attr_name’: attr_val, … } } and a node label string

calc_step_sz(geom_obj, limit)[source]
With many voxets being so large, we have to increase sample size so we don’t
create too much data, to be improved later on.
Params geom_obj:
 MODEL_GEOMETRY object
Params limit:the higher this number the more cubes will be used to represent the voxet data
Returns:step size as an integer, point (sample) size as list of 3 integers [X,Y,Z]
compute_neighbours(xyz_list, step)[source]

Counts the number of neighbours of each point in a 3d array

Params xyz_listr:
 list of (X,Y,Z) coordinates
Returns:dictionary: key is (X,Y,Z), value is number of neighbours
end_collada(out_filename, node_label)[source]

Close out a COLLADA, writing the mesh object to file

Parameters:
  • out_filename – path & filename of COLLADA file to output, without extension
  • node_label – label for the COLLADA “Node” object (used by the website to recognise model parts)
end_write()

Generic routine to write out the accumulated GSM objects

make_colour_material(mesh, colour_tup, colour_idx)[source]

Adds a colour material to COLLADA object

Params mesh:pycollada ‘collada’ object
Params colour_tup:
 tuple of floats (R,G,B,A)
Params colour_idx:
 integer index, used to refer to the material
make_false_colour_materials(mesh, max_colours_flt)[source]

Adds a list of coloured materials to COLLADA object using a false colour map

Params mesh:pycollada ‘collada’ object
Params max_colours_flt:
 number of colours to add, float
make_mapped_colour_materials(mesh, colour_map)[source]

Adds a list of coloured materials to COLLADA object using supplied colour_map

Params mesh:COLLADA object
Params colour_map:
 dict of colours, key is integer, value is RGBA tuple of 4 floats
next_to(a_val, b_val, step)[source]

Returns True iff a equals b or if a is exactly ‘step’ units away from b

start_collada()[source]

Initiate creation of a COLLADA file

start_write()

Generic routine to start the process write out multiple GSM objects

write(geom_obj, style_obj, meta_obj, file_name)

Generic routine to write out a single GSM object

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename file to output
write_borehole(base_vrtx, borehole_name, colour_info_dict, height_reso, out_filename)[source]

Write out a COLLADA file of a borehole stick

Parameters:
  • base_vrtx – base vertex, position of the object within the model [x,y,z]
  • borehole_name – name of borehole
  • colour_info_dict – dict of colour info; key - depth, float, val - { ‘colour’ : (R,B,G,A), ‘classText’ : mineral name } where R,G,B,A are floats
  • height_reso – height resolution for colour info dict
  • out_filename – path & filename of COLLADA file to output, without extension
write_collada(geom_obj, style_obj, meta_obj, out_filename)[source]

Write out a COLLADA file

Parameters:
  • geom_obj – MODEL_GEOMETRY object that geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename of COLLADA file to output, without extension
Returns:

a dictionary of popup info objects popup info dict format: { object_name: { ‘attr_name’: attr_val, … } }

write_point_collada(geom_obj, style_obj, meta_obj, out_filename)[source]

Write out a COLLADA file from a point geometry file

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename of COLLADA file to output, without extension
write_vol_collada(geom_obj, style_obj, meta_obj, out_filename)[source]

Write out a COLLADA file from a vo file

Parameters:
  • geom_obj – MODEL_GEOMETRY object that geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename of COLLADA file to output, without extension

exports.collada_out module

Contains the ColladaOut class

class exports.collada_out.ColladaOut(debug_level)[source]

Bases: object

Class to output specific geometries as pycollada objects

Initialise class

Parameters:debug_level – debug level, using python’s ‘logger’ class
make_colour_borehole_marker(mesh, pos, borehole_label, geomnode_list, colour_info_dict, ht_resol)[source]

Makes a borehole marker stick with triangular cross section using pycollada objects

Parameters:
  • mesh – pycollada ‘Collada’ object
  • pos – x,y,z position of collar of borehole
  • borehole_label – geometry label for this borehole stick
  • geomnode_list – list of pycollada ‘GeometryNode’ objects
  • colour_info_dict – dict of: key = height, float; value = { ‘colour’: (R,G,B,A), ‘classText’: label }
  • ht_reso – height resolution
make_cube(mesh, colour_num, x_val, y_val, z_val, geom_obj, pt_size, geometry_name, file_cnt, point_cnt, geomnode_list)[source]

Makes a cube using pycollada objects

Parameters:
  • mesh – pycollada ‘Collada’ object
  • colour_num – index value for colour table
  • x,y,z – integer xyz coords in volume
  • geom_obj – MODEL_GEOMETRY object
  • pt_size – size of cube, float
  • geometry_name – generic label for all cubes
  • file_cnt – file counter
  • point_cnt – cube counter within this file
  • geomnode_list – pycollada ‘GeometryNode’ list
Returns:

the geometry label of this cube

make_line(mesh, geometry_name, geomnode_list, seg_arr, vrtx_arr, obj_cnt, line_width, z_expand)[source]

Makes a line using pycollada objects

Parameters:
  • mesh – pycollada ‘Collada’ object
  • geometry_name – generic label for all cubes
  • geomnode_list – list of pycollada ‘GeometryNode’ objects
  • seg_arr – array of SEG objects, defines line segments
  • vrtx_arr – array of VRTX objects, all points along line
  • obj_cnt – object counter within this file (an object may contain many lines)
  • line_width – line width, float
  • z_expand – is true if line width is drawn in z-direction else x-direction
Returns:

the line’s geometry label

make_pyramid(mesh, geometry_name, geomnode_list, vrtx, point_cnt, point_sz, colour_num)[source]

Makes a pyramid using pycollada objects

Parameters:
  • mesh – pycollada ‘Collada’ object
  • geometry_name – generic label for all pyramids
  • geomnode_list – list of pycollada ‘GeometryNode’ objects
  • vrtx – VTRX object
  • point_cnt – pyramid counter within this file
  • point_sz – size of pyramid
  • colour_num – integer index into mesh materials, determines colour of pyramid
Returns:

the pyramid’s geometry label

exports.export_kit module

Parent class for all ‘_kit’ classes

class exports.export_kit.ExportKit(debug_level)[source]

Bases: object

Initialise class :param debug_level: debug level taken from python’s ‘logging’ module

add_geom(geom_obj, style_obj, meta_obj)[source]

Generic routine to add GSM objects to be written out in future

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
end_write()[source]

Generic routine to write out the accumulated GSM objects

start_write()[source]

Generic routine to start the process write out multiple GSM objects

write(geom_obj, style_obj, meta_obj, file_name)[source]

Generic routine to write out a single GSM object

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename file to output

exports.geometry_gen module

A collection of Python generator functions used to create geometries, including: borehole sticks, lines, cubes and pyramids

exports.geometry_gen.colour_borehole_gen(pos, borehole_name, colour_info_dict, ht_resol)[source]

A generator which is used to make a borehole marker stick with triangular cross section

Parameters:
  • pos – x,y,z position of collar of borehole, tuple of 3 floats
  • borehole_name – borehole’s name
  • colour_info_dict – dict of: key = height, float; value = { ‘colour’: (R,G,B,A) floats, ‘classText’: mineral name, ‘className’: measurement class }
  • ht_reso – height resolution, float
Returns vert_list:
 

list of floats, (x,y,z) vertices; indices - list of integers, index pointers to which vertices are joined as triangles; colour_idx - integer index pointing to material object array; depth - depth of borehole segment, float; colour_info - colour information dict: { ‘colour’: (R,G,B,A) floats, ‘classText’: mineral name, ‘className’ : meas class } mesh_name - used to label meshes during mesh generation (bytes object)

exports.geometry_gen.cube_gen(x_val, y_val, z_val, geom_obj, pt_size)[source]

A single iteration generator which is used to create a cube

Parameters:
  • x,y,z – x,y,z index coordinates of cube, integers
  • geom_obj – MODEL_GEOMETRY object, holds the volume geometry details
  • pt_size – size of cube, three float tuple
Returns vert_floats, indices:
 

vert_floats - list of (x,y,z) vertices, floats; indices - integer index pointers to which vertices are joined as triangles

exports.geometry_gen.line_gen(seg_arr, vrtx_arr, line_width, z_expand)[source]

A generator which is used to make lines

Parameters:
  • seg_arr – line segment array, an array of SEG objects
  • vrtx_arr – vertex array, an array of VRTX objects
  • line_width – line width, float
  • z_expand – if true will expand width in z-direction, else x-direction
Returns point_cnt, vert_floats, indices:
 

point_cnt - count of iterations; vert_floats - list of (x,y,z) vertices, floats; indices - integer index pointers to which vertices are joined as triangles

exports.geometry_gen.pyramid_gen(vrtx, point_sz)[source]

A single iteration generator which is used to create a pyramid

Parameters:
  • vrtx – VRTX object, position of pyramid
  • pt_size – size of pyramid, float
Returns vert_floats, indices:
 

vert_floats - list of (x,y,z) vertices, floats; indices - integer index pointers to which vertices are joined as triangles

exports.geometry_gen.tri_gen(trgl_arr, vrtx_arr, mesh_name)[source]

A generator which is used to make a triangular mesh

:param trgl_arr triangle array, an array of TRGL objects :param vrtx_arr: vertex array, an array of VRTX objects

exports.netcdf_kit module

Contains the NetCDFKit class

class exports.netcdf_kit.NetCDFKit(debug_level)[source]

Bases: lib.exports.export_kit.ExportKit

Class used to output NetCDF4 files, given geometry, style and metadata data structures

Initialise class

Parameters:debug_level – debug level taken from python’s ‘logging’ module
add_geom(geom_obj, style_obj, meta_obj)

Generic routine to add GSM objects to be written out in future

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
end_write()

Generic routine to write out the accumulated GSM objects

start_write()

Generic routine to start the process write out multiple GSM objects

write(geom_obj, style_obj, meta_obj, file_name)

Generic routine to write out a single GSM object

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename file to output
write_points(geom_obj, style_obj, meta_obj, out_filename)[source]

Write out a NetCDF file from a point geometry file

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename of NetCDF file to output, without extension

exports.obj_out module

Contains ObjOut class

class exports.obj_out.ObjKit(debug_level)[source]

Bases: object

Class to output geometries to Wavefront OBJ format

Initialise class

Parameters:debug_level – debug level, using python’s ‘logging’ module
MAX_COLOURS = 256.0
write_obj(geom_obj, style_obj, file_name, src_file_str)[source]

Writes out an OBJ file

Parameters:
  • style_obj – STYLE object
  • geom_obj – MODEL_GEOMETRY object
  • fileName – filename of OBJ file, without extension
  • src_file_str – filename of gocad file
NOTES:
OBJ is very simple, and has shortcomings: 1. Does not include annotations (only comments and a group name) 2. Lines and points do not have a colour

I am only using it here because GOCAD VOXEL files are too big for COLLADA format

write_voxel_obj(geom_obj, out_fp, file_name, src_file_str, step_sz, use_full_cubes=False)[source]

Writes out voxel data to Wavefront OBJ and MTL files

Parameters:
  • out_fp – open file handle of OBJ file
  • geom_obj – MODEL_GEOMETRY object
  • fileName – filename of OBJ file without the ‘OBJ’ extension
  • src_file_str – filename of gocad file
  • step_sz – when stepping through the voxel block this is the step size
  • use_full_cubes – (optional, default to false) will write out full cubes to file if true, else will remove non-visible faces

exports.png_kit module

Contains PngKit class

class exports.png_kit.PngKit(debug_level)[source]

Bases: lib.exports.export_kit.ExportKit

Class used to output PNG files, given geometry, style and metadata data structures

Initialise class

Parameters:debug_level – debug level taken from python’s ‘logging’ module
add_geom(geom_obj, style_obj, meta_obj)

Generic routine to add GSM objects to be written out in future

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
end_write()

Generic routine to write out the accumulated GSM objects

start_write()

Generic routine to start the process write out multiple GSM objects

write(geom_obj, style_obj, meta_obj, file_name)

Generic routine to write out a single GSM object

Parameters:
  • geom_obj – MODEL_GEOMETRY object that hold geometry and text
  • style_obj – STYLE object containing colour info
  • meta_obj – METADATA object, used for labelling
  • out_filename – path & filename file to output
write_single_voxel_png(geom_obj, style_obj, meta_obj, file_name)[source]

Writes out a PNG file of the top layer of the voxel data

Parameters:
  • geom_obj – MODEL_GEOMETRY object that holds voxel data
  • style_obj – SYTLE object, contains colour map
  • meta_obj – FILENAME object, contains object information
  • file_name – filename of PNG file, without extension

exports.print_assimp module

Functions used to print out “assimp” (https://github.com/assimp/assimp) data structures, used for debugging purposes

exports.print_assimp.print_blob(blob)[source]

Prints a binary blob object :param blob: binary blob object

exports.print_assimp.print_colours(col_list)[source]

Prints out the RGBA colours in a colour list :param col_list: list of eight colours

exports.print_assimp.print_faces(face)[source]

Prints out an assimp face object :param face: assimp face object

exports.print_assimp.print_materials(mat)[source]

Prints out an assimp materials object :param mat: assimp materials object

exports.print_assimp.print_matrix4x4(matrix)[source]

Prints out a 4x4 matrix :param matrix: matrix object with attributes a1,a2,a3,a4, b1,b2 …

exports.print_assimp.print_mesh(mesh)[source]

Prints out an assimp mesh object :param mesh: assimp mesh object

exports.print_assimp.print_node(node)[source]

Prints out an assimp node object :param node: assimp node object

exports.print_assimp.print_properties(prop)[source]

Prints out assimp properties :param prop: assimp properties object

exports.print_assimp.print_scene(scene)[source]

Prints out the entire scene contained in the assimp data structure :param scene: assimp scene object

exports.print_assimp.print_texture(texture)[source]

Prints out an assimp texture object :param texture: texture object

exports.print_assimp.print_uvcomponents(comp)[source]

Prints out a list of eight assimp UV component objects :param comp: UV component object

exports.print_assimp.print_vertices(vert)[source]

Prints out the XYZ coords of a vertex object

Module contents