csiborgtools/scripts_independent/A2_to_hdf5.ipynb
Richard Stiskalek a65e3cb15b
Add simple distance flow model (#114)
* Add imports

* Add field LOS paths

* Add basic flow model

* Edit script

* Add nb

* Add nb

* Update nb

* Add some docs

* Add RA reading

* Add imoprts

* Updates to the flow model

* Update script

* Bring back A2

* Update imports

* Update imports

* Add Carrick to ICs

* Add Carrick boxsize

* Add Carrick and fix minor bugs

* Add Carrick box

* Update script

* Edit imports

* Add fixed flow!

* Update omega_m and add it

* Update nb

* Update nb

* Update nb

* Remove old print statements

* Update params

* Add thinning of chains

* Add import

* Add flow validation script

* Add submit script

* Add ksmooth

* Update nb

* Update params

* Update script

* Update string

* Move where distributions are defined

* Add density bias parameter

* Add lognorm mean

* Update scripts

* Update script
2024-03-08 10:44:19 +00:00

4 KiB

In [1]:
# Copyright (C) 2024 Richard Stiskalek
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
from os.path import join

import numpy as np
import matplotlib.pyplot as plt
from h5py import File

%matplotlib inline

Supernovae data

In [2]:
a2dir = "/Users/richard/Data/PV/A2_paper_data/A2"

LOSS data set

In [3]:
names = ["z_CMB", "mB", "x1", "c", "e_mB", "e_x1", "e_c", "RA", "DEC"]
dtype = [(n, np.float32) for n in names]
data = np.genfromtxt(join(a2dir, "loss.csv"), delimiter=",", skip_header=1,
                     usecols=[5 + n for n in range(len(names))])

loss_data = np.empty(len(data), dtype=dtype)
for i, n in enumerate(names):
    loss_data[n] = data[:, i]

Foundation data set

In [4]:
names = ["z_CMB", "RA", "DEC", "x1", "mB", "c", "peak", "e_peak", "e_x1", "e_mB", "e_c"]
dtype = [(n, np.float32) for n in names]
data = np.genfromtxt(join(a2dir, "foundation.csv"), delimiter=",", skip_header=1,
                     usecols=[3 + n for n in range(len(names))])

foundation_data = np.empty(len(data), dtype=dtype)
for i, n in enumerate(names):
    foundation_data[n] = data[:, i]

Write output as HDF5 file

In [5]:
outdir = "/Users/richard/Downloads"
fname = "PV_compilation_Supranta2019.hdf5"

with File(join(outdir, fname), 'w') as f:
    # Write LOSS
    grp = f.create_group("LOSS")
    for name in loss_data.dtype.names:
        grp.create_dataset(name, data=loss_data[name])

    # Write Foundation
    grp = f.create_group("Foundation")
    for name in foundation_data.dtype.names:
        grp.create_dataset(name, data=foundation_data[name])
In [ ]: