We present and test a framework that models the three-dimensional
distribution of mass in the Universe as a function of cosmological and
astrophysical parameters. Our approach combines two different techniques: a
rescaling algorithm that modifies the cosmology of gravity-only N-body
simulations, and a baryonification algorithm which mimics the effects of
astrophysical processes induced by baryons, such as star formation and AGN
feedback. We show how this approach can accurately reproduce the effects of
baryons on the matter power spectrum of various state-of-the-art
hydro-dynamical simulations (EAGLE, Illustris, Illustris-TNG, Horizon-AGN, and
OWLS,Cosmo-OWLS and BAHAMAS), to percent level from very large down to small,
highly nonlinear scales, k= 5 h/Mpc, and from z=0 up to z=2. We highlight that,
thanks to the heavy optimisation of the algorithms, we can obtain these
predictions for arbitrary baryonic models and cosmology (including massive
neutrinos and dynamical dark energy models) with an almost negligible CPU cost.
Therefore, this approach is efficient enough for cosmological data analyses.
With these tools in hand we explore the degeneracies between cosmological and
astrophysical parameters in the nonlinear mass power spectrum. Our findings
suggest that after marginalising over baryonic physics, cosmological
constraints inferred from weak gravitational lensing should be moderately
degraded.