spectrochempy.Project
- class Project(*args, argnames=None, name=None, **meta)[source][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 asScript
. 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.
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
All items contained in this project (list).
Names of all objects contained in this project (list).
Datasets included in this project excluding those located in subprojects.
Names of all dataset included in this project.
Current filename for this dataset.
Type of current file.
Readonly object identifier (str).
Metadata for the project (meta).
A user-friendly name for the project.
Instance of the Project which is the parent (if any) of the current project (project).
Subprojects included in this project (list).
Names of all subprojects included in this project (list).
Scripts included in this project (list).
Names of all scripts included in this project (list).
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.
loads
(js, Any])Deserialize dataset from JSON.
Remove all dataset from the 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 dataset in native .scp 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][source]
Add a single dataset to the current project.
- Parameters:
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][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][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][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][source]
Add one script to the current project.
- Parameters:
script (a
Script
instance)name (str)
- add_scripts(*scripts)[source][source]
Add one or a series of scripts to the current project.
- Parameters:
scripts (
Script
instances)
- 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:
- Other Parameters:
content (str, optional) – The optional content of the file(s) to be loaded as a binary string.
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)
- classmethod loads(js: dict[str, Any]) -> Any: """ Deserialize dataset from JSON. Parameters ---------- js : Dict[str, Any] JSON object to deserialize Returns ------- Any Deserialized dataset object Raises ------ TypeError If JSON cannot be deserialized """ from spectrochempy.core.dataset.nddataset import NDDataset from spectrochempy.core.project.project import Project from spectrochempy.core.script import Script # ......................... def item_to_attr(obj, dic)[source]
Deserialize dataset from JSON.
- Parameters:
js (Dict[str, Any]) – JSON object to deserialize
- Returns:
Any – Deserialized dataset object
- Raises:
TypeError – If JSON cannot be deserialized
- remove_dataset(name)[source][source]
Remove a dataset from the project.
- Parameters:
name (str) – Name of the dataset to remove.
- remove_project(name)[source][source]
Remove one project from the current project.
- Parameters:
name (str) – Name of the project to remove.
- save(**kwargs: Any)[source]
Save dataset in native .scp format.
- Parameters:
**kwargs (Any) – Optional arguments passed to save_as()
- Returns:
Optional[pathlib.Path] – Path to saved file if successful
- 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 thefilename
will be appended.
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