Warning

You are reading the documentation related to the development version. Go here if you are looking for the documentation of the stable release.

spectrochempy.Project

class Project(*args, argnames=None, name=None, **meta)[source]

A manager for projects, datasets and scripts.

It can handle multiple datasets, subprojects, and scripts in a main project.

Parameters
  • *args (Series of objects, optional) – Argument type will be interpreted correctly if they are of type NDDataset , Project , or other objects such as Script . This is optional, as they can be added later.

  • argnames (list, optional) – If not None, this list gives the names associated to each object passed as args. It MUST be the same length that the number of args, or an error will be raised. If None, the internal name of each object will be used instead.

  • name (str, optional) – The name of the project. If the name is not provided, it will be generated automatically.

  • **meta (dict) – Any other attributes to describe the project.

See also

NDDataset

The main object containing arrays.

Script

Executables scripts container.

Examples

>>> myproj = scp.Project(name='project_1')
>>> ds = scp.NDDataset([1., 2., 3.], name='dataset_1')
>>> myproj.add_dataset(ds)
>>> print(myproj)
Project project_1:
    ⤷ dataset_1 (dataset)

Attributes Summary

allitems

All items contained in this project (list).

allnames

Names of all objects contained in this project (list).

datasets

Datasets included in this project excluding those located in subprojects (list).

datasets_names

Names of all dataset included in this project.

filename

Current filename for this dataset.

filetype

Type of current file.

id

Readonly object identifier (str).

meta

Metadata for the project (meta).

name

A user-friendly name for the project.

parent

Instance of the Project which is the parent (if any) of the current project (project).

projects

Subprojects included in this project (list).

projects_names

Names of all subprojects included in this project (list).

scripts

Scripts included in this project (list).

scripts_names

Names of all scripts included in this project (list).

suffix

Filename suffix.

Methods Summary

add_dataset(dataset[, name])

Add a single dataset to the current project.

add_datasets(*datasets)

Add several datasets to the current project.

add_project(proj[, name])

Add one project to the current project.

add_projects(*projects)

Add one or a series of projects to the current project.

add_script(script[, name])

Add one script to the current project.

add_scripts(*scripts)

Add one or a series of scripts to the current project.

copy()

Make an exact copy of the current project.

dump(filename, **kwargs)

Save the current object into compressed native spectrochempy format.

load(filename, **kwargs)

Open data from a '*.scp' (NDDataset) or '*.pscp' (Project) file.

remove_all_dataset()

Remove all dataset from the project.

remove_all_project()

Remove all projects from the current project.

remove_dataset(name)

Remove a dataset from the project.

remove_project(name)

Remove one project from the current project.

save(**kwargs)

Save the current object in SpectroChemPy format.

save_as([filename])

Save the current NDDataset in SpectroChemPy format (*.scp).

Attributes Documentation

allitems

All items contained in this project (list).

allnames

Names of all objects contained in this project (list).

datasets

Datasets included in this project excluding those located in subprojects (list).

datasets_names

Names of all dataset included in this project. (does not return those located in sub-folders) (list).

filename

Current filename for this dataset.

filetype

Type of current file.

id

Readonly object identifier (str).

meta

Metadata for the project (meta).

meta contains all attribute except the name, id and parent of the current project.

name

A user-friendly name for the project.

The default is automatically generated (str).

parent

Instance of the Project which is the parent (if any) of the current project (project).

projects

Subprojects included in this project (list).

projects_names

Names of all subprojects included in this project (list).

scripts

Scripts included in this project (list).

scripts_names

Names of all scripts included in this project (list).

suffix

Filename suffix.

Read Only property - automatically set when the filename is updated if it has a suffix, else give the default suffix for the given type of object.

Methods Documentation

add_dataset(dataset, name=None)[source]

Add a single dataset to the current project.

Parameters
  • dataset (NDDataset) – Datasets to add. The name of the entry will be the name of the dataset, except if parameter name is defined.

  • name (str, optional) – If provided the name will be used to name the entry in the project.

See also

add_datasets

Add several datasets to the current project.

Examples

>>> ds1 = scp.NDDataset([1, 2, 3])
>>> proj = scp.Project()
>>> proj.add_dataset(ds1, name='Toto')
add_datasets(*datasets)[source]

Add several datasets to the current project.

Parameters

*datasets (series of NDDataset) – Datasets to add to the current project. The name of the entries in the project will be identical to the names of the datasets.

See also

add_dataset

Add a single dataset to the current project.

Examples

>>> ds1 = scp.NDDataset([1, 2, 3])
>>> ds2 = scp.NDDataset([4, 5, 6])
>>> ds3 = scp.NDDataset([7, 8, 9])
>>> proj = scp.Project()
>>> proj.add_datasets(ds1, ds2, ds3)
add_project(proj, name=None)[source]

Add one project to the current project.

Parameters

proj (a project instance) – A project to add to the current one.

add_projects(*projects)[source]

Add one or a series of projects to the current project.

Parameters

projects (project instances) – The projects to add to the current ones.

add_script(script, name=None)[source]

Add one script to the current project.

Parameters
  • script (a Script instance)

  • name (str)

add_scripts(*scripts)[source]

Add one or a series of scripts to the current project.

Parameters

scripts (Script instances)

copy()[source]

Make an exact copy of the current project.

dump(filename, **kwargs)[source]

Save the current object into compressed native spectrochempy format.

Parameters

filename (str of pathlib object) – File name where to save the current object.

classmethod load(filename, **kwargs)[source]

Open data from a ‘*.scp’ (NDDataset) or ‘*.pscp’ (Project) file.

Parameters
  • filename (str , pathlib or file objects) – The name of the file to read (or a file objects).

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters

content (str, optional) – The optional content of the file(s) to be loaded as a binary string.

See also

read

Import dataset from various orgines.

save

Save the current dataset.

Notes

Adapted from numpy.load .

Examples

>>> nd1 = scp.read('irdata/nh4y-activation.spg')
>>> f = nd1.save()
>>> f.name
'nh4y-activation.scp'
>>> nd2 = scp.load(f)

Alternatively, this method can be called as a class method of NDDataset or Project object:

>>> from spectrochempy import *
>>> nd2 = NDDataset.load(f)
remove_all_dataset()[source]

Remove all dataset from the project.

remove_all_project()[source]

Remove all projects from the current project.

remove_dataset(name)[source]

Remove a dataset from the project.

Parameters

name (str) – Name of the dataset to remove.

remove_project(name)[source]

Remove one project from the current project.

Parameters

name (str) – Name of the project to remove.

save(**kwargs)[source]

Save the current object in SpectroChemPy format.

Default extension is .scp for NDDataset’s and .pscp for

Project’s.

Parameters

**kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters

confirm (bool)

See also

save_as

Save current object with a different name and/or directory.

write

Export current object to different format.

Examples

Read some data from an OMNIC file

>>> nd = scp.read_omnic('wodger.spg')
>>> assert nd.name == 'wodger'

Write it in SpectroChemPy format (.scp) (return a pathlib object)

>>> filename = nd.save()

Check the existence of the scp fie

>>> assert filename.is_file()
>>> assert filename.name == 'wodger.scp'

Remove this file

>>> filename.unlink()
save_as(filename='', **kwargs)[source]

Save the current NDDataset in SpectroChemPy format (*.scp).

Parameters
  • filename (str) – The filename of the file where to save the current dataset.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Other Parameters

directory (str, optional) – If specified, the given directory and the filename will be appended.

See also

save

Save current dataset.

write

Export current dataset to different format.

Notes

Adapted from numpy.savez .

Examples

Read some data from an OMNIC file

>>> nd = scp.read_omnic('wodger.spg')
>>> assert nd.name == 'wodger'

Write it in SpectroChemPy format (.scp) (return a pathlib object)

>>> filename = nd.save_as('new_wodger')

Check the existence of the scp file

>>> assert filename.is_file()
>>> assert filename.name == 'new_wodger.scp'

Remove this file

>>> filename.unlink()

Examples using spectrochempy.Project

Project creation

Project creation