cratonapi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. cratonapi-0.1.0/PKG-INFO +16 -0
  2. cratonapi-0.1.0/README.md +0 -0
  3. cratonapi-0.1.0/cratonapi/__init__.py +8 -0
  4. cratonapi-0.1.0/cratonapi/dataconnector.py +99 -0
  5. cratonapi-0.1.0/cratonapi/datacontainers/__init__.py +11 -0
  6. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/__init__.cpython-311.pyc +0 -0
  7. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/color.cpython-311.pyc +0 -0
  8. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/grid.cpython-311.pyc +0 -0
  9. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/griddisplayproperties.cpython-311.pyc +0 -0
  10. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/gridinfo.cpython-311.pyc +0 -0
  11. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/stratigraphiclevel.cpython-311.pyc +0 -0
  12. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/well.cpython-311.pyc +0 -0
  13. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/wellcurve.cpython-311.pyc +0 -0
  14. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/wellhodograph.cpython-311.pyc +0 -0
  15. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/wellinfo.cpython-311.pyc +0 -0
  16. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/wellstratigraphiclevel.cpython-311.pyc +0 -0
  17. cratonapi-0.1.0/cratonapi/datacontainers/__pycache__/welltrajectory.cpython-311.pyc +0 -0
  18. cratonapi-0.1.0/cratonapi/datacontainers/color.py +9 -0
  19. cratonapi-0.1.0/cratonapi/datacontainers/grid.py +18 -0
  20. cratonapi-0.1.0/cratonapi/datacontainers/griddisplayproperties.py +22 -0
  21. cratonapi-0.1.0/cratonapi/datacontainers/gridinfo.py +9 -0
  22. cratonapi-0.1.0/cratonapi/datacontainers/stratigraphiclevel.py +8 -0
  23. cratonapi-0.1.0/cratonapi/datacontainers/well.py +11 -0
  24. cratonapi-0.1.0/cratonapi/datacontainers/wellcurve.py +11 -0
  25. cratonapi-0.1.0/cratonapi/datacontainers/wellhodograph.py +10 -0
  26. cratonapi-0.1.0/cratonapi/datacontainers/wellinfo.py +7 -0
  27. cratonapi-0.1.0/cratonapi/datacontainers/wellstratigraphiclevel.py +7 -0
  28. cratonapi-0.1.0/cratonapi/datacontainers/welltrajectory.py +11 -0
  29. cratonapi-0.1.0/cratonapi/ioconnections/__init__.py +4 -0
  30. cratonapi-0.1.0/cratonapi/ioconnections/__pycache__/__init__.cpython-311.pyc +0 -0
  31. cratonapi-0.1.0/cratonapi/ioconnections/__pycache__/iobase.cpython-311.pyc +0 -0
  32. cratonapi-0.1.0/cratonapi/ioconnections/__pycache__/iofile.cpython-311.pyc +0 -0
  33. cratonapi-0.1.0/cratonapi/ioconnections/__pycache__/iopipe.cpython-311.pyc +0 -0
  34. cratonapi-0.1.0/cratonapi/ioconnections/__pycache__/ioreader.cpython-311.pyc +0 -0
  35. cratonapi-0.1.0/cratonapi/ioconnections/iobase.py +23 -0
  36. cratonapi-0.1.0/cratonapi/ioconnections/iofile.py +30 -0
  37. cratonapi-0.1.0/cratonapi/ioconnections/iopipe.py +77 -0
  38. cratonapi-0.1.0/cratonapi/ioconnections/ioreader.py +30 -0
  39. cratonapi-0.1.0/cratonapi/parsers/__init__.py +0 -0
  40. cratonapi-0.1.0/cratonapi/parsers/__pycache__/__init__.cpython-311.pyc +0 -0
  41. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__init__.py +12 -0
  42. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/__init__.cpython-311.pyc +0 -0
  43. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/griddisplaypropertiesparser.cpython-311.pyc +0 -0
  44. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/gridlistparser.cpython-311.pyc +0 -0
  45. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/gridparser.cpython-311.pyc +0 -0
  46. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/stratigraphiclevelsparser.cpython-311.pyc +0 -0
  47. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/wellcurvesparser.cpython-311.pyc +0 -0
  48. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/wellhodographparser.cpython-311.pyc +0 -0
  49. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/welllistparser.cpython-311.pyc +0 -0
  50. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/wellsparser.cpython-311.pyc +0 -0
  51. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/wellstratigraphiclevelsparser.cpython-311.pyc +0 -0
  52. cratonapi-0.1.0/cratonapi/parsers/dataparsers/__pycache__/welltrajectoryparser.cpython-311.pyc +0 -0
  53. cratonapi-0.1.0/cratonapi/parsers/dataparsers/griddisplaypropertiesparser.py +73 -0
  54. cratonapi-0.1.0/cratonapi/parsers/dataparsers/gridlistparser.py +31 -0
  55. cratonapi-0.1.0/cratonapi/parsers/dataparsers/gridparser.py +36 -0
  56. cratonapi-0.1.0/cratonapi/parsers/dataparsers/stratigraphiclevelsparser.py +31 -0
  57. cratonapi-0.1.0/cratonapi/parsers/dataparsers/wellcurvesparser.py +43 -0
  58. cratonapi-0.1.0/cratonapi/parsers/dataparsers/wellhodographparser.py +31 -0
  59. cratonapi-0.1.0/cratonapi/parsers/dataparsers/welllistparser.py +31 -0
  60. cratonapi-0.1.0/cratonapi/parsers/dataparsers/wellsparser.py +33 -0
  61. cratonapi-0.1.0/cratonapi/parsers/dataparsers/wellstratigraphiclevelsparser.py +27 -0
  62. cratonapi-0.1.0/cratonapi/parsers/dataparsers/welltrajectoryparser.py +34 -0
  63. cratonapi-0.1.0/cratonapi/parsers/signalparsers/__init__.py +4 -0
  64. cratonapi-0.1.0/cratonapi/parsers/signalparsers/__pycache__/__init__.cpython-311.pyc +0 -0
  65. cratonapi-0.1.0/cratonapi/parsers/signalparsers/__pycache__/griddisplaypropertieschangesignalparser.cpython-311.pyc +0 -0
  66. cratonapi-0.1.0/cratonapi/parsers/signalparsers/__pycache__/signalcodeparser.cpython-311.pyc +0 -0
  67. cratonapi-0.1.0/cratonapi/parsers/signalparsers/griddisplaypropertieschangesignalparser.py +8 -0
  68. cratonapi-0.1.0/cratonapi/parsers/signalparsers/signalcodeparser.py +23 -0
  69. cratonapi-0.1.0/cratonapi/requests/__init__.py +0 -0
  70. cratonapi-0.1.0/cratonapi/requests/__pycache__/__init__.cpython-311.pyc +0 -0
  71. cratonapi-0.1.0/cratonapi/requests/datarequests/__init__.py +12 -0
  72. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/__init__.cpython-311.pyc +0 -0
  73. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/griddisplaypropertiesrequest.cpython-311.pyc +0 -0
  74. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/gridlistrequest.cpython-311.pyc +0 -0
  75. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/gridrequest.cpython-311.pyc +0 -0
  76. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/stratigraphiclevellistrequest.cpython-311.pyc +0 -0
  77. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/wellcurvesrequest.cpython-311.pyc +0 -0
  78. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/wellhodographrequest.cpython-311.pyc +0 -0
  79. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/welllistrequest.cpython-311.pyc +0 -0
  80. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/wellsrequest.cpython-311.pyc +0 -0
  81. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/wellstratigraphiclevellistrequest.cpython-311.pyc +0 -0
  82. cratonapi-0.1.0/cratonapi/requests/datarequests/__pycache__/welltrajectoryrequest.cpython-311.pyc +0 -0
  83. cratonapi-0.1.0/cratonapi/requests/datarequests/griddisplaypropertiesrequest.py +10 -0
  84. cratonapi-0.1.0/cratonapi/requests/datarequests/gridlistrequest.py +10 -0
  85. cratonapi-0.1.0/cratonapi/requests/datarequests/gridrequest.py +10 -0
  86. cratonapi-0.1.0/cratonapi/requests/datarequests/stratigraphiclevellistrequest.py +10 -0
  87. cratonapi-0.1.0/cratonapi/requests/datarequests/wellcurvesrequest.py +10 -0
  88. cratonapi-0.1.0/cratonapi/requests/datarequests/wellhodographrequest.py +10 -0
  89. cratonapi-0.1.0/cratonapi/requests/datarequests/welllistrequest.py +10 -0
  90. cratonapi-0.1.0/cratonapi/requests/datarequests/wellsrequest.py +28 -0
  91. cratonapi-0.1.0/cratonapi/requests/datarequests/wellstratigraphiclevellistrequest.py +10 -0
  92. cratonapi-0.1.0/cratonapi/requests/datarequests/welltrajectoryrequest.py +10 -0
  93. cratonapi-0.1.0/cratonapi/requests/utilityrequests/__init__.py +1 -0
  94. cratonapi-0.1.0/cratonapi/requests/utilityrequests/__pycache__/__init__.cpython-311.pyc +0 -0
  95. cratonapi-0.1.0/cratonapi/requests/utilityrequests/__pycache__/dataconnectorgreetingrequest.cpython-311.pyc +0 -0
  96. cratonapi-0.1.0/cratonapi/requests/utilityrequests/__pycache__/listenergreetingrequest.cpython-311.pyc +0 -0
  97. cratonapi-0.1.0/cratonapi/requests/utilityrequests/dataconnectorgreetingrequest.py +8 -0
  98. cratonapi-0.1.0/cratonapi/requests/utilityrequests/listenergreetingrequest.py +17 -0
  99. cratonapi-0.1.0/cratonapi/signalconnector.py +35 -0
  100. cratonapi-0.1.0/cratonapi/signals/__init__.py +4 -0
  101. cratonapi-0.1.0/cratonapi/signals/__pycache__/__init__.cpython-311.pyc +0 -0
  102. cratonapi-0.1.0/cratonapi/signals/__pycache__/abstractsignal.cpython-311.pyc +0 -0
  103. cratonapi-0.1.0/cratonapi/signals/__pycache__/griddisplaypropertieschangedsignal.cpython-311.pyc +0 -0
  104. cratonapi-0.1.0/cratonapi/signals/__pycache__/gridlistchangedsignal.cpython-311.pyc +0 -0
  105. cratonapi-0.1.0/cratonapi/signals/__pycache__/signaltype.cpython-311.pyc +0 -0
  106. cratonapi-0.1.0/cratonapi/signals/abstractsignal.py +7 -0
  107. cratonapi-0.1.0/cratonapi/signals/griddisplaypropertieschangedsignal.py +8 -0
  108. cratonapi-0.1.0/cratonapi/signals/gridlistchangedsignal.py +8 -0
  109. cratonapi-0.1.0/cratonapi/signals/signaltype.py +6 -0
  110. cratonapi-0.1.0/pyproject.toml +22 -0
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: cratonapi
3
+ Version: 0.1.0
4
+ Summary: Python support for W-Seis interprocess communication API
5
+ Author: Kirill Natalin
6
+ Author-email: natalin.2000@mail.ru
7
+ Requires-Python: >=3.11,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: numpy (>=1.26.4,<2.0.0)
12
+ Requires-Dist: pywin32 (>=306,<307)
13
+ Requires-Dist: pywin32-ctypes (>=0.2.2,<0.3.0)
14
+ Description-Content-Type: text/markdown
15
+
16
+
File without changes
@@ -0,0 +1,8 @@
1
+ import cratonapi.datacontainers
2
+ import cratonapi.ioconnections
3
+ import cratonapi.parsers
4
+ import cratonapi.requests
5
+ import cratonapi.signals
6
+
7
+ from .dataconnector import DataConnector
8
+ from .signalconnector import SignalConnector
@@ -0,0 +1,99 @@
1
+ import numpy as np
2
+
3
+ from cratonapi.datacontainers import (
4
+ Grid,
5
+ GridDisplayProperties,
6
+ WellHodograph,
7
+ WellTrajectory,
8
+ )
9
+ from cratonapi.ioconnections import IOBase, IOPipe
10
+ from cratonapi.parsers.dataparsers import *
11
+ from cratonapi.requests.datarequests import *
12
+ from cratonapi.requests.utilityrequests import dataconnectorgreetingrequest
13
+
14
+
15
+ class DataConnector:
16
+ connection: IOBase
17
+ app_id: int
18
+
19
+ def __init__(self, connection: IOBase, new_app_id: int = 1):
20
+ self.connection = connection
21
+ self.app_id = new_app_id
22
+ self.__greeting()
23
+
24
+ def __greeting(self) -> None:
25
+ message = dataconnectorgreetingrequest.request(self.app_id)
26
+ self.connection.write(message)
27
+
28
+ def get_wells_list(self) -> np.ndarray:
29
+ """Request code 1"""
30
+ message = welllistrequest.request()
31
+ self.connection.write(message)
32
+ answer = self.connection.read()
33
+ return welllistparser.parse(answer)
34
+
35
+ def get_wells_data(self, count: int = 0, *wells_ids: int) -> np.ndarray:
36
+ """Request code 2"""
37
+ message = wellsrequest.request(count, *wells_ids)
38
+ self.connection.write(message)
39
+ answer = self.connection.read()
40
+ return wellsparser.parse(answer)
41
+
42
+ def get_well_curves(self, well_id: int) -> np.ndarray:
43
+ """Request code 3"""
44
+ message = wellcurvesrequest.request(well_id)
45
+ self.connection.write(message)
46
+ answer = self.connection.read()
47
+ return wellcurvesparser.parse(answer)
48
+
49
+ def get_stratigraphic_levels(self) -> np.ndarray:
50
+ """Request code 4"""
51
+ message = stratigraphiclevellistrequest.request()
52
+ self.connection.write(message)
53
+ answer = self.connection.read()
54
+ return stratigraphiclevelsparser.parse(answer)
55
+
56
+ def get_well_stratigraphic_levels(self, well_id: int) -> np.ndarray:
57
+ """Request code 5"""
58
+ message = wellstratigraphiclevellistrequest.request(well_id)
59
+ self.connection.write(message)
60
+ answer = self.connection.read()
61
+ return wellstratigraphiclevelsparser.parse(answer)
62
+
63
+ def get_grids_list(self) -> np.ndarray:
64
+ """Request code 6"""
65
+ message = gridlistrequest.request()
66
+ self.connection.write(message)
67
+ answer = self.connection.read()
68
+ return gridlistparser.parse(answer)
69
+
70
+ def get_grid(self, grid_id: int) -> Grid:
71
+ """Request code 7"""
72
+ message = gridrequest.request(grid_id)
73
+ self.connection.write(message)
74
+ answer = self.connection.read()
75
+ return gridparser.parse(answer)
76
+
77
+ def get_well_hodograph(self, well_id: int) -> WellHodograph:
78
+ """Request code 8"""
79
+ message = wellhodographrequest.request(well_id)
80
+ self.connection.write(message)
81
+ answer = self.connection.read()
82
+ return wellhodographparser.parse(answer)
83
+
84
+ def get_well_trajectory(self, well_id: int) -> WellTrajectory:
85
+ """Request code 9"""
86
+ message = welltrajectoryrequest.request(well_id)
87
+ self.connection.write(message)
88
+ answer = self.connection.read()
89
+ return welltrajectoryparser.parse(answer)
90
+
91
+ def get_grid_display_properties(self, grid_id: int) -> GridDisplayProperties:
92
+ """Request code 10"""
93
+ message = griddisplaypropertiesrequest.request(grid_id)
94
+ self.connection.write(message)
95
+ answer = self.connection.read()
96
+ return griddisplaypropertiesparser.parse(answer)
97
+
98
+ def disconnect(self) -> None:
99
+ self.connection.disconnect()
@@ -0,0 +1,11 @@
1
+ from .color import Color
2
+ from .grid import Grid
3
+ from .griddisplayproperties import GridDisplayProperties
4
+ from .gridinfo import GridInfo
5
+ from .stratigraphiclevel import StratigraphicLevel
6
+ from .well import Well
7
+ from .wellcurve import WellCurve
8
+ from .wellhodograph import WellHodograph
9
+ from .wellinfo import WellInfo
10
+ from .wellstratigraphiclevel import WellStratigraphicLevel
11
+ from .welltrajectory import WellTrajectory
@@ -0,0 +1,9 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class Color:
6
+ alpha: int
7
+ red: int
8
+ green: int
9
+ blue: int
@@ -0,0 +1,18 @@
1
+ from dataclasses import dataclass
2
+
3
+ from numpy import ndarray
4
+
5
+
6
+ @dataclass
7
+ class Grid:
8
+ n_id: int
9
+ n_x: int
10
+ n_y: int
11
+ x_min: float
12
+ x_max: float
13
+ y_min: float
14
+ y_max: float
15
+ z_min: float
16
+ z_max: float
17
+ blank_code: float
18
+ data: ndarray
@@ -0,0 +1,22 @@
1
+ from dataclasses import dataclass
2
+
3
+ from numpy import ndarray
4
+
5
+ from . import Color
6
+
7
+
8
+ @dataclass
9
+ class GridDisplayProperties:
10
+ isoline_min_level: float
11
+ isoline_max_level: float
12
+ isoline_level_step: float
13
+ minor_isoline_color: Color
14
+ minor_isoline_thickness: float
15
+ major_isoline_color: Color
16
+ major_isoline_thickness: float
17
+ major_isoline_step: int
18
+ min_palette_level: float
19
+ max_palette_level: float
20
+ color_interpolation_type: int
21
+ palette_values: ndarray
22
+ palette_colors: ndarray
@@ -0,0 +1,9 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class GridInfo:
6
+ grid_id: int
7
+ grid_name: str
8
+ grid_type: int
9
+ grid_visibility: int
@@ -0,0 +1,8 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class StratigraphicLevel:
6
+ level_id: int
7
+ level_age: float
8
+ level_name: str
@@ -0,0 +1,11 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class Well:
6
+ well_id: int
7
+ well_name: str
8
+ outfall_x: float
9
+ outfall_y: float
10
+ altitude: float
11
+ bottom: float
@@ -0,0 +1,11 @@
1
+ from dataclasses import dataclass
2
+
3
+ from numpy import ndarray
4
+
5
+
6
+ @dataclass
7
+ class WellCurve:
8
+ curve_type: int
9
+ curve_name: str
10
+ point_values: ndarray
11
+ point_depths: ndarray
@@ -0,0 +1,10 @@
1
+ from dataclasses import dataclass
2
+
3
+ from numpy import ndarray
4
+
5
+
6
+ @dataclass
7
+ class WellHodograph:
8
+ time_shift: float
9
+ point_times: ndarray
10
+ point_depths: ndarray
@@ -0,0 +1,7 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class WellInfo:
6
+ well_id: int
7
+ well_name: str
@@ -0,0 +1,7 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class WellStratigraphicLevel:
6
+ level_id: int
7
+ level_depth: float
@@ -0,0 +1,11 @@
1
+ from dataclasses import dataclass
2
+
3
+ from numpy import ndarray
4
+
5
+
6
+ @dataclass
7
+ class WellTrajectory:
8
+ point_depths: ndarray
9
+ point_x_shifts: ndarray
10
+ point_y_shifts: ndarray
11
+ point_z_shifts: ndarray
@@ -0,0 +1,4 @@
1
+ from .iobase import IOBase
2
+ from .iofile import IOFile
3
+ from .iopipe import IOPipe
4
+ from .ioreader import IOReader
@@ -0,0 +1,23 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class IOBase(ABC):
5
+ @abstractmethod
6
+ def __init__(self, path: str) -> None:
7
+ pass
8
+
9
+ @abstractmethod
10
+ def connect(self) -> None:
11
+ pass
12
+
13
+ @abstractmethod
14
+ def disconnect(self) -> None:
15
+ pass
16
+
17
+ @abstractmethod
18
+ def read(self) -> bytes:
19
+ pass
20
+
21
+ @abstractmethod
22
+ def write(self, message: bytes) -> None:
23
+ pass
@@ -0,0 +1,30 @@
1
+ import sys
2
+ from typing import BinaryIO, TextIO
3
+
4
+ from . import IOBase
5
+
6
+
7
+ class IOFile(IOBase):
8
+ file: BinaryIO
9
+ path: str
10
+ mode: str
11
+
12
+ def __init__(self, path: str) -> None:
13
+ self.path = path
14
+ self.connect()
15
+
16
+ def connect(self) -> None:
17
+ try:
18
+ self.file = open(self.path, "rb+")
19
+ except OSError:
20
+ print("Unable to open file!")
21
+ sys.exit(-1)
22
+
23
+ def read(self) -> bytes:
24
+ return self.file.read()
25
+
26
+ def write(self, message: bytes) -> None:
27
+ self.file.write(message)
28
+
29
+ def disconnect(self) -> None:
30
+ self.file.close()
@@ -0,0 +1,77 @@
1
+ import time
2
+ from ctypes.wintypes import HANDLE
3
+
4
+ import win32con
5
+ import win32event
6
+ import win32file
7
+ import win32pipe
8
+ from win32ctypes.pywin32.pywintypes import error
9
+
10
+ from . import IOBase
11
+
12
+
13
+ class IOPipe(IOBase):
14
+ handler: HANDLE
15
+ overlapped: win32file.OVERLAPPED
16
+ continue_work: bool
17
+ path: str
18
+
19
+ def __init__(self, path: str) -> None:
20
+ self.overlapped = win32file.OVERLAPPED()
21
+ self.overlapped.hEvent = win32event.CreateEvent(None, True, 0, None)
22
+ self.continue_work = True
23
+ self.path = path
24
+ self.connect()
25
+
26
+ def connect(self) -> None:
27
+ try:
28
+ self.handler = win32file.CreateFile(
29
+ self.path,
30
+ win32file.GENERIC_READ | win32file.GENERIC_WRITE,
31
+ 0,
32
+ None,
33
+ win32file.OPEN_EXISTING,
34
+ win32con.FILE_FLAG_OVERLAPPED,
35
+ None,
36
+ )
37
+ if self.handler != win32file.INVALID_HANDLE_VALUE:
38
+ win32pipe.SetNamedPipeHandleState(
39
+ self.handler, win32pipe.PIPE_READMODE_BYTE, None, None
40
+ )
41
+ self.continue_work = True
42
+ else:
43
+ raise RuntimeError("Connection failed! ")
44
+ except error:
45
+ raise RuntimeError("Connection failed! ")
46
+
47
+ def read(self) -> bytes:
48
+ try:
49
+ _, available_data, _ = win32pipe.PeekNamedPipe(self.handler, 0)
50
+ while available_data == 0 and self.continue_work:
51
+ _, available_data, _ = win32pipe.PeekNamedPipe(self.handler, 0)
52
+ if not self.continue_work:
53
+ return bytes()
54
+ result, data = win32file.ReadFile(
55
+ self.handler, available_data, self.overlapped
56
+ )
57
+ buf = data.obj
58
+ available_data = 0
59
+ while available_data == 0:
60
+ _, available_data, _ = win32pipe.PeekNamedPipe(self.handler, 0)
61
+ while available_data != 0:
62
+ result, data = win32file.ReadFile(
63
+ self.handler, available_data, self.overlapped
64
+ )
65
+ buf += data.obj
66
+ time.sleep(0.1)
67
+ _, available_data, _ = win32pipe.PeekNamedPipe(self.handler, 0)
68
+ return buf
69
+ except error:
70
+ raise RuntimeError("Listening has been stopped")
71
+
72
+ def write(self, message: bytes) -> None:
73
+ win32file.WriteFile(self.handler, message)
74
+
75
+ def disconnect(self) -> None:
76
+ self.continue_work = False
77
+ win32file.CloseHandle(self.handler)
@@ -0,0 +1,30 @@
1
+ import sys
2
+ from typing import BinaryIO, TextIO
3
+
4
+ from . import IOBase
5
+
6
+
7
+ class IOReader(IOBase):
8
+ file: BinaryIO
9
+
10
+ mode: str
11
+
12
+ def __init__(self, path: str) -> None:
13
+ self.path = path
14
+ self.connect()
15
+
16
+ def connect(self) -> None:
17
+ try:
18
+ self.file = open(self.path, "rb+")
19
+ except OSError:
20
+ print("Unable to open file!")
21
+ sys.exit(-1)
22
+
23
+ def read(self) -> bytes:
24
+ return self.file.read()
25
+
26
+ def write(self, message: bytes) -> None:
27
+ pass
28
+
29
+ def disconnect(self) -> None:
30
+ self.file.close()
File without changes
@@ -0,0 +1,12 @@
1
+ from . import (
2
+ griddisplaypropertiesparser,
3
+ gridlistparser,
4
+ gridparser,
5
+ stratigraphiclevelsparser,
6
+ wellcurvesparser,
7
+ wellhodographparser,
8
+ welllistparser,
9
+ wellsparser,
10
+ wellstratigraphiclevelsparser,
11
+ welltrajectoryparser,
12
+ )
@@ -0,0 +1,73 @@
1
+ import struct
2
+
3
+ import numpy as np
4
+
5
+ from cratonapi.datacontainers import Color, GridDisplayProperties
6
+
7
+
8
+ def parse(message: bytes) -> GridDisplayProperties:
9
+ if len(message) < 16:
10
+ raise RuntimeError("Incomplete message!")
11
+ signature = message[0:4].decode("utf-8")
12
+ if signature != "WSPM":
13
+ raise RuntimeError("Incorrect signature!")
14
+ size, operation, request, uid = struct.unpack("<IHHI", message[4:16])
15
+ if operation != 3 or request != 10:
16
+ raise RuntimeError("Incorrect operation or request codes!")
17
+ if len(message) - 8 != size:
18
+ raise RuntimeError("Incomplete message!")
19
+ (
20
+ isoline_min_level,
21
+ isoline_max_level,
22
+ isoline_level_step,
23
+ minor_isoline_alpha,
24
+ minor_isoline_red,
25
+ minor_isoline_green,
26
+ minor_isoline_blue,
27
+ minor_isoline_thickness,
28
+ major_isoline_alpha,
29
+ major_isoline_red,
30
+ major_isoline_green,
31
+ major_isoline_blue,
32
+ major_isoline_thickness,
33
+ major_isoline_step,
34
+ palette_min_level,
35
+ palette_max_level,
36
+ color_interpolation_type,
37
+ points_count,
38
+ ) = struct.unpack("<3f4Bf4BfH2dBI", message[16:67])
39
+ offset: int = 0
40
+ point_values = np.empty(points_count)
41
+ point_colors = np.empty(points_count, Color)
42
+ for point in range(points_count):
43
+ value, alpha, red, green, blue = struct.unpack(
44
+ "<f4B", message[67 + offset : 75 + offset]
45
+ )
46
+ offset += 8
47
+ point_values[point] = value
48
+ point_colors[point] = Color(alpha, red, green, blue)
49
+ return GridDisplayProperties(
50
+ isoline_min_level,
51
+ isoline_max_level,
52
+ isoline_level_step,
53
+ Color(
54
+ minor_isoline_alpha,
55
+ minor_isoline_red,
56
+ minor_isoline_green,
57
+ minor_isoline_blue,
58
+ ),
59
+ minor_isoline_thickness,
60
+ Color(
61
+ major_isoline_alpha,
62
+ major_isoline_red,
63
+ major_isoline_green,
64
+ major_isoline_blue,
65
+ ),
66
+ major_isoline_thickness,
67
+ major_isoline_step,
68
+ palette_min_level,
69
+ palette_max_level,
70
+ color_interpolation_type,
71
+ point_values,
72
+ point_colors,
73
+ )
@@ -0,0 +1,31 @@
1
+ import struct
2
+
3
+ import numpy as np
4
+
5
+ from cratonapi.datacontainers import GridInfo
6
+
7
+
8
+ def parse(message: bytes) -> np.ndarray:
9
+ if len(message) < 16:
10
+ raise RuntimeError("Incomplete message!")
11
+ signature = message[0:4].decode("utf-8")
12
+ if signature != "WSPM":
13
+ raise RuntimeError("Incorrect signature!")
14
+ size, operation, request, uid = struct.unpack("<IHHI", message[4:16])
15
+ if operation != 3 or request != 6:
16
+ raise RuntimeError("Incorrect operation or request codes!")
17
+ if len(message) - 8 != size:
18
+ raise RuntimeError("Incomplete message!")
19
+ grids_count = struct.unpack("<I", message[16:20])[0]
20
+ offset = 0
21
+ grid_list = np.empty(grids_count, GridInfo)
22
+ for grid_num in range(grids_count):
23
+ grid_id, grid_type, grid_visibility, grid_name_symbols_count = struct.unpack(
24
+ "<IBBH", message[20 + offset : 28 + offset]
25
+ )
26
+ grid_name_bytes = message[28 + offset : 28 + offset + grid_name_symbols_count]
27
+ offset += grid_name_symbols_count + 8
28
+ grid_name = grid_name_bytes.decode("cp1251")
29
+ new_grid = GridInfo(grid_id, grid_name, grid_type, grid_visibility)
30
+ grid_list[grid_num] = new_grid
31
+ return grid_list