dataset production

This commit is contained in:
Mayeul Aubin 2025-06-05 15:16:06 +02:00
parent 46bc5a3a86
commit c5f464d031
6 changed files with 9856 additions and 0 deletions

0
sCOCA_ML/__init__.py Normal file
View file

View file

View file

@ -0,0 +1,921 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7dcb16bc",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b580fb3f",
"metadata": {},
"outputs": [],
"source": [
"## Since we don't have access to the DESI MCMC chains, we will use their table of results and approximate the posterior as Gaussians with no correlations.\n",
"## This is a very crude approximation, but it will allow us to probe a bit the impact of w0wa on our simulations.\n",
"\n",
"# Let's define the cosmological parameters, their mean and standard deviation (from the DESI paper)\n",
"DESI_cosmo_table = [\n",
" ['Omega_m', 0.3142, 0.0063],\n",
" ['sigma8', 0.8163, 0.0083],\n",
" ['H0', 67.48, 0.6200],\n",
" ['w0', -0.761, 0.0650],\n",
" ['wa', -0.96, 0.3000],\n",
"]\n",
"\n",
"Planck2018_additional_cosmo_table = [\n",
" ['Omega_bh^2', 0.02242, 0.00014],\n",
" ['n_s', 0.9665, 0.0038],\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "4105ff31",
"metadata": {},
"outputs": [],
"source": [
"## Now let's sample N cosmological parameters sets from the DESI and Planck tables, assuming uncorrelated Gaussians posterior distributions.\n",
"N=30\n",
"\n",
"# For each parameter, create an array of samples\n",
"samples = {}\n",
"for param, mean, std in DESI_cosmo_table + Planck2018_additional_cosmo_table:\n",
" samples[param] = np.random.normal(loc=mean, scale=std, size=N)\n",
"\n",
"# Convert the samples to a DataFrame\n",
"cosmo_samples = pd.DataFrame(samples)\n",
"\n",
"# Change H0 in h:=H0/100\n",
"cosmo_samples['h'] = cosmo_samples['H0'] / 100.0\n",
"cosmo_samples = cosmo_samples.drop(columns=['H0'])\n",
"\n",
"# Change Omega_bh^2 in Omega_b\n",
"cosmo_samples['Omega_b'] = cosmo_samples['Omega_bh^2'] / cosmo_samples['h']**2\n",
"cosmo_samples = cosmo_samples.drop(columns=['Omega_bh^2'])\n",
"\n",
"# Define Omega_q as Omega_q = 1 - Omega_m\n",
"cosmo_samples['Omega_q'] = 1.0 - cosmo_samples['Omega_m']\n",
"\n",
"# Round values to 4 decimal places\n",
"cosmo_samples = cosmo_samples.round(4)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6006ce1d",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "Omega_m",
"rawType": "float64",
"type": "float"
},
{
"name": "sigma8",
"rawType": "float64",
"type": "float"
},
{
"name": "w0",
"rawType": "float64",
"type": "float"
},
{
"name": "wa",
"rawType": "float64",
"type": "float"
},
{
"name": "n_s",
"rawType": "float64",
"type": "float"
},
{
"name": "h",
"rawType": "float64",
"type": "float"
},
{
"name": "Omega_b",
"rawType": "float64",
"type": "float"
},
{
"name": "Omega_q",
"rawType": "float64",
"type": "float"
}
],
"ref": "c3749bad-2115-4fab-9dd2-407301414639",
"rows": [
[
"0",
"0.3072",
"0.8143",
"-0.7615",
"-0.7624",
"0.9679",
"0.6789",
"0.049",
"0.6928"
],
[
"1",
"0.3139",
"0.8227",
"-0.9124",
"-0.7684",
"0.9639",
"0.6778",
"0.0489",
"0.6861"
],
[
"2",
"0.3179",
"0.8266",
"-0.7549",
"-0.7952",
"0.9679",
"0.6593",
"0.0524",
"0.6821"
],
[
"3",
"0.3142",
"0.8238",
"-0.7042",
"-1.0894",
"0.9634",
"0.6762",
"0.0491",
"0.6858"
],
[
"4",
"0.3136",
"0.809",
"-0.7589",
"-0.5622",
"0.969",
"0.6703",
"0.0502",
"0.6864"
],
[
"5",
"0.3185",
"0.8256",
"-0.7325",
"-1.1989",
"0.9661",
"0.661",
"0.0517",
"0.6815"
],
[
"6",
"0.3124",
"0.8109",
"-0.7643",
"-1.1421",
"0.9676",
"0.6756",
"0.0495",
"0.6876"
],
[
"7",
"0.3228",
"0.8133",
"-0.8212",
"-0.6498",
"0.9634",
"0.6738",
"0.0494",
"0.6772"
],
[
"8",
"0.3208",
"0.8174",
"-0.5928",
"-1.1095",
"0.9681",
"0.6791",
"0.0483",
"0.6792"
],
[
"9",
"0.3212",
"0.8384",
"-0.7382",
"-1.0966",
"0.9685",
"0.6716",
"0.0496",
"0.6788"
],
[
"10",
"0.3157",
"0.8079",
"-0.834",
"-0.713",
"0.9633",
"0.6745",
"0.0491",
"0.6843"
],
[
"11",
"0.3043",
"0.812",
"-0.841",
"-1.2495",
"0.9626",
"0.677",
"0.0492",
"0.6957"
],
[
"12",
"0.316",
"0.8309",
"-0.7108",
"-0.9241",
"0.9589",
"0.687",
"0.0479",
"0.684"
],
[
"13",
"0.3069",
"0.8263",
"-0.6679",
"-1.1336",
"0.9663",
"0.6668",
"0.0507",
"0.6931"
],
[
"14",
"0.3224",
"0.8179",
"-0.7521",
"-1.185",
"0.9661",
"0.6803",
"0.0488",
"0.6776"
],
[
"15",
"0.3233",
"0.8196",
"-0.8316",
"-1.0697",
"0.9616",
"0.6703",
"0.0502",
"0.6767"
],
[
"16",
"0.3179",
"0.8065",
"-0.7125",
"-1.1323",
"0.9696",
"0.67",
"0.0504",
"0.6821"
],
[
"17",
"0.3125",
"0.8175",
"-0.6896",
"-1.2742",
"0.9649",
"0.6796",
"0.048",
"0.6875"
],
[
"18",
"0.3115",
"0.824",
"-0.6955",
"-1.0946",
"0.9679",
"0.6767",
"0.0494",
"0.6885"
],
[
"19",
"0.3121",
"0.8188",
"-0.7677",
"-1.0277",
"0.9569",
"0.679",
"0.0487",
"0.6879"
],
[
"20",
"0.3169",
"0.8271",
"-0.8419",
"-0.9485",
"0.9646",
"0.6723",
"0.0492",
"0.6831"
],
[
"21",
"0.3084",
"0.8191",
"-0.858",
"-0.9611",
"0.9674",
"0.6761",
"0.0491",
"0.6916"
],
[
"22",
"0.3106",
"0.8203",
"-0.7033",
"-0.9152",
"0.9709",
"0.679",
"0.0482",
"0.6894"
],
[
"23",
"0.3144",
"0.8214",
"-0.7278",
"-0.8972",
"0.9688",
"0.6778",
"0.0489",
"0.6856"
],
[
"24",
"0.3113",
"0.8223",
"-0.635",
"-1.2027",
"0.9619",
"0.6723",
"0.0498",
"0.6887"
],
[
"25",
"0.3111",
"0.8139",
"-0.6984",
"-0.7764",
"0.9661",
"0.6641",
"0.0512",
"0.6889"
],
[
"26",
"0.3144",
"0.8079",
"-0.7536",
"-1.1702",
"0.9608",
"0.6621",
"0.0507",
"0.6856"
],
[
"27",
"0.3146",
"0.8191",
"-0.6247",
"-1.0546",
"0.9707",
"0.6775",
"0.0488",
"0.6854"
],
[
"28",
"0.3134",
"0.809",
"-0.7978",
"-1.154",
"0.9678",
"0.6727",
"0.0498",
"0.6866"
],
[
"29",
"0.3173",
"0.8119",
"-0.7385",
"-1.0606",
"0.9642",
"0.6732",
"0.0493",
"0.6827"
]
],
"shape": {
"columns": 8,
"rows": 30
}
},
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Omega_m</th>\n",
" <th>sigma8</th>\n",
" <th>w0</th>\n",
" <th>wa</th>\n",
" <th>n_s</th>\n",
" <th>h</th>\n",
" <th>Omega_b</th>\n",
" <th>Omega_q</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.3072</td>\n",
" <td>0.8143</td>\n",
" <td>-0.7615</td>\n",
" <td>-0.7624</td>\n",
" <td>0.9679</td>\n",
" <td>0.6789</td>\n",
" <td>0.0490</td>\n",
" <td>0.6928</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.3139</td>\n",
" <td>0.8227</td>\n",
" <td>-0.9124</td>\n",
" <td>-0.7684</td>\n",
" <td>0.9639</td>\n",
" <td>0.6778</td>\n",
" <td>0.0489</td>\n",
" <td>0.6861</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.3179</td>\n",
" <td>0.8266</td>\n",
" <td>-0.7549</td>\n",
" <td>-0.7952</td>\n",
" <td>0.9679</td>\n",
" <td>0.6593</td>\n",
" <td>0.0524</td>\n",
" <td>0.6821</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.3142</td>\n",
" <td>0.8238</td>\n",
" <td>-0.7042</td>\n",
" <td>-1.0894</td>\n",
" <td>0.9634</td>\n",
" <td>0.6762</td>\n",
" <td>0.0491</td>\n",
" <td>0.6858</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.3136</td>\n",
" <td>0.8090</td>\n",
" <td>-0.7589</td>\n",
" <td>-0.5622</td>\n",
" <td>0.9690</td>\n",
" <td>0.6703</td>\n",
" <td>0.0502</td>\n",
" <td>0.6864</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.3185</td>\n",
" <td>0.8256</td>\n",
" <td>-0.7325</td>\n",
" <td>-1.1989</td>\n",
" <td>0.9661</td>\n",
" <td>0.6610</td>\n",
" <td>0.0517</td>\n",
" <td>0.6815</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.3124</td>\n",
" <td>0.8109</td>\n",
" <td>-0.7643</td>\n",
" <td>-1.1421</td>\n",
" <td>0.9676</td>\n",
" <td>0.6756</td>\n",
" <td>0.0495</td>\n",
" <td>0.6876</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>0.3228</td>\n",
" <td>0.8133</td>\n",
" <td>-0.8212</td>\n",
" <td>-0.6498</td>\n",
" <td>0.9634</td>\n",
" <td>0.6738</td>\n",
" <td>0.0494</td>\n",
" <td>0.6772</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>0.3208</td>\n",
" <td>0.8174</td>\n",
" <td>-0.5928</td>\n",
" <td>-1.1095</td>\n",
" <td>0.9681</td>\n",
" <td>0.6791</td>\n",
" <td>0.0483</td>\n",
" <td>0.6792</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>0.3212</td>\n",
" <td>0.8384</td>\n",
" <td>-0.7382</td>\n",
" <td>-1.0966</td>\n",
" <td>0.9685</td>\n",
" <td>0.6716</td>\n",
" <td>0.0496</td>\n",
" <td>0.6788</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>0.3157</td>\n",
" <td>0.8079</td>\n",
" <td>-0.8340</td>\n",
" <td>-0.7130</td>\n",
" <td>0.9633</td>\n",
" <td>0.6745</td>\n",
" <td>0.0491</td>\n",
" <td>0.6843</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>0.3043</td>\n",
" <td>0.8120</td>\n",
" <td>-0.8410</td>\n",
" <td>-1.2495</td>\n",
" <td>0.9626</td>\n",
" <td>0.6770</td>\n",
" <td>0.0492</td>\n",
" <td>0.6957</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>0.3160</td>\n",
" <td>0.8309</td>\n",
" <td>-0.7108</td>\n",
" <td>-0.9241</td>\n",
" <td>0.9589</td>\n",
" <td>0.6870</td>\n",
" <td>0.0479</td>\n",
" <td>0.6840</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>0.3069</td>\n",
" <td>0.8263</td>\n",
" <td>-0.6679</td>\n",
" <td>-1.1336</td>\n",
" <td>0.9663</td>\n",
" <td>0.6668</td>\n",
" <td>0.0507</td>\n",
" <td>0.6931</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>0.3224</td>\n",
" <td>0.8179</td>\n",
" <td>-0.7521</td>\n",
" <td>-1.1850</td>\n",
" <td>0.9661</td>\n",
" <td>0.6803</td>\n",
" <td>0.0488</td>\n",
" <td>0.6776</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>0.3233</td>\n",
" <td>0.8196</td>\n",
" <td>-0.8316</td>\n",
" <td>-1.0697</td>\n",
" <td>0.9616</td>\n",
" <td>0.6703</td>\n",
" <td>0.0502</td>\n",
" <td>0.6767</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>0.3179</td>\n",
" <td>0.8065</td>\n",
" <td>-0.7125</td>\n",
" <td>-1.1323</td>\n",
" <td>0.9696</td>\n",
" <td>0.6700</td>\n",
" <td>0.0504</td>\n",
" <td>0.6821</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>0.3125</td>\n",
" <td>0.8175</td>\n",
" <td>-0.6896</td>\n",
" <td>-1.2742</td>\n",
" <td>0.9649</td>\n",
" <td>0.6796</td>\n",
" <td>0.0480</td>\n",
" <td>0.6875</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>0.3115</td>\n",
" <td>0.8240</td>\n",
" <td>-0.6955</td>\n",
" <td>-1.0946</td>\n",
" <td>0.9679</td>\n",
" <td>0.6767</td>\n",
" <td>0.0494</td>\n",
" <td>0.6885</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>0.3121</td>\n",
" <td>0.8188</td>\n",
" <td>-0.7677</td>\n",
" <td>-1.0277</td>\n",
" <td>0.9569</td>\n",
" <td>0.6790</td>\n",
" <td>0.0487</td>\n",
" <td>0.6879</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>0.3169</td>\n",
" <td>0.8271</td>\n",
" <td>-0.8419</td>\n",
" <td>-0.9485</td>\n",
" <td>0.9646</td>\n",
" <td>0.6723</td>\n",
" <td>0.0492</td>\n",
" <td>0.6831</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>0.3084</td>\n",
" <td>0.8191</td>\n",
" <td>-0.8580</td>\n",
" <td>-0.9611</td>\n",
" <td>0.9674</td>\n",
" <td>0.6761</td>\n",
" <td>0.0491</td>\n",
" <td>0.6916</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>0.3106</td>\n",
" <td>0.8203</td>\n",
" <td>-0.7033</td>\n",
" <td>-0.9152</td>\n",
" <td>0.9709</td>\n",
" <td>0.6790</td>\n",
" <td>0.0482</td>\n",
" <td>0.6894</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>0.3144</td>\n",
" <td>0.8214</td>\n",
" <td>-0.7278</td>\n",
" <td>-0.8972</td>\n",
" <td>0.9688</td>\n",
" <td>0.6778</td>\n",
" <td>0.0489</td>\n",
" <td>0.6856</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>0.3113</td>\n",
" <td>0.8223</td>\n",
" <td>-0.6350</td>\n",
" <td>-1.2027</td>\n",
" <td>0.9619</td>\n",
" <td>0.6723</td>\n",
" <td>0.0498</td>\n",
" <td>0.6887</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>0.3111</td>\n",
" <td>0.8139</td>\n",
" <td>-0.6984</td>\n",
" <td>-0.7764</td>\n",
" <td>0.9661</td>\n",
" <td>0.6641</td>\n",
" <td>0.0512</td>\n",
" <td>0.6889</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>0.3144</td>\n",
" <td>0.8079</td>\n",
" <td>-0.7536</td>\n",
" <td>-1.1702</td>\n",
" <td>0.9608</td>\n",
" <td>0.6621</td>\n",
" <td>0.0507</td>\n",
" <td>0.6856</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>0.3146</td>\n",
" <td>0.8191</td>\n",
" <td>-0.6247</td>\n",
" <td>-1.0546</td>\n",
" <td>0.9707</td>\n",
" <td>0.6775</td>\n",
" <td>0.0488</td>\n",
" <td>0.6854</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>0.3134</td>\n",
" <td>0.8090</td>\n",
" <td>-0.7978</td>\n",
" <td>-1.1540</td>\n",
" <td>0.9678</td>\n",
" <td>0.6727</td>\n",
" <td>0.0498</td>\n",
" <td>0.6866</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>0.3173</td>\n",
" <td>0.8119</td>\n",
" <td>-0.7385</td>\n",
" <td>-1.0606</td>\n",
" <td>0.9642</td>\n",
" <td>0.6732</td>\n",
" <td>0.0493</td>\n",
" <td>0.6827</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Omega_m sigma8 w0 wa n_s h Omega_b Omega_q\n",
"0 0.3072 0.8143 -0.7615 -0.7624 0.9679 0.6789 0.0490 0.6928\n",
"1 0.3139 0.8227 -0.9124 -0.7684 0.9639 0.6778 0.0489 0.6861\n",
"2 0.3179 0.8266 -0.7549 -0.7952 0.9679 0.6593 0.0524 0.6821\n",
"3 0.3142 0.8238 -0.7042 -1.0894 0.9634 0.6762 0.0491 0.6858\n",
"4 0.3136 0.8090 -0.7589 -0.5622 0.9690 0.6703 0.0502 0.6864\n",
"5 0.3185 0.8256 -0.7325 -1.1989 0.9661 0.6610 0.0517 0.6815\n",
"6 0.3124 0.8109 -0.7643 -1.1421 0.9676 0.6756 0.0495 0.6876\n",
"7 0.3228 0.8133 -0.8212 -0.6498 0.9634 0.6738 0.0494 0.6772\n",
"8 0.3208 0.8174 -0.5928 -1.1095 0.9681 0.6791 0.0483 0.6792\n",
"9 0.3212 0.8384 -0.7382 -1.0966 0.9685 0.6716 0.0496 0.6788\n",
"10 0.3157 0.8079 -0.8340 -0.7130 0.9633 0.6745 0.0491 0.6843\n",
"11 0.3043 0.8120 -0.8410 -1.2495 0.9626 0.6770 0.0492 0.6957\n",
"12 0.3160 0.8309 -0.7108 -0.9241 0.9589 0.6870 0.0479 0.6840\n",
"13 0.3069 0.8263 -0.6679 -1.1336 0.9663 0.6668 0.0507 0.6931\n",
"14 0.3224 0.8179 -0.7521 -1.1850 0.9661 0.6803 0.0488 0.6776\n",
"15 0.3233 0.8196 -0.8316 -1.0697 0.9616 0.6703 0.0502 0.6767\n",
"16 0.3179 0.8065 -0.7125 -1.1323 0.9696 0.6700 0.0504 0.6821\n",
"17 0.3125 0.8175 -0.6896 -1.2742 0.9649 0.6796 0.0480 0.6875\n",
"18 0.3115 0.8240 -0.6955 -1.0946 0.9679 0.6767 0.0494 0.6885\n",
"19 0.3121 0.8188 -0.7677 -1.0277 0.9569 0.6790 0.0487 0.6879\n",
"20 0.3169 0.8271 -0.8419 -0.9485 0.9646 0.6723 0.0492 0.6831\n",
"21 0.3084 0.8191 -0.8580 -0.9611 0.9674 0.6761 0.0491 0.6916\n",
"22 0.3106 0.8203 -0.7033 -0.9152 0.9709 0.6790 0.0482 0.6894\n",
"23 0.3144 0.8214 -0.7278 -0.8972 0.9688 0.6778 0.0489 0.6856\n",
"24 0.3113 0.8223 -0.6350 -1.2027 0.9619 0.6723 0.0498 0.6887\n",
"25 0.3111 0.8139 -0.6984 -0.7764 0.9661 0.6641 0.0512 0.6889\n",
"26 0.3144 0.8079 -0.7536 -1.1702 0.9608 0.6621 0.0507 0.6856\n",
"27 0.3146 0.8191 -0.6247 -1.0546 0.9707 0.6775 0.0488 0.6854\n",
"28 0.3134 0.8090 -0.7978 -1.1540 0.9678 0.6727 0.0498 0.6866\n",
"29 0.3173 0.8119 -0.7385 -1.0606 0.9642 0.6732 0.0493 0.6827"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cosmo_samples"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "51e830b5",
"metadata": {},
"outputs": [],
"source": [
"## Reorder the columns: h, Omega_m, Omega_b, Omega_q, n_s, sigma8, A_s, w0, wa\n",
"ordered_columns = ['h', 'Omega_m', 'Omega_b', 'Omega_q', 'n_s', 'sigma8','w0', 'wa']\n",
"cosmo_samples = cosmo_samples[ordered_columns]\n",
"## Rename index to 'Run' and set it to 'train_LCDM_{index+1}'\n",
"cosmo_samples.index = [f'train_w0wa_{i+1}' for i in range(len(cosmo_samples))]\n",
"cosmo_samples.index.name = 'Run'\n",
"## Save the sampled chain to a CSV file\n",
"output_file = \"/home/aubin/PotentialBCs/Planck2018/w0wa_set.csv\"\n",
"cosmo_samples.to_csv(output_file, index=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "febf6a0e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View file

@ -0,0 +1,183 @@
def create_parameters_dict(ID,ts_file,cosmo_params):
"""
Create a dictionnary of paramters for a given ID for the sbmy_control program.
"""
params=dict(directory="/home/aubin/data/PotentialBCs/ML_dataset/",
simname=ID,
mode="alltCOLA",
ICs_gen="monofonic",
verbose=1,
nthreads=128,
execution="slurm",
N_particles=768,
L=480.0,
ICs="/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_"+ID+"_DM_delta.h5",
WriteGravPot=True,
OutputGravitationalPotentialBase="/home/aubin/data/PotentialBCs/ML_dataset/gravitational_potential/gravpot_"+ID,
MeshGravPot=768,
WriteDensity=True,
OutputDensityBase="/home/aubin/data/PotentialBCs/ML_dataset/density/density_"+ID,
MeshDensity=768,
WriteReferenceFrame=True,
OutputMomentaBase="/home/aubin/data/PotentialBCs/ML_dataset/momenta/momenta_"+ID+"_",
monofonic_config="/home/aubin/data/PotentialBCs/ML_dataset/monofonic_config/monofonic_config_"+ID+".conf",
monofonic_output="/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_"+ID+"_",
TimeSteppingFileName=ts_file,
Omega_m=cosmo_params["Omega_m"],
Omega_b=cosmo_params["Omega_b"],
Omega_q=cosmo_params["Omega_q"],
h=cosmo_params["h"],
n_s=cosmo_params["n_s"],
sigma8=cosmo_params["sigma8"],
Tcmb=cosmo_params["Tcmb"],
k_p=cosmo_params["k_p"],
N_ur=cosmo_params["N_ur"],
m_nu1=cosmo_params["m_nu1"],
m_nu2=cosmo_params["m_nu2"],
m_nu3=cosmo_params["m_nu3"],
w_0=cosmo_params["w_0"],
w_a=cosmo_params["w_a"],
fnl=cosmo_params["fnl"],
gnl=cosmo_params["gnl"],
)
return params
if __name__ == "__main__":
import numpy as np
import pandas as pd
from pysbmy.timestepping import StandardTimeStepping
from pysbmy.cosmology import full_growthfactors_solver
from sbmy_control.parameters_monofonic import get_config_from_dict, create_monofonic_config
# Read the cosmological parameter from the CSV file
w0wa_set_file = "/home/aubin/PotentialBCs/Planck2018/w0wa_set.csv"
w0wa_set = pd.read_csv(w0wa_set_file)
# Extract the IDs from the DataFrame
IDs = w0wa_set['Run'].tolist()
# Define the timestepping configurations (TimeStepDistribution, nsteps, name)
ts_configs=[(0,10,'Ta1'),
(0,20,'Ta2'),
(3,10,'TD1'),
(3,20,'TD2'),]
# Define the additional cosmological parameters
cosmo_defaults_add = {
"Omega_k":0.0,
"Omega_r": 0.0,
"Tcmb": 2.7255,
"k_p": 0.05,
"N_ur": 2.046,
"m_nu1": 0.06,
"m_nu2": 0.0,
"m_nu3": 0.0,
"fnl": 0.0,
"gnl": 0.0,
"k_max":10.0,
"tau_reio":0.06,
"WhichSpectrum":"EH",
}
# Iterate over the IDs
for k, ID in enumerate(IDs):
if k<6: # Skip the first 6 IDs, already done
continue
print(f"Processing ID {k+1}/{len(IDs)}: {ID}")
# Get the cosmological parameters for the current ID
cosmo_params = w0wa_set[w0wa_set['Run'] == ID].iloc[0].to_dict()
# Add the additional cosmological parameters
cosmo_params.update(cosmo_defaults_add)
cosmo_params["w_0"] = cosmo_params["w0"]
cosmo_params["w_a"] = cosmo_params["wa"]
cosmo_params["w0_fld"] = cosmo_params["w0"]
cosmo_params["wa_fld"] = cosmo_params["wa"]
# Create the timestepping
print(f"> Creating timestepping with configuration {ts_configs[k % len(ts_configs)]} for ID {ID}")
this_ts_config = ts_configs[k % len(ts_configs)]
TS = StandardTimeStepping(
ai= 1/(1+19.0),
af = 1.,
integrator=2,
TimeStepDistribution=this_ts_config[0],
nsteps=this_ts_config[1],
cosmo=cosmo_params
)
# Write the timestepping
print(f"> Writing timestepping to file for ID {ID}")
ts_file = f"/home/aubin/data/PotentialBCs/ML_dataset/params/ts_{ID}_{this_ts_config[2]}.h5"
TS.write(ts_file)
# For each force evaluation, get the following values: a, D1, D2, which can be obtained with
print(f"> Calculating growth factors for ID {ID}")
a_force = TS.aStart[TS.operations == 2]
D_array = full_growthfactors_solver(a_force, cosmo_params)
D1_force = D_array[:, 0]
D2_force = D_array[:, 2]
# For each force evaluation, save the following values to a file: ID, nforce, a, D1, D2, h, Omega_m, sigma8
print(f"> Saving the cosmological parameters and time values for ID {ID}")
for nforce in range(len(a_force)):
output_file = f"/home/aubin/data/PotentialBCs/ML_dataset/cosmo_and_time/cosmo_and_time_parameters_{ID}_nforce{nforce}.txt"
with open(output_file, 'w') as f:
f.write(f"ID: {ID}\n")
f.write(f"nforce: {nforce}\n")
f.write(f"a: {a_force[nforce]}\n")
f.write(f"D1: {D1_force[nforce]}\n")
f.write(f"D2: {D2_force[nforce]}\n")
f.write(f"h: {cosmo_params['h']}\n")
f.write(f"Omega_m: {cosmo_params['Omega_m']}\n")
f.write(f"sigma8: {cosmo_params['sigma8']}\n")
# Create the configuration file for monofonic
print(f"> Creating the configuration file for monofonic for ID {ID}")
monofonic_config_file = f"/home/aubin/data/PotentialBCs/ML_dataset/monofonic_config/monofonic_config_{ID}.conf"
monofonic_dict = {
"config" : monofonic_config_file,
"output" : f"/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_{ID}_",
"gridres": 768,
"boxlength": 480.0,
"seed" : np.random.randint(0, 2**32),
"ParameterSet":None,
"nthreads":128,
**cosmo_params,
}
create_monofonic_config(monofonic_config_file, get_config_from_dict(monofonic_dict))
# Run the sbmy_control command with the parameters for the current ID
print(f"> Running sbmy_control for ID {ID}")
params = create_parameters_dict(ID,ts_file,cosmo_params)
import subprocess
command_args = ["sbmy_control"]
for key, value in params.items():
command_args.append(f"--{key}")
command_args.append(f"{value}")
subprocess.run(command_args)
# Remove the initial conditions particles files that are unnecessary
print(f"> Removing unnecessary initial conditions files for ID {ID}")
import os
import glob
ic_particles_files = glob.glob(f"/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_{ID}_particles*")
for file in ic_particles_files:
os.remove(file)
# Remove monofonic slurm script
monofonic_slurm_script = f"/home/aubin/data/PotentialBCs/ML_dataset/slurm_scripts/monofonic.sh"
if os.path.isfile(monofonic_slurm_script):
print(f"> Removing monofonic slurm script for ID {ID}")
os.remove(monofonic_slurm_script)
print(f"> Finished processing ID {ID}\n\n\n")

View file

@ -0,0 +1,185 @@
def create_parameters_dict(ID,ts_file,cosmo_params):
"""
Create a dictionnary of paramters for a given ID for the sbmy_control program.
"""
params=dict(directory="/home/aubin/data/PotentialBCs/ML_dataset/",
simname=ID,
mode="alltCOLA",
ICs_gen="monofonic",
verbose=1,
nthreads=128,
execution="slurm",
N_particles=768,
L=480.0,
ICs="/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_"+ID+"_DM_delta.h5",
WriteGravPot=True,
OutputGravitationalPotentialBase="/home/aubin/data/PotentialBCs/ML_dataset/gravitational_potential/gravpot_"+ID,
MeshGravPot=768,
WriteDensity=True,
OutputDensityBase="/home/aubin/data/PotentialBCs/ML_dataset/density/density_"+ID,
MeshDensity=768,
WriteReferenceFrame=True,
OutputMomentaBase="/home/aubin/data/PotentialBCs/ML_dataset/momenta/momenta_"+ID+"_",
monofonic_config="/home/aubin/data/PotentialBCs/ML_dataset/monofonic_config/monofonic_config_"+ID+".conf",
monofonic_output="/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_"+ID+"_",
TimeSteppingFileName=ts_file,
Omega_m=cosmo_params["Omega_m"],
Omega_b=cosmo_params["Omega_b"],
Omega_q=cosmo_params["Omega_q"],
h=cosmo_params["h"],
n_s=cosmo_params["n_s"],
sigma8=cosmo_params["sigma8"],
A_s=cosmo_params["A_s"],
Tcmb=cosmo_params["Tcmb"],
k_p=cosmo_params["k_p"],
N_ur=cosmo_params["N_ur"],
m_nu1=cosmo_params["m_nu1"],
m_nu2=cosmo_params["m_nu2"],
m_nu3=cosmo_params["m_nu3"],
w_0=cosmo_params["w_0"],
w_a=cosmo_params["w_a"],
fnl=cosmo_params["fnl"],
gnl=cosmo_params["gnl"],
)
return params
if __name__ == "__main__":
import numpy as np
import pandas as pd
from pysbmy.timestepping import StandardTimeStepping
from pysbmy.cosmology import full_growthfactors_solver
from sbmy_control.parameters_monofonic import get_config_from_dict, create_monofonic_config
# Read the cosmological parameter from the CSV file
planck_set_file = "/home/aubin/PotentialBCs/Planck2018/Planck_set.csv"
planck_set = pd.read_csv(planck_set_file)
# Extract the IDs from the DataFrame
IDs = planck_set['Run'].tolist()
# Define the timestepping configurations (TimeStepDistribution, nsteps, name)
ts_configs=[(0,10,'Ta1'),
(0,20,'Ta2'),
(3,10,'TD1'),
(3,20,'TD2'),]
# Define the additional cosmological parameters
cosmo_defaults_add = {
"Omega_k":0.0,
"Omega_r": 0.0,
"Tcmb": 2.7255,
"k_p": 0.05,
"N_ur": 2.046,
"m_nu1": 0.06,
"m_nu2": 0.0,
"m_nu3": 0.0,
"w_0": -1.0,
"w_a": 0.0,
"fnl": 0.0,
"gnl": 0.0,
"k_max":10.0,
"tau_reio":0.06,
"WhichSpectrum":"EH",
"w0_fld":-1.0,
"wa_fld":0.0,
}
# Iterate over the IDs
for k, ID in enumerate(IDs):
print(f"Processing ID {k+1}/{len(IDs)}: {ID}")
if k < 4:
continue # Already done for the first 4 IDs
# Get the cosmological parameters for the current ID
cosmo_params = planck_set[planck_set['Run'] == ID].iloc[0].to_dict()
# Add the additional cosmological parameters
cosmo_params.update(cosmo_defaults_add)
# Multiply A_s by 1e-9 to convert it to the correct units
cosmo_params["A_s"] *= 1e-9
# Create the timestepping
print(f"> Creating timestepping with configuration {ts_configs[k % len(ts_configs)]} for ID {ID}")
this_ts_config = ts_configs[k % len(ts_configs)]
TS = StandardTimeStepping(
ai= 1/(1+19.0),
af = 1.,
integrator=2,
TimeStepDistribution=this_ts_config[0],
nsteps=this_ts_config[1],
cosmo=cosmo_params
)
# Write the timestepping
print(f"> Writing timestepping to file for ID {ID}")
ts_file = f"/home/aubin/data/PotentialBCs/ML_dataset/params/ts_{ID}_{this_ts_config[2]}.h5"
TS.write(ts_file)
# For each force evaluation, get the following values: a, D1, D2, which can be obtained with
print(f"> Calculating growth factors for ID {ID}")
a_force = TS.aStart[TS.operations == 2]
D_array = full_growthfactors_solver(a_force, cosmo_params)
D1_force = D_array[:, 0]
D2_force = D_array[:, 2]
# For each force evaluation, save the following values to a file: ID, nforce, a, D1, D2, h, Omega_m, sigma8
print(f"> Saving the cosmological parameters and time values for ID {ID}")
for nforce in range(len(a_force)):
output_file = f"/home/aubin/data/PotentialBCs/ML_dataset/cosmo_and_time/cosmo_and_time_parameters_{ID}_nforce{nforce}.txt"
with open(output_file, 'w') as f:
f.write(f"ID: {ID}\n")
f.write(f"nforce: {nforce}\n")
f.write(f"a: {a_force[nforce]}\n")
f.write(f"D1: {D1_force[nforce]}\n")
f.write(f"D2: {D2_force[nforce]}\n")
f.write(f"h: {cosmo_params['h']}\n")
f.write(f"Omega_m: {cosmo_params['Omega_m']}\n")
f.write(f"sigma8: {cosmo_params['sigma8']}\n")
# Create the configuration file for monofonic
print(f"> Creating the configuration file for monofonic for ID {ID}")
monofonic_config_file = f"/home/aubin/data/PotentialBCs/ML_dataset/monofonic_config/monofonic_config_{ID}.conf"
monofonic_dict = {
"config" : monofonic_config_file,
"output" : f"/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_{ID}_",
"gridres": 768,
"boxlength": 480.0,
"seed" : np.random.randint(0, 2**32),
"ParameterSet":None,
"nthreads":128,
**cosmo_params,
}
create_monofonic_config(monofonic_config_file, get_config_from_dict(monofonic_dict))
# Run the sbmy_control command with the parameters for the current ID
print(f"> Running sbmy_control for ID {ID}")
params = create_parameters_dict(ID,ts_file,cosmo_params)
import subprocess
command_args = ["sbmy_control"]
for key, value in params.items():
command_args.append(f"--{key}")
command_args.append(f"{value}")
subprocess.run(command_args)
# Remove the initial conditions particles files that are unnecessary
print(f"> Removing unnecessary initial conditions files for ID {ID}")
import os
import glob
ic_particles_files = glob.glob(f"/home/aubin/data/PotentialBCs/ML_dataset/initial_conditions/ICs_{ID}_particles*")
for file in ic_particles_files:
os.remove(file)
# Remove monofonic slurm script
monofonic_slurm_script = f"/home/aubin/data/PotentialBCs/ML_dataset/slurm_scripts/monofonic.sh"
if os.path.isfile(monofonic_slurm_script):
print(f"> Removing monofonic slurm script for ID {ID}")
os.remove(monofonic_slurm_script)
print(f"> Finished processing ID {ID}\n\n\n")

File diff suppressed because it is too large Load diff