libs5-python 1.0.5__py3-none-any.whl

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.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: libs5-python
3
+ Version: 1.0.5
4
+ Summary: libs5 python scripts, and helper classes (useg e.g. in BEANS software)
5
+ Project-URL: Homepage, https://gitlab.com/ahypki/libs5-python
6
+ Project-URL: Issues, https://gitlab.com/ahypki/libs5-python/-/issues/
7
+ Author: Arkadiusz Hypki
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+
15
+ # libs5-python
16
+
17
+ `libs5-python` is a package with `Python` scripts, and helper classes which are used e.g. in `BEANS` software
18
+
19
+
20
+ ## Installation
21
+
22
+ To install `libs5-python` type in the console:
23
+
24
+ ```
25
+ pip install libs5-python
26
+ ```
27
+
28
+ To upgrade `libs5-python` type in the console:
29
+
30
+ ```
31
+ pip install libs5-python --upgrade
32
+ ```
33
+
34
+ ## Roadmap
35
+
36
+ There is no specific roadmap for `libs5-python`. New features are added if they are needed.
37
+
38
+ ## Contributing
39
+
40
+ Feel free to contribute to this project by sending me your opinion, patches, or requesting some features through gitlab issue system.
41
+
42
+ ## Links
43
+
44
+ Home page: https://gitlab.com/ahypki/libs5-python/
45
+ Issues : https://gitlab.com/ahypki/libs5-python/-/issues/
46
+
47
+ ## License
48
+
49
+ `libs5-python` is released under the MIT license.
@@ -0,0 +1,22 @@
1
+ net/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ net/hypki/File.py,sha256=52wnCUBcDlBGH5swwR-PHJ9ofaW6BYloNgCLR605o9g,1007
3
+ net/hypki/Ini.py,sha256=938r36Pd1hRnwjX5ZjXqZIbRyIlklh1hjZfA1DN8ZPU,3044
4
+ net/hypki/Logger.py,sha256=vvJXYtb5qnLWmSoEnrtM937BWT2DAQUquBm-DN2umo8,1650
5
+ net/hypki/StringUtils.py,sha256=UuUnPIlkIe0WzUo-Q0o8HmE0kQP6MJwNZzK2fm39J-Y,438
6
+ net/hypki/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ net/hypki/apiutils.py,sha256=E_0EKQ46BbdTHqVABky8DqIe1WetpglmsPWgnjUGeJQ,1036
8
+ net/hypki/args.py,sha256=pXCJs2-LP1w8-3V-6KtOZuw4V9Q3VP7typ54qJ62GqM,516
9
+ net/hypki/asserts.py,sha256=awT2uysmbsPFpOBf6vaS0r39QBvsI5QGrwreXk0bwhE,198
10
+ net/hypki/io.py,sha256=H1ImSJojFbVa8Ww1iQ1Nr-sIjz_hEM0HkhMmSkFZEzo,1878
11
+ net/hypki/log.py,sha256=Qlbm1nZVBgs7EXF3Y12upGOU5Mpg0tL5YhJ3e6HGthQ,1730
12
+ net/hypki/math.py,sha256=-ZcIvUcSD5VTtPer6chvrARjL4BKEGqwsgnmAyfld4Q,197
13
+ net/hypki/random.py,sha256=svaPZV2B5DQj_GToIX49pOKxbgdKYY8hmu743Gyvw_c,231
14
+ net/hypki/regex.py,sha256=t80iy6fXiiQOYB1FIjpgpfrLdG2QOwKtRgnrCAn-9Ws,934
15
+ net/hypki/system.py,sha256=9MOAIJ221BH4GR4KKpPXexJGmFaWGZ1_wgi49kaFpmE,558
16
+ net/hypki/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ net/hypki/tests/kepler.py,sha256=3mEdHecMvM_ztUO17ZVvhxIXTze12-xx71A6Y3iaf_M,2307
18
+ net/hypki/tests/numpytest.py,sha256=FAyGjE2u_rqcoXUtj8HP4VbWP2f_LhOJ3hYVp37tDsA,378
19
+ libs5_python-1.0.5.dist-info/METADATA,sha256=mU-_CkJ3BqnoPIumvMAz762Y0w91WJG-464PLI73lQ4,1257
20
+ libs5_python-1.0.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
+ libs5_python-1.0.5.dist-info/licenses/LICENSE,sha256=jUGenC6Eo6P1BkABG3AQ2ThWGSDHgxa58dRIB8iR8Pc,1072
22
+ libs5_python-1.0.5.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Arkadiusz Hypki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
net/__init__.py ADDED
File without changes
net/hypki/File.py ADDED
@@ -0,0 +1,52 @@
1
+ '''
2
+ Created on Oct 14, 2025
3
+
4
+ @author: ahypki
5
+ '''
6
+ import os
7
+ import shutil
8
+ from pathlib import Path
9
+
10
+ class File(object):
11
+ '''
12
+ classdocs
13
+ '''
14
+ __absPath = None
15
+
16
+ def __init__(self, path):
17
+ '''
18
+ Constructor
19
+ '''
20
+ if isinstance(path, str):
21
+ self.setAbsPath(path)
22
+ elif len(path) == 1:
23
+ self.setAbsPath(path[0])
24
+ else:
25
+ self.setAbsPath("/".join(path))
26
+ # p2 = "/"
27
+ # for p1 in path:
28
+ # p1 +=
29
+
30
+ def getAbsPath(self):
31
+ return self.__absPath
32
+
33
+
34
+ def setAbsPath(self, path):
35
+ self.__absPath = Path(path).expanduser()# os.path.abspath(path)
36
+
37
+ def exists(self):
38
+ return os.path.exists(self.__absPath)
39
+
40
+ def mkdirs(self):
41
+ os.makedirs(self.__absPath, exist_ok=True)
42
+
43
+
44
+ def copy(self, destination):
45
+ shutil.copy2(self.__absPath, destination)
46
+
47
+
48
+ def remove(self):
49
+ os.remove(self.__absPath)
50
+
51
+
52
+
net/hypki/Ini.py ADDED
@@ -0,0 +1,102 @@
1
+ '''
2
+ Created on Oct 15, 2025
3
+
4
+ @author: ahypki
5
+ '''
6
+ import re
7
+
8
+ class Ini(object):
9
+ '''
10
+ classdocs
11
+ '''
12
+ __path = None
13
+ __iniLines = None
14
+
15
+ def __init__(self, path):
16
+ '''
17
+ Constructor
18
+ '''
19
+ self.__path = path
20
+
21
+ def __getIni(self):
22
+ if self.__iniLines is None:
23
+ self.__iniLines = open(self.__path, "r").readlines()
24
+
25
+ return self.__iniLines
26
+
27
+ def __isKey(self, line):
28
+ k = self.__getKey(line)
29
+ return False if k is None else True
30
+
31
+ def __getKey(self, line):
32
+ m = re.match("^[\s]*(\w[\w\d]*)[\s]*=[\s]*.*$", line)
33
+ if m:
34
+ return m.group(1)
35
+ return None
36
+
37
+ def __isSection(self, line):
38
+ sec = self.__getSection(line)
39
+ return False if sec is None else True
40
+
41
+ def __getSection(self, line):
42
+ m = re.match("^[\s]*\[(\w[\w\d]+)\][\s]*$", line)
43
+ if m:
44
+ return m.group(1)
45
+ return None
46
+
47
+ def getSections(self):
48
+ sections = []
49
+ for line in self.__getIni():
50
+ if self.__isSection(line):
51
+ sections.append(self.__getSection(line))
52
+ return sections
53
+
54
+ def getKeys(self, section):
55
+ keys = []
56
+ currentSection = None
57
+ for line in self.__getIni():
58
+ if self.__isSection(line):
59
+ currentSection = self.__getSection(line)
60
+ continue
61
+ if self.__isKey(line):
62
+ if currentSection is not None and currentSection == section:
63
+ keys.append(self.__getKey(line))
64
+ return keys
65
+
66
+ def set(self, section, key, value):
67
+ newLines = []
68
+ currentSection = None
69
+ for line in self.__getIni():
70
+ lineAdded = False
71
+
72
+ if self.__isSection(line):
73
+ currentSection = self.__getSection(line)
74
+
75
+ if self.__isKey(line):
76
+ currentKey = self.__getKey(line)
77
+ if currentSection is not None and currentSection == section and currentKey == key:
78
+ newLines.append(key + " = " + value)
79
+ lineAdded = True
80
+
81
+ if not lineAdded:
82
+ newLines.append(line)
83
+
84
+ self.__iniLines = newLines
85
+
86
+ def get(self, section, key):
87
+ currentSection = None
88
+ for line in self.__getIni():
89
+ if self.__isSection(line):
90
+ currentSection = self.__getSection(line)
91
+ continue
92
+ if self.__isKey(line):
93
+ currentKey = self.__getKey(line)
94
+ if currentSection is not None and currentSection == section and currentKey == key:
95
+ return line[(line.index("=") + 1):].strip()
96
+ return None
97
+
98
+ def save(self):
99
+ if self.__iniLines is not None:
100
+ with open(self.__path, 'w') as f:
101
+ for line in self.__iniLines:
102
+ f.write(f"{line.strip()}\n")
net/hypki/Logger.py ADDED
@@ -0,0 +1,51 @@
1
+ '''
2
+ Created on Aug 13, 2025
3
+
4
+ @author: ahypki
5
+ '''
6
+ from rich.console import Console
7
+
8
+ console = Console()
9
+
10
+ class Logger:
11
+ BLUE = '[blue]'#'\033[94m'
12
+ BLUE_END = '[/blue]'
13
+ GREEN = '[green]'#'\033[92m'
14
+ GREEN_END = '[/green]'
15
+ RED = '[red]'#'\033[91m'
16
+ RED_END = '[/red]'
17
+ WARNING = '[yellow]'#'\033[93m'
18
+ WARNING_END = '[/yellow]'
19
+ FAIL = RED#'\033[91m'
20
+ FAIL_END = RED_END
21
+ # ENDC = '\033[0m'
22
+
23
+ DEBUG = False
24
+ INFO = True
25
+
26
+ PRINT_LEVEL = True
27
+
28
+ # def blue(s): # @NoSelf
29
+ # return Logger.BLUE + s + Logger.BLUE_END
30
+
31
+ def debug(msg, printLogLevel = True, printNewLine = True): # @NoSelf
32
+ if Logger.DEBUG:
33
+ console.print(("DEBUG " if printLogLevel and Logger.PRINT_LEVEL else '')
34
+ + str(msg),
35
+ end = ('\n' if printNewLine else ''))
36
+
37
+ def info(msg, printLogLevel = True, printNewLine = True): # @NoSelf
38
+ if Logger.INFO:
39
+ console.print(("INFO " if printLogLevel and Logger.PRINT_LEVEL else '')
40
+ + str(msg),
41
+ end = ('\n' if printNewLine else ''))
42
+
43
+ def warn(msg, printLogLevel = True, printNewLine = True): # @NoSelf
44
+ console.print(("WARN " if printLogLevel and Logger.PRINT_LEVEL else '')
45
+ + str(Logger.WARNING + msg + Logger.WARNING_END),
46
+ end = ('\n' if printNewLine else ''))
47
+
48
+ def error(msg, printLogLevel = True, printNewLine = True): # @NoSelf
49
+ console.print(("ERROR " if printLogLevel and Logger.PRINT_LEVEL else '')
50
+ + str(msg),
51
+ end = ('\n' if printNewLine else ''))
@@ -0,0 +1,23 @@
1
+ '''
2
+ Created on Oct 14, 2025
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ class StringUtils(object):
8
+ '''
9
+ classdocs
10
+ '''
11
+
12
+
13
+ def __init__(self, params):
14
+ '''
15
+ Constructor
16
+ '''
17
+ pass
18
+
19
+ def notEmpty(s): # @NoSelf
20
+ return not StringUtils.isEmpty(s) #len(s.strip()) > 0 if s is not None else False
21
+
22
+ def isEmpty(s): # @NoSelf
23
+ return s is None or len(s.strip()) == 0 if s is not None else False
net/hypki/__init__.py ADDED
File without changes
net/hypki/apiutils.py ADDED
@@ -0,0 +1,32 @@
1
+ '''
2
+ Created on Aug 15, 2025
3
+
4
+ @author: ahypki
5
+ '''
6
+ import requests
7
+ from requests_toolbelt.multipart.encoder import MultipartEncoder
8
+
9
+ def streamGET(url, params):
10
+ s = requests.Session()
11
+ return s.get(url, params=params, headers=None, stream=True).iter_lines()
12
+ # with s.get(url, params=params, headers=None, stream=True) as resp:
13
+ # for line in resp.iter_lines():
14
+ # if line:
15
+ # print(line)
16
+
17
+ def streamPOST(url, file, params):
18
+ # s = requests.Session()
19
+ # Specify the content type
20
+ # headers = {'Content-Type': 'application/octet-stream'}
21
+ # headers = {'Content-Type': 'multipart/form-data'}
22
+ # return s.post(url, headers=headers, data=stream)
23
+ fields = params
24
+ fields['file'] = (file, open(file, 'rb'), 'text/plain')
25
+ multipart_data = MultipartEncoder(
26
+ fields=fields
27
+ )
28
+ return requests.post(url,
29
+ data=multipart_data,
30
+ headers={'Content-Type': multipart_data.content_type},
31
+ timeout=30)
32
+
net/hypki/args.py ADDED
@@ -0,0 +1,21 @@
1
+ '''
2
+ Created on 15-06-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import sys
8
+
9
+ class ArgUtils:
10
+
11
+ def getString(name, defaultvalue): # @NoSelf
12
+ for i in range(len(sys.argv)):
13
+ if sys.argv[i] == "--" + name or sys.argv[i] == "-" + name:
14
+ return sys.argv[i + 1].strip()
15
+ return defaultvalue
16
+
17
+ def isArgPresent(name): # @NoSelf
18
+ for i in range(len(sys.argv)):
19
+ if sys.argv[i] == "--" + name or sys.argv[i] == "-" + name:
20
+ return True
21
+ return False
net/hypki/asserts.py ADDED
@@ -0,0 +1,12 @@
1
+ '''
2
+ Created on 15-06-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import sys
8
+ from builtins import Exception
9
+
10
+ def assertTrue(condition, msg):
11
+ if condition is False:
12
+ raise Exception("Assertion failed", msg)
net/hypki/io.py ADDED
@@ -0,0 +1,71 @@
1
+ '''
2
+ Created on 08-05-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import os.path
8
+ import re
9
+ import subprocess
10
+ import sys
11
+ import time
12
+ import urllib.request
13
+ from net.hypki.regex import *
14
+ from net.hypki.log import *
15
+
16
+ def absolutePath(path):
17
+ return os.__path.abspath(path)
18
+
19
+ def findFolders(path):
20
+ dirsAll = []
21
+ for dirName, dirs, files in os.walk(path):
22
+ dirsAll.append(dirName)
23
+ # path = root.split('/')
24
+ # print (len(path) - 1) *'---' , os.path.basename(root)
25
+ # for file in files:
26
+ # print len(path)*'---', file
27
+ return dirsAll
28
+
29
+ def readString( prompt ):
30
+ print(bcolors.OKBLUE + prompt + bcolors.ENDC, end = '', flush = True)
31
+ return sys.stdin.readline().strip()
32
+
33
+ def linux_cmd(cmd, workingDir = None, printImmediatelly = False):
34
+ if printImmediatelly:
35
+ debug("linux cmd: " + cmd);
36
+ result = []
37
+ s = subprocess.Popen(cmd, cwd = workingDir, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
38
+ for line in s.stdout.readlines():
39
+ strLine = str(line).rstrip()
40
+ # if printImmediatelly is False:
41
+ result.append(firstGroup(strLine, 'b\'(.*)\\\\n\''))
42
+ # else:
43
+ if printImmediatelly:
44
+ print(firstGroup(strLine, 'b\'(.*)\\\\n\''))
45
+ return result
46
+
47
+ def linux_cmd_fork(cmd):
48
+ # info("linux cmd fork: " + cmd);
49
+ os.system(cmd)
50
+
51
+ def is_file_exists(path):
52
+ return os.path.exists(path)
53
+
54
+ def url_read(url):
55
+ resp = urllib.request.urlopen(url)
56
+ return resp.read().decode('utf-8')
57
+
58
+ def read_file(path):
59
+ with open(path, 'r') as content_file:
60
+ return content_file.read()
61
+
62
+ def append_to_file(path, line):
63
+ with open(path, 'a') as content_file:
64
+ content_file.write('\n')
65
+ content_file.write(line)
66
+
67
+ def file_save(path, content):
68
+ myFile = open(path, 'w', encoding = 'UTF8')
69
+ myFile.write(content)
70
+ myFile.close()
71
+
net/hypki/log.py ADDED
@@ -0,0 +1,76 @@
1
+ '''
2
+ Created on 08-05-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import os.path
8
+ import re
9
+ import subprocess
10
+ import sys
11
+ import time
12
+ import urllib.request
13
+
14
+ TRACE = False
15
+ DEBUG = True
16
+ INFO = True
17
+
18
+ class bcolors:
19
+ HEADER = '\033[95m'
20
+ OKBLUE = '\033[94m'
21
+ OKGREEN = '\033[92m'
22
+ RED = '\033[91m'
23
+ WARNING = '\033[93m'
24
+ FAIL = '\033[91m'
25
+ ENDC = '\033[0m'
26
+
27
+ def disable(self):
28
+ self.HEADER = ''
29
+ self.OKBLUE = ''
30
+ self.OKGREEN = ''
31
+ self.RED = ''
32
+ self.WARNING = ''
33
+ self.FAIL = ''
34
+ self.ENDC = ''
35
+
36
+ def green( msg ):
37
+ print(bcolors.OKGREEN + str(msg) + bcolors.ENDC)
38
+ return
39
+
40
+ def blue( msg ):
41
+ print(bcolors.OKBLUE + msg + bcolors.ENDC)
42
+ return
43
+
44
+ def red( msg ):
45
+ print(bcolors.RED + msg + bcolors.ENDC)
46
+ return
47
+
48
+ def msg( msg ):
49
+ print(bcolors.OKBLUE + msg + bcolors.ENDC)
50
+ return
51
+
52
+ def trace( parameters ):
53
+ if (TRACE):
54
+ print("TRACE " + parameters)
55
+ return
56
+
57
+ def debug(parameters, printLogLevel = True, printNewLine = True):
58
+ if (DEBUG):
59
+ print(("DEBUG " if printLogLevel else '') + str(parameters), end = ('\n' if printNewLine else ''))
60
+ return
61
+
62
+ def log( parameters ):
63
+ debug(parameters)
64
+
65
+ def info( parameters, printLogLevel = True, printNewLine = True):
66
+ if (INFO):
67
+ print(("INFO " if printLogLevel else '') + str(parameters), end = ('\n' if printNewLine else ''))
68
+ return
69
+
70
+ def warn(parameters, printLogLevel = True, printNewLine = True):
71
+ print(bcolors.WARNING + "WARN " + str(parameters) + bcolors.ENDC)
72
+ return
73
+
74
+ def error( parameters, printLogLevel = True, printNewLine = True, end = '' ):
75
+ print(bcolors.FAIL + "ERROR " + str(parameters) + bcolors.ENDC, end, file=sys.stderr)
76
+ return
net/hypki/math.py ADDED
@@ -0,0 +1,13 @@
1
+
2
+ import subprocess
3
+ import sys
4
+ import re
5
+ import os
6
+ from net.hypki.io import *
7
+ from net.hypki.args import *
8
+
9
+ def math_eval(s):
10
+ try:
11
+ return eval(s)
12
+ except SyntaxError:
13
+ return 0
net/hypki/random.py ADDED
@@ -0,0 +1,14 @@
1
+ '''
2
+ Created on 18-07-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import os
8
+ import uuid
9
+ import base64
10
+
11
+ def nextUuid():
12
+ return str(uuid.uuid4())
13
+ # r_uuid = base64.urlsafe_b64encode(uuid.uuid4().bytes)
14
+ # return str(r_uuid.replace('=', ''))
net/hypki/regex.py ADDED
@@ -0,0 +1,50 @@
1
+ '''
2
+ Created on 08-05-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ from net.hypki import *
8
+ import os.path
9
+ import re
10
+ import subprocess
11
+ import sys
12
+ import time
13
+ # import urllib.request
14
+
15
+ def replace(string, searchPattern, replacement):
16
+ return re.sub(searchPattern, replacement, string, count=0, flags=0)
17
+
18
+ def firstGroup(s, regex):
19
+ r = re.compile(regex)
20
+ m = r.search(s)
21
+ if m:
22
+ return m.group(1)
23
+ return ""
24
+
25
+ def allGroups(s, regex):
26
+ r = re.compile(regex)
27
+ m = r.search(s)
28
+ if m:
29
+ return m.groups()
30
+ return ""
31
+
32
+ def isLong(strNumber):
33
+ return matches(strNumber, "^[\d]+$")
34
+
35
+ def isDouble(strNumber):
36
+ return matches(strNumber, "[\d]+\.[\d\+\-eE]+")
37
+
38
+ def matches(s, regex):
39
+ r = re.compile(regex)
40
+ m = r.search(s)
41
+ if m:
42
+ return True
43
+ return False
44
+
45
+ def matchesIgnoreCase(s, regex):
46
+ r = re.compile(regex, re.IGNORECASE)
47
+ m = r.search(s)
48
+ if m:
49
+ return True
50
+ return False
net/hypki/system.py ADDED
@@ -0,0 +1,28 @@
1
+ '''
2
+ Created on 18-07-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import inspect
8
+ import os.path
9
+ import re
10
+ import subprocess
11
+ import sys
12
+ import time
13
+ import urllib.request
14
+
15
+
16
+ def getThisScriptPath():
17
+ return inspect.stack()[1][1] # inspect.getfile(inspect.currentframe()) # script filename (usually with path)
18
+
19
+
20
+ def getThisScriptDirectory():
21
+ return os.__path.dirname(os.__path.abspath(inspect.stack()[1][1])) # script directory
22
+
23
+
24
+ def getSystemVariable(name):
25
+ for param in os.environ.keys():
26
+ if param == name:
27
+ return os.environ[param]
28
+ return None
File without changes
@@ -0,0 +1,91 @@
1
+ from astropy.constants import G, M_earth, R_earth
2
+ from astropy import units as u
3
+ import numpy as np
4
+
5
+ mu = G.value*M_earth.value
6
+ Re = R_earth.value
7
+
8
+ #Test vectors
9
+ r_test = np.array([Re + 600.0*1000, 0, 50])
10
+ v_test = np.array([0, 6.5 * 1000, 0])
11
+ t = 0
12
+
13
+
14
+ def cart_2_kep(r_vec,v_vec):
15
+ #1
16
+ h_bar = np.cross(r_vec,v_vec)
17
+ h = np.linalg.norm(h_bar)
18
+ #2
19
+ r = np.linalg.norm(r_vec)
20
+ v = np.linalg.norm(v_vec)
21
+ #3
22
+ E = 0.5*(v**2) - mu/r
23
+ #4
24
+ a = -mu/(2*E)
25
+ #5
26
+ e = np.sqrt(1 - (h**2)/(a*mu))
27
+ #6
28
+ i = np.arccos(h_bar[2]/h)
29
+ #7
30
+ omega_LAN = np.arctan2(h_bar[0],-h_bar[1])
31
+ #8
32
+ #beware of division by zero here
33
+ lat = np.arctan2(np.divide(r_vec[2],(np.sin(i))),\
34
+ (r_vec[0]*np.cos(omega_LAN) + r_vec[1]*np.sin(omega_LAN)))
35
+ #9
36
+ p = a*(1-e**2)
37
+ nu = np.arctan2(np.sqrt(p/mu) * np.dot(r_vec,v_vec), p-r)
38
+ #10
39
+ omega_AP = lat - nu
40
+ #11
41
+ EA = 2*np.arctan(np.sqrt((1-e)/(1+e)) * np.tan(nu/2))
42
+ #12
43
+ n = np.sqrt(mu/(a**3))
44
+ T = t - (1/n)*(EA - e*np.sin(EA))
45
+
46
+ return a,e,i,omega_AP,omega_LAN,T, EA
47
+
48
+ def kep_2_cart(a,e,i,omega_AP,omega_LAN,T, EA):
49
+
50
+ #1
51
+ n = np.sqrt(mu/(a**3))
52
+ M = n*(t - T)
53
+ #2
54
+ MA = EA - e*np.sin(EA)
55
+ #3
56
+ #
57
+ # ERROR WAS HERE
58
+ #nu = 2*np.arctan(np.sqrt((1-e)/(1+e)) * np.tan(EA/2))
59
+ nu = 2*np.arctan(np.sqrt((1+e)/(1-e)) * np.tan(EA/2))
60
+ #4
61
+ r = a*(1 - e*np.cos(EA))
62
+ #5
63
+ h = np.sqrt(mu*a * (1 - e**2))
64
+ #6
65
+ Om = omega_LAN
66
+ w = omega_AP
67
+
68
+ X = r*(np.cos(Om)*np.cos(w+nu) - np.sin(Om)*np.sin(w+nu)*np.cos(i))
69
+ Y = r*(np.sin(Om)*np.cos(w+nu) + np.cos(Om)*np.sin(w+nu)*np.cos(i))
70
+ Z = r*(np.sin(i)*np.sin(w+nu))
71
+
72
+ #7
73
+ p = a*(1-e**2)
74
+
75
+ V_X = (X*h*e/(r*p))*np.sin(nu) - (h/r)*(np.cos(Om)*np.sin(w+nu) + \
76
+ np.sin(Om)*np.cos(w+nu)*np.cos(i))
77
+ V_Y = (Y*h*e/(r*p))*np.sin(nu) - (h/r)*(np.sin(Om)*np.sin(w+nu) - \
78
+ np.cos(Om)*np.cos(w+nu)*np.cos(i))
79
+ V_Z = (Z*h*e/(r*p))*np.sin(nu) + (h/r)*(np.cos(w+nu)*np.sin(i))
80
+
81
+ return [X,Y,Z],[V_X,V_Y,V_Z]
82
+
83
+ a,e,i,omega_AP,omega_LAN,T, EA = cart_2_kep(r_test,v_test)
84
+ r_test2, v_test2 = kep_2_cart(a,e,i,omega_AP,omega_LAN,T, EA)
85
+
86
+
87
+ # print(r_test2 - r_test)
88
+ # print(v_test2 - v_test)
89
+ for x in range(100):
90
+ r_test2, v_test2 = kep_2_cart(a,e,i,omega_AP+x,omega_LAN,T, EA)
91
+ print(r_test2, v_test2)
@@ -0,0 +1,34 @@
1
+ '''
2
+ Created on 21-06-2013
3
+
4
+ @author: ahypki
5
+ '''
6
+
7
+ import numpy as np
8
+ import scipy.signal
9
+
10
+ a = np.zeros(100)
11
+ a[0] = 1
12
+ a[1] = 2
13
+ a[2] = 3
14
+ a[3] = 4
15
+ a[4] = 3
16
+ a[5] = 1
17
+ a[6] = 0
18
+ a[7] = -1
19
+ a[8] = 2
20
+ a[9] = 3
21
+ a[10] = 2
22
+ a[11] = 1
23
+ print(a)
24
+ res = scipy.signal.argrelmax(a)
25
+ print(res)
26
+
27
+ b = np.zeros(100)
28
+ b[0] = 1
29
+ b[1] = 2
30
+ b[2] = 1
31
+ b[3] = 2
32
+ bb = np.trim_zeros(b)
33
+ print(bb.mean())
34
+ print(bb.std())