-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: fitting and constraints with scripts
- Loading branch information
Showing
6 changed files
with
541 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
800 0.001643 | ||
798 0.001743 | ||
796 0.001408 | ||
794 0.001468 | ||
792 0.001379 | ||
790 0.001525 | ||
788 0.001843 | ||
786 0.001415 | ||
784 0.001803 | ||
782 0.001845 | ||
780 0.001629 | ||
778 0.001667 | ||
776 0.001895 | ||
774 0.001646 | ||
772 0.001383 | ||
770 0.00246 | ||
768 0.002561 | ||
766 0.002367 | ||
764 0.002536 | ||
762 0.002606 | ||
760 0.002308 | ||
758 0.002297 | ||
756 0.002836 | ||
754 0.002659 | ||
752 0.003465 | ||
750 0.003127 | ||
748 0.003031 | ||
746 0.003029 | ||
744 0.003542 | ||
742 0.003489 | ||
740 0.003467 | ||
738 0.0041 | ||
736 0.003593 | ||
734 0.0036 | ||
732 0.003593 | ||
730 0.004186 | ||
728 0.004185 | ||
726 0.004569 | ||
724 0.004929 | ||
722 0.004644 | ||
720 0.005095 | ||
718 0.004828 | ||
716 0.005149 | ||
714 0.005618 | ||
712 0.005928 | ||
710 0.00574 | ||
708 0.005709 | ||
706 0.005426 | ||
704 0.006111 | ||
702 0.006343 | ||
700 0.006348 | ||
698 0.006494 | ||
696 0.006924 | ||
694 0.007119 | ||
692 0.007312 | ||
690 0.007651 | ||
688 0.008147 | ||
686 0.008378 | ||
684 0.008518 | ||
682 0.008955 | ||
680 0.00894 | ||
678 0.009101 | ||
676 0.009647 | ||
674 0.009995 | ||
672 0.010283 | ||
670 0.010837 | ||
668 0.011105 | ||
666 0.011565 | ||
664 0.012201 | ||
662 0.012485 | ||
660 0.012852 | ||
658 0.013529 | ||
656 0.01396 | ||
654 0.014362 | ||
652 0.014922 | ||
650 0.015571 | ||
648 0.016087 | ||
646 0.016744 | ||
644 0.017519 | ||
642 0.018117 | ||
640 0.018654 | ||
638 0.019088 | ||
636 0.020056 | ||
634 0.020963 | ||
632 0.021443 | ||
630 0.022259 | ||
628 0.02252 | ||
626 0.023889 | ||
624 0.025035 | ||
622 0.026036 | ||
620 0.026991 | ||
618 0.028047 | ||
616 0.028953 | ||
614 0.03016 | ||
612 0.031286 | ||
610 0.032255 | ||
608 0.033422 | ||
606 0.034664 | ||
604 0.03608 | ||
602 0.037399 | ||
600 0.038317 | ||
598 0.039408 | ||
596 0.041086 | ||
594 0.042381 | ||
592 0.043706 | ||
590 0.044969 | ||
588 0.046131 | ||
586 0.04739 | ||
584 0.048911 | ||
582 0.050126 | ||
580 0.051712 | ||
578 0.052873 | ||
576 0.053823 | ||
574 0.054594 | ||
572 0.055445 | ||
570 0.056521 | ||
568 0.057103 | ||
566 0.057817 | ||
564 0.058624 | ||
562 0.059114 | ||
560 0.059913 | ||
558 0.060496 | ||
556 0.060658 | ||
554 0.060684 | ||
552 0.060566 | ||
550 0.060088 | ||
548 0.059807 | ||
546 0.059161 | ||
544 0.058739 | ||
542 0.058047 | ||
540 0.057424 | ||
538 0.056486 | ||
536 0.055476 | ||
534 0.054197 | ||
532 0.052917 | ||
530 0.051735 | ||
528 0.050462 | ||
526 0.049202 | ||
524 0.048093 | ||
522 0.046993 | ||
520 0.045851 | ||
518 0.044667 | ||
516 0.043455 | ||
514 0.042189 | ||
512 0.041042 | ||
510 0.039808 | ||
508 0.039027 | ||
506 0.038089 | ||
504 0.037114 | ||
502 0.036467 | ||
500 0.035897 | ||
498 0.034787 | ||
496 0.034242 | ||
494 0.033755 | ||
492 0.033474 | ||
490 0.033171 | ||
488 0.032616 | ||
486 0.032217 | ||
484 0.031976 | ||
482 0.031685 | ||
480 0.031401 | ||
478 0.031147 | ||
476 0.031171 | ||
474 0.03102 | ||
472 0.030966 | ||
470 0.031028 | ||
468 0.030878 | ||
466 0.030911 | ||
464 0.030897 | ||
462 0.031188 | ||
460 0.03135 | ||
458 0.03129 | ||
456 0.031277 | ||
454 0.031181 | ||
452 0.031216 | ||
450 0.0313 | ||
448 0.031556 | ||
446 0.03169 | ||
444 0.031457 | ||
442 0.0314 | ||
440 0.031682 | ||
438 0.031929 | ||
436 0.031899 | ||
434 0.032046 | ||
432 0.032269 | ||
430 0.03234 | ||
428 0.032347 | ||
426 0.032419 | ||
424 0.032349 | ||
422 0.032482 | ||
420 0.032601 | ||
418 0.03274 | ||
416 0.033093 | ||
414 0.033116 | ||
412 0.033373 | ||
410 0.033469 | ||
408 0.033483 | ||
406 0.033842 | ||
404 0.03411 | ||
402 0.034002 | ||
400 0.034068 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
from mstm_studio.alloy_AuAg import AlloyAuAg | ||
from mstm_studio.contributions import LinearBackground, MieLognormSpheresCached | ||
from mstm_studio.fit_spheres_optic import Fitter | ||
|
||
fitter = Fitter(exp_filename='experiment.dat') # load experiment from tabbed file | ||
fitter.set_extra_contributions( | ||
[LinearBackground(fitter.wls), # wavelengths from experiment | ||
MieLognormSpheresCached(fitter.wls, 'LN Mie')], # cached version for faster fittting | ||
[0.02, 0.0001, 0.1, 2.0, 0.4]) # initial values for a, b, C, mu, sigma | ||
fitter.extra_contributions[1].set_material(AlloyAuAg(1.), 1.5) # gold particles in glass | ||
fitter.set_spheres(None) # no spheres - no slow MSTM runs | ||
|
||
# run fit (takes ~20 seconds on 2GHz CPU) | ||
fitter.run() | ||
|
||
fitter.report_result() | ||
|
||
# plot results | ||
import matplotlib.pyplot as plt | ||
plt.plot(fitter.wls, fitter.exp, 'ro', label='exp.') | ||
plt.plot(fitter.wls, fitter.calc, 'b-', label='fit') | ||
plt.xlabel('Wavelength, nm') | ||
plt.ylabel('Exctinction, a.u.') | ||
plt.legend() | ||
plt.savefig('fit_by_Mie.png', bbox_inches='tight') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
from mstm_studio.alloy_AuAg import AlloyAuAg | ||
from mstm_studio.contributions import LinearBackground, MieLognormSpheresCached | ||
from mstm_studio.mstm_spectrum import ExplicitSpheres, Profiler | ||
from mstm_studio.fit_spheres_optic import Fitter, FixConstraint, ConcentricConstraint | ||
|
||
fitter = Fitter(exp_filename='experiment.dat') # load experiment from tabbed file | ||
fitter.set_extra_contributions( | ||
[LinearBackground(fitter.wls)], # wavelengths from experiment | ||
[0.02, 0.0001]) # initial values for a, b | ||
|
||
spheres = ExplicitSpheres(2, [0,0,0,10,0,0,0,12], mat_filename=[AlloyAuAg(1.),AlloyAuAg(0.)]) | ||
fitter.set_spheres(spheres) # core-shell Au@Ag particle | ||
fitter.set_matrix(1.5) # in glass | ||
|
||
fitter.add_constraint(ConcentricConstraint(0, 1)) # 0 -> 1 | ||
fitter.add_constraint(FixConstraint('x00')) | ||
fitter.add_constraint(FixConstraint('y00')) | ||
fitter.add_constraint(FixConstraint('z00')) | ||
|
||
# run fit (takes ~200 seconds on 2GHz CPU) | ||
with Profiler(): | ||
fitter.run() | ||
|
||
fitter.report_result() | ||
|
||
# plot results | ||
import matplotlib.pyplot as plt | ||
plt.plot(fitter.wls, fitter.exp, 'ro', label='exp.') | ||
plt.plot(fitter.wls, fitter.calc, 'b-', label='fit') | ||
plt.xlabel('Wavelength, nm') | ||
plt.ylabel('Exctinction, a.u.') | ||
plt.legend() | ||
plt.savefig('fit_by_core-shell.png', bbox_inches='tight') | ||
|
||
|
||
# ~ ChiSq: 0.002354 | ||
# ~ Optimal parameters | ||
# ~ a00: 1.284882 (Varied:True) | ||
# ~ a01: 1.958142 (Varied:True) | ||
# ~ ext00: 0.186312 (Varied:True) | ||
# ~ ext01: -0.000247 (Varied:True) | ||
# ~ scale: -0.063814 (Varied:True) | ||
# ~ x00: 0.000000 (Varied:False) | ||
# ~ x01: 0.000000 (Varied:False) | ||
# ~ y00: 0.000000 (Varied:False) | ||
# ~ y01: 0.000000 (Varied:False) | ||
# ~ z00: 0.000000 (Varied:False) | ||
# ~ z01: 0.000000 (Varied:False) | ||
|
Oops, something went wrong.