geosoft.gxpy.utility

Utility functions to support Geosoft Python scripts and modules.

Note

Regression tests provide usage examples: Tests

Functions

_t(s)

_temp_dict_file_name()

Name of the expected python dictionary as a json file from run_external_python().

_validate_parameter(s)

check_version(v[, raise_on_fail])

Check the minimum API version.

crc32(byte_buffer[, crc])

Return 32-bit CRC of a byte buffer.

crc32_file(filename[, crc])

Return 32-bit CRC of a file.

crc32_str(s[, crc])

Return 32-bit CRC of a string.

datetime_from_year(year)

Return the Python datetime from a decimal Gregorian year.

decode(s, f)

Decode a string (s) to a numpy format defined by string (f).

delete_file(file_name)

Delete a file, does nothing if file does not exist.

delete_files_by_root(file_root)

Delete all files that have the same file_root (without extension).

delete_folder(folder_name[, age, raise_on_error])

Delete a folder if all files and sub-folders are accessible and deletable.

dict_from_http_response_text(text[, ...])

Decode http response text to a dictionary.

dict_from_lst(lst[, ordered])

Return a dictionary from a Geosoft geosoft.gxapi.GXLST instance.

dict_from_reg(reg[, ordered])

dictionary from a geosoft.gxapi.GXREG instance

dict_from_xml(xml)

Return a dictionary of an xml string.

display_message(title, message)

Display a message to the user.

dtype_gx(gtype)

returns:

numpy dtype from a GX type

dtype_gx_dimension(gtype)

returns:

numpy dtype and dimension of the type, 1, 2 or 3. The dimension indicates 1D, 2D or 3D data.

dummyMask(npd)

Deprecated since version 9.2: use dummy_mask()

dummy_mask(npd)

Return a 1-D dummy mask that is True for all rows in a 2D numpy array that have a Geosoft dummy value.

dummy_none(v)

Returns None if dummy, otherwise the value.

dummy_to_nan(data)

Replaces dummies in float data to numpy.nan.

file_age(file_name)

Returns the age of a file in seconds from now.

folder_temp([use_override])

Return the Geosoft temporary folder name.

folder_user()

Return the Geosoft user configurations folder name.

folder_workspace()

Return the Geosoft project folder name.

geosoft_metadata(geosoft_file_name)

Get the metadata dictionary for a geosoft data file.

geosoft_xml_from_dict(d[, pretty])

Return a unicode XML string of a dictionary with geosoft namespace defined.

get_parameters([group, parms, default])

Get parameters from the Project Parameter Block.

get_shared_dict()

Get a dictionary shared by an external application.

gxDummy(dtype)

Deprecated since version 9.2: use gx_dummy()

gx_dtype(dtype)

returns:

GX type for a numpy dtype

gx_dtype_dimension(dtype[, dimension])

returns:

GX type for a numpy dtype, with dimensions 2 and 3

gx_dummy(dtype)

Return the dummy for this value, or this type.

is_file_locked(file_name[, age])

Returns True if the file exists and is currently locked by another process or is younger than age.

is_float(gxtype)

Return True of gxtype can be stored in a 64-bit float

is_int(gxtype)

Return True of gxtype can be stored in a 64-bit integer

is_path_locked(path[, age])

Returns True if any files in this folder or sub-folders are locked or younger than age.

is_string(gxtype)

Return length of a gxtype string, 0 (False) if not a string.

jupyter_markdown_toc(j_file[, numbered, ...])

Create a markdoown table-of-content string from a jupyter notebook based on markdown "#".

merge_dict(d, d2)

Update a dictionary by adding key-values from second dictionary.

normalize_file_name(fn)

Normalize a file name string by replacing '' with '/'.

rdecode(s)

Geosoft string (number, date, time, geographic) conversion to a number, always works.

rdecode_err(s)

Geosoft string conversion to a number, raising ValueError on failure

reg_from_dict(rd[, max_size, json_encode])

geosoft.gxapi.GXREG instance from a dictionary

run_external_python(script[, script_args, ...])

Run a python script as an external program, returning results as a dictionary.

save_parameters([group, parms])

Save parameters to the Project Parameter Block.

set_shared_dict([shared_dict])

Save a dictionary to be shared by an separate application.

str_significant(value, n[, mode])

Return a formatted string to n significant figures.

time_stamp()

current date-time as a string.

unique_name(name[, invalid, separator, ...])

Build a unique name or file name.

url_retrieve(url[, filename, overwrite, ...])

Retrieve a URL resource as a file.

uuid()

returns:

a uuid as a string

vector_normalize(v)

Normalise (Euclidean) the last axis of a numpy array

xml_from_dict(d[, pretty, xmlns])

Return a unicode XML string of a dictionary.

yearFromJulianDay2(jd1, jd2)

Julian year

year_from_datetime(dt)

Return a decimal Gregorian calendar year from a Python datetime.

Exceptions

UtilityException(message)

Exceptions from geosoft.gxpy.utility.