Skip to content

Commit 60648b7

Browse files
committed
deploy: cf160d7
1 parent f0ea994 commit 60648b7

File tree

30 files changed

+156049
-170
lines changed

30 files changed

+156049
-170
lines changed

tutorials/1_models-quick-fit.html

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@
197197
<ul class="current nav bd-sidenav">
198198
<li class="toctree-l1 current active"><a class="current reference internal" href="#">Modeling 1: Make a quick fit using astropy.modeling</a></li>
199199
<li class="toctree-l1"><a class="reference internal" href="2_user-defined-model.html">Modeling 2: Create a User Defined Model using astropy.modeling</a></li>
200-
201-
202200
</ul>
203201

204202
</div>
@@ -690,7 +688,7 @@ <h2>2) Fit a Polynomial model: Choose fitter wisely<a class="headerlink" href="#
690688
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Text(0, 0.5, &#39;$y_1$&#39;)
691689
</pre></div>
692690
</div>
693-
<img alt="_images/29eeec4d3dad2b705ea5f7b2791844247afecb976c6f267ff16f1118872200e5.png" src="_images/29eeec4d3dad2b705ea5f7b2791844247afecb976c6f267ff16f1118872200e5.png" />
691+
<img alt="_images/3634bb8b4c277819f7ce4c233fc84552a8f897def45ba7df53cedd5578cf8fde.png" src="_images/3634bb8b4c277819f7ce4c233fc84552a8f897def45ba7df53cedd5578cf8fde.png" />
694692
</div>
695693
</div>
696694
<p>To fit this data let’s remember the three steps: model, fitter and perform fit.</p>
@@ -717,8 +715,8 @@ <h2>2) Fit a Polynomial model: Choose fitter wisely<a class="headerlink" href="#
717715
Degree: 3
718716
Parameters:
719717
c0 c1 c2 c3
720-
------------------ ----------------- ------------------- ------------------
721-
-9.172425941582441 12.59165151659485 -6.4125256413095135 1.0733596272176298
718+
------------------ ------------------ ------------------ ------------------
719+
-8.414565124986794 11.315131284061778 -5.936420715916029 1.0350472068170264
722720
</pre></div>
723721
</div>
724722
</div>
@@ -751,9 +749,9 @@ <h2>2) Fit a Polynomial model: Choose fitter wisely<a class="headerlink" href="#
751749
Model set size: 1
752750
Degree: 3
753751
Parameters:
754-
c0 c1 c2 c3
755-
------------------ -------------------- ------------------ ------------------
756-
-2.181910827369914 -0.09737921440192401 -0.641962352228048 0.3102451837171443
752+
c0 c1 c2 c3
753+
------------------- -------------------- ------------------ ------------------
754+
0.20564283089638824 -0.15716654941300878 -1.239243988919935 0.4355616696000767
757755
</pre></div>
758756
</div>
759757
</div>
@@ -788,7 +786,7 @@ <h3>Compare results<a class="headerlink" href="#compare-results" title="Link to
788786
</div>
789787
</div>
790788
<div class="cell_output docutils container">
791-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared with LinearLSQFitter: 1.976453546686968
789+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared with LinearLSQFitter: 1.7254506507627694
792790
</pre></div>
793791
</div>
794792
</div>
@@ -801,7 +799,7 @@ <h3>Compare results<a class="headerlink" href="#compare-results" title="Link to
801799
</div>
802800
</div>
803801
<div class="cell_output docutils container">
804-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared with SimplexLSQFitter: 3.6404719596242217
802+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared with SimplexLSQFitter: 4.580753153741815
805803
</pre></div>
806804
</div>
807805
</div>
@@ -820,10 +818,10 @@ <h3>Compare results<a class="headerlink" href="#compare-results" title="Link to
820818
</div>
821819
</div>
822820
<div class="cell_output docutils container">
823-
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;matplotlib.legend.Legend at 0x7f043d6b6c60&gt;
821+
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;matplotlib.legend.Legend at 0x7ff08227ba10&gt;
824822
</pre></div>
825823
</div>
826-
<img alt="_images/5daacb87eb9a956a0a0d1bf47cf76b22fef5b552f8d494da052155270d4be995.png" src="_images/5daacb87eb9a956a0a0d1bf47cf76b22fef5b552f8d494da052155270d4be995.png" />
824+
<img alt="_images/b2cb6953351ca9c5f39fbc468440cdd51731a2b59186590a4e26b1d805a046f3.png" src="_images/b2cb6953351ca9c5f39fbc468440cdd51731a2b59186590a4e26b1d805a046f3.png" />
827825
</div>
828826
</div>
829827
<p>Results are as espected, the fit performed with the linear fitter is better than the second, non linear one.</p>
@@ -860,7 +858,7 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
860858
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Text(0, 0.5, &#39;$y_2$&#39;)
861859
</pre></div>
862860
</div>
863-
<img alt="_images/a439ff8bd1722f8eb99d8ab93605e4bbd374fe7ac8a966b770601e8129461f6d.png" src="_images/a439ff8bd1722f8eb99d8ab93605e4bbd374fe7ac8a966b770601e8129461f6d.png" />
861+
<img alt="_images/9424b3add19b739bc9cbfc66cf567663995d37f79f0e0ac2bab63e87ff87f7d1.png" src="_images/9424b3add19b739bc9cbfc66cf567663995d37f79f0e0ac2bab63e87ff87f7d1.png" />
864862
</div>
865863
</div>
866864
<p>Let’s do our three steps to make the fit we want. For this fit we’re going to use a non-linear fitter, <code class="docutils literal notranslate"><span class="pre">LevMarLSQFitter</span></code>, because the model we need (<code class="docutils literal notranslate"><span class="pre">Gaussian1D</span></code>) is non-linear in the parameters.</p>
@@ -885,9 +883,9 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
885883
Outputs: (&#39;y&#39;,)
886884
Model set size: 1
887885
Parameters:
888-
amplitude mean stddev
889-
----------------- ------------------ -----------------
890-
9.703971972909294 0.2905529841691312 10.24439667276053
886+
amplitude mean stddev
887+
------------------ ------------------- ------------------
888+
10.161667885872756 0.16429784623682972 10.000409076033547
891889
</pre></div>
892890
</div>
893891
</div>
@@ -913,7 +911,7 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
913911
</div>
914912
</div>
915913
<div class="cell_output docutils container">
916-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[0.05013324 0.07443702 0.07476521]
914+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[0.05133544 0.06625433 0.06645726]
917915
</pre></div>
918916
</div>
919917
</div>
@@ -934,9 +932,9 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
934932
</div>
935933
</div>
936934
<div class="cell_output docutils container">
937-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Amplitude: 9.703971972909294 +\- 0.22390454000753693
938-
Mean: 0.2905529841691312 +\- 0.27283148663688805
939-
Standard Deviation: 10.24439667276053 +\- 0.2734322676754956
935+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Amplitude: 10.161667885872756 +\- 0.2265732649327809
936+
Mean: 0.16429784623682972 +\- 0.2573991704994828
937+
Standard Deviation: 10.000409076033547 +\- 0.2577930649461142
940938
</pre></div>
941939
</div>
942940
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;&gt;:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
@@ -945,11 +943,11 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
945943
&lt;&gt;:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
946944
&lt;&gt;:4: SyntaxWarning: invalid escape sequence &#39;\-&#39;
947945
&lt;&gt;:6: SyntaxWarning: invalid escape sequence &#39;\-&#39;
948-
/tmp/ipykernel_3578/1659586526.py:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
946+
/tmp/ipykernel_3529/1659586526.py:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
949947
&quot;Amplitude: {} +\- {}&quot;.format(best_fit_gauss.amplitude.value, np.sqrt(cov_diag[0]))
950-
/tmp/ipykernel_3578/1659586526.py:4: SyntaxWarning: invalid escape sequence &#39;\-&#39;
948+
/tmp/ipykernel_3529/1659586526.py:4: SyntaxWarning: invalid escape sequence &#39;\-&#39;
951949
print(&quot;Mean: {} +\- {}&quot;.format(best_fit_gauss.mean.value, np.sqrt(cov_diag[1])))
952-
/tmp/ipykernel_3578/1659586526.py:6: SyntaxWarning: invalid escape sequence &#39;\-&#39;
950+
/tmp/ipykernel_3529/1659586526.py:6: SyntaxWarning: invalid escape sequence &#39;\-&#39;
953951
&quot;Standard Deviation: {} +\- {}&quot;.format(
954952
</pre></div>
955953
</div>
@@ -980,7 +978,7 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
980978
</div>
981979
</div>
982980
<div class="cell_output docutils container">
983-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 9.70397395 0.29055502 10.24439249]
981+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[10.16166902 0.1642994 10.00040685]
984982
</pre></div>
985983
</div>
986984
</div>
@@ -994,9 +992,9 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
994992
</div>
995993
</div>
996994
<div class="cell_output docutils container">
997-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Amplitude: 9.703973951984176 +\- 0.2085755106086411
998-
Mean: 0.2905550176310043 +\- 0.25415064931293285
999-
Standard Deviation: 10.24439248784542 +\- 0.25471029589649113
995+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Amplitude: 10.16166901860214 +\- 0.2180138118181192
996+
Mean: 0.1642993992949413 +\- 0.24767662180935193
997+
Standard Deviation: 10.00040684622568 +\- 0.24805566376335159
1000998
</pre></div>
1001999
</div>
10021000
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;&gt;:1: SyntaxWarning: invalid escape sequence &#39;\-&#39;
@@ -1005,11 +1003,11 @@ <h2>3) Fit a Gaussian: Let’s compare to scipy<a class="headerlink" href="#fit-
10051003
&lt;&gt;:1: SyntaxWarning: invalid escape sequence &#39;\-&#39;
10061004
&lt;&gt;:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
10071005
&lt;&gt;:3: SyntaxWarning: invalid escape sequence &#39;\-&#39;
1008-
/tmp/ipykernel_3578/2222327920.py:1: SyntaxWarning: invalid escape sequence &#39;\-&#39;
1006+
/tmp/ipykernel_3529/2222327920.py:1: SyntaxWarning: invalid escape sequence &#39;\-&#39;
10091007
print(&quot;Amplitude: {} +\- {}&quot;.format(p_opt[0], np.sqrt(p_cov[0, 0])))
1010-
/tmp/ipykernel_3578/2222327920.py:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
1008+
/tmp/ipykernel_3529/2222327920.py:2: SyntaxWarning: invalid escape sequence &#39;\-&#39;
10111009
print(&quot;Mean: {} +\- {}&quot;.format(p_opt[1], np.sqrt(p_cov[1, 1])))
1012-
/tmp/ipykernel_3578/2222327920.py:3: SyntaxWarning: invalid escape sequence &#39;\-&#39;
1010+
/tmp/ipykernel_3529/2222327920.py:3: SyntaxWarning: invalid escape sequence &#39;\-&#39;
10131011
print(&quot;Standard Deviation: {} +\- {}&quot;.format(p_opt[2], np.sqrt(p_cov[2, 2])))
10141012
</pre></div>
10151013
</div>
@@ -1025,7 +1023,7 @@ <h3>Compare results<a class="headerlink" href="#id1" title="Link to this heading
10251023
</div>
10261024
</div>
10271025
<div class="cell_output docutils container">
1028-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared using astropy.modeling: 0.8677576541316718
1026+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared using astropy.modeling: 0.9258750059366527
10291027
</pre></div>
10301028
</div>
10311029
</div>
@@ -1038,7 +1036,7 @@ <h3>Compare results<a class="headerlink" href="#id1" title="Link to this heading
10381036
</div>
10391037
</div>
10401038
<div class="cell_output docutils container">
1041-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared using scipy: 0.8677576541512168
1039+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Reduced Chi Squared using scipy: 0.9258750059343416
10421040
</pre></div>
10431041
</div>
10441042
</div>
@@ -1056,10 +1054,10 @@ <h3>Compare results<a class="headerlink" href="#id1" title="Link to this heading
10561054
</div>
10571055
</div>
10581056
<div class="cell_output docutils container">
1059-
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;matplotlib.legend.Legend at 0x7f043df28680&gt;
1057+
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;matplotlib.legend.Legend at 0x7ff0821b5cd0&gt;
10601058
</pre></div>
10611059
</div>
1062-
<img alt="_images/6ba5eb18131d7de1839874150236563bd66c697a852a18b44ca6d275eb605649.png" src="_images/6ba5eb18131d7de1839874150236563bd66c697a852a18b44ca6d275eb605649.png" />
1060+
<img alt="_images/9d65948539694d6a9224f22edf286e6e920acf5805cb94eeeb84f92f19db8cf0.png" src="_images/9d65948539694d6a9224f22edf286e6e920acf5805cb94eeeb84f92f19db8cf0.png" />
10631061
</div>
10641062
</div>
10651063
<p><strong>Conclusion:</strong> Choose the method most convenient for every case you need to fit. We recomend <code class="docutils literal notranslate"><span class="pre">astropy.modeling</span></code> because is easier to write the name of the function you want to fit than to remember the expression every time we want to use it. Also, <code class="docutils literal notranslate"><span class="pre">astropy.modeling</span></code> becomes useful with more complicated models like <a class="reference external" href="http://docs.astropy.org/en/stable/modeling/#compound-models">two gaussians</a> plus a <a class="reference external" href="http://docs.astropy.org/en/stable/modeling/#blackbody-radiation">black body</a>, but that is another tutorial.</p>
@@ -1111,7 +1109,7 @@ <h2>4) Exercise: Your turn to choose<a class="headerlink" href="#exercise-your-t
11111109
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Text(0, 0.5, &#39;$y_3$&#39;)
11121110
</pre></div>
11131111
</div>
1114-
<img alt="_images/fa0bf1710de39a1ec3631f0a0a5f8d3d9eb331e2454ba3c044a3b4f74c5a81f9.png" src="_images/fa0bf1710de39a1ec3631f0a0a5f8d3d9eb331e2454ba3c044a3b4f74c5a81f9.png" />
1112+
<img alt="_images/5224aeb98f66c2f8304a7ecdd3d93e75f3acdf064da194bc12dfc2cfbbe1e7e0.png" src="_images/5224aeb98f66c2f8304a7ecdd3d93e75f3acdf064da194bc12dfc2cfbbe1e7e0.png" />
11151113
</div>
11161114
</div>
11171115
</section>

0 commit comments

Comments
 (0)