Repository: ArgonneCPAC/diffstar (language: python)

Issue:
Fix bug in unit testing data
This PR resolves a bug in the unit-testing data brought in by #3. Previously, the `dt` array was computed incorrectly, which is now fixed. The effect was not small, as the figure shows. 
![buggy_freeze_pr](https://user-images.githubusercontent.com/6951595/184443241-addf10d6-0f0d-471f-8665-57f451458378.png)


Improve unit testing that freezes the behavior of Diffstar
In PR #3 we brought in code that was intended to freeze the behavior of Diffstar to agree with the results we submitted for publication. However, that PR #3 had a bug in the generation of the unit-testing data, as shown in #10. This bug never would have been made if we had instead taken the extra step to reproduce the actual published fits that we made publicly available as part of the paper. Before publishing, we should take this extra step to improve the rigor of our unit testing by reproducing, say, 10 actual published fits that become included as part of the unit-testing suite. 


Discussion / hints:

Fix patch:
diff --git a/scripts/load_bpl.py b/scripts/load_bpl.py
new file mode 100644
index 0000000..6d6cb83
--- /dev/null
+++ b/scripts/load_bpl.py
@@ -0,0 +1,156 @@
+"""
+"""
+import os
+import numpy as np
+import h5py
+from collections import OrderedDict
+from astropy.table import Table
+from diffstar.utils import _jax_get_dt_array
+from diffstar.stars import _get_bounded_sfr_params_vmap
+from diffstar.quenching import _get_bounded_q_params_vmap
+
+LGT0 = 1.13980
+
+TASSO_BPL_DRN = "/Users/aphearin/work/DATA/diffstar_data"
+BEBOP_BPL_DRN = "/lcrc/project/halotools/diffstar_data"
+
+MAH_COLNAMES = [
+    "mah_fit_logmp",
+    "mah_fit_logtc",
+    "mah_fit_early_index",
+    "mah_fit_late_index",
+]
+MS_U_COLNAMES = [
+    "sfh_fit_u_lgmcrit",
+    "sfh_fit_u_lgy_at_mcrit",
+    "sfh_fit_u_indx_lo",
+    "sfh_fit_u_indx_hi",
+    "sfh_fit_u_tau_dep",
+]
+Q_U_COLNAMES = [
+    "sfh_fit_u_qt",
+    "sfh_fit_u_qs",
+    "sfh_fit_u_q_drop",
+    "sfh_fit_u_q_rejuv",
+]
+
+
+def load_bpl_diffstar_data(
+    drn,
+    mah_colnames=MAH_COLNAMES,
+    ms_u_colnames=MS_U_COLNAMES,
+    q_u_colnames=Q_U_COLNAMES,
+):
+    bpl_fn = os.path.join(drn, "bpl_diffmah_cens.npy")
+    trunks = np.load(bpl_fn)
+
+    diffmah_fn = os.path.join(drn, "run1_bpl_diffmah")
+    diffmah_fits = OrderedDict()
+    with h5py.File(diffmah_fn) as hdf:
+        for key in hdf.keys():
+            diffmah_fits[key] = hdf[key][...]
+
+    diffstar_fn = os.path.join(drn, "run1_bpl_diffstar_default.h5")
+    diffstar_fits = OrderedDict()
+    with h5py.File(diffstar_fn) as hdf:
+        for key in hdf.keys():
+            diffstar_fits[key] = hdf[key][...]
+
+    pat = "{0} and {1} have mismatched halo_id column"
+    msg = pat.format(bpl_fn, diffmah_fn)
+    assert np.allclose(trunks["halo_id"], diffmah_fits["halo_id"]), msg
+
+    msg = pat.format(bpl_fn, diffstar_fn)
+    assert np.allclose(trunks["halo_id"], diffstar_fits["halo_id"]), msg
+
+    bpl = Table()
+    bpl["halo_id"] = trunks["halo_id"]
+    bpl["upid"] = trunks["upid"]
+    bpl["sfrh_sim"] = trunks["sfr_history_main_prog"]
+
+    time_fn = os.path.join(drn, "bpl_cosmic_time.npy")
+    t_bpl = np.load(time_fn)
+    dt_bpl = _jax_get_dt_array(t_bpl)
+    log_mahs, log_smh = _compute_logmah_logsmh(
+        dt_bpl, trunks["mpeak_history_main_prog"], trunks["sfr_history_main_prog"]
+    )
+    bpl["log_mah_sim"] = log_mahs
+    bpl["logsmh_sim"] = log_smh
+
+    mah_keys = ["logmp_fit", "mah_logtc", "mah_k", "early_index", "late_index", "loss"]
+    for key in mah_keys:
+        if key[:4] != "mah_":
+            newkey = "mah_fit_" + key
+        else:
+            newkey = "mah_fit_" + key[4:]
+        bpl[newkey] = diffmah_fits[key]
+    bpl.rename_column("mah_fit_logmp_fit", "mah_fit_logmp")
+
+    diffstar_param_keys = [
+        "lgmcrit",
+        "lgy_at_mcrit",
+        "indx_lo",
+        "indx_hi",
+        "tau_dep",
+        "qt",
+        "qs",
+        "q_drop",
+        "q_rejuv",
+        "loss",
+        "success",
+    ]
+    for key in diffstar_param_keys:
+        bpl["sfh_fit_u_" + key] = diffstar_fits[key]
+
+    u_ms_colnames = [
+        "sfh_fit_u_lgmcrit",
+        "sfh_fit_u_lgy_at_mcrit",
+        "sfh_fit_u_indx_lo",
+        "sfh_fit_u_indx_hi",
+        "sfh_fit_u_tau_dep",
+    ]
+    ms_u_params_list = [bpl[key] for key in ms_u_colnames]
+
+    u_q_colnames = [
+        "sfh_fit_u_qt",
+        "sfh_fit_u_qs",
+        "sfh_fit_u_q_drop",
+        "sfh_fit_u_q_rejuv",
+    ]
+    q_u_params_list = [bpl[key] for key in q_u_colnames]
+
+    bounded_ms_params = _get_bounded_sfr_params_vmap(*ms_u_params_list)
+    lgmcrit, lgy_at_mcrit, indx_lo, indx_hi, tau_dep = bounded_ms_params
+
+    bounded_q_params = _get_bounded_q_params_vmap(*q_u_params_list)
+    lg_qt, lg_qs, lg_drop, lg_rejuv = bounded_q_params
+
+    for key, arr in zip(u_ms_colnames, bounded_ms_params):
+        newkey = key.replace("_u_", "_")
+        bpl[newkey] = arr
+
+    for key, arr in zip(u_q_colnames, bounded_q_params):
+        newkey = key.replace("_u_", "_")
+        bpl[newkey] = arr
+
+    bpl["sfh_fit_u_lg_qs"] = None
+
+    bpl.rename_column("sfh_fit_qs", "sfh_fit_lg_qs")
+    bpl.rename_column("sfh_fit_qt", "sfh_fit_lg_qt")
+
+    all_param_colnames = mah_colnames, u_ms_colnames, u_q_colnames
+    return bpl, t_bpl, all_param_colnames
+
+
+def _compute_logmah_logsmh(dt, mah, sfrh):
+    smh = np.cumsum(sfrh * dt, axis=1) * 1e9
+    mah = np.maximum.accumulate(mah, axis=1)
+
+    EPS = 0.01
+    mah = np.where(mah <= EPS, EPS, mah)
+    smh = np.where(smh <= EPS, EPS, smh)
+
+    log_mahs = np.log10(mah)
+    log_smh = np.log10(smh)
+
+    return log_mahs, log_smh


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 95189b1..6e262cd 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -27,10 +27,10 @@ jobs:
         shell: bash -l {0}
         run: |
           conda config --set always_yes yes
-          mamba install --quiet \
+          conda install --quiet \
             --file=requirements.txt
           python -m pip install --no-deps -e .
-          mamba install -y -q \
+          conda install -y -q \
             flake8 \
             pytest \
             pytest-xdist
diff --git a/diffstar/tests/test_diffstar_is_frozen.py b/diffstar/tests/test_diffstar_is_frozen.py
index 4a030c6..fd9e6b7 100644
--- a/diffstar/tests/test_diffstar_is_frozen.py
+++ b/diffstar/tests/test_diffstar_is_frozen.py
@@ -157,3 +157,46 @@ def test_diffmah_behavior_is_frozen():
     frozen_dmhdt = np.loadtxt(dmhdt_fn)
     msg = "Diffmah dmhdt has changed when evaluated on default parameters"
     assert np.allclose(frozen_dmhdt, dmhdt, rtol=1e-4), msg
+
+
+def test_sfh_is_frozen_on_example_bpl_sample():
+    """Freeze model behavior against precomputed testing data from 4 BPL fits."""
+    LGT0_BPL = 1.13980
+
+    sfh_fn = os.path.join(TESTING_DATA_DRN, "sfh_test_sample.txt")
+    lgt_fn = os.path.join(TESTING_DATA_DRN, "lgt_bpl.txt")
+    dt_fn = os.path.join(TESTING_DATA_DRN, "dt_bpl.txt")
+    mah_params_fn = os.path.join(TESTING_DATA_DRN, "mah_params_test_sample.txt")
+    ms_params_fn = os.path.join(TESTING_DATA_DRN, "ms_u_params_test_sample.txt")
+    q_params_fn = os.path.join(TESTING_DATA_DRN, "q_u_params_test_sample.txt")
+
+    frozen_sfhs = np.loadtxt(sfh_fn)
+    lgt_bpl = np.loadtxt(lgt_fn)
+    dt_bpl = np.loadtxt(dt_fn)
+    mah_params_test_sample = np.loadtxt(mah_params_fn)
+    ms_u_params_test_sample = np.loadtxt(ms_params_fn)
+    q_u_params_test_sample = np.loadtxt(q_params_fn)
+
+    sfh_test_sample = []
+    for ih in range(mah_params_test_sample.shape[0]):
+        all_mah_params_ih = np.array(
+            (
+                LGT0_BPL,
+                mah_params_test_sample[ih, 0],
+                mah_params_test_sample[ih, 1],
+                DEFAULT_MAH_PARAMS["mah_k"],
+                mah_params_test_sample[ih, 2],
+                mah_params_test_sample[ih, 3],
+            )
+        )
+        ms_u_params_ih = np.array(ms_u_params_test_sample[ih, :])
+        q_u_params_ih = np.array(q_u_params_test_sample[ih, :])
+
+        dmhdt_ih, log_mah_ih = _calc_halo_history(lgt_bpl, *all_mah_params_ih)
+        sfh_ih = _sfr_history_from_mah(
+            lgt_bpl, dt_bpl, dmhdt_ih, log_mah_ih, ms_u_params_ih, q_u_params_ih
+        )
+
+        sfh_test_sample.append(sfh_ih)
+    sfh_test_sample = np.array(sfh_test_sample)
+    assert np.allclose(frozen_sfhs, sfh_test_sample, rtol=1e-4)
diff --git a/diffstar/tests/testing_data/dt_bpl.txt b/diffstar/tests/testing_data/dt_bpl.txt
new file mode 100644
index 0000000..c7c872e
--- /dev/null
+++ b/diffstar/tests/testing_data/dt_bpl.txt
@@ -0,0 +1,178 @@
+2.804413437843322754e-02
+2.123560011386871338e-02
+1.455873250961303711e-02
+1.481968164443969727e-02
+1.507604122161865234e-02
+1.532807946205139160e-02
+1.557591557502746582e-02
+1.581981778144836426e-02
+1.605996489524841309e-02
+1.629644632339477539e-02
+1.652947068214416504e-02
+2.101975679397583008e-02
+2.564573287963867188e-02
+2.614346146583557129e-02
+2.663150429725646973e-02
+2.711045742034912109e-02
+2.758073806762695312e-02
+2.804255485534667969e-02
+2.849662303924560547e-02
+2.894306182861328125e-02
+2.938210964202880859e-02
+2.981436252593994141e-02
+3.023993968963623047e-02
+3.065890073776245117e-02
+3.107172250747680664e-02
+3.147864341735839844e-02
+3.187960386276245117e-02
+4.046326875686645508e-02
+4.928529262542724609e-02
+5.014228820800781250e-02
+5.098235607147216797e-02
+5.180621147155761719e-02
+5.261445045471191406e-02
+5.340778827667236328e-02
+5.418646335601806641e-02
+5.495095252990722656e-02
+5.570197105407714844e-02
+5.643928050994873047e-02
+5.716395378112792969e-02
+5.787575244903564453e-02
+5.857539176940917969e-02
+5.926275253295898438e-02
+5.993843078613281250e-02
+6.060218811035156250e-02
+6.125473976135253906e-02
+6.189584732055664062e-02
+6.252610683441162109e-02
+6.314527988433837891e-02
+6.375384330749511719e-02
+6.435155868530273438e-02
+6.493902206420898438e-02
+6.551575660705566406e-02
+6.608271598815917969e-02
+6.663918495178222656e-02
+6.718540191650390625e-02
+6.772160530090332031e-02
+6.824827194213867188e-02
+6.876492500305175781e-02
+6.927156448364257812e-02
+6.976866722106933594e-02
+7.025599479675292969e-02
+7.073402404785156250e-02
+7.120227813720703125e-02
+7.166075706481933594e-02
+7.210302352905273438e-02
+7.255005836486816406e-02
+7.298016548156738281e-02
+7.340145111083984375e-02
+7.381319999694824219e-02
+7.421612739562988281e-02
+7.460927963256835938e-02
+7.499337196350097656e-02
+7.536864280700683594e-02
+7.573437690734863281e-02
+7.609152793884277344e-02
+7.643961906433105469e-02
+7.677793502807617188e-02
+7.710790634155273438e-02
+7.742977142333984375e-02
+7.774114608764648438e-02
+7.804441452026367188e-02
+7.833957672119140625e-02
+7.862567901611328125e-02
+7.890224456787109375e-02
+7.917118072509765625e-02
+7.943058013916015625e-02
+7.968235015869140625e-02
+7.992553710937500000e-02
+8.015966415405273438e-02
+8.038568496704101562e-02
+8.060359954833984375e-02
+8.081340789794921875e-02
+8.101415634155273438e-02
+8.120775222778320312e-02
+8.139276504516601562e-02
+8.156967163085937500e-02
+8.173894882202148438e-02
+8.190059661865234375e-02
+8.205318450927734375e-02
+8.219957351684570312e-02
+8.233737945556640625e-02
+8.246803283691406250e-02
+8.259057998657226562e-02
+8.270645141601562500e-02
+8.281469345092773438e-02
+8.291578292846679688e-02
+8.300876617431640625e-02
+8.309650421142578125e-02
+8.317518234252929688e-02
+8.324813842773437500e-02
+8.331394195556640625e-02
+8.337306976318359375e-02
+8.342552185058593750e-02
+8.347129821777343750e-02
+8.351898193359375000e-02
+8.354377746582031250e-02
+8.357048034667968750e-02
+8.359098434448242188e-02
+8.360576629638671875e-02
+8.361339569091796875e-02
+8.361625671386718750e-02
+8.361339569091796875e-02
+8.360385894775390625e-02
+8.358955383300781250e-02
+8.356952667236328125e-02
+8.354377746582031250e-02
+8.351230621337890625e-02
+8.347606658935546875e-02
+8.343601226806640625e-02
+8.338832855224609375e-02
+8.333778381347656250e-02
+8.328247070312500000e-02
+8.322143554687500000e-02
+8.315467834472656250e-02
+8.308601379394531250e-02
+1.037454605102539062e-01
+1.243324279785156250e-01
+1.241388320922851562e-01
+1.239385604858398438e-01
+1.237192153930664062e-01
+1.234760284423828125e-01
+1.232318878173828125e-01
+1.229820251464843750e-01
+1.227130889892578125e-01
+1.224250793457031250e-01
+1.221351623535156250e-01
+1.218414306640625000e-01
+1.215324401855468750e-01
+1.212043762207031250e-01
+1.208772659301757812e-01
+1.205482482910156250e-01
+1.202039718627929688e-01
+1.198425292968750000e-01
+1.194839477539062500e-01
+1.191253662109375000e-01
+1.187515258789062500e-01
+1.183643341064453125e-01
+1.179790496826171875e-01
+1.175966262817382812e-01
+1.171998977661132812e-01
+1.167907714843750000e-01
+1.163864135742187500e-01
+1.159820556640625000e-01
+1.155691146850585938e-01
+1.151437759399414062e-01
+1.147212982177734375e-01
+1.143045425415039062e-01
+1.138772964477539062e-01
+1.134376525878906250e-01
+1.130046844482421875e-01
+1.125774383544921875e-01
+1.121387481689453125e-01
+1.116924285888671875e-01
+1.112518310546875000e-01
+1.108150482177734375e-01
+1.103706359863281250e-01
+9.325790405273437500e-02
+8.481121063232421875e-02
diff --git a/diffstar/tests/testing_data/halo_ids_test_sample.txt b/diffstar/tests/testing_data/halo_ids_test_sample.txt
new file mode 100644
index 0000000..8400ecf
--- /dev/null
+++ b/diffstar/tests/testing_data/halo_ids_test_sample.txt
@@ -0,0 +1,4 @@
+2.811277077000000000e+09
+2.810821061000000000e+09
+2.810385737000000000e+09
+2.819082853000000000e+09
diff --git a/diffstar/tests/testing_data/lgt_bpl.txt b/diffstar/tests/testing_data/lgt_bpl.txt
new file mode 100644
index 0000000..ce0aa55
--- /dev/null
+++ b/diffstar/tests/testing_data/lgt_bpl.txt
@@ -0,0 +1,178 @@
+-6.466462095305246516e-01
+-5.957621102195794771e-01
+-5.717374610367249588e-01
+-5.485678653424884699e-01
+-5.261946142346707322e-01
+-5.045648487770623136e-01
+-4.836308079045060215e-01
+-4.633491934298706316e-01
+-4.436806309340556309e-01
+-4.245892096743676958e-01
+-4.060420880087483031e-01
+-3.880091534506506790e-01
+-3.618639101967379701e-01
+-3.367293720117865430e-01
+-3.125305090171606737e-01
+-2.892003625574705028e-01
+-2.666789280670803786e-01
+-2.449122247564570198e-01
+-2.238515158392142268e-01
+-2.034526509827404850e-01
+-1.836755086909406531e-01
+-1.644835209310519242e-01
+-1.458432658645545943e-01
+-1.277241172995015883e-01
+-1.100979416410487050e-01
+-9.293883482055306788e-02
+-7.622289303681099859e-02
+-5.992801222488375323e-02
+-3.623308310383392683e-02
+-1.337213872233449646e-02
+8.702411690953686801e-03
+3.005033121681681407e-02
+5.070933354053558384e-02
+7.072945956975808246e-02
+9.014090144708251928e-02
+1.089861092102509671e-01
+1.272894568377365421e-01
+1.450873732220772649e-01
+1.623996696636682557e-01
+1.792579315219987590e-01
+1.956783485089766683e-01
+2.116885605035728479e-01
+2.273018517116346671e-01
+2.425426115262982740e-01
+2.574217708861926690e-01
+2.719610137185705656e-01
+2.861693487585311169e-01
+3.000661870363363071e-01
+3.136589552614548748e-01
+3.269651386589111919e-01
+3.399908530482991798e-01
+3.527519391522231373e-01
+3.652534199745313681e-01
+3.775097218210628491e-01
+3.895249517377508686e-01
+4.013123114055718310e-01
+4.128751364403484003e-01
+4.242255616814821773e-01
+4.353662702529578765e-01
+4.463084622797723888e-01
+4.570542669080971954e-01
+4.676140609393421022e-01
+4.779895016273929542e-01
+4.881902369503664518e-01
+4.982175210451397773e-01
+5.080784218018511433e-01
+5.177796438797229728e-01
+5.273219425022449558e-01
+5.367134719226751560e-01
+5.459547128300408225e-01
+5.550533269371071832e-01
+5.640095588518287961e-01
+5.728306259773057185e-01
+5.815165697148716450e-01
+5.900742052376656277e-01
+5.985033989462844595e-01
+6.068106006493034776e-01
+6.149955260268228363e-01
+6.230642919463871277e-01
+6.310164843317892513e-01
+6.388579157316469637e-01
+6.465880604643874374e-01
+6.542124521141406968e-01
+6.617304691484372503e-01
+6.691473887207941562e-01
+6.764625071529407618e-01
+6.836808652573781453e-01
+6.908016891561445938e-01
+6.978298012841807063e-01
+7.047643679949556761e-01
+7.116100094533137632e-01
+7.183658413661642150e-01
+7.250362961100914605e-01
+7.316204467327542815e-01
+7.381225508759078346e-01
+7.445416459289065925e-01
+7.508818265932084568e-01
+7.571421007410776838e-01
+7.633264108155284333e-01
+7.694337405617155401e-01
+7.754678898599731696e-01
+7.814278230603828312e-01
+7.873172063002321641e-01
+7.931349886891064793e-01
+7.988847106605853066e-01
+8.045653097305401902e-01
+8.101802079716647897e-01
+8.157283345055947876e-01
+8.212129997639089352e-01
+8.266331272788635109e-01
+8.319919220022377049e-01
+8.372883043331567077e-01
+8.425253794034157639e-01
+8.477020666269499127e-01
+8.528213765242314004e-01
+8.578832235586191235e-01
+8.628875459625768851e-01
+8.678372212232507987e-01
+8.727311739736900442e-01
+8.775721984183743052e-01
+8.823592237691938456e-01
+8.870949648976056423e-01
+8.917783567364387931e-01
+8.964120384879480374e-01
+9.009949517892936743e-01
+9.055296635780741843e-01
+9.100151230384404544e-01
+9.144538280123728491e-01
+9.188447359489153587e-01
+9.231902785492759334e-01
+9.274894221347501633e-01
+9.317445350255636471e-01
+9.359545929247400364e-01
+9.401219033534566893e-01
+9.442454518193478252e-01
+9.483274874641024477e-01
+9.543721019566507868e-01
+9.603240766114949922e-01
+9.661869296400041884e-01
+9.719617689745420064e-01
+9.776504415596948272e-01
+9.832540128387419198e-01
+9.887757093554991883e-01
+9.942164928330802232e-01
+9.995780245723795421e-01
+1.004861232698095685e+00
+1.010069086538840422e+00
+1.015202423502717943e+00
+1.020262743549778195e+00
+1.025250857261930548e+00
+1.030169505311090417e+00
+1.035019418247113521e+00
+1.039801954511542892e+00
+1.044517823055729711e+00
+1.049169559919937322e+00
+1.053757802939024435e+00
+1.058283785460460313e+00
+1.062748127817010335e+00
+1.067153181909655579e+00
+1.071499504503703903e+00
+1.075788217669154889e+00
+1.080019863931197976e+00
+1.084196628750060398e+00
+1.088318997561147805e+00
+1.092387992943349095e+00
+1.096404088732238602e+00
+1.100369319400145374e+00
+1.104284107316534147e+00
+1.108149385748918858e+00
+1.111965567637823282e+00
+1.115734550084536147e+00
+1.119456699494258745e+00
+1.123132868708717869e+00
+1.126763416514769967e+00
+1.130350114732792122e+00
+1.133893279972804757e+00
+1.137393692474689244e+00
+1.139804050726022533e+00
diff --git a/diffstar/tests/testing_data/mah_params_test_sample.txt b/diffstar/tests/testing_data/mah_params_test_sample.txt
new file mode 100644
index 0000000..42da435
--- /dev/null
+++ b/diffstar/tests/testing_data/mah_params_test_sample.txt
@@ -0,0 +1,4 @@
+1.209999999999999964e+01 3.049330000000000096e-01 1.877129999999999965e+00 7.179270000000000096e-02
+1.284999999999999964e+01 1.066740000000000049e-02 4.332320000000000171e+00 5.104199999999999848e-01
+1.359999999999999964e+01 6.638849999999999474e-01 2.098749999999999893e+00 1.184130000000000044e-01
+1.435050000000000026e+01 6.758490000000000331e-01 1.965829999999999966e+00 7.700719999999999787e-02
diff --git a/diffstar/tests/testing_data/ms_u_params_test_sample.txt b/diffstar/tests/testing_data/ms_u_params_test_sample.txt
new file mode 100644
index 0000000..ed9082e
--- /dev/null
+++ b/diffstar/tests/testing_data/ms_u_params_test_sample.txt
@@ -0,0 +1,4 @@
+1.207920000000000016e+01 5.358840000000000270e-01 -4.978139999999999822e-03 -7.671320000000000361e-01 1.308270000000000088e+01
+1.212330000000000041e+01 -1.786969999999999947e-01 1.321080000000000032e-01 -7.671320000000000361e-01 4.245809999999999640e+00
+1.247259999999999991e+01 -7.580459999999999976e-01 8.896410000000000429e-02 -7.671320000000000361e-01 -3.811059999999999892e+00
+1.243120000000000047e+01 1.380109999999999992e+01 -9.077030000000000376e-01 -7.671320000000000361e-01 1.351149999999999984e+01
diff --git a/diffstar/tests/testing_data/q_u_params_test_sample.txt b/diffstar/tests/testing_data/q_u_params_test_sample.txt
new file mode 100644
index 0000000..702e8b1
--- /dev/null
+++ b/diffstar/tests/testing_data/q_u_params_test_sample.txt
@@ -0,0 +1,4 @@
+8.909240000000000492e-01 -1.257429999999999937e-01 -1.294200000000000017e+00 -3.040509999999999824e+00
+8.649900000000000366e-01 1.747249999999999970e+00 -2.089960000000000040e+00 2.592340000000000089e+01
+6.808389999999999720e-01 1.242050000000000098e+00 -2.297769999999999868e+00 -4.573180000000000023e-01
+4.273350000000000204e-01 8.229420000000000357e+01 -2.561149999999999949e+01 -2.195600000000000218e+00
diff --git a/diffstar/tests/testing_data/sfh_test_sample.txt b/diffstar/tests/testing_data/sfh_test_sample.txt
new file mode 100644
index 0000000..1e69896
--- /dev/null
+++ b/diffstar/tests/testing_data/sfh_test_sample.txt
@@ -0,0 +1,4 @@
+1.584365782036911696e-05 3.509874295559711754e-05 5.105723539600148797e-05 7.067793194437399507e-05 9.450221114093437791e-05 1.232138602063059807e-04 1.575806527398526669e-04 1.984693371923640370e-04 2.468643942847847939e-04 3.038691938854753971e-04 3.707195573952049017e-04 4.625074507202953100e-04 6.078913575038313866e-04 7.883452344685792923e-04 1.011445652693510056e-03 1.285478938370943069e-03 1.620100345462560654e-03 2.026475733146071434e-03 2.517309738323092461e-03 3.107263240963220596e-03 3.812914481386542320e-03 4.653095267713069916e-03 5.648877937346696854e-03 6.823930423706769943e-03 8.204824291169643402e-03 9.820713661611080170e-03 1.170398481190204620e-02 1.423853263258934021e-02 1.828246377408504486e-02 2.323655970394611359e-02 2.928794734179973602e-02 3.662165999412536621e-02 4.543695226311683655e-02 5.595538020133972168e-02 6.840974837541580200e-02 8.305250853300094604e-02 1.001424491405487061e-01 1.199587658047676086e-01 1.427783370018005371e-01 1.688934564590454102e-01 1.985929608345031738e-01 2.321696579456329346e-01 2.699111998081207275e-01 3.121067583560943604e-01 3.590286076068878174e-01 4.109519124031066895e-01 4.681285619735717773e-01 5.308184027671813965e-01 5.992459654808044434e-01 6.736453771591186523e-01 7.542124390602111816e-01 8.411660790443420410e-01 9.346655607223510742e-01 1.034909009933471680e+00 1.142029643058776855e+00 1.256196737289428711e+00 1.377513766288757324e+00 1.506119847297668457e+00 1.642083764076232910e+00 1.785507917404174805e+00 1.936417102813720703e+00 2.094871282577514648e+00 2.260827541351318359e+00 2.434303998947143555e+00 2.615171670913696289e+00 2.803372144699096680e+00 2.998766183853149414e+00 3.201116800308227539e+00 3.410256147384643555e+00 3.625839471817016602e+00 3.847607612609863281e+00 4.075144290924072266e+00 4.308094024658203125e+00 4.545962810516357422e+00 4.788315296173095703e+00 5.034603595733642578e+00 5.284339427947998047e+00 5.536903381347656250e+00 5.791803836822509766e+00 6.048375606536865234e+00 6.306116104125976562e+00 6.564377784729003906e+00 6.822643756866455078e+00 7.080287933349609375e+00 7.336834907531738281e+00 7.591688632965087891e+00 7.844405174255371094e+00 8.094438552856445312e+00 8.341406822204589844e+00 8.584721565246582031e+00 8.817735671997070312e+00 9.012421607971191406e+00 9.125032424926757812e+00 9.108830451965332031e+00 8.926809310913085938e+00 8.561891555786132812e+00 8.021808624267578125e+00 7.338625431060791016e+00 6.560700416564941406e+00 5.743468284606933594e+00 4.938076972961425781e+00 4.185376644134521484e+00 3.511492729187011719e+00 2.929419994354248047e+00 2.440618038177490234e+00 2.039501190185546875e+00 1.716003537178039551e+00 1.458785295486450195e+00 1.256423115730285645e+00 1.098774552345275879e+00 9.770377278327941895e-01 8.840504288673400879e-01 8.139641880989074707e-01 7.621578574180603027e-01 7.248945832252502441e-01 6.991701722145080566e-01 6.824894547462463379e-01 6.727139353752136230e-01 6.679893136024475098e-01 6.666712760925292969e-01 6.673437952995300293e-01 6.688597202301025391e-01 6.704241037368774414e-01 6.716912984848022461e-01 6.726507544517517090e-01 6.733743548393249512e-01 6.739604473114013672e-01 6.745207905769348145e-01 6.751661896705627441e-01 6.760025024414062500e-01 6.771211028099060059e-01 6.785970926284790039e-01 6.804856657981872559e-01 6.828243732452392578e-01 6.856297850608825684e-01 6.887929439544677734e-01 6.939934492111206055e-01 7.004837989807128906e-01 7.076444029808044434e-01 7.152209281921386719e-01 7.229157686233520508e-01 7.304080724716186523e-01 7.373682856559753418e-01 7.434706687927246094e-01 7.484133243560791016e-01 7.519279122352600098e-01 7.537942528724670410e-01 7.538498640060424805e-01 7.519940733909606934e-01 7.481909394264221191e-01 7.424665689468383789e-01 7.349076867103576660e-01 7.256506085395812988e-01 7.148710489273071289e-01 7.027706503868103027e-01 6.895704865455627441e-01 6.754971146583557129e-01 6.607703566551208496e-01 6.455888152122497559e-01 6.301388740539550781e-01 6.145668625831604004e-01 5.989922881126403809e-01 5.834909081459045410e-01 5.681106448173522949e-01 5.528795123100280762e-01 5.378260016441345215e-01 5.229703783988952637e-01 5.083401203155517578e-01 4.939551353454589844e-01 4.798370003700256348e-01 4.659990668296813965e-01 4.524606764316558838e-01 4.392337799072265625e-01 4.263307154178619385e-01 4.137586653232574463e-01 4.015264213085174561e-01 3.904480636119842529e-01 3.828646242618560791e-01
+6.070043356842802496e-10 2.328474080215414688e-09 4.490841476467721805e-09 8.277000418388524849e-09 1.477077660183567787e-08 2.572304858006191353e-08 4.392723340629345330e-08 7.378871202945447294e-08 1.221827119479712564e-07 1.997264291730971308e-07 3.226431886105274316e-07 5.477790523400472011e-07 1.084757968783378601e-06 2.099297716995351948e-06 3.976568677899194881e-06 7.379226190096233040e-06 1.342383711744332686e-05 2.395181036263238639e-05 4.193781933281570673e-05 7.208865281427279115e-05 1.217024546349421144e-04 2.018719678744673729e-04 3.291319590061903000e-04 5.276575684547424316e-04 8.321393397636711597e-04 1.291460124775767326e-03 1.973261125385761261e-03 3.132724668830633163e-03 5.618332419544458389e-03 9.753334335982799530e-03 1.642318442463874817e-02 2.686703018844127655e-02 4.276029020547866821e-02 6.631031632423400879e-02 1.003253236413002014e-01 1.483023017644882202e-01 2.144520878791809082e-01 3.037605881690979004e-01 4.219419062137603760e-01 5.754785537719726562e-01 7.714896798133850098e-01 1.017795801162719727e+00 1.322736144065856934e+00 1.695337891578674316e+00 2.145137548446655273e+00 2.682555675506591797e+00 3.318765401840209961e+00 4.066197872161865234e+00 4.938272953033447266e+00 5.949692249298095703e+00 7.115147113800048828e+00 8.448621749877929688e+00 9.959640502929687500e+00 1.165033245086669922e+01 1.350910186767578125e+01 1.550673007965087891e+01 1.759191513061523438e+01 1.969363975524902344e+01 2.172163009643554688e+01 2.356188774108886719e+01 2.508652305603027344e+01 2.617664337158203125e+01 2.674305915832519531e+01 2.673992538452148438e+01 2.617094421386718750e+01 2.508478164672851562e+01 2.356467247009277344e+01 2.171809005737304688e+01 1.965913009643554688e+01 1.750095748901367188e+01 1.534179306030273438e+01 1.326372909545898438e+01 1.132552719116210938e+01 9.566842079162597656e+00 8.006834030151367188e+00 6.650862693786621094e+00 5.491463661193847656e+00 4.514636993408203125e+00 3.701008319854736328e+00 3.030160427093505859e+00 2.481061458587646484e+00 2.034456968307495117e+00 1.672601699829101562e+00 1.380353927612304688e+00 1.144554972648620605e+00 9.544378519058227539e-01 8.009673953056335449e-01 6.769372224807739258e-01 5.764131546020507812e-01 4.947403669357299805e-01 4.281237125396728516e-01 3.736096322536468506e-01 3.287959992885589600e-01 2.918215990066528320e-01 2.611685097217559814e-01 2.356583178043365479e-01 2.143279165029525757e-01 1.964239627122879028e-01 1.813254505395889282e-01 1.685442924499511719e-01 1.576728820800781250e-01 1.483893245458602905e-01 1.404197067022323608e-01 1.335472911596298218e-01 1.275835484266281128e-01 1.223780140280723572e-01 1.177986562252044678e-01 1.137400642037391663e-01 1.101072803139686584e-01 1.068255305290222168e-01 1.038270443677902222e-01 1.010593771934509277e-01 9.847544133663177490e-02 9.604055434465408325e-02 9.372378140687942505e-02 9.150411933660507202e-02 8.936682343482971191e-02 8.730112016201019287e-02 8.530450612306594849e-02 8.337631076574325562e-02 8.152186870574951172e-02 7.974594086408615112e-02 7.805745303630828857e-02 7.646279036998748779e-02 7.497094571590423584e-02 7.358799874782562256e-02 7.232227176427841187e-02 7.117876410484313965e-02 7.016388326883316040e-02 6.928151845932006836e-02 6.853757798671722412e-02 6.793426722288131714e-02 6.747624278068542480e-02 6.716620177030563354e-02 6.700813770294189453e-02 6.713213026523590088e-02 6.711354106664657593e-02 6.777533143758773804e-02 6.881838291883468628e-02 7.025992870330810547e-02 7.211920619010925293e-02 7.441926002502441406e-02 7.718674838542938232e-02 8.045238256454467773e-02 8.425096422433853149e-02 8.862132579088211060e-02 9.360788017511367798e-02 9.925919771194458008e-02 1.056280359625816345e-01 1.127711459994316101e-01 1.207523941993713379e-01 1.296374052762985229e-01 1.394966840744018555e-01 1.504022032022476196e-01 1.624329537153244019e-01 1.756673902273178101e-01 1.901851445436477661e-01 2.060648500919342041e-01 2.233904451131820679e-01 2.422383576631546021e-01 2.626832127571105957e-01 2.847929298877716064e-01 3.086367547512054443e-01 3.342687487602233887e-01 3.617369830608367920e-01 3.910744190216064453e-01 4.223121404647827148e-01 4.554582536220550537e-01 4.905093908309936523e-01 5.274410247802734375e-01 5.662263035774230957e-01 6.068073511123657227e-01 6.491152644157409668e-01 6.930559277534484863e-01 7.385329008102416992e-01 7.854217290878295898e-01 8.316177129745483398e-01 8.697744607925415039e-01
+2.403594553470611572e-03 5.324011202901601791e-03 7.736902218312025070e-03 1.067171711474657059e-02 1.420229952782392502e-02 1.841052435338497162e-02 2.338595688343048096e-02 2.922667562961578369e-02 3.603930771350860596e-02 4.393996298313140869e-02 5.305453762412071228e-02 6.536220014095306396e-02 8.424147218465805054e-02 1.071256399154663086e-01 1.345916539430618286e-01 1.673175692558288574e-01 2.060514390468597412e-01 2.516151070594787598e-01 3.049089312553405762e-01 3.669159412384033203e-01 4.387054741382598877e-01 5.214388370513916016e-01 6.163696050643920898e-01 7.248525619506835938e-01 8.483473658561706543e-01 9.884241819381713867e-01 1.146760463714599609e+00 1.356488466262817383e+00 1.665839076042175293e+00 2.037241458892822266e+00 2.473836898803710938e+00 2.984489679336547852e+00 3.579018354415893555e+00 4.268521785736083984e+00 5.065436840057373047e+00 5.983977317810058594e+00 7.040316581726074219e+00 8.253094673156738281e+00 9.643626213073730469e+00 1.123671817779541016e+01 1.306101322174072266e+01 1.514909267425537109e+01 1.753622055053710938e+01 2.025741004943847656e+01 2.334070587158203125e+01 2.679585075378417969e+01 3.059752082824707031e+01 3.465725708007812500e+01 3.872787475585937500e+01 4.233635711669921875e+01 4.486949920654296875e+01 4.574651336669921875e+01 4.463579940795898438e+01 4.158444213867187500e+01 3.701789474487304688e+01 3.157544326782226562e+01 2.592609214782714844e+01 2.059865570068359375e+01 1.592966556549072266e+01 1.205826282501220703e+01 8.986549377441406250e+00 6.628190517425537109e+00 4.863632202148437500e+00 3.566495895385742188e+00 2.625154733657836914e+00 1.946743965148925781e+00 1.459122061729431152e+00 1.108620405197143555e+00 8.556249141693115234e-01 6.720684766769409180e-01 5.378116369247436523e-01 4.388451576232910156e-01 3.651793301105499268e-01 3.098848164081573486e-01 2.679781317710876465e-01 2.359782010316848755e-01 2.113319784402847290e-01 1.922287940979003906e-01 1.773010641336441040e-01 1.655585020780563354e-01 1.562229692935943604e-01 1.487183421850204468e-01 1.425727009773254395e-01 1.374315917491912842e-01 1.329972892999649048e-01 1.290535926818847656e-01 1.254222095012664795e-01 1.219916939735412598e-01 1.186814829707145691e-01 1.154713705182075500e-01 1.123621985316276550e-01 1.093918234109878540e-01 1.065933331847190857e-01 1.040199100971221924e-01 1.017086282372474670e-01 9.970788657665252686e-02 9.804810583591461182e-02 9.676819294691085815e-02 9.589024633169174194e-02 9.544620662927627563e-02 9.545419365167617798e-02 9.594285488128662109e-02 9.693022817373275757e-02 9.844705462455749512e-02 1.005159243941307068e-01 1.031720489263534546e-01 1.064456105232238770e-01 1.103795692324638367e-01 1.150131002068519592e-01 1.203982532024383545e-01 1.265837997198104858e-01 1.336312741041183472e-01 1.415980607271194458e-01 1.505545824766159058e-01 1.605667620897293091e-01 1.717069149017333984e-01 1.840498149394989014e-01 1.976645886898040771e-01 2.126276791095733643e-01 2.290015816688537598e-01 2.468554824590682983e-01 2.662378251552581787e-01 2.872012257575988770e-01 3.097711801528930664e-01 3.339747190475463867e-01 3.598040938377380371e-01 3.872492015361785889e-01 4.162617623805999756e-01 4.467905759811401367e-01 4.787350893020629883e-01 5.119972825050354004e-01 5.464262366294860840e-01 5.818769931793212891e-01 6.181436777114868164e-01 6.550432443618774414e-01 7.032774090766906738e-01 7.454349994659423828e-01 8.003659248352050781e-01 8.539821505546569824e-01 9.055364131927490234e-01 9.542651772499084473e-01 9.994748830795288086e-01 1.040447831153869629e+00 1.076530218124389648e+00 1.107022523880004883e+00 1.131621956825256348e+00 1.150521516799926758e+00 1.163824915885925293e+00 1.171690583229064941e+00 1.174431681632995605e+00 1.172385692596435547e+00 1.166006088256835938e+00 1.155762314796447754e+00 1.142182230949401855e+00 1.125738859176635742e+00 1.106946229934692383e+00 1.086269378662109375e+00 1.064190745353698730e+00 1.041050434112548828e+00 1.017259120941162109e+00 9.931073784828186035e-01 9.689023494720458984e-01 9.448147416114807129e-01 9.210754632949829102e-01 8.977953195571899414e-01 8.751240372657775879e-01 8.530824780464172363e-01 8.317519426345825195e-01 8.111266493797302246e-01 7.912330627441406250e-01 7.720033526420593262e-01 7.534391880035400391e-01 7.354999184608459473e-01 7.181776762008666992e-01 7.014226913452148438e-01 6.852290034294128418e-01 6.610342860221862793e-01 6.653063893318176270e-01
+5.865773186087608337e-02 1.184094026684761047e-01 1.644618809223175049e-01 2.174465060234069824e-01 2.778163254261016846e-01 3.462088108062744141e-01 4.233642518520355225e-01 5.100135803222656250e-01 6.069866418838500977e-01 7.151345610618591309e-01 8.353824019432067871e-01 9.959617853164672852e-01 1.227993726730346680e+00 1.495325803756713867e+00 1.803353309631347656e+00 2.156935691833496094e+00 2.561756849288940430e+00 3.024400234222412109e+00 3.552326440811157227e+00 4.154445648193359375e+00 4.841104030609130859e+00 5.624584674835205078e+00 6.518286228179931641e+00 7.537257671356201172e+00 8.696235656738281250e+00 1.000686168670654297e+01 1.147285461425781250e+01 1.336846351623535156e+01 1.604759979248046875e+01 1.872005844116210938e+01 2.107645988464355469e+01 2.282552719116210938e+01 2.374772071838378906e+01 2.361244010925292969e+01 2.229597854614257812e+01 1.988345718383789062e+01 1.669246292114257812e+01 1.318653964996337891e+01 9.832313537597656250e+00 6.960686206817626953e+00 4.719478607177734375e+00 3.095440387725830078e+00 1.986295342445373535e+00 1.260820031166076660e+00 8.004480600357055664e-01 5.131996870040893555e-01 3.352417051792144775e-01 2.246906906366348267e-01 1.554140895605087280e-01 1.113652214407920837e-01 8.289264142513275146e-02 6.414850056171417236e-02 5.160740762948989868e-02 4.309722781181335449e-02 3.727619722485542297e-02 3.328844532370567322e-02 3.058357723057270050e-02 2.879173867404460907e-02 2.765989676117897034e-02 2.700394019484519958e-02 2.668677829205989838e-02 2.660021558403968811e-02 2.665933594107627869e-02 2.679748646914958954e-02 2.696836180984973907e-02 2.714720927178859711e-02 2.732942812144756317e-02 2.752096578478813171e-02 2.773116715252399445e-02 2.797245420515537262e-02 2.825785614550113678e-02 2.860145084559917450e-02 2.901661209762096405e-02 2.951687574386596680e-02 3.011506050825119019e-02 3.082360699772834778e-02 3.165475279092788696e-02 3.262025490403175354e-02 3.373201563954353333e-02 3.500161319971084595e-02 3.644098713994026184e-02 3.806181997060775757e-02 3.987615182995796204e-02 4.189568758010864258e-02 4.413267225027084351e-02 4.659815132617950439e-02 4.930391162633895874e-02 5.225995555520057678e-02 5.547671392560005188e-02 5.896187573671340942e-02 6.272356212139129639e-02 6.676612794399261475e-02 7.109379023313522339e-02 7.570624351501464844e-02 8.060299605131149292e-02 8.577780425548553467e-02 9.122416377067565918e-02 9.692893922328948975e-02 1.028796285390853882e-01 1.090559884905815125e-01 1.154383495450019836e-01 1.219999194145202637e-01 1.287156343460083008e-01 1.355526894330978394e-01 1.424810886383056641e-01 1.494640707969665527e-01 1.564686000347137451e-01 1.634563952684402466e-01 1.703932434320449829e-01 1.772412359714508057e-01 1.839679330587387085e-01 1.905385851860046387e-01 1.969231665134429932e-01 2.030915617942810059e-01 2.090208083391189575e-01 2.146864086389541626e-01 2.200691699981689453e-01 2.251547873020172119e-01 2.299298197031021118e-01 2.343876212835311890e-01 2.385219633579254150e-01 2.423314899206161499e-01 2.458179891109466553e-01 2.489851862192153931e-01 2.518405020236968994e-01 2.543925940990447998e-01 2.566532194614410400e-01 2.586347460746765137e-01 2.603510022163391113e-01 2.618176639080047607e-01 2.630490958690643311e-01 2.640632092952728271e-01 2.648744881153106689e-01 2.654998898506164551e-01 2.659549713134765625e-01 2.666433453559875488e-01 2.669139802455902100e-01 2.667935192584991455e-01 2.664426565170288086e-01 2.658958137035369873e-01 2.651815712451934814e-01 2.643212378025054932e-01 2.633311748504638672e-01 2.622186243534088135e-01 2.609886825084686279e-01 2.596421837806701660e-01 2.581817805767059326e-01 2.566097676753997803e-01 2.549293935298919678e-01 2.531428635120391846e-01 2.512539625167846680e-01 2.492652386426925659e-01 2.471812665462493896e-01 2.450055629014968872e-01 2.427416741847991943e-01 2.403937280178070068e-01 2.379660755395889282e-01 2.354633510112762451e-01 2.328892201185226440e-01 2.302485555410385132e-01 2.275457531213760376e-01 2.247864902019500732e-01 2.219744473695755005e-01 2.191142737865447998e-01 2.162106633186340332e-01 2.132695168256759644e-01 2.102939337491989136e-01 2.072897255420684814e-01 2.042606472969055176e-01 2.012118101119995117e-01 1.981467604637145996e-01 1.950709372758865356e-01 1.919877231121063232e-01 1.889017820358276367e-01 1.858163923025131226e-01 1.827358305454254150e-01 1.798211187124252319e-01 1.778328418731689453e-01
diff --git a/scripts/generate_unit_testing_data.py b/scripts/generate_unit_testing_data.py
index 9be5b05..8828998 100644
--- a/scripts/generate_unit_testing_data.py
+++ b/scripts/generate_unit_testing_data.py
@@ -9,6 +9,13 @@
 import numpy as np
 from diffstar.tests.test_diffstar_is_frozen import calc_sfh_on_default_params
 from diffstar.tests.test_diffstar_is_frozen import _get_default_mah_params
+from load_bpl import load_bpl_diffstar_data, TASSO_BPL_DRN, LGT0 as LGT0_BPL
+from diffmah.individual_halo_assembly import _calc_halo_history, DEFAULT_MAH_PARAMS
+from diffstar.stars import _sfr_history_from_mah
+from diffstar.utils import _jax_get_dt_array
+
+
+MAH_K = DEFAULT_MAH_PARAMS["mah_k"]
 
 
 TASSO = "/Users/aphearin/work/repositories/python/diffstar/diffstar/tests/testing_data"
@@ -21,6 +28,7 @@
     args = parser.parse_args()
     testing_drn = args.testing_drn
 
+    # Calculate SFH for default parameters
     sfh_args, sfh = calc_sfh_on_default_params()
     lgt, dt, dmhdt, log_mah, u_ms_params, u_q_params = sfh_args
 
@@ -41,3 +49,59 @@
         os.path.join(testing_drn, "default_params_test_diffmah_params.txt"),
         default_mah_params,
     )
+
+    # Calculate SFH for 4 example BPL subhalos
+    bpl, t_bpl, all_param_colnames = load_bpl_diffstar_data(TASSO_BPL_DRN)
+    lgt_bpl = np.log10(t_bpl)
+    dt_bpl = _jax_get_dt_array(t_bpl)
+    mah_colnames, u_ms_colnames, u_q_colnames = all_param_colnames
+
+    halo_ids_test_sample = np.array([2811277077, 2810821061, 2810385737, 2819082853])
+    indx_test = np.array(
+        [np.argmin(np.abs(bpl["halo_id"] - hid)) for hid in halo_ids_test_sample]
+    )
+    sample = bpl[indx_test]
+
+    mah_params_test_sample = np.array([sample[key] for key in mah_colnames]).T
+    ms_u_params_test_sample = np.array([sample[key] for key in u_ms_colnames]).T
+    q_u_params_test_sample = np.array([sample[key] for key in u_q_colnames]).T
+
+    sfh_test_sample = []
+    for ih in range(mah_params_test_sample.shape[0]):
+        all_mah_params_ih = np.array(
+            (
+                LGT0_BPL,
+                mah_params_test_sample[ih, 0],
+                mah_params_test_sample[ih, 1],
+                MAH_K,
+                mah_params_test_sample[ih, 2],
+                mah_params_test_sample[ih, 3],
+            )
+        )
+        ms_u_params_ih = np.array(ms_u_params_test_sample[ih, :])
+        q_u_params_ih = np.array(q_u_params_test_sample[ih, :])
+
+        dmhdt_ih, log_mah_ih = _calc_halo_history(lgt_bpl, *all_mah_params_ih)
+        sfh_ih = _sfr_history_from_mah(
+            lgt_bpl, dt_bpl, dmhdt_ih, log_mah_ih, ms_u_params_ih, q_u_params_ih
+        )
+
+        sfh_test_sample.append(sfh_ih)
+    sfh_test_sample = np.array(sfh_test_sample)
+
+    np.savetxt(os.path.join(testing_drn, "sfh_test_sample.txt"), sfh_test_sample)
+    np.savetxt(
+        os.path.join(testing_drn, "mah_params_test_sample.txt"), mah_params_test_sample
+    )
+    np.savetxt(
+        os.path.join(testing_drn, "ms_u_params_test_sample.txt"),
+        ms_u_params_test_sample,
+    )
+    np.savetxt(
+        os.path.join(testing_drn, "q_u_params_test_sample.txt"), q_u_params_test_sample
+    )
+    np.savetxt(
+        os.path.join(testing_drn, "halo_ids_test_sample.txt"), halo_ids_test_sample
+    )
+    np.savetxt(os.path.join(testing_drn, "lgt_bpl.txt"), lgt_bpl)
+    np.savetxt(os.path.join(testing_drn, "dt_bpl.txt"), dt_bpl)