Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NIRS_Workflow
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CEFE
PACE
NIRS_Workflow
Commits
7988d10c
Commit
7988d10c
authored
11 months ago
by
DIANE
Browse files
Options
Downloads
Patches
Plain Diff
more dependencies loading
parent
c9f13282
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
Class_Mod/DxReader.py
+92
-0
92 additions, 0 deletions
Class_Mod/DxReader.py
Packages.py
+2
-0
2 additions, 0 deletions
Packages.py
with
94 additions
and
0 deletions
Class_Mod/DxReader.py
0 → 100644
+
92
−
0
View file @
7988d10c
from
Packages
import
*
class
DxReader
:
'''
This module is designed to help retrieve spectral data as well as metadata of smaples from jcamp file
'''
def
__init__
(
self
,
path
):
self
.
__path
=
path
.
replace
(
'
\\
'
,
'
/
'
)
self
.
__dxfile
=
jc
.
jcamp_readfile
(
self
.
__path
)
# Access samples data
self
.
__nb
=
self
.
__dxfile
[
'
blocks
'
]
# Get the total number of blocks = The total number of scanned samples
self
.
__list_of_blocks
=
self
.
__dxfile
[
'
children
'
]
# Store all blocks within a a list
self
.
__wl
=
self
.
__list_of_blocks
[
0
][
"
x
"
]
# Wavelengths/frequencies/range
# Start retreiving the data
specs
=
np
.
zeros
((
self
.
__nb
,
len
(
self
.
__list_of_blocks
[
0
][
"
y
"
])),
dtype
=
float
)
# preallocate a np matrix for sotoring spectra
self
.
idx
=
np
.
arange
(
self
.
__nb
)
# This list is designed to store samples name
self
.
__met
=
{}
for
i
in
range
(
self
.
__nb
):
# Loop over the blocks
specs
[
i
]
=
self
.
__list_of_blocks
[
i
][
'
y
'
]
block_met
=
{
'
name
'
:
self
.
__list_of_blocks
[
i
][
'
title
'
],
'
origin
'
:
self
.
__list_of_blocks
[
i
][
'
origin
'
],
'
date
'
:
self
.
__list_of_blocks
[
i
][
'
date
'
],
'
time
'
:
self
.
__list_of_blocks
[
i
][
'
time
'
],
'
spectrometer/data system
'
:
self
.
__list_of_blocks
[
i
][
'
spectrometer/data system
'
],
'
instrumental parameters
'
:
self
.
__list_of_blocks
[
i
][
'
instrumental parameters
'
],
'
xunits
'
:
self
.
__list_of_blocks
[
i
][
'
xunits
'
],
'
yunits
'
:
self
.
__list_of_blocks
[
i
][
'
yunits
'
],
'
xfactor
'
:
self
.
__list_of_blocks
[
i
][
'
xfactor
'
],
'
yfactor
'
:
self
.
__list_of_blocks
[
i
][
'
yfactor
'
],
'
firstx
'
:
self
.
__list_of_blocks
[
i
][
'
firstx
'
],
'
lastx
'
:
self
.
__list_of_blocks
[
i
][
'
lastx
'
],
'
firsty
'
:
self
.
__list_of_blocks
[
i
][
'
firsty
'
],
'
miny
'
:
self
.
__list_of_blocks
[
i
][
'
miny
'
],
'
maxy
'
:
self
.
__list_of_blocks
[
i
][
'
maxy
'
],
'
npoints
'
:
self
.
__list_of_blocks
[
i
][
'
npoints
'
],
'
concentrations
'
:
self
.
__list_of_blocks
[
i
][
'
concentrations
'
],
'
deltax
'
:
self
.
__list_of_blocks
[
i
][
'
deltax
'
],
}
self
.
__met
[
f
'
{
i
}
'
]
=
block_met
self
.
metadata_
=
pd
.
DataFrame
(
self
.
__met
).
T
self
.
spectra
=
pd
.
DataFrame
(
np
.
fliplr
(
specs
),
columns
=
self
.
__wl
[::
-
1
])
# Storing spectra in a pd.dataframe
#### Concentrarions
self
.
pattern
=
r
"
\(([^,]+),(\d+(\.\d+)?),([^)]+)
"
aa
=
self
.
__list_of_blocks
[
0
][
'
concentrations
'
]
a
=
'
\n
'
.
join
(
line
for
line
in
aa
.
split
(
'
\n
'
)
if
"
NCU
"
not
in
line
and
"
<<undef>>
"
not
in
line
)
n_elements
=
a
.
count
(
'
(
'
)
## Get the name of analyzed chamical elements
elements_name
=
[]
for
match
in
re
.
findall
(
self
.
pattern
,
a
):
elements_name
.
append
(
match
[
0
])
## Retrieve concentrationds
df
=
self
.
metadata_
[
'
concentrations
'
]
cc
=
{}
for
i
in
range
(
self
.
metadata_
.
shape
[
0
]):
cc
[
df
.
index
[
i
]]
=
self
.
conc
(
df
[
str
(
i
)])
### dataframe conntaining chemical data
self
.
chem_data
=
pd
.
DataFrame
(
cc
,
index
=
elements_name
).
T
### Method for retrieving the concentration of a single sample
def
conc
(
self
,
sample
):
prep
=
'
\n
'
.
join
(
line
for
line
in
sample
.
split
(
'
\n
'
)
if
"
NCU
"
not
in
line
and
"
<<undef>>
"
not
in
line
)
c
=
[]
for
match
in
re
.
findall
(
self
.
pattern
,
prep
):
c
.
append
(
match
[
1
])
concentration
=
np
.
array
(
c
)
return
concentration
@property
def
specs_df_
(
self
):
return
self
.
spectra
@property
def
md_df_
(
self
):
return
self
.
metadata_
@property
def
chem_data_
(
self
):
return
self
.
chem_data
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Packages.py
+
2
−
0
View file @
7988d10c
...
...
@@ -3,6 +3,8 @@
import
os
import
sys
import
csv
import
re
import
jcamp
import
random
import
numpy
as
np
import
pandas
as
pd
...
...
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