Project management

from pathlib import Path

[1]:
from spectrochempy import Project
from spectrochempy import pathclean
from spectrochempy import preferences as prefs
  SpectroChemPy's API - v.0.8.2.dev20
©Copyright 2014-2025 - A.Travert & C.Fernandez @ LCS
Running on GitHub Actions
MPL Configuration directory: /home/runner/.config/matplotlib
Stylelib directory: /home/runner/.config/matplotlib/stylelib

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_9b40076e'

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"

from spectrochempy import read_topspin

nd1 = read_topspin(
    path / "topspin_1d", expno=1, remove_digital_filter=True, name="NMR_1D"
)
nd2 = 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]:
NDDataset: [complex128] pp (size: 12411)[NMR_1D]
Summary
name
:
NMR_1D
author
:
runner@runnervmwhb2z
created
:
2025-10-12 01:34:34+00:00
Data
title
:
intensity
values
:
...
R[ 1078 2284 ... 0.2342 -0.1008] pp
I[ -1037 -2200 ... 0.06203 -0.05273] pp
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()
[13]:
../../../_images/userguide_objects_project_project_25_1.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], shape=(12411,))
[15]:
proj.NMR_2D
[15]:
NDDataset: [quaternion] pp (shape: (y:96, x:948))[NMR_2D]
Summary
name
:
NMR_2D
author
:
runner@runnervmwhb2z
created
:
2025-10-12 01:34:34+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]] pp
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]] pp
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]] pp
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]] pp
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/sources/userguide/objects/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()
[20]:
../../../_images/userguide_objects_project_project_36_1.png
[21]:
proj2.NMR_2D
[21]:
NDDataset: [quaternion] pp (shape: (y:96, x:948))[NMR_2D]
Summary
name
:
NMR_2D
author
:
runner@runnervmwhb2z
created
:
2025-10-12 01:34:34+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]] pp
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]] pp
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]] pp
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]] pp
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()
[22]:
../../../_images/userguide_objects_project_project_38_1.png
[ ]: