friction_loss.utils.converting_units

  1from typing import Optional, Dict, Union
  2
  3import numpy as np
  4from custom_plugin_base.services.clients.unisum_client import UnisumClient
  5from custom_plugin_base.utils.service_enum import LangEnum
  6
  7from friction_loss.utils.const import DAYS_TO_SECONDS, MM_TO_INCHES
  8from friction_loss.utils.plugin_dataclasses import TransientData, PolypresInputParameter
  9from friction_loss.utils.set_language import UNIT_SYSTEMS, UNIT_NAMES_TRANSLATOR, NAMES_COLUMNS_TRANSLATOR
 10
 11
 12def convert_report_data(diff_pressure: Dict[str, Union[TransientData, np.ndarray, None]],
 13                        initial_pressure: np.ndarray, time: Dict[str, Union[np.ndarray, str]],
 14                        unit_system: str, language: LangEnum):
 15    """
 16    Convert report data into interface units
 17    """
 18    convert = UnisumClient()
 19
 20    units_pressure = UNIT_SYSTEMS[LangEnum.US][unit_system]['Pressure']
 21    units_lenght = UNIT_SYSTEMS[LangEnum.US][unit_system]['Length']
 22    units_time = UNIT_SYSTEMS[LangEnum.US][unit_system]['Time']
 23    units_flow_rate = UNIT_SYSTEMS[LangEnum.US][unit_system]['Flow rate']
 24    units_flow_rate_lang = UNIT_SYSTEMS[language][unit_system]['Flow rate']
 25
 26    downhole_pressure = np.array([convert.convert_many_to_numpy_array('Pa', units_pressure, pres)
 27                                  for pres in diff_pressure['downhole_pressure']], dtype=object)
 28    diff_pressure['downhole_pressure'] = downhole_pressure
 29
 30    data = diff_pressure['data']
 31    out = np.empty(len(data), object)
 32
 33    for idx, well in enumerate(data):
 34        x = convert.convert_many_to_numpy_array('m', units_lenght, well.pressure[0])
 35
 36        new_y = np.zeros_like(well.pressure[1])
 37        for i, val in enumerate(well.pressure[1]):
 38            new_y[i] = convert.convert_many_to_numpy_array('Pa', units_pressure, val)
 39
 40        out[idx] = TransientData(pressure=np.array([x, new_y.T], dtype=object),
 41                                 qo=convert.convert_many_to_numpy_array('m^3/day',
 42                                                            units_flow_rate, well.qo) * DAYS_TO_SECONDS,
 43                                 qg=convert.convert_many_to_numpy_array('m^3/day',
 44                                                            units_flow_rate, well.qg) * DAYS_TO_SECONDS,
 45                                 qw=convert.convert_many_to_numpy_array('m^3/day',
 46                                                            units_flow_rate, well.qw) * DAYS_TO_SECONDS,
 47                                 pressure_unit=units_pressure,
 48                                 qo_unit=units_flow_rate_lang,
 49                                 qg_unit=units_flow_rate_lang,
 50                                 qw_unit=units_flow_rate_lang)
 51
 52    diff_pressure['data'] = out
 53
 54    # Массив исходного давления
 55    initial_pressure = np.array([convert.convert_many_to_numpy_array('Pa', units_pressure, pres)
 56                                 for pres in initial_pressure], dtype=object)
 57
 58    # Словарь содержащий ЕИ и массив времени
 59    new_t = {'unit': units_time,
 60             'value': np.array([convert.convert_many_to_numpy_array('hr', units_time,
 61                                            t['graphic_times']['value']) for t in time], dtype=object)}
 62
 63    return diff_pressure, initial_pressure, new_t
 64
 65
 66def convert_gauge_data(pressure: np.ndarray, time: np.ndarray, unit: Dict[str, str]) -> Dict[str, np.ndarray]:
 67    """
 68    Convert gauge data into Russian units (Russian because in this plugin selected the Russian system of units)
 69    """
 70    unisum_convert = UnisumClient()
 71
 72    n = len(pressure)
 73    p = np.empty(n, np.ndarray)
 74    time_in_current_unit = np.empty(n, np.ndarray)
 75
 76    for idx in range(n):
 77        p[idx] = unisum_convert.convert_many_to_numpy_array('Pa', unit['Pressure'], pressure[idx])
 78
 79        t = time[idx]['graphic_times']
 80        time_in_current_unit[idx] = unisum_convert.convert_many_to_numpy_array(t['unit'], unit['Time'], t['value'])
 81
 82    return {'pressure': p,
 83            'time': time_in_current_unit,
 84            'gauge message': np.array([i['gauge message'] for i in time]),
 85            'calendar_time': np.array([i['calendar_time'] for i in time])}
 86
 87
 88def convert_template_data(data: Dict[str, Optional[float]], units: str,
 89                          language: LangEnum) -> Dict[str, PolypresInputParameter]:
 90    """
 91    Convert default data to project units.
 92    """
 93    unisum_convert = UnisumClient()
 94
 95    ret = {}
 96    value = unit = None
 97
 98    for name, default_value in data.items():
 99        if name not in ['angle', 'report', 'pump']:
100            # параметры, которые заданы в мм и дюймах
101            if name in ['d', 'd_choke', 'd_tbg', 'd_csg', 'e']:
102                if units == 'Field':
103                    value = default_value / MM_TO_INCHES  # convert mm -> inches
104                else:
105                    value = default_value
106                unit = UNIT_SYSTEMS[language][units]['Diameter']
107
108            # параметры, которые заданы в метрах и футах
109            else:
110                value = unisum_convert.convert_one('m', UNIT_SYSTEMS[LangEnum.US][units]['Length'],
111                                                   default_value)
112                unit = UNIT_SYSTEMS[language][units]['Length']
113
114        if name == 'angle':
115            if units == 'Field':
116                unit = UNIT_NAMES_TRANSLATOR[language]['angle'][1]
117            else:
118                unit = UNIT_NAMES_TRANSLATOR[language]['angle'][0]
119            value = unisum_convert.convert_one('^o', UNIT_SYSTEMS[LangEnum.US][units]['Angle'],
120                                               default_value)
121        if name == 'pump':
122            unit = '-'
123            value = NAMES_COLUMNS_TRANSLATOR[language]['no_pump']
124
125        ret[name] = PolypresInputParameter(name=name,
126                                           value=value,
127                                           unit=unit)
128    return ret
def convert_report_data( diff_pressure: Dict[str, Union[friction_loss.utils.plugin_dataclasses.TransientData, numpy.ndarray, NoneType]], initial_pressure: numpy.ndarray, time: Dict[str, Union[str, numpy.ndarray]], unit_system: str, language: custom_plugin_base.utils.service_enum.LangEnum):
13def convert_report_data(diff_pressure: Dict[str, Union[TransientData, np.ndarray, None]],
14                        initial_pressure: np.ndarray, time: Dict[str, Union[np.ndarray, str]],
15                        unit_system: str, language: LangEnum):
16    """
17    Convert report data into interface units
18    """
19    convert = UnisumClient()
20
21    units_pressure = UNIT_SYSTEMS[LangEnum.US][unit_system]['Pressure']
22    units_lenght = UNIT_SYSTEMS[LangEnum.US][unit_system]['Length']
23    units_time = UNIT_SYSTEMS[LangEnum.US][unit_system]['Time']
24    units_flow_rate = UNIT_SYSTEMS[LangEnum.US][unit_system]['Flow rate']
25    units_flow_rate_lang = UNIT_SYSTEMS[language][unit_system]['Flow rate']
26
27    downhole_pressure = np.array([convert.convert_many_to_numpy_array('Pa', units_pressure, pres)
28                                  for pres in diff_pressure['downhole_pressure']], dtype=object)
29    diff_pressure['downhole_pressure'] = downhole_pressure
30
31    data = diff_pressure['data']
32    out = np.empty(len(data), object)
33
34    for idx, well in enumerate(data):
35        x = convert.convert_many_to_numpy_array('m', units_lenght, well.pressure[0])
36
37        new_y = np.zeros_like(well.pressure[1])
38        for i, val in enumerate(well.pressure[1]):
39            new_y[i] = convert.convert_many_to_numpy_array('Pa', units_pressure, val)
40
41        out[idx] = TransientData(pressure=np.array([x, new_y.T], dtype=object),
42                                 qo=convert.convert_many_to_numpy_array('m^3/day',
43                                                            units_flow_rate, well.qo) * DAYS_TO_SECONDS,
44                                 qg=convert.convert_many_to_numpy_array('m^3/day',
45                                                            units_flow_rate, well.qg) * DAYS_TO_SECONDS,
46                                 qw=convert.convert_many_to_numpy_array('m^3/day',
47                                                            units_flow_rate, well.qw) * DAYS_TO_SECONDS,
48                                 pressure_unit=units_pressure,
49                                 qo_unit=units_flow_rate_lang,
50                                 qg_unit=units_flow_rate_lang,
51                                 qw_unit=units_flow_rate_lang)
52
53    diff_pressure['data'] = out
54
55    # Массив исходного давления
56    initial_pressure = np.array([convert.convert_many_to_numpy_array('Pa', units_pressure, pres)
57                                 for pres in initial_pressure], dtype=object)
58
59    # Словарь содержащий ЕИ и массив времени
60    new_t = {'unit': units_time,
61             'value': np.array([convert.convert_many_to_numpy_array('hr', units_time,
62                                            t['graphic_times']['value']) for t in time], dtype=object)}
63
64    return diff_pressure, initial_pressure, new_t

Convert report data into interface units

def convert_gauge_data( pressure: numpy.ndarray, time: numpy.ndarray, unit: Dict[str, str]) -> Dict[str, numpy.ndarray]:
67def convert_gauge_data(pressure: np.ndarray, time: np.ndarray, unit: Dict[str, str]) -> Dict[str, np.ndarray]:
68    """
69    Convert gauge data into Russian units (Russian because in this plugin selected the Russian system of units)
70    """
71    unisum_convert = UnisumClient()
72
73    n = len(pressure)
74    p = np.empty(n, np.ndarray)
75    time_in_current_unit = np.empty(n, np.ndarray)
76
77    for idx in range(n):
78        p[idx] = unisum_convert.convert_many_to_numpy_array('Pa', unit['Pressure'], pressure[idx])
79
80        t = time[idx]['graphic_times']
81        time_in_current_unit[idx] = unisum_convert.convert_many_to_numpy_array(t['unit'], unit['Time'], t['value'])
82
83    return {'pressure': p,
84            'time': time_in_current_unit,
85            'gauge message': np.array([i['gauge message'] for i in time]),
86            'calendar_time': np.array([i['calendar_time'] for i in time])}

Convert gauge data into Russian units (Russian because in this plugin selected the Russian system of units)

def convert_template_data( data: Dict[str, Union[float, NoneType]], units: str, language: custom_plugin_base.utils.service_enum.LangEnum) -> Dict[str, friction_loss.utils.plugin_dataclasses.PolypresInputParameter]:
 89def convert_template_data(data: Dict[str, Optional[float]], units: str,
 90                          language: LangEnum) -> Dict[str, PolypresInputParameter]:
 91    """
 92    Convert default data to project units.
 93    """
 94    unisum_convert = UnisumClient()
 95
 96    ret = {}
 97    value = unit = None
 98
 99    for name, default_value in data.items():
100        if name not in ['angle', 'report', 'pump']:
101            # параметры, которые заданы в мм и дюймах
102            if name in ['d', 'd_choke', 'd_tbg', 'd_csg', 'e']:
103                if units == 'Field':
104                    value = default_value / MM_TO_INCHES  # convert mm -> inches
105                else:
106                    value = default_value
107                unit = UNIT_SYSTEMS[language][units]['Diameter']
108
109            # параметры, которые заданы в метрах и футах
110            else:
111                value = unisum_convert.convert_one('m', UNIT_SYSTEMS[LangEnum.US][units]['Length'],
112                                                   default_value)
113                unit = UNIT_SYSTEMS[language][units]['Length']
114
115        if name == 'angle':
116            if units == 'Field':
117                unit = UNIT_NAMES_TRANSLATOR[language]['angle'][1]
118            else:
119                unit = UNIT_NAMES_TRANSLATOR[language]['angle'][0]
120            value = unisum_convert.convert_one('^o', UNIT_SYSTEMS[LangEnum.US][units]['Angle'],
121                                               default_value)
122        if name == 'pump':
123            unit = '-'
124            value = NAMES_COLUMNS_TRANSLATOR[language]['no_pump']
125
126        ret[name] = PolypresInputParameter(name=name,
127                                           value=value,
128                                           unit=unit)
129    return ret

Convert default data to project units.