Project management

from pathlib import Path

[1]:
from spectrochempy import NDDataset, Project, pathclean
from spectrochempy import preferences as prefs
  SpectroChemPy's API - v.0.6.5
© Copyright 2014-2023 - A.Travert & C.Fernandez @ LCS

Project creation

We can easily create a new project to store various datasets

[2]:
proj = Project()

As we did not specify a name, a name has been attributed automatically:

[3]:
proj.name
[3]:
'Project-Project_32c8852c'

To get the signature of the object, one can use the usual ‘?’. Uncomment the following line to check

[4]:
# Project?

Let’s change this name

[5]:
proj.name = "myNMRdata"
proj
[5]:
Project myNMRdata:
    (empty project)

Now we will add a dataset to the project.

First we read the dataset (here some NMR data) and we give it some name (e.g. ‘nmr n°1’)

[6]:
datadir = pathclean(prefs.datadir)
path = datadir / "nmrdata" / "bruker" / "tests" / "nmr"
nd1 = NDDataset.read_topspin(
    path / "topspin_1d", expno=1, remove_digital_filter=True, name="NMR_1D"
)
nd2 = NDDataset.read_topspin(
    path / "topspin_2d", expno=1, remove_digital_filter=True, name="NMR_2D"
)
 WARNING | (UserWarning) (196608,)cannot be shaped into(147, 1024)

To add it to the project, we use the add_dataset function for a single dataset:

[7]:
proj.add_datasets(nd1)

or add_datasets for several datasets.

[8]:
proj.add_datasets(nd1, nd2)

Display its structure

[9]:
proj
[9]:
Project myNMRdata:
    ⤷ NMR_1D (dataset)
    ⤷ NMR_2D (dataset)

It is also possible to add other projects as sub-project (using the add_project )

Remove an element from a project

[10]:
proj.remove_dataset("NMR_1D")
proj
[10]:
Project myNMRdata:
    ⤷ NMR_2D (dataset)

Get project’s elements

[11]:
proj.add_datasets(nd1, nd2)
proj
[11]:
Project myNMRdata:
    ⤷ NMR_1D (dataset)
    ⤷ NMR_2D (dataset)

We can just use the name of the element as a project attribute.

[12]:
proj.NMR_1D
[12]:
name NMR_1D
author runner@fv-az626-878
created 2023-06-06 01:33:54+00:00
DATA
title intensity
values
R[ 1078 2284 ... 0.2342 -0.1008]
I[ -1037 -2200 ... 0.06203 -0.05273]
size 12411 (complex)
DIMENSION `x`
size 12411
title F1 acquisition time
coordinates
[ 0 4 ... 4.964e+04 4.964e+04] µs
[13]:
_ = proj.NMR_1D.plot()
../../_images/userguide_project_project_25_0.png

However, this work only if the name contains no space, dot, comma, colon, etc. The only special character allowed is the underscore _ . If the name is not respecting this, then it is possible to use the following syntax (as a project behave as a dictionary). For example:

[14]:
proj["NMR_1D"].data
[14]:
array([1.08e+03-1.04e+03j, 2.28e+03-2.2e+03j, ...,    0.234+0.062j,   -0.101-0.0527j])
[15]:
proj.NMR_2D
[15]:
name NMR_2D
author runner@fv-az626-878
created 2023-06-06 01:33:54+00:00
DATA
title intensity
values
RR[[ -0.2238 -0.1985 ... -0.1662 0.03262]
[-0.006566 0.0282 ... -0.02949 -0.06717]
...
[ 0 0 ... 0 0]
[ 0 0 ... 0 0]]
RI[[ 0.06219 0.1467 ... 0.04565 0.03068]
[-0.05969 -0.08752 ... -0.05134 -0.05994]
...
[ -0 -0 ... -0 -0]
[ -0 -0 ... -0 -0]]
IR[[ -0.1623 -0.0563 ... 0.02654 -0.01094]
[ 0.1344 -0.006515 ... -0.08239 0.00516]
...
[ 0 0 ... 0 0]
[ 0 0 ... 0 0]]
II[[-0.003312 -0.001535 ... 0.02067 -0.08058]
[-0.05685 0.1174 ... 0.05831 -0.003414]
...
[ -0 -0 ... -0 -0]
[ -0 -0 ... -0 -0]]
shape (y:96(complex), x:948(complex))
DIMENSION `x`
size 948
title F2 acquisition time
coordinates
[ 0 48 ... 4.541e+04 4.546e+04] µs
DIMENSION `y`
size 96
title F1 acquisition time
coordinates
[ 0 74 ... 6956 7030] µs

Saving and loading projects

[16]:
proj
[16]:
Project myNMRdata:
    ⤷ NMR_1D (dataset)
    ⤷ NMR_2D (dataset)

Saving

[17]:
proj.save_as("NMR")
[17]:
PosixPath('/home/runner/work/spectrochempy/spectrochempy/docs/userguide/project/NMR.pscp')

Loading

[18]:
proj2 = Project.load("NMR")
[19]:
proj2
[19]:
Project NMR:
    ⤷ NMR_1D (dataset)
    ⤷ NMR_2D (dataset)
[20]:
_ = proj2.NMR_1D.plot()
../../_images/userguide_project_project_36_0.png
[21]:
proj2.NMR_2D
[21]:
name NMR_2D
author runner@fv-az626-878
created 2023-06-06 01:33:54+00:00
DATA
title intensity
values
RR[[ -0.2238 -0.1985 ... -0.1662 0.03262]
[-0.006566 0.0282 ... -0.02949 -0.06717]
...
[ 0 0 ... 0 0]
[ 0 0 ... 0 0]]
RI[[ 0.06219 0.1467 ... 0.04565 0.03068]
[-0.05969 -0.08752 ... -0.05134 -0.05994]
...
[ -0 -0 ... -0 -0]
[ -0 -0 ... -0 -0]]
IR[[ -0.1623 -0.0563 ... 0.02654 -0.01094]
[ 0.1344 -0.006515 ... -0.08239 0.00516]
...
[ 0 0 ... 0 0]
[ 0 0 ... 0 0]]
II[[-0.003312 -0.001535 ... 0.02067 -0.08058]
[-0.05685 0.1174 ... 0.05831 -0.003414]
...
[ -0 -0 ... -0 -0]
[ -0 -0 ... -0 -0]]
shape (y:96(complex), x:948(complex))
DIMENSION `x`
size 948
title F2 acquisition time
coordinates
[ 0 48 ... 4.541e+04 4.546e+04] µs
DIMENSION `y`
size 96
title F1 acquisition time
coordinates
[ 0 74 ... 6956 7030] µs
[22]:
_ = proj.NMR_2D.plot()
../../_images/userguide_project_project_38_0.png
[ ]: