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
24511ca4
Commit
24511ca4
authored
2 years ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
first Version of DCC JSON Creation Functions
parent
5d26f82e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pccDccTools.py
+36
-2
36 additions, 2 deletions
pccDccTools.py
pyDCCTestAndExamples.py
+8
-1
8 additions, 1 deletion
pyDCCTestAndExamples.py
with
44 additions
and
3 deletions
pccDccTools.py
+
36
−
2
View file @
24511ca4
...
...
@@ -53,10 +53,14 @@ revd = dict([reversed(i) for i in DsiASCICOnversion.items()])
DsiASCICOnversion
.
update
(
revd
)
del
revd
def
npArrayToXMLList
(
array
):
if
array
.
ndim
!=
1
:
raise
RuntimeError
(
"
conversion onlly supportet for 1D Array but Array is
"
+
str
(
array
.
ndim
)
+
"
dimensional
"
)
return
str
(
array
).
replace
(
'
\n
'
,
''
).
replace
(
'
.
'
,
'
.0
'
)
class
dsiVector
:
def
__init__
(
self
,
values
:
np
.
ndarray
,
uncer
:
Union
[
np
.
ndarray
,
None
],
quantity
:
str
,
unit
:
str
,
uncerType
:
str
=
"
absolute
"
)
->
dsiVector
:
def
__init__
(
self
,
values
:
np
.
ndarray
,
uncer
:
Union
[
np
.
ndarray
,
None
],
quantity
:
str
,
unit
:
str
,
uncerType
:
str
=
"
absolute
"
,
refType
:
str
=
"
dummy_xxx
"
,
uncerParams
:
dict
=
{
'
coverageFactor
'
:
2.0
,
'
coverageProbability
'
:
0.95
,
'
distribution
'
:
'
normal
'
}
)
->
dsiVector
:
'''
:param values:
...
...
@@ -69,6 +73,8 @@ class dsiVector:
self
.
dsiToolsVersion
=
DSITOOLSVERSION
self
.
quantity
=
str
(
quantity
)
self
.
unit
=
str
(
unit
)
self
.
refType
=
str
(
refType
)
self
.
uncerParams
=
uncerParams
if
type
(
values
)
==
np
.
array
:
self
.
values
=
values
else
:
...
...
@@ -170,7 +176,35 @@ class dsiVector:
dictToDump
=
self
.
__dict__
dictToDump
[
'
uncer
'
]
=
None
return
json
.
dumps
(
dictToDump
,
cls
=
dsiJSONEncoder
)
def
toDCCrealListXMLList
(
self
,
uncer
:
bool
=
True
):
if
not
uncer
:
DCCrealListXMLList
=
{
'
si:valueXMLList
'
:{
'
#text
'
:
npArrayToXMLList
(
self
.
values
)},
'
si:unitXMLList
'
:{
'
#text
'
:
self
.
unit
}}
if
uncer
:
if
self
.
uncer
is
not
None
:
#self.uncerParams={'coverageFactor':2.0,'coverageProbability':0.95,'distribution':'normal'}
expandeduncerDict
=
self
.
uncerParams
expandeduncerDict
[
'
si:uncertaintyXMLList
'
]
=
npArrayToXMLList
(
self
.
uncer
)
#for uncerParamKey in self.uncerParams.keys():
# expandeduncerDict['si:'+str(uncerParamKey)+'XMLList']=str(self.uncerParams[uncerParamKey])#add every key
DCCrealListXMLList
=
{
'
si:valueXMLList
'
:{
'
#text
'
:
npArrayToXMLList
(
self
.
values
)},
'
si:unitXMLList
'
:{
'
#text
'
:
self
.
unit
},
'
si:expandedUncXMLList
'
:
expandeduncerDict
}
else
:
raise
RuntimeWarning
(
"
No uncer in
"
+
str
(
self
)
+
"
Ignoring uncer
"
)
DCCrealListXMLList
=
{
'
si:valueXMLList
'
:
{
'
#text
'
:
npArrayToXMLList
(
self
.
values
)},
'
si:unitXMLList
'
:
{
'
#text
'
:
self
.
unit
}}
return
DCCrealListXMLList
def
toDCCQuantity
(
self
,
uncer
:
Union
[
bool
,
str
]
=
True
):
resultDict
=
{
'
@refType
'
:
self
.
refType
,
'
dcc:name
'
:{
'
dcc:content
'
:[{
'
@lang
'
:
'
de
'
,
'
#text
'
:
str
(
self
.
quantity
)}]},
#todo add multi language Support
'
dcc:realXMLList
'
:
self
.
toDCCrealListXMLList
(
bool
(
uncer
))}
if
uncer
in
[
'
relative
'
,
'
rel
'
]:
resultDict
[
'
dcc:relativeUncertainty
'
]
=
{
'
dcc:relativeUncertainty
'
:{
'
dcc:relativeUncertaintyXmlList
'
:{
'
si:valueXMLList
'
:
npArrayToXMLList
(
self
.
__getitem__
(
'
uncer_rel
'
)),
'
si:unitXMLList
'
:{
'
#text
'
:
r
'
\one
'
}}}}
return
resultDict
def
__getitem__
(
self
,
item
):
# print(key)
if
type
(
item
)
==
int
:
...
...
This diff is collapsed.
Click to expand it.
pyDCCTestAndExamples.py
+
8
−
1
View file @
24511ca4
...
...
@@ -9,6 +9,7 @@ if __name__ == "__main__":
testDsiVectors
=
[
testDSiVectorFreq
,
testDsiVectorMag
,
testDsiVectorPhase
,
testDsiVectorFreqWOUncer
]
serilizedStrs
=
[]
loadedVectors
=
[]
for
testDSiVector
in
testDsiVectors
:
print
(
"
__________ New Vector________________
"
)
print
(
str
(
testDSiVector
))
...
...
@@ -49,4 +50,10 @@ if __name__ == "__main__":
print
(
reconstructedMultiVector
[
'
Phase
'
,
1.25
])
######## Devel #######
examlpeJsonDict
=
{
'
dcc:list
'
:
{
'
dcc:quantity
'
:
[{
'
@refType
'
:
'
basic_xxx
'
,
'
dcc:name
'
:
{
'
dcc:content
'
:
[{
'
@lang
'
:
'
de
'
,
'
#text
'
:
'
Frequenz
'
},
{
'
@lang
'
:
'
en
'
,
'
#text
'
:
'
en
'
}]},
'
si:realListXMLList
'
:
{
'
si:valueXMLList
'
:
{
'
#text
'
:
'
10 12.5 16 20 25
'
},
'
si:unitXMLList
'
:
{
'
#text
'
:
'
\\
second
\\
tothe{-1}
'
}}},
{
'
@refType
'
:
'
basic_xxx
'
,
'
dcc:name
'
:
{
'
dcc:content
'
:
[{
'
@lang
'
:
'
de
'
,
'
#text
'
:
'
Beschleunigungsamplitude
'
},
{
'
@lang
'
:
'
en
'
,
'
#text
'
:
'
en
'
}]},
'
si:realListXMLList
'
:
{
'
si:valueXMLList
'
:
{
'
#text
'
:
'
5 5 5 10 10
'
},
'
si:unitXMLList
'
:
{
'
#text
'
:
'
\\
metre
\\
second
\\
tothe{-2}
'
}}},
{
'
@refType
'
:
'
basic_xxx
'
,
'
dcc:name
'
:
{
'
dcc:content
'
:
[{
'
@lang
'
:
'
de
'
,
'
#text
'
:
'
Ãœbertragungskoeffizient Betrag
'
},
{
'
@lang
'
:
'
en
'
,
'
#text
'
:
'
en
'
}]},
'
si:realListXMLList
'
:
{
'
si:valueXMLList
'
:
{
'
#text
'
:
'
0.1301 0.1302 0.1302 0.1302 0.1302
'
},
'
si:unitXMLList
'
:
{
'
#text
'
:
'
\\
pico
\\
coulomb
\\
metre
\\
tothe{-1}
\\
second
\\
tothe{2}
'
},
'
si:expandedUncXMLList
'
:
{
'
si:uncertaintyXMLList
'
:
{
'
#text
'
:
'
0.002602 0.002604 0.002604 0.002604 0.002604
'
},
'
si:coverageFactorXMLList
'
:
{
'
#text
'
:
'
2
'
},
'
si:coverageProbabilityXMLList
'
:
{
'
#text
'
:
'
0.95
'
},
'
si:distributionXMLList
'
:
{
'
#text
'
:
'
normal
'
}}},
'
dcc:relativeUncertainty
'
:
{
'
dcc:relativeUncertaintyXmlList
'
:
{
'
si:valueXMLList
'
:
{
'
#text
'
:
'
0.002 0.002 0.002 0.002 0.002
'
},
'
si:unitXMLList
'
:
{
'
#text
'
:
'
\\
one
'
}}}},
{
'
@refType
'
:
'
basic_xxx
'
,
'
dcc:name
'
:
{
'
dcc:content
'
:
[{
'
@lang
'
:
'
de
'
,
'
#text
'
:
'
Ãœbertragungskoeffizient Phasenverschiebung
'
},
{
'
@lang
'
:
'
en
'
,
'
#text
'
:
'
en
'
}]},
'
si:realListXMLList
'
:
{
'
si:valueXMLList
'
:
{
'
#text
'
:
'
-0.02 -0.03 -0.02 -0.02 -0.01
'
},
'
si:unitXMLList
'
:
{
'
#text
'
:
'
\\
degree
'
},
'
si:expandedUncXMLList
'
:
{
'
si:uncertaintyXMLList
'
:
{
'
#text
'
:
'
0.3 0.3 0.3 0.3 0.3
'
},
'
si:coverageFactorXMLList
'
:
{
'
#text
'
:
'
2
'
},
'
si:coverageProbabilityXMLList
'
:
{
'
#text
'
:
'
0.95
'
},
'
si:distributionXMLList
'
:
{
'
#text
'
:
'
normal
'
}}}}],
'
@_Comment
'
:
'
\n
<dcc:measurementMetaData>
\n
<dcc:metaData>
\n
<dcc:declaration>
\n
<dcc:content lang=
"
de
"
>Hier steht der Text mit Leerzeichen.</dcc:content>
\n
</dcc:declaration>
\n
<dcc:valid>false false true fals false</dcc:valid>
\n
</dcc:metaData>
\n
</dcc:measurementMetaData>
\n
'
}}
print
(
"
Done
"
)
print
(
loadedVectors
[
0
].
toDCCQuantity
())
print
(
loadedVectors
[
0
].
toDCCQuantity
(
uncer
=
False
))
print
(
loadedVectors
[
0
].
toDCCQuantity
(
uncer
=
'
rel
'
))
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