Quickstart/Cheat-Sheet
Since this documentation is written in a jupyter-notebook we will import a little ipython helper function to display file with syntax highlighting.
[1]:
from glotaran.utils.ipython import display_file
To start using pyglotaran
in your project, you have to import it first. In addition we need to import some extra components for later use.
[2]:
from glotaran.analysis.optimize import optimize
from glotaran.io import load_model
from glotaran.io import load_parameters
from glotaran.io import save_dataset
from glotaran.io.prepare_dataset import prepare_time_trace_dataset
from glotaran.project.scheme import Scheme
Let us get some example data to analyze:
[3]:
from glotaran.examples.sequential import dataset
dataset
[3]:
<xarray.Dataset> Dimensions: (time: 2100, spectral: 72) Coordinates: * time (time) float64 -1.0 -0.99 -0.98 -0.97 ... 19.96 19.97 19.98 19.99 * spectral (spectral) float64 600.0 601.4 602.8 604.2 ... 696.6 698.0 699.4 Data variables: data (time, spectral) float64 -0.000586 0.00234 ... 1.719 1.528 Attributes: source_path: dataset_1.nc
- time: 2100
- spectral: 72
- time(time)float64-1.0 -0.99 -0.98 ... 19.98 19.99
array([-1. , -0.99, -0.98, ..., 19.97, 19.98, 19.99])
- spectral(spectral)float64600.0 601.4 602.8 ... 698.0 699.4
array([600. , 601.4, 602.8, 604.2, 605.6, 607. , 608.4, 609.8, 611.2, 612.6, 614. , 615.4, 616.8, 618.2, 619.6, 621. , 622.4, 623.8, 625.2, 626.6, 628. , 629.4, 630.8, 632.2, 633.6, 635. , 636.4, 637.8, 639.2, 640.6, 642. , 643.4, 644.8, 646.2, 647.6, 649. , 650.4, 651.8, 653.2, 654.6, 656. , 657.4, 658.8, 660.2, 661.6, 663. , 664.4, 665.8, 667.2, 668.6, 670. , 671.4, 672.8, 674.2, 675.6, 677. , 678.4, 679.8, 681.2, 682.6, 684. , 685.4, 686.8, 688.2, 689.6, 691. , 692.4, 693.8, 695.2, 696.6, 698. , 699.4])
- data(time, spectral)float64-0.000586 0.00234 ... 1.719 1.528
array([[-5.86038361e-04, 2.33993988e-03, 1.92999378e-06, ..., -3.27618703e-02, 6.80903114e-03, 9.09582717e-03], [ 2.15081684e-02, 9.33258579e-03, -3.30303699e-03, ..., 5.43301598e-03, -1.51602576e-04, 2.83015454e-02], [-4.94221245e-03, -1.47757608e-02, -8.59637818e-03, ..., 1.44047106e-02, -3.70825959e-03, -7.73454580e-05], ..., [ 1.48304462e+00, 1.61764197e+00, 1.81170440e+00, ..., 1.88045830e+00, 1.69949107e+00, 1.57300271e+00], [ 1.46399503e+00, 1.63121314e+00, 1.81263203e+00, ..., 1.86811079e+00, 1.71666576e+00, 1.55515505e+00], [ 1.45329984e+00, 1.61872027e+00, 1.81361768e+00, ..., 1.88692088e+00, 1.71907949e+00, 1.52831632e+00]])
- source_path :
- dataset_1.nc
Like all data in pyglotaran
, the dataset is a xarray.Dataset. You can find more information about the xarray
library the xarray hompage.
The loaded dataset is a simulated sequential model.
Plotting raw data
Now we lets plot some time traces.
[4]:
plot_data = dataset.data.sel(spectral=[620, 630, 650], method="nearest")
plot_data.plot.line(x="time", aspect=2, size=5);
We can also plot spectra at different times.
[5]:
plot_data = dataset.data.sel(time=[1, 10, 20], method="nearest")
plot_data.plot.line(x="spectral", aspect=2, size=5);
Preparing data
To get an idea about how to model your data, you should inspect the singular value decomposition. Pyglotaran has a function to calculate it (among other things).
[6]:
dataset = prepare_time_trace_dataset(dataset)
dataset
[6]:
<xarray.Dataset> Dimensions: (time: 2100, spectral: 72, left_singular_value_index: 72, singular_value_index: 72, right_singular_value_index: 72) Coordinates: * time (time) float64 -1.0 -0.99 -0.98 ... 19.98 19.99 * spectral (spectral) float64 600.0 601.4 ... 698.0 699.4 Dimensions without coordinates: left_singular_value_index, singular_value_index, right_singular_value_index Data variables: data (time, spectral) float64 -0.000586 ... 1.528 data_left_singular_vectors (time, left_singular_value_index) float64 2.... data_singular_values (singular_value_index) float64 4.62e+03 ... ... data_right_singular_vectors (right_singular_value_index, spectral) float64 ... Attributes: source_path: dataset_1.nc
- time: 2100
- spectral: 72
- left_singular_value_index: 72
- singular_value_index: 72
- right_singular_value_index: 72
- time(time)float64-1.0 -0.99 -0.98 ... 19.98 19.99
array([-1. , -0.99, -0.98, ..., 19.97, 19.98, 19.99])
- spectral(spectral)float64600.0 601.4 602.8 ... 698.0 699.4
array([600. , 601.4, 602.8, 604.2, 605.6, 607. , 608.4, 609.8, 611.2, 612.6, 614. , 615.4, 616.8, 618.2, 619.6, 621. , 622.4, 623.8, 625.2, 626.6, 628. , 629.4, 630.8, 632.2, 633.6, 635. , 636.4, 637.8, 639.2, 640.6, 642. , 643.4, 644.8, 646.2, 647.6, 649. , 650.4, 651.8, 653.2, 654.6, 656. , 657.4, 658.8, 660.2, 661.6, 663. , 664.4, 665.8, 667.2, 668.6, 670. , 671.4, 672.8, 674.2, 675.6, 677. , 678.4, 679.8, 681.2, 682.6, 684. , 685.4, 686.8, 688.2, 689.6, 691. , 692.4, 693.8, 695.2, 696.6, 698. , 699.4])
- data(time, spectral)float64-0.000586 0.00234 ... 1.719 1.528
array([[-5.86038361e-04, 2.33993988e-03, 1.92999378e-06, ..., -3.27618703e-02, 6.80903114e-03, 9.09582717e-03], [ 2.15081684e-02, 9.33258579e-03, -3.30303699e-03, ..., 5.43301598e-03, -1.51602576e-04, 2.83015454e-02], [-4.94221245e-03, -1.47757608e-02, -8.59637818e-03, ..., 1.44047106e-02, -3.70825959e-03, -7.73454580e-05], ..., [ 1.48304462e+00, 1.61764197e+00, 1.81170440e+00, ..., 1.88045830e+00, 1.69949107e+00, 1.57300271e+00], [ 1.46399503e+00, 1.63121314e+00, 1.81263203e+00, ..., 1.86811079e+00, 1.71666576e+00, 1.55515505e+00], [ 1.45329984e+00, 1.61872027e+00, 1.81361768e+00, ..., 1.88692088e+00, 1.71907949e+00, 1.52831632e+00]])
- data_left_singular_vectors(time, left_singular_value_index)float642.449e-06 9.014e-06 ... -0.01364
array([[ 2.44943694e-06, 9.01416634e-06, -4.45129581e-05, ..., -3.47673151e-02, -1.80378532e-02, -3.98535649e-02], [ 4.14547008e-06, -2.23720946e-06, 7.64256341e-05, ..., 5.67303197e-03, 3.86744993e-02, 4.03800351e-02], [-1.90490543e-06, -8.08314311e-06, -1.39816350e-04, ..., -3.70960569e-03, 1.19919417e-02, -1.71930493e-02], ..., [ 1.22468825e-02, -8.35982452e-03, 1.20662264e-02, ..., 1.09930860e-02, 6.22386891e-02, -5.38663084e-03], [ 1.22364659e-02, -8.37343376e-03, 1.19478315e-02, ..., 8.30310874e-03, 4.04378726e-02, -1.06524217e-02], [ 1.22237116e-02, -8.34329537e-03, 1.19094926e-02, ..., -8.47808147e-03, 1.17526992e-02, -1.36360414e-02]])
- data_singular_values(singular_value_index)float644.62e+03 1.126e+03 ... 0.3763
array([4.62002474e+03, 1.12636575e+03, 1.79751383e+02, 5.35260544e-01, 5.31122805e-01, 5.28877304e-01, 5.25509422e-01, 5.23266326e-01, 5.22194827e-01, 5.16359272e-01, 5.14305554e-01, 5.12652857e-01, 5.09907532e-01, 5.05480646e-01, 5.04015417e-01, 5.02318803e-01, 4.99462131e-01, 4.97448848e-01, 4.94422492e-01, 4.91737910e-01, 4.89791543e-01, 4.88547628e-01, 4.86087049e-01, 4.83543908e-01, 4.82511635e-01, 4.80324736e-01, 4.78917908e-01, 4.73526032e-01, 4.72663122e-01, 4.70204880e-01, 4.69560976e-01, 4.66729465e-01, 4.65815575e-01, 4.63933467e-01, 4.59550974e-01, 4.59427795e-01, 4.56327306e-01, 4.55814267e-01, 4.54433404e-01, 4.52366448e-01, 4.49754221e-01, 4.47539566e-01, 4.45595235e-01, 4.44688795e-01, 4.43340924e-01, 4.38818611e-01, 4.37830289e-01, 4.36580579e-01, 4.33796007e-01, 4.30573259e-01, 4.29370391e-01, 4.27058708e-01, 4.25159118e-01, 4.24213946e-01, 4.23876410e-01, 4.19229330e-01, 4.17944595e-01, 4.17257090e-01, 4.15619955e-01, 4.13852053e-01, 4.11377081e-01, 4.08864260e-01, 4.01602134e-01, 4.00711782e-01, 3.97725540e-01, 3.94820609e-01, 3.93499778e-01, 3.93116549e-01, 3.88148436e-01, 3.86557075e-01, 3.81195105e-01, 3.76347947e-01])
- data_right_singular_vectors(right_singular_value_index, spectral)float640.03527 0.03907 ... -0.155 0.06859
array([[ 0.03526636, 0.03906864, 0.04312902, ..., 0.02800223, 0.02528531, 0.02276681], [ 0.0906663 , 0.09932325, 0.10800835, ..., -0.03120745, -0.028196 , -0.02536842], [ 0.15375784, 0.16815716, 0.18254412, ..., 0.00719359, 0.00647238, 0.00576013], ..., [-0.05990057, -0.30349225, 0.1006487 , ..., 0.05541322, -0.20414381, 0.12637247], [ 0.08748348, -0.17617409, -0.20057318, ..., 0.23134028, 0.20007644, 0.19510811], [-0.0088166 , 0.03594634, 0.10807513, ..., 0.09673333, -0.15503601, 0.06858887]])
- source_path :
- dataset_1.nc
First, take a look at the first 10 singular values:
[7]:
plot_data = dataset.data_singular_values.sel(singular_value_index=range(0, 10))
plot_data.plot(yscale="log", marker="o", linewidth=0, aspect=2, size=5);
Working with models
To analyze our data, we need to create a model.
Create a file called model.yaml
in your working directory and fill it with the following:
[8]:
display_file("model.yaml", syntax="yaml")
[8]:
default_megacomplex: decay
initial_concentration:
input:
compartments: [s1, s2, s3]
parameters: [input.1, input.0, input.0]
k_matrix:
k1:
matrix:
(s2, s1): kinetic.1
(s3, s2): kinetic.2
(s3, s3): kinetic.3
megacomplex:
m1:
k_matrix: [k1]
irf:
irf1:
type: gaussian
center: irf.center
width: irf.width
dataset:
dataset1:
initial_concentration: input
megacomplex: [m1]
irf: irf1
Now you can load the model file.
[9]:
model = load_model("model.yaml")
You can check your model for problems with model.validate
.
[10]:
model.validate()
[10]:
'Your model is valid.'
Working with parameters
Now define some starting parameters. Create a file called parameters.yaml
with the following content.
[11]:
display_file("parameters.yaml", syntax="yaml")
[11]:
input:
- ['1', 1, {'vary': False, 'non-negative': False}]
- ['0', 0, {'vary': False, 'non-negative': False}]
kinetic: [
0.5,
0.3,
0.1,
]
irf:
- ['center', 0.3]
- ['width', 0.1]
[12]:
parameters = load_parameters("parameters.yaml")
You can model.validate
also to check for missing parameters.
[13]:
model.validate(parameters=parameters)
[13]:
'Your model is valid.'
Since not all problems in the model can be detected automatically it is wise to visually inspect the model. For this purpose, you can just print the model.
[14]:
model
[14]:
Model
Megacomplex Types: decay
Dataset Groups
default:
Label: default
residual_function: variable_projection
link_clp: None
K Matrix
k1:
Label: k1
Matrix:
(‘s2’, ‘s1’): kinetic.1(nan)
(‘s3’, ‘s2’): kinetic.2(nan)
(‘s3’, ‘s3’): kinetic.3(nan)
Initial Concentration
input:
Label: input
Compartments:
s1
s2
s3
Parameters:
input.1(nan)
input.0(nan)
input.0(nan)
Exclude From Normalize:
Irf
irf1 (gaussian):
Label: irf1
Type: gaussian
Center: irf.center(nan)
Width: irf.width(nan)
Normalize: True
Backsweep: False
Megacomplex
m1 (None):
Label: m1
Dimension: time
K Matrix:
k1
Dataset
dataset1:
Label: dataset1
Group: default
Megacomplex:
m1
Initial Concentration: input
Irf: irf1
The same way you should inspect your parameters.
[15]:
parameters
[15]:
input:
Label
Value
Standard Error
Minimum
Maximum
Vary
Non-Negative
Expression
1
1.000e+00
nan
-inf
inf
False
False
None
0
0.000e+00
nan
-inf
inf
False
False
None
irf:
Label
Value
Standard Error
Minimum
Maximum
Vary
Non-Negative
Expression
center
3.000e-01
nan
-inf
inf
True
False
None
width
1.000e-01
nan
-inf
inf
True
False
None
kinetic:
Label
Value
Standard Error
Minimum
Maximum
Vary
Non-Negative
Expression
1
5.000e-01
nan
-inf
inf
True
False
None
2
3.000e-01
nan
-inf
inf
True
False
None
3
1.000e-01
nan
-inf
inf
True
False
None
Optimizing data
Now we have everything together to optimize our parameters. First we import optimize.
[16]:
scheme = Scheme(model, parameters, {"dataset1": dataset})
result = optimize(scheme)
result
Iteration Total nfev Cost Cost reduction Step norm Optimality
0 1 7.5629e+00 6.68e+01
1 2 7.5624e+00 4.68e-04 8.07e-05 2.26e-01
2 3 7.5624e+00 4.33e-10 2.33e-08 6.04e-06
`ftol` termination condition is satisfied.
Function evaluations 3, initial cost 7.5629e+00, final cost 7.5624e+00, first-order optimality 6.04e-06.
[16]:
Optimization Result |
|
---|---|
Number of residual evaluation |
3 |
Number of variables |
5 |
Number of datapoints |
151200 |
Degrees of freedom |
151195 |
Chi Square |
1.51e+01 |
Reduced Chi Square |
1.00e-04 |
Root Mean Square Error (RMSE) |
1.00e-02 |
RMSE additional penalty |
[array([], dtype=float64)] |
Model
Megacomplex Types: decay
Dataset Groups
default:
Label: default
residual_function: variable_projection
link_clp: None
K Matrix
k1:
Label: k1
Matrix:
(‘s2’, ‘s1’): kinetic.1(5.00e-01±7.26e-05, initial: 5.00e-01)
(‘s3’, ‘s2’): kinetic.2(3.00e-01±4.19e-05, initial: 3.00e-01)
(‘s3’, ‘s3’): kinetic.3(1.00e-01±4.78e-06, initial: 1.00e-01)
Initial Concentration
input:
Label: input
Compartments:
s1
s2
s3
Parameters:
input.1(1.00e+00, fixed)
input.0(0.00e+00, fixed)
input.0(0.00e+00, fixed)
Exclude From Normalize:
Irf
irf1 (gaussian):
Label: irf1
Type: gaussian
Center: irf.center(3.00e-01±5.01e-06, initial: 3.00e-01)
Width: irf.width(1.00e-01±6.71e-06, initial: 1.00e-01)
Normalize: True
Backsweep: False
Megacomplex
m1 (None):
Label: m1
Dimension: time
K Matrix:
k1
Dataset
dataset1:
Label: dataset1
Group: default
Megacomplex:
m1
Initial Concentration: input
Irf: irf1
[17]:
result.optimized_parameters
[17]:
input:
Label
Value
Standard Error
Minimum
Maximum
Vary
Non-Negative
Expression
1
1.000e+00
nan
-inf
inf
False
False
None
0
0.000e+00
nan
-inf
inf
False
False
None
irf:
Label
Value
Standard Error
Minimum
Maximum
Vary
Non-Negative
Expression
center
3.000e-01
5.012e-06
-inf
inf
True
False
None
width
1.000e-01
6.705e-06
-inf
inf
True
False
None
kinetic:
Label
Value
Standard Error
Minimum
Maximum
Vary
Non-Negative
Expression
1
5.000e-01
7.256e-05
-inf
inf
True
False
None
2
2.999e-01
4.191e-05
-inf
inf
True
False
None
3
1.000e-01
4.783e-06
-inf
inf
True
False
None
You can get the resulting data for your dataset with result.get_dataset
.
[18]:
result_dataset = result.data["dataset1"]
result_dataset
[18]:
<xarray.Dataset> Dimensions: (clp_label: 3, time: 2100, spectral: 72, left_singular_value_index: 72, singular_value_index: 72, right_singular_value_index: 72, species: 3, component: 3, to_species: 3, from_species: 3) Coordinates: * clp_label (clp_label) object 's1' 's2' 's3' * time (time) float64 -1.0 ... 19.99 * spectral (spectral) float64 600.0 ... 699.4 * species (species) <U2 's1' 's2' 's3' * component (component) int64 0 1 2 rate (component) float64 -0.5 ... -0.1 lifetime (component) float64 -2.0 ... -9... * to_species (to_species) <U2 's1' 's2' 's3' * from_species (from_species) <U2 's1' 's2' 's3' Dimensions without coordinates: left_singular_value_index, singular_value_index, right_singular_value_index Data variables: (12/24) data (time, spectral) float64 -0.000... data_left_singular_vectors (time, left_singular_value_index) float64 ... data_singular_values (singular_value_index) float64 ... data_right_singular_vectors (spectral, right_singular_value_index) float64 ... matrix (time, clp_label) float64 6.101... clp (spectral, clp_label) float64 1... ... ... irf_center float64 0.3 irf_width float64 0.1 decay_associated_spectra (spectral, component) float64 2... a_matrix (component, species) float64 1.... k_matrix (to_species, from_species) float64 ... k_matrix_reduced (to_species, from_species) float64 ... Attributes: source_path: dataset_1.nc root_mean_square_error: 0.01000158369561628 weighted_root_mean_square_error: 0.01000158369561628 dataset_scale: 1
- clp_label: 3
- time: 2100
- spectral: 72
- left_singular_value_index: 72
- singular_value_index: 72
- right_singular_value_index: 72
- species: 3
- component: 3
- to_species: 3
- from_species: 3
- clp_label(clp_label)object's1' 's2' 's3'
array(['s1', 's2', 's3'], dtype=object)
- time(time)float64-1.0 -0.99 -0.98 ... 19.98 19.99
array([-1. , -0.99, -0.98, ..., 19.97, 19.98, 19.99])
- spectral(spectral)float64600.0 601.4 602.8 ... 698.0 699.4
array([600. , 601.4, 602.8, 604.2, 605.6, 607. , 608.4, 609.8, 611.2, 612.6, 614. , 615.4, 616.8, 618.2, 619.6, 621. , 622.4, 623.8, 625.2, 626.6, 628. , 629.4, 630.8, 632.2, 633.6, 635. , 636.4, 637.8, 639.2, 640.6, 642. , 643.4, 644.8, 646.2, 647.6, 649. , 650.4, 651.8, 653.2, 654.6, 656. , 657.4, 658.8, 660.2, 661.6, 663. , 664.4, 665.8, 667.2, 668.6, 670. , 671.4, 672.8, 674.2, 675.6, 677. , 678.4, 679.8, 681.2, 682.6, 684. , 685.4, 686.8, 688.2, 689.6, 691. , 692.4, 693.8, 695.2, 696.6, 698. , 699.4])
- species(species)<U2's1' 's2' 's3'
array(['s1', 's2', 's3'], dtype='<U2')
- component(component)int640 1 2
array([0, 1, 2])
- rate(component)float64-0.5 -0.2999 -0.1
array([-0.50003798, -0.29992983, -0.10001011])
- lifetime(component)float64-2.0 -3.334 -9.999
array([-1.9998481 , -3.33411323, -9.99898888])
- to_species(to_species)<U2's1' 's2' 's3'
array(['s1', 's2', 's3'], dtype='<U2')
- from_species(from_species)<U2's1' 's2' 's3'
array(['s1', 's2', 's3'], dtype='<U2')
- data(time, spectral)float64-0.000586 0.00234 ... 1.719 1.528
array([[-5.86038361e-04, 2.33993988e-03, 1.92999378e-06, ..., -3.27618703e-02, 6.80903114e-03, 9.09582717e-03], [ 2.15081684e-02, 9.33258579e-03, -3.30303699e-03, ..., 5.43301598e-03, -1.51602576e-04, 2.83015454e-02], [-4.94221245e-03, -1.47757608e-02, -8.59637818e-03, ..., 1.44047106e-02, -3.70825959e-03, -7.73454580e-05], ..., [ 1.48304462e+00, 1.61764197e+00, 1.81170440e+00, ..., 1.88045830e+00, 1.69949107e+00, 1.57300271e+00], [ 1.46399503e+00, 1.63121314e+00, 1.81263203e+00, ..., 1.86811079e+00, 1.71666576e+00, 1.55515505e+00], [ 1.45329984e+00, 1.61872027e+00, 1.81361768e+00, ..., 1.88692088e+00, 1.71907949e+00, 1.52831632e+00]])
- data_left_singular_vectors(time, left_singular_value_index)float642.449e-06 9.014e-06 ... -0.01364
array([[ 2.44943694e-06, 9.01416634e-06, -4.45129581e-05, ..., -3.47673151e-02, -1.80378532e-02, -3.98535649e-02], [ 4.14547008e-06, -2.23720946e-06, 7.64256341e-05, ..., 5.67303197e-03, 3.86744993e-02, 4.03800351e-02], [-1.90490543e-06, -8.08314311e-06, -1.39816350e-04, ..., -3.70960569e-03, 1.19919417e-02, -1.71930493e-02], ..., [ 1.22468825e-02, -8.35982452e-03, 1.20662264e-02, ..., 1.09930860e-02, 6.22386891e-02, -5.38663084e-03], [ 1.22364659e-02, -8.37343376e-03, 1.19478315e-02, ..., 8.30310874e-03, 4.04378726e-02, -1.06524217e-02], [ 1.22237116e-02, -8.34329537e-03, 1.19094926e-02, ..., -8.47808147e-03, 1.17526992e-02, -1.36360414e-02]])
- data_singular_values(singular_value_index)float644.62e+03 1.126e+03 ... 0.3763
array([4.62002474e+03, 1.12636575e+03, 1.79751383e+02, 5.35260544e-01, 5.31122805e-01, 5.28877304e-01, 5.25509422e-01, 5.23266326e-01, 5.22194827e-01, 5.16359272e-01, 5.14305554e-01, 5.12652857e-01, 5.09907532e-01, 5.05480646e-01, 5.04015417e-01, 5.02318803e-01, 4.99462131e-01, 4.97448848e-01, 4.94422492e-01, 4.91737910e-01, 4.89791543e-01, 4.88547628e-01, 4.86087049e-01, 4.83543908e-01, 4.82511635e-01, 4.80324736e-01, 4.78917908e-01, 4.73526032e-01, 4.72663122e-01, 4.70204880e-01, 4.69560976e-01, 4.66729465e-01, 4.65815575e-01, 4.63933467e-01, 4.59550974e-01, 4.59427795e-01, 4.56327306e-01, 4.55814267e-01, 4.54433404e-01, 4.52366448e-01, 4.49754221e-01, 4.47539566e-01, 4.45595235e-01, 4.44688795e-01, 4.43340924e-01, 4.38818611e-01, 4.37830289e-01, 4.36580579e-01, 4.33796007e-01, 4.30573259e-01, 4.29370391e-01, 4.27058708e-01, 4.25159118e-01, 4.24213946e-01, 4.23876410e-01, 4.19229330e-01, 4.17944595e-01, 4.17257090e-01, 4.15619955e-01, 4.13852053e-01, 4.11377081e-01, 4.08864260e-01, 4.01602134e-01, 4.00711782e-01, 3.97725540e-01, 3.94820609e-01, 3.93499778e-01, 3.93116549e-01, 3.88148436e-01, 3.86557075e-01, 3.81195105e-01, 3.76347947e-01])
- data_right_singular_vectors(spectral, right_singular_value_index)float640.03527 0.09067 ... 0.1951 0.06859
array([[ 0.03526636, 0.0906663 , 0.15375784, ..., -0.05990057, 0.08748348, -0.0088166 ], [ 0.03906864, 0.09932325, 0.16815716, ..., -0.30349225, -0.17617409, 0.03594634], [ 0.04312902, 0.10800835, 0.18254412, ..., 0.1006487 , -0.20057318, 0.10807513], ..., [ 0.02800223, -0.03120745, 0.00719359, ..., 0.05541322, 0.23134028, 0.09673333], [ 0.02528531, -0.028196 , 0.00647238, ..., -0.20414381, 0.20007644, -0.15503601], [ 0.02276681, -0.02536842, 0.00576013, ..., 0.12637247, 0.19510811, 0.06858887]])
- matrix(time, clp_label)float646.101e-39 2.314e-41 ... 0.2516
array([[6.10072642e-39, 2.31444836e-41, 5.24498291e-44], [2.24434927e-38, 8.57879892e-41, 1.95867290e-43], [8.17488070e-38, 3.14855890e-40, 7.24285217e-43], ..., [5.35711584e-05, 6.71723774e-03, 2.52095615e-01], [5.33039509e-05, 6.69738773e-03, 2.51863727e-01], [5.30380762e-05, 6.67759584e-03, 2.51632011e-01]])
- clp(spectral, clp_label)float6415.0 0.03952 ... 0.002203 6.107
array([[ 1.50016760e+01, 3.95233239e-02, 5.83434089e+00], [ 1.64707909e+01, 7.21680436e-02, 6.48584872e+00], [ 1.79674818e+01, 1.18165832e-01, 7.19375482e+00], [ 1.94619002e+01, 2.02846603e-01, 7.95051908e+00], [ 2.09455075e+01, 3.20344210e-01, 8.76361164e+00], [ 2.23854289e+01, 5.13041362e-01, 9.63045309e+00], [ 2.37596548e+01, 7.91130283e-01, 1.05495429e+01], [ 2.50511111e+01, 1.18486728e+00, 1.15223485e+01], [ 2.62330840e+01, 1.72739278e+00, 1.25481577e+01], [ 2.72858465e+01, 2.45291828e+00, 1.36217738e+01], [ 2.81865706e+01, 3.39497230e+00, 1.47422594e+01], [ 2.89205086e+01, 4.56644977e+00, 1.59087928e+01], [ 2.94704612e+01, 5.98084502e+00, 1.71153452e+01], [ 2.98332157e+01, 7.62007173e+00, 1.83584619e+01], [ 2.99930567e+01, 9.45074258e+00, 1.96308600e+01], [ 2.99495364e+01, 1.14078225e+01, 2.09314695e+01], [ 2.97009601e+01, 1.34028437e+01, 2.22479458e+01], [ 2.92594040e+01, 1.53230937e+01, 2.35768608e+01], [ 2.86279615e+01, 1.70482668e+01, 2.49090011e+01], [ 2.78168004e+01, 1.84616304e+01, 2.62373922e+01], ... [ 2.39458014e-01, 2.68140244e-03, 2.68045504e+01], [ 1.86349877e-01, 7.08644301e-04, 2.54807565e+01], [ 1.37346316e-01, 3.49714776e-03, 2.41482176e+01], [ 1.05949155e-01, -1.62090633e-04, 2.28180363e+01], [ 7.96999117e-02, 3.57992647e-03, 2.14935145e+01], [ 5.93096082e-02, 3.77463116e-03, 2.01854888e+01], [ 4.60181066e-02, 8.73441902e-05, 1.89017529e+01], [ 3.18905809e-02, 4.35547020e-03, 1.76439676e+01], [ 2.22055101e-02, 2.23141112e-03, 1.64221858e+01], [ 1.58257399e-02, 3.94070253e-03, 1.52372878e+01], [ 1.24914179e-02, 6.66951526e-04, 1.40964168e+01], [ 9.81662626e-03, -1.85220999e-03, 1.30028557e+01], [ 4.79021597e-03, 8.85610175e-04, 1.19556466e+01], [ 4.56566765e-03, -1.01233875e-03, 1.09613399e+01], [ 3.85883713e-03, 1.15878939e-03, 1.00177122e+01], [ 4.08008222e-03, 1.70189606e-04, 9.12895219e+00], [ 8.40513011e-04, -4.49357932e-04, 8.29367344e+00], [ 1.29739459e-03, -8.28982274e-04, 7.51201898e+00], [-8.27264600e-04, -6.05035215e-04, 6.78357652e+00], [-3.67739879e-04, 2.20284859e-03, 6.10654367e+00]])
- weighted_residual(time, spectral)float64-0.000586 0.00234 ... -0.0083
array([[-5.86038361e-04, 2.33993988e-03, 1.92999382e-06, ..., -3.27618703e-02, 6.80903114e-03, 9.09582717e-03], [ 2.15081684e-02, 9.33258579e-03, -3.30303699e-03, ..., 5.43301598e-03, -1.51602576e-04, 2.83015454e-02], [-4.94221245e-03, -1.47757608e-02, -8.59637818e-03, ..., 1.44047106e-02, -3.70825959e-03, -7.73454581e-05], ..., [ 1.11637185e-02, -1.87791818e-02, -3.56593464e-03, ..., -1.32832463e-02, -1.06147099e-02, 3.35550528e-02], [-6.52816555e-03, -3.69818414e-03, -9.63013504e-04, ..., -2.38888181e-02, 8.13299539e-03, 1.71234733e-02], [-1.58666685e-02, -1.46823764e-02, 1.69666696e-03, ..., -3.33809495e-03, 1.21185672e-02, -8.30023199e-03]])
- residual(time, spectral)float64-0.000586 0.00234 ... -0.0083
array([[-5.86038361e-04, 2.33993988e-03, 1.92999382e-06, ..., -3.27618703e-02, 6.80903114e-03, 9.09582717e-03], [ 2.15081684e-02, 9.33258579e-03, -3.30303699e-03, ..., 5.43301598e-03, -1.51602576e-04, 2.83015454e-02], [-4.94221245e-03, -1.47757608e-02, -8.59637818e-03, ..., 1.44047106e-02, -3.70825959e-03, -7.73454581e-05], ..., [ 1.11637185e-02, -1.87791818e-02, -3.56593464e-03, ..., -1.32832463e-02, -1.06147099e-02, 3.35550528e-02], [-6.52816555e-03, -3.69818414e-03, -9.63013504e-04, ..., -2.38888181e-02, 8.13299539e-03, 1.71234733e-02], [-1.58666685e-02, -1.46823764e-02, 1.69666696e-03, ..., -3.33809495e-03, 1.21185672e-02, -8.30023199e-03]])
- weighted_residual_left_singular_vectors(time, left_singular_value_index)float64-0.01895 0.01523 ... -0.01482
array([[-0.01894855, 0.01523405, 0.01938034, ..., -0.02427674, -0.01326057, -0.03539317], [-0.02056209, -0.03044261, -0.02787418, ..., 0.01755108, 0.04057635, 0.0320475 ], [ 0.03892461, 0.00577106, 0.01684504, ..., 0.00668768, 0.00543015, -0.02113443], ..., [ 0.00610236, -0.0072145 , 0.02027675, ..., 0.00917276, 0.06251087, -0.01245815], [-0.02505806, -0.01475628, 0.02498017, ..., 0.0059477 , 0.04031986, -0.02588554], [ 0.03112891, 0.00133743, 0.03220895, ..., 0.00428565, 0.01051782, -0.0148186 ]])
- weighted_residual_singular_values(singular_value_index)float640.5361 0.5318 ... 0.3808 0.3743
array([0.53606556, 0.53183234, 0.53026022, 0.52843202, 0.52454015, 0.52325718, 0.51946369, 0.51643009, 0.51366028, 0.50999476, 0.50945057, 0.50494574, 0.50439065, 0.50084274, 0.50009243, 0.4951946 , 0.49354277, 0.49197319, 0.49014801, 0.48809796, 0.48641966, 0.48393184, 0.4830583 , 0.48095344, 0.47774737, 0.47513735, 0.47461724, 0.47106964, 0.46930451, 0.46876492, 0.46685872, 0.46452184, 0.46195046, 0.45951578, 0.45708428, 0.45572346, 0.4552988 , 0.45159829, 0.45026924, 0.44976904, 0.44698286, 0.44473276, 0.44395882, 0.44044129, 0.43940338, 0.43706707, 0.43640693, 0.43450485, 0.43332084, 0.4288044 , 0.42801376, 0.42621219, 0.42206566, 0.42173048, 0.41964406, 0.41868728, 0.41699256, 0.4152083 , 0.41349024, 0.4119684 , 0.40881955, 0.4079785 , 0.40124726, 0.39912175, 0.39698473, 0.39305605, 0.3922677 , 0.39165456, 0.38554183, 0.38456357, 0.38082229, 0.37430355])
- weighted_residual_right_singular_vectors(right_singular_value_index, spectral)float64-0.06183 -0.08975 ... 0.06401
array([[-6.18279783e-02, -8.97505392e-02, 2.13891284e-02, ..., 3.84872532e-02, 1.37906275e-01, 2.67543606e-05], [ 2.75935673e-02, 4.90844921e-02, -1.20512600e-01, ..., -2.98876321e-03, 1.28935955e-01, 6.23416812e-02], [-1.32118249e-01, -4.52348305e-02, 1.75139331e-01, ..., 6.86631468e-02, 5.28425736e-03, 1.54428476e-01], ..., [-6.40365007e-02, -3.10203408e-01, 1.17917412e-01, ..., 1.04900158e-01, -1.55924056e-01, 1.76205700e-01], [ 1.06744892e-01, -1.18967849e-01, -2.12115265e-01, ..., 2.04308543e-01, 2.26209859e-01, 1.61689986e-01], [-3.21125977e-02, 6.68501327e-02, 1.14579446e-01, ..., 7.41766407e-02, -1.52010264e-01, 6.40050540e-02]])
- residual_left_singular_vectors(time, left_singular_value_index)float64-0.01895 0.01523 ... -0.01482
array([[-0.01894855, 0.01523405, 0.01938034, ..., -0.02427674, -0.01326057, -0.03539317], [-0.02056209, -0.03044261, -0.02787418, ..., 0.01755108, 0.04057635, 0.0320475 ], [ 0.03892461, 0.00577106, 0.01684504, ..., 0.00668768, 0.00543015, -0.02113443], ..., [ 0.00610236, -0.0072145 , 0.02027675, ..., 0.00917276, 0.06251087, -0.01245815], [-0.02505806, -0.01475628, 0.02498017, ..., 0.0059477 , 0.04031986, -0.02588554], [ 0.03112891, 0.00133743, 0.03220895, ..., 0.00428565, 0.01051782, -0.0148186 ]])
- residual_singular_values(singular_value_index)float640.5361 0.5318 ... 0.3808 0.3743
array([0.53606556, 0.53183234, 0.53026022, 0.52843202, 0.52454015, 0.52325718, 0.51946369, 0.51643009, 0.51366028, 0.50999476, 0.50945057, 0.50494574, 0.50439065, 0.50084274, 0.50009243, 0.4951946 , 0.49354277, 0.49197319, 0.49014801, 0.48809796, 0.48641966, 0.48393184, 0.4830583 , 0.48095344, 0.47774737, 0.47513735, 0.47461724, 0.47106964, 0.46930451, 0.46876492, 0.46685872, 0.46452184, 0.46195046, 0.45951578, 0.45708428, 0.45572346, 0.4552988 , 0.45159829, 0.45026924, 0.44976904, 0.44698286, 0.44473276, 0.44395882, 0.44044129, 0.43940338, 0.43706707, 0.43640693, 0.43450485, 0.43332084, 0.4288044 , 0.42801376, 0.42621219, 0.42206566, 0.42173048, 0.41964406, 0.41868728, 0.41699256, 0.4152083 , 0.41349024, 0.4119684 , 0.40881955, 0.4079785 , 0.40124726, 0.39912175, 0.39698473, 0.39305605, 0.3922677 , 0.39165456, 0.38554183, 0.38456357, 0.38082229, 0.37430355])
- residual_right_singular_vectors(right_singular_value_index, spectral)float64-0.06183 -0.08975 ... 0.06401
array([[-6.18279783e-02, -8.97505392e-02, 2.13891284e-02, ..., 3.84872532e-02, 1.37906275e-01, 2.67543606e-05], [ 2.75935673e-02, 4.90844921e-02, -1.20512600e-01, ..., -2.98876321e-03, 1.28935955e-01, 6.23416812e-02], [-1.32118249e-01, -4.52348305e-02, 1.75139331e-01, ..., 6.86631468e-02, 5.28425736e-03, 1.54428476e-01], ..., [-6.40365007e-02, -3.10203408e-01, 1.17917412e-01, ..., 1.04900158e-01, -1.55924056e-01, 1.76205700e-01], [ 1.06744892e-01, -1.18967849e-01, -2.12115265e-01, ..., 2.04308543e-01, 2.26209859e-01, 1.61689986e-01], [-3.21125977e-02, 6.68501327e-02, 1.14579446e-01, ..., 7.41766407e-02, -1.52010264e-01, 6.40050540e-02]])
- fitted_data(time, spectral)float64-1.095e-13 5.835e-15 ... 1.537
array([[-1.09470918e-13, 5.83517609e-15, -3.24611109e-14, ..., 2.10595430e-14, 6.60842908e-15, 1.59698643e-14], [-1.73784598e-14, -4.38919734e-14, 1.99493200e-15, ..., -3.32373018e-15, 1.71245125e-14, -4.41036097e-14], [ 2.49062923e-14, 5.62397351e-15, 1.05609965e-14, ..., -4.53803661e-15, -2.76167977e-14, 4.03787924e-14], ..., [ 1.47188090e+00, 1.63642115e+00, 1.81527033e+00, ..., 1.89374154e+00, 1.71010578e+00, 1.53944766e+00], [ 1.47052319e+00, 1.63491132e+00, 1.81359504e+00, ..., 1.89199961e+00, 1.70853277e+00, 1.53803158e+00], [ 1.46916651e+00, 1.63340264e+00, 1.81192102e+00, ..., 1.89025898e+00, 1.70696092e+00, 1.53661656e+00]])
- species_concentration(time, species)float646.101e-39 2.314e-41 ... 0.2516
array([[6.10072642e-39, 2.31444836e-41, 5.24498291e-44], [2.24434927e-38, 8.57879892e-41, 1.95867290e-43], [8.17488070e-38, 3.14855890e-40, 7.24285217e-43], ..., [5.35711584e-05, 6.71723774e-03, 2.52095615e-01], [5.33039509e-05, 6.69738773e-03, 2.51863727e-01], [5.30380762e-05, 6.67759584e-03, 2.51632011e-01]])
- species_associated_spectra(spectral, species)float6415.0 0.03952 ... 0.002203 6.107
array([[ 1.50016760e+01, 3.95233239e-02, 5.83434089e+00], [ 1.64707909e+01, 7.21680436e-02, 6.48584872e+00], [ 1.79674818e+01, 1.18165832e-01, 7.19375482e+00], [ 1.94619002e+01, 2.02846603e-01, 7.95051908e+00], [ 2.09455075e+01, 3.20344210e-01, 8.76361164e+00], [ 2.23854289e+01, 5.13041362e-01, 9.63045309e+00], [ 2.37596548e+01, 7.91130283e-01, 1.05495429e+01], [ 2.50511111e+01, 1.18486728e+00, 1.15223485e+01], [ 2.62330840e+01, 1.72739278e+00, 1.25481577e+01], [ 2.72858465e+01, 2.45291828e+00, 1.36217738e+01], [ 2.81865706e+01, 3.39497230e+00, 1.47422594e+01], [ 2.89205086e+01, 4.56644977e+00, 1.59087928e+01], [ 2.94704612e+01, 5.98084502e+00, 1.71153452e+01], [ 2.98332157e+01, 7.62007173e+00, 1.83584619e+01], [ 2.99930567e+01, 9.45074258e+00, 1.96308600e+01], [ 2.99495364e+01, 1.14078225e+01, 2.09314695e+01], [ 2.97009601e+01, 1.34028437e+01, 2.22479458e+01], [ 2.92594040e+01, 1.53230937e+01, 2.35768608e+01], [ 2.86279615e+01, 1.70482668e+01, 2.49090011e+01], [ 2.78168004e+01, 1.84616304e+01, 2.62373922e+01], ... [ 2.39458014e-01, 2.68140244e-03, 2.68045504e+01], [ 1.86349877e-01, 7.08644301e-04, 2.54807565e+01], [ 1.37346316e-01, 3.49714776e-03, 2.41482176e+01], [ 1.05949155e-01, -1.62090633e-04, 2.28180363e+01], [ 7.96999117e-02, 3.57992647e-03, 2.14935145e+01], [ 5.93096082e-02, 3.77463116e-03, 2.01854888e+01], [ 4.60181066e-02, 8.73441902e-05, 1.89017529e+01], [ 3.18905809e-02, 4.35547020e-03, 1.76439676e+01], [ 2.22055101e-02, 2.23141112e-03, 1.64221858e+01], [ 1.58257399e-02, 3.94070253e-03, 1.52372878e+01], [ 1.24914179e-02, 6.66951526e-04, 1.40964168e+01], [ 9.81662626e-03, -1.85220999e-03, 1.30028557e+01], [ 4.79021597e-03, 8.85610175e-04, 1.19556466e+01], [ 4.56566765e-03, -1.01233875e-03, 1.09613399e+01], [ 3.85883713e-03, 1.15878939e-03, 1.00177122e+01], [ 4.08008222e-03, 1.70189606e-04, 9.12895219e+00], [ 8.40513011e-04, -4.49357932e-04, 8.29367344e+00], [ 1.29739459e-03, -8.28982274e-04, 7.51201898e+00], [-8.27264600e-04, -6.05035215e-04, 6.78357652e+00], [-3.67739879e-04, 2.20284859e-03, 6.10654367e+00]])
- irf(time)float642.007e-37 7.328e-37 ... 0.0 0.0
array([2.00721127e-37, 7.32823924e-37, 2.64888597e-36, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00])
- irf_center()float640.3
array(0.29999419)
- irf_width()float640.1
array(0.1000002)
- decay_associated_spectra(spectral, component)float6425.83 -21.77 10.94 ... -22.89 11.45
array([[ 25.83390168, -21.77351699, 10.94129129], [ 28.44208175, -24.13437173, 12.16308087], [ 31.1501362 , -26.67329004, 13.49063561], [ 33.85079437, -29.29870946, 14.90981531], [ 36.56417182, -32.05329328, 16.43462895], [ 39.14665363, -34.82146404, 18.06023927], [ 41.54795024, -37.57212768, 19.7838323 ], [ 43.67813108, -40.23518004, 21.60816004], [ 45.4263353 , -42.72513792, 23.53188659], [ 46.67761094, -44.9370312 , 25.54526677], [ 47.32359115, -46.78356323, 27.64654264], [ 47.31576634, -48.22943081, 29.83417303], [ 46.59192207, -49.2183131 , 32.09685227], [ 45.18756719, -49.7824527 , 34.42810122], [ 43.15677155, -49.97797743, 36.8142626 ], [ 40.65959448, -49.9633876 , 39.25332948], [ 37.89227943, -49.91347106, 41.72215172], [ 35.14213062, -50.09702721, 44.21430063], [ 32.6956036 , -50.78014001, 46.71249791], [ 30.8414956 , -52.22835953, 49.20366437], ... [ 50.45269293, -100.48050581, 50.2672709 ], [ 47.92430696, -95.52268277, 47.7847257 ], [ 45.37174367, -90.52017813, 45.28578078], [ 42.8573159 , -85.54262404, 42.79125729], [ 40.34014481, -80.56779199, 40.3073471 ], [ 37.86860312, -75.66366584, 37.85437234], [ 35.45936933, -70.86030031, 35.44694909], [ 33.07804006, -66.134341 , 33.08819152], [ 30.7845812 , -61.55932813, 30.79695244], [ 28.55395252, -57.11300907, 28.5748823 ], [ 26.42130848, -52.84419435, 26.43537728], [ 24.37607619, -48.7508532 , 24.38459363], [ 22.40219926, -44.81814419, 22.42073515], [ 20.54382411, -41.09534442, 20.55608598], [ 18.76974874, -37.55236625, 18.78647635], [ 17.10729508, -34.22297659, 17.11976158], [ 15.54065876, -31.09315986, 15.55334161], [ 14.07758767, -28.16377493, 14.08748466], [ 12.7101227 , -25.43236753, 12.72141756], [ 11.43510407, -22.88723206, 11.45176025]])
- a_matrix(component, species)float641.0 -2.499 1.874 ... 0.0 0.0 1.875
array([[ 1. , -2.49883862, 1.87356007], [ 0. , 2.49883862, -3.74888609], [ 0. , 0. , 1.87532602]])
- k_matrix(to_species, from_species)float64-0.5 0.0 0.0 ... 0.0 0.2999 -0.1
array([[-0.50003798, 0. , 0. ], [ 0.50003798, -0.29992983, 0. ], [ 0. , 0.29992983, -0.10001011]])
- k_matrix_reduced(to_species, from_species)float640.0 0.0 0.0 0.5 ... 0.0 0.2999 0.1
array([[0. , 0. , 0. ], [0.50003798, 0. , 0. ], [0. , 0.29992983, 0.10001011]])
- source_path :
- dataset_1.nc
- root_mean_square_error :
- 0.01000158369561628
- weighted_root_mean_square_error :
- 0.01000158369561628
- dataset_scale :
- 1
Visualize the Result
The resulting data can be visualized the same way as the dataset. To judge the quality of the fit, you should look at first left and right singular vectors of the residual.
[19]:
residual_left = result_dataset.residual_left_singular_vectors.sel(left_singular_value_index=0)
residual_right = result_dataset.residual_right_singular_vectors.sel(right_singular_value_index=0)
residual_left.plot.line(x="time", aspect=2, size=5)
residual_right.plot.line(x="spectral", aspect=2, size=5);
Finally, you can save your result.
[20]:
save_dataset(result_dataset, "dataset1.nc")