drillcore_transformations.usage module

Module with all usage methods i.e. for converting data files and manipulating the config.

exception drillcore_transformations.usage.ColumnException

Bases: Exception

Raise when there are errors with the columns of your data.

These can be related to not recognizing the column or if multiple columns match identifiers in config.ini.

Most issues can be fixed by checking the config.ini config file and adding your data file column names as identifiers or by removing identical identifiers.

drillcore_transformations.usage.add_column_name(header, base_column, name, config_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/drillcore-transformations/checkouts/latest/docs_src/config.ini'))

Add a column name to recognize measurement type.

E.g. if your alpha measurements are in a column that is named “alpha_measurements” you can add it to the config.ini file with:

If the inputted column name is already in the config file, this will be printed out and config will not be changed.

Parameters
  • header (str) – You may add new column names to the measurements file and to the file containing measurement depth information.

  • base_column (str) – Which type of measurement is the column name. Base types for measurements are: “alpha” “beta” “gamma” “measurement_depth” Base types for depths are: “depth” Base types for borehole are: “borehole_trend” “borehole_plunge”

  • name (str) – Name of the new column you want to add.

drillcore_transformations.usage.apply_conventions(df, col_dict)

Apply conventions from the config.ini file to given DataFrame.

col_dict is used to identify the correct columns.

Recognized conventions are: “negative” “none”

Parameters
  • df (pandas.DataFrame) – DataFrame

  • col_dict (dict) – Dictionary with identifiers for measurement data.

Returns

DataFrame with applied conventions in new columns. Modified col_dict.

Return type

tuple[pandas.DataFrame, dict]

drillcore_transformations.usage.apply_conventions_manual(df, col_dict, convention_dict)

Apply conventions from manual input to given DataFrame.

Creates new columns with conventioned data. col_dict is used to identify the correct columns.

Recognized conventions are: “negative” “none”

Parameters
  • df (pandas.DataFrame) – DataFrame

  • col_dict (dict) – Dictionary with identifiers for measurement data.

  • convention_dict (dict) – Dictionary with conventions

Returns

DataFrame with applied conventions in new columns.

Return type

pandas.DataFrame

drillcore_transformations.usage.change_conventions(convention_dict, config_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/drillcore-transformations/checkouts/latest/docs_src/config.ini'))

Change config.ini conventions by passing a dictionary.

Parameters

convention_dict (dict) – Dictionary with new conventions.

Returns

None if successful and False if key was not recognized or convention was not recognized or dictionary was invalid.

Return type

None | bool

drillcore_transformations.usage.convention_testing_csv(filename, with_gamma=False, output=None, visualize=False, img_dir=None)

Test multitudes of conventions on data in a .csv file.

TODO: Currently a crude, alpha, method, desperately needs improving and specifying.

Parameters
  • filename (str) – .csv file with data

  • with_gamma (bool) – If data contains gamma measurements

  • output (str) – output file with tested conventions

  • visualize (bool) – Whether to visualize each calculation (not worth it unless only 1 row of data)

  • img_dir (str) – Directory to save visualization images

drillcore_transformations.usage.find_config()

Return config.ini file path.

Returns

config.ini file path

Return type

Path

drillcore_transformations.usage.get_config_identifiers()

Get config identifiers.

drillcore_transformations.usage.initialize_config(config_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/drillcore-transformations/checkouts/latest/docs_src/config.ini'))

Create a configfile with default names for alpha, beta, etc.

Filename will be config.ini. Manual editing of this file is allowed but editing methods are also present for adding column names.

Will overwrite if needed.

drillcore_transformations.usage.parse_column(header, base_column, columns, config_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/drillcore-transformations/checkouts/latest/docs_src/config.ini'))

Find a given base_column in given columns.

Tries to match it to identifiers in config.ini.

Parameters
  • header (str) – “MEASUREMENTS”, “DEPTHS” or “BOREHOLE”

  • base_column (str) – The base measurement type to identify. (E.g. “alpha”, “beta”)

  • columns (list) – Columns from given data file.

Returns

Column name in your data file that matches the given base_column

Return type

str

Raises

ColumnException – When there are problems with identifying columns.

drillcore_transformations.usage.parse_columns_one_file(columns, with_gamma)

Match columns to column bases in config.ini.

Used when there is only one data file with all required data. I.e. at minimum: alpha, beta, borehole trend, borehole plunge

If gamma data exists => with_gamma should be given as True

Parameters
  • columns (list) – Given columns

  • with_gamma (bool) – Whether there are gamma measurements in file or not.

Returns

Matched columns as a dictionary.

Return type

dict

drillcore_transformations.usage.parse_columns_two_files(columns, with_gamma)

Match columns to column bases in config.ini.

Used when there’s a separate file with depth data.

Parameters
  • columns (list) – Given columns

  • with_gamma (bool) – Whether there are gamma measurements in file or not.

Returns

Matched columns as a dictionary.

Return type

dict

drillcore_transformations.usage.remove_column_name(header, base_column, name, config_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/drillcore-transformations/checkouts/latest/docs_src/config.ini'))

Remove a column name from config.ini.

Parameters
  • header (str) – Input the the header in which under the name is.

  • base_column (str) – Which type of measurement is the column name. Base types for measurements are: “alpha” “beta” “gamma” “measurement_depth” Base types for depths are: “depth” Base types for borehole are: “borehole_trend” “borehole_plunge”

  • name (str) – Name of the new column you want to remove.

drillcore_transformations.usage.round_outputs(number)

Round number.

drillcore_transformations.usage.save_config(config, config_path)

Save config.ini.

drillcore_transformations.usage.transform_csv(filename, with_gamma=False, output=None)

Transform data from a given .csv file.

File must have columns with alpha and beta measurements and borehole trend and plunge.

Saves new .csv file in the given output path.

Parameters
  • filename (str) – Path to file for reading.

  • output (str) – Path for output file. Will default filename+_transformed.csv.

  • with_gamma (bool) – Do gamma calculations or not

drillcore_transformations.usage.transform_csv_two_files(measurement_filename, depth_filename, with_gamma, output=None)

Transform with two csv files.

drillcore_transformations.usage.transform_excel(measurement_filename, with_gamma, output=None)

Transform excel file.

drillcore_transformations.usage.transform_excel_two_files(measurement_filename, depth_filename, with_gamma, output)

Transform with two excel files.

drillcore_transformations.usage.transform_with_two_files(measurements, depth, with_gamma, output=None)

Transform with two loaded DataFrames.