<jupyter_start><jupyter_text>Simulate/fit/analyze in batch mode  Generate observed binary properties<jupyter_code>import numpy as np

from isochrones import get_ichrone

bands = ['J', 'H', 'K', 'G', 'BP', 'RP']
mist = get_ichrone('mist', bands=bands)
from itertools import product

primary_masses = [0.8, 1.0]
mass_ratios = [0.5, 0.9]
feh_grid = [-0.25, 0.0]
age = 9.7
distance = 500
AV = 0.

m1, m2, feh, name = zip(*[(m, q*m, f, f'{m:.2f}_{q*m:0.2f}_{f:0.2f}') 
                          for m, q, f 
                          in product(primary_masses, mass_ratios, feh_grid)])

df = mist.generate_binary(m1, m2, age, feh, distance=distance, AV=AV, accurate=True)

# add uncertainties for each band

uncs = {'J': 0.02, 'H': 0.02, 'K':0.02, 'G': 0.002, 'BP': 0.002, 'RP':0.002}

for b in bands:
    df[f'{b}_mag_unc'] = uncs[b]
    
# Add parallax & uncertainty
df['parallax'] = 1000/distance
df['parallax_unc'] = 0.02
df.index = name<jupyter_output><empty_output><jupyter_text>Use a StarCatalog to organize data<jupyter_code>from isochrones.catalog import StarCatalog
from isochrones.priors import FlatPrior

catalog = StarCatalog(df, bands=bands, props=['parallax'])
catalog.set_prior(AV=FlatPrior((0, 0.0001)), age=FlatPrior((8.5, 10)))<jupyter_output><empty_output><jupyter_text>Fit modelsHere is a snippet to fit all the models (using the convenient `.iter_models()` API); this could easily be adapted into a cluster script (e.g., using `schwimmbad`) to run thousands of fits.<jupyter_code>from multiprocessing import Pool

def fit_model(mod):
    print(mod.mnest_basename)
    mod.fit(verbose=True)
    return mod.derived_samples

pool = Pool(processes=8)  # e.g.

samples = pool.map(fit_model, catalog.iter_models(N=2))<jupyter_output>./chains/0.80_0.40_0.00-mist-binary-
./chains/0.80_0.72_-0.25-mist-binary-
./chains/0.80_0.40_-0.25-mist-binary-
./chains/0.80_0.72_0.00-mist-binary-
./chains/1.00_0.90_-0.25-mist-binary-
./chains/1.00_0.50_0.00-mist-binary-
./chains/1.00_0.50_-0.25-mist-binary-
./chains/1.00_0.90_0.00-mist-binary-<jupyter_text>Analyze samplesA `StarCatalog` could probably have some convenience methods for some of this stuff, but this for now.<jupyter_code>cols = ['mass_0', 'mass_1', 'age', 'feh', 'AV']
qs = [0.05, 0.16, 0.5, 0.84, 0.95]
for name, samps in zip(catalog.df.index, samples):
    print(name)
    print(samps[cols].quantile(qs))
from corner import corner

corner(samples[-1][['mass_0', 'mass_1', 'age', 'feh', 'distance']]);
corner(samples[-1][['J_mag', 'K_mag', 'G_mag', 'BP_mag', 'RP_mag']]);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17127286882055273, 'fraction_numerical': 0.06228104320747373, 'mean_word_length': 4.456475583864119, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '334958', 'license': 'MIT', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1031, 'n_words': 222, 'path': 'notebooks/batch-demo.ipynb', 'repo_name': 'Sam-2727/isochrones', 'size': '2569'}