Advertisement
boolit

mnem_unit_matching

Jan 26th, 2023 (edited)
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.50 KB | None | 0 0
  1. """ import required modules"""
  2. import json
  3. import numpy as np
  4. import pandas as pd
  5. import lasio
  6. import pickle
  7. import lasio
  8. from scipy import stats
  9. import json
  10.  
  11. class Las_dict_of_mnemonics_matching():
  12.     def __init__(self, las_file_path, path_to_wl_unit_lang_model, lang, confidence_level, dict_of_mnemonic):
  13.        
  14.         " read las file using lasio library"
  15.         self.las  = lasio.read(las_file_path)
  16.        
  17.         " load ML model to predict unit of measurement using well logging data  "
  18.         self.loaded_model = pickle.load(open(path_to_wl_unit_lang_model, "rb"))[0]
  19.        
  20.         " user language "
  21.         self.lang = lang
  22.        
  23.         " confidence lavel "
  24.         self.confidence_level = confidence_level
  25.        
  26.         " read dict_of_mnemonic "
  27.         self.dict_of_mnemonic = dict_of_mnemonic
  28.        
  29.     def get_inlog_mnemonic(self, curve):
  30.              
  31.         find_inLog = []
  32.         for mnem_element in self.dict_of_mnemonic:
  33.             if curve.mnemonic.lower() in mnem_element['possible_mnemonics']:
  34.                  find_inLog.append(mnem_element['log_' + self.lang])
  35.                    
  36.         inLog_mnem = ''    
  37.         if len(find_inLog) > 0:
  38.             inLog_mnem = find_inLog[0]
  39.        
  40.         return(inLog_mnem)
  41.    
  42.     def get_pred_unit(self, curve, inLog_mnem):
  43.        
  44.         pred_Unit = ''
  45.         if len(inLog_mnem) > 0:
  46.             """ generate input data """
  47.             log_values = curve.data
  48.             log_values = log_values[~np.isnan(log_values)]
  49.             median = np.median(log_values)
  50.             mean = np.mean(log_values)
  51.             mode = stats.mode(log_values)[0][0]
  52.             min_ = np.min(log_values)
  53.             max_ = np.max(log_values)
  54.             input_ = np.array([[median, mean, mode, min_, max_]]).reshape(1, -1)
  55.            
  56.             """ get predict using Machine Learning model """
  57.             probs = self.loaded_model.predict_proba(input_)
  58.             if any(k >= self.confidence_level for k in probs[0]):
  59.                 pred_Unit = self.loaded_model.predict(input_)[0]
  60.            
  61.         return(pred_Unit)
  62.    
  63.     def get_found_inlog_unit(self, curve):
  64.        
  65.         find_inLog_unit = ''
  66.         find_unit = []
  67.         for mnem_element in self.dict_of_mnemonic:
  68.             if curve.mnemonic.lower() in mnem_element['possible_mnemonics']:
  69.                 find_unit.append(list(mnem_element['inlog_unit_and_convertation_' + self.lang].keys()))
  70.         if len(find_unit) > 0:
  71.             find_inLog_unit = find_unit[0][0]
  72.        
  73.         return(find_inLog_unit)
  74.    
  75.     def get_convertation_func(self, curve, pred_Unit, find_inLog_unit):
  76.        
  77.         convertation_func = ''
  78.         # generate rule of convertation
  79.         if pred_Unit == find_inLog_unit != '':
  80.             convertation_func = 1
  81.  
  82.         if len(pred_Unit) > 0 and len(find_inLog_unit) > 0 and pred_Unit != find_inLog_unit:
  83.             convertation_func_list = []
  84.             for mnem_element in self.dict_of_mnemonic:
  85.                 if curve.mnemonic.lower() in mnem_element['possible_mnemonics']:
  86.                     convertation_func_list.append(mnem_element['inlog_unit_and_convertation_' + lang][find_inLog_unit][pred_Unit])
  87.             convertation_func = convertation_func_list[0]
  88.         return(convertation_func)
  89.        
  90.    
  91.        
  92.     def get_matching_matrix(self):
  93.         output_list = []
  94.         for curve in self.las.curves:
  95.             """ get inLog_mnem """
  96.             inLog_mnem = self.get_inlog_mnemonic(curve)
  97.            
  98.             """ predict units for curve where inLog mnemonic detected """
  99.             pred_Unit = self.get_pred_unit(curve, inLog_mnem)  
  100.            
  101.             """ find inLog unit """
  102.             find_inLog_unit = self.get_found_inlog_unit(curve)
  103.            
  104.             """ find inLog unit """
  105.             convertation_func = self.get_convertation_func(curve, pred_Unit, find_inLog_unit)
  106.            
  107.             output_list.append(
  108.             [
  109.             curve.descr,
  110.             curve.mnemonic,
  111.             inLog_mnem,
  112.             curve.unit,
  113.             pred_Unit,
  114.             find_inLog_unit,
  115.             convertation_func,
  116.             ]
  117.             )
  118.                    
  119.         return(output_list)
  120.    
  121. lang = 'ru'
  122. CONFIDENCE_LAVEL = 0.9
  123. mnemonics_matching = Las_dict_of_mnemonics_matching('welllogging_example.las', "wl_18_unit_model_" + lang + ".pickle", lang, CONFIDENCE_LAVEL, mnemonics)
  124. output_list = mnemonics_matching.get_matching_matrix()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement