Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pyDCCandDBTools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benedikt
pyDCCandDBTools
Commits
8a39a4d3
Commit
8a39a4d3
authored
2 years ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
added type Hints
parent
20ddb972
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pccDccTools.py
+24
-19
24 additions, 19 deletions
pccDccTools.py
with
24 additions
and
19 deletions
pccDccTools.py
+
24
−
19
View file @
8a39a4d3
from
__future__
import
annotations
#for type annotations
import
json
import
numpy
as
np
import
scipy.interpolate
...
...
@@ -5,6 +9,8 @@ import scipy.interpolate
import
scipy
as
sp
import
functools
DSITOOLSVERSION
=
'
0.1.0
'
def
checkDSiToolsVersionCompatibility
(
versionToCheck
):
...
...
@@ -40,7 +46,7 @@ del revd
class
dsiVector
:
def
__init__
(
self
,
values
,
uncer
,
quantity
,
unit
,
uncerType
=
"
absolute
"
)
:
def
__init__
(
self
,
values
:
np
.
ndarray
,
uncer
:
np
.
ndarray
,
quantity
:
str
,
unit
:
str
,
uncerType
:
str
=
"
absolute
"
)
->
dsiVector
:
'''
:param values:
...
...
@@ -72,11 +78,10 @@ class dsiVector:
else
:
raise
NotImplementedError
(
"
uncetType
"
+
str
(
uncerType
)
+
r
"
is not supoorted/implemented use [
'
absolute
'
,
'
rel
'
,
'
relPercent
'
,
'
relPPM
'
]
"
)
self
.
isInterPolatedData
=
False
@classmethod
def
fromdict
(
cls
,
dict
)
:
def
fromdict
(
cls
,
dict
:
dict
)
->
dsiVector
:
'''
:param dict:
...
...
@@ -96,7 +101,7 @@ class dsiVector:
return
instance
@classmethod
def
fromjson
(
cls
,
jsonstr
)
:
def
fromjson
(
cls
,
jsonstr
:
str
)
->
dsiVector
:
'''
:param jsonstr:
...
...
@@ -105,7 +110,7 @@ class dsiVector:
dict
=
json
.
loads
(
jsonstr
)
return
cls
.
fromdict
(
dict
)
def
InterPolatedValuesTODSIVector
(
self
,
values
,
uncer
)
:
def
InterPolatedValuesTODSIVector
(
self
,
values
:
np
.
ndarray
,
uncer
:
np
.
ndarray
)
->
dsiVector
:
'''
:param values:
...
...
@@ -134,7 +139,7 @@ class dsiVector:
resultDSiVector
.
__dict__
[
"
self.isInterPolatedData
"
]
=
True
return
resultDSiVector
def
jsonDumps
(
self
):
def
jsonDumps
(
self
)
->
str
:
'''
:return:
...
...
@@ -181,7 +186,7 @@ class dsiVector:
list
(
self
.
__dict__
.
keys
()))
+
r
"
or
'
uncer_relPercent
'
,
'
uncer_relPPM
"
+
"
dsiVector[values,int] or dsiVector[
'
uncer
'
,int]
"
)
def
__str__
(
self
):
def
__str__
(
self
)
->
str
:
length
=
self
[
'
values
'
].
size
interpolatedPrfix
=
""
if
self
.
isInterPolatedData
:
...
...
@@ -201,12 +206,12 @@ class dsiVector:
string
=
string
+
firstblock
+
'
...
'
+
secondblock
return
string
def
__repr__
(
self
):
def
__repr__
(
self
)
->
str
:
return
str
(
self
.
dataType
)
+
"
@
"
+
hex
(
id
(
self
))
+
'
'
+
self
.
__str__
()
class
dsiMultiVector
:
def
__init__
(
self
,
indexVector
,
valueVectors
,
interpolationTypes
=
None
)
:
#TODO add interpolation args
def
__init__
(
self
,
indexVector
:
dsiVector
,
valueVectors
:
dsiVector
,
interpolationTypes
:
str
=
'
None
'
)
->
dsiMultiVector
:
#TODO add interpolation args
'''
:param indexVector:
...
...
@@ -217,12 +222,12 @@ class dsiMultiVector:
self
.
dsiToolsVersion
=
DSITOOLSVERSION
self
.
index
=
indexVector
self
.
valueVectorsQuantitys
=
[]
if
interpolationTypes
!=
None
:
if
interpolationTypes
!=
'
None
'
:
self
.
interpolationTypes
=
interpolationTypes
self
.
interpolators
=
{}
for
valueVector
in
valueVectors
:
self
.
valueVectorsQuantitys
.
append
(
valueVector
[
'
quantity
'
])
if
interpolationTypes
!=
None
:
if
interpolationTypes
!=
'
None
'
:
try
:
interPolatorTypeToUse
=
interpolationTypes
[
valueVector
[
'
quantity
'
]]
except
KeyError
:
...
...
@@ -241,7 +246,7 @@ class dsiMultiVector:
print
(
"
INIT Done
"
)
@classmethod
def
fromdict
(
cls
,
dict
)
:
def
fromdict
(
cls
,
dict
:
dict
)
->
dsiMultiVector
:
'''
:param dict:
...
...
@@ -272,7 +277,7 @@ class dsiMultiVector:
return
instance
@classmethod
def
fromjson
(
cls
,
jsonstr
)
:
def
fromjson
(
cls
,
jsonstr
:
str
)
->
dsiMultiVector
:
'''
:param jsonstr:
...
...
@@ -298,7 +303,7 @@ class dsiMultiVector:
except
KeyError
as
ke
:
raise
ke
def
jsonDumps
(
self
):
def
jsonDumps
(
self
)
->
str
:
return
json
.
dumps
(
self
.
__dict__
,
cls
=
dsiJSONEncoder
)
def
__repr__
(
self
):
...
...
@@ -307,7 +312,7 @@ class dsiMultiVector:
class
dsiInterpolator
:
def
__init__
(
self
,
indexVector
,
dataVector
,
type
)
:
def
__init__
(
self
,
indexVector
:
dsiVector
,
dataVector
:
dsiVector
,
type
:
str
)
->
dsiInterpolator
:
'''
:param indexVector:
...
...
@@ -330,10 +335,10 @@ class dsiInterpolator:
else
:
raise
KeyError
(
"
Interpolator Kind >
"
+
str
(
type
)
+
"
not supported, no interpolator created. Use
'
linear
'
,
'
nearest
'
,
'
nearest-up
'
,
'
zero
'
,
'
slinear
'
,
'
quadratic
'
,
'
cubic
'
,
'
previous
'
or
'
next
'"
)
def
__repr__
(
self
):
def
__repr__
(
self
)
->
str
:
return
str
(
self
.
dataType
)
+
"
@
"
+
hex
(
id
(
self
))
+
'
'
+
str
(
self
.
type
)
+
'
'
+
str
(
self
.
interpolatorSoftware
)
+
'
'
+
str
(
self
.
interPolatorSoftwareVersion
)
+
'
X>
'
+
str
(
self
.
indexQuantity
)
+
'
Y>
'
+
str
(
self
.
dataQuantity
)
def
toDict
(
self
):
def
toDict
(
self
)
->
dict
:
'''
:return:
...
...
@@ -341,9 +346,9 @@ class dsiInterpolator:
exclude_keys
=
[
'
interpolators
'
,
'
dataVector
'
,
'
indexVector
'
]
return
{
k
:
self
.
__dict__
[
k
]
for
k
in
set
(
list
(
self
.
__dict__
.
keys
()))
-
set
(
exclude_keys
)}
def
__str__
(
self
):
def
__str__
(
self
)
->
str
:
return
self
.
__repr__
()
def
__call__
(
self
,
args
)
:
def
__call__
(
self
,
args
:
np
.
array
)
->
dsiVector
:
return
self
.
dataVector
.
InterPolatedValuesTODSIVector
(
self
.
interpolators
[
'
values
'
](
args
),
self
.
interpolators
[
'
uncer
'
](
args
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment