Skip to content

Commit

Permalink
Merge pull request #169 from deepskies/114-document-run-sims-thoroughly
Browse files Browse the repository at this point in the history
Cleaned up top-level directory, document run_sims
  • Loading branch information
samueldmcdermott authored Sep 28, 2023
2 parents 32c9441 + c7ec702 commit 49f1cbb
Show file tree
Hide file tree
Showing 27 changed files with 1,077 additions and 763 deletions.
Binary file modified .DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions .github/workflows/paper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on: [push]

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper/paper.pdf
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
run: |
conda env update --file environment.yml --name base
python -m pip install colossus pixell camb
python -m pip install .
- name: Test with pytest
run: |
conda install pytest
Expand Down
Binary file added notebooks/massdist.h5
Binary file not shown.
23 changes: 23 additions & 0 deletions notebooks/outfiles/params_230920173614790725_150_233437.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
COSMOLOGY:
Battaglia2012:
flat: True
H0: 70
Omega_m0: 0.25
Omega_b0: 0.043
sigma8: 0.8
ns: 0.96
cosmo_h: 0.7
t_cmb: 2.725 #K

SURVEYS:
ACTDR5:
150: #Observation frequency [GHz]
beam_size: 1.3 #From published survey properties
noise_level: 30 #From published survey properties

IMAGES:
image_size: 41
pix_size: 0.5



Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
854 changes: 854 additions & 0 deletions notebooks/simsz_run_simulation.ipynb

Large diffs are not rendered by default.

Binary file added notebooks/sz_sim_data.h5
Binary file not shown.
File renamed without changes.
Empty file added paper/figures/figures.md
Empty file.
Empty file added paper/paper.bib
Empty file.
59 changes: 59 additions & 0 deletions paper/paper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: 'DeepSZSim: A Python code for fast, tunable Sunyaev–Zeldovich effect submap simulations'
tags:
- Python
- cosmology
- cosmic microwave background
- galaxy clusters
- astronomy
authors:
- name: Author 1
orcid: 0000-0000-0000-0000
equal-contrib: true
affiliation: "1, 2" # (Multiple affiliations must be quoted)

affiliations:
- name: Affil 1
index: 1
- name: Affil 2
index: 2
- name: Affil 3
index: 3
date: 13 August 2023
bibliography: paper.bib


---

based on: https://joss.theoj.org/papers/10.21105/joss.00388

# Summary

< 10 sentences

Broad context of the field. State of the art simulations for SZ effect. Need for and current lack of fast, accessible simulations for ML. Dual purpose of student training. Tunability of sims and near-term goals for ML use with Deep Skies.

# Statement of need

< 20 sentences

Field need for well-tuned sims and ML methods. Niche our sims fill with Deep Skies, student training, and future science plans.

# Features

Descriptions of functions included in DeepSZSim. Figure 1: code schematic. Figure 2: Submaps, 4x4, including 1D pressure profile, 2D Compton-y map, 2D all-noise map, and 2D all+noise map.

# Citations


For a quick reference, the following citation commands can be used:
- `@author:2001` -> "Author et al. (2001)"
- `[@author:2001]` -> "(Author et al., 2001)"
- `[@author1:2001; @author2:2001]` -> "(Author1 et al., 2001; Author2 et al., 2002)"


# Acknowledgements

We acknowledge the Deep Skies Lab as a community of multi-domain experts and collaborators who’ve facilitated an environment of open discussion, idea-generation, and collaboration. This community was important for the development of this project.

# References
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tool.poetry]
name = "simsz"
version = "0.1.0"
description = "code for fast simulations of galaxy clusters"
authors = ["Eve Vavagiakis"]
license = "LICENSE.txt"

[tool.poetry.dependencies]
python = "^3.9"
camb = "^1.4.0"
h5py = "^3.8.0"
numpy = "^1.24.3"

[tool.poetry.dev-dependencies]
pytest = "^7.3.1"
pytest-cov = "^4.0.0"

pymaster = { version = "^1.5", optional = true }
[tool.poetry.extras]
pymaster = ["pymaster"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
726 changes: 0 additions & 726 deletions run_sims.ipynb

This file was deleted.

8 changes: 8 additions & 0 deletions simsz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import simsz.make_sz_cluster as make_sz_cluster

try:
from simsz.filters import get_tSZ_signal_aperture_photometry
from simsz.utils import Mpc_to_arcmin
except ModuleNotFoundError:
pass
File renamed without changes.
30 changes: 21 additions & 9 deletions simsz/load_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,38 @@
from astropy.cosmology import FlatLambdaCDM
import simsz.read_yaml as read_yaml
from typing import Union
import os

class load_vars(object):

def __init__(self, file_path= Union[None, str]):
self.file_path = file_path
def __init__(self,
file_path=os.path.join(os.path.dirname(__file__), "Settings", "inputdata.yaml")):
self.data = []
self.file_path = file_path

def make_dict_and_flatLCDM(self):
d = {}
ref=read_yaml.YAMLOperator(self.file_path).parse_yaml()
survey=[key for key in ref['SURVEYS'].keys()][0]
survey_freq=[key for key in ref['SURVEYS'][survey].keys()][0]
beam_size=ref['SURVEYS'][survey][survey_freq]['beam_size']
noise_level=ref['SURVEYS'][survey][survey_freq]['noise_level']
image_size = ref['IMAGES']['image_size']
pix_size = ref['IMAGES']['pix_size']
survey = [key for key in ref['SURVEYS'].keys()][0]
survey_freq = [key for key in ref['SURVEYS'][survey].keys()][0]
beam_size_arcmin = ref['SURVEYS'][survey][survey_freq]['beam_size']
noise_level = ref['SURVEYS'][survey][survey_freq]['noise_level']
image_size_arcmin = ref['IMAGES']['image_size']
pix_size_arcmin = ref['IMAGES']['pix_size']
d["survey"] = survey
d["survey_freq"] = survey_freq
d["beam_size_arcmin"] = beam_size_arcmin
d["noise_level"] = noise_level
d["image_size_arcmin"] = image_size_arcmin
d["pix_size_arcmin"] = pix_size_arcmin
for key in ref['COSMOLOGY'].keys():
cosmo_dict=ref['COSMOLOGY'][key] #Read in cosmological parameters

sigma8=cosmo_dict['sigma8']
ns=cosmo_dict['ns']

cosmo=FlatLambdaCDM(cosmo_dict['H0'], cosmo_dict['Omega_m0'], Tcmb0=cosmo_dict['t_cmb'], Ob0=cosmo_dict['Omega_b0'])
return(survey,survey_freq,beam_size,noise_level,image_size,pix_size,cosmo,sigma8,ns)
d["sigma8"] = sigma8
d["ns"] = ns
d["cosmo"] = cosmo
return d
40 changes: 19 additions & 21 deletions make_sz_cluster.py → simsz/make_sz_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def Pth_Battaglia2012(radius_mpc,R200_mpc,gamma,alpha,beta,xc,P0):
Returns:
--------
Pth: float
Pth: array of floats
the thermal pressure profile normalized over P200, units of
keV/cm**3
'''
Expand All @@ -208,7 +208,7 @@ def epp_to_y(profile, radii_mpc, P200_kevcm3, R200_mpc, **kwargs):
Parameters:
-----------
profile:
profile: method
Method to get thermal pressure profile in Kev/cm^3, accepts radius,
R200 and **kwargs
radii_mpc: array
Expand Down Expand Up @@ -389,23 +389,21 @@ def simulate_submap(M200_dist, z_dist, id_dist=None,
"""
#Make a dictionary and cosmology from the .yaml
(survey,freq_GHz,beam_size_fwhp_arcmin,noise_level,
image_size,pix_size_arcmin,cosmo,sigma8,ns)=load_vars.load_vars(
settings_yaml).make_dict_and_flatLCDM()
d=load_vars.load_vars().make_dict_and_flatLCDM()

M200_dist = np.asarray(M200_dist)
z_dist = np.asarray(z_dist)
if add_cmb:
# To make sure to only calculate this once if its a dist
ps = simtools.get_cls(ns=ns, cosmo=cosmo)
ps = simtools.get_cls(ns=d['ns'], cosmo=d['cosmo'])

if not os.path.exists(savedir):
print(f"making local directory `{savedir}`")
os.mkdir(savedir)

# Generate a run_id based on time of running and freq
rand_num = np.random.randint(10**6)
run_id = dt.now().strftime('%y%m%d%H%M%S%f_')+str(freq_GHz)+'_'+str(
run_id = dt.now().strftime('%y%m%d%H%M%S%f_')+str(d['survey_freq'])+'_'+str(
rand_num).zfill(6)

f = h5py.File(os.path.join(savedir, f'sz_sim_{run_id}.h5'), 'a')
Expand All @@ -415,20 +413,20 @@ def simulate_submap(M200_dist, z_dist, id_dist=None,
for index, M200 in np.ndenumerate(M200_dist):
z = z_dist[index]
if R200_dist is None:
(M200,R200,_c200)= get_r200_and_c200(cosmo,sigma8,
ns,M200,z)
(M200,R200,_c200)= get_r200_and_c200(d['cosmo'],d['sigma8'],
d['ns'],M200,z)
else:
R200 = R200_dist[index]


y_map = generate_y_submap(z, M200, R200, cosmo,
image_size, pix_size_arcmin)
y_map = generate_y_submap(z, M200, R200, d['cosmo'],
d['image_size_arcmin'], d['pix_size_arcmin'])
#get f_SZ for observation frequency
fSZ = simtools.f_sz(freq_GHz,cosmo.Tcmb0)
dT_map = (y_map * cosmo.Tcmb0 * fSZ).to(u.uK)
fSZ = simtools.f_sz(d['survey_freq'],d['cosmo'].Tcmb0)
dT_map = (y_map * d['cosmo'].Tcmb0 * fSZ).to(u.uK)

cluster = {'M200': M200, 'R200': R200, 'redshift_z': z,
'y_central': y_map[image_size//2][image_size//2]}
'y_central': y_map[d['image_size_arcmin']//2][d['image_size_arcmin']//2]}

if id_dist is not None:
cluster['ID'] = id_dist[index]
Expand All @@ -440,17 +438,17 @@ def simulate_submap(M200_dist, z_dist, id_dist=None,
if add_cmb:
conv_map, cmb_map = simtools.add_cmb_map_and_convolve(dT_map,
ps,
pix_size_arcmin,
beam_size_fwhp_arcmin)
d['pix_size_arcmin'],
d['beam_size_arcmin'])
cluster['CMB_map'] = cmb_map

else:
conv_map = simtools.convolve_map_with_gaussian_beam(
pix_size_arcmin, beam_size_fwhp_arcmin, dT_map)
d['pix_size_arcmin'], d['beam_size_fwhp_arcmin'], dT_map)

if not noise_level == 0:
noise_map=noise.generate_noise_map(image_size,
noise_level, pix_size_arcmin)
if not d['noise_level'] == 0:
noise_map=noise.generate_noise_map(d['image_size_arcmin'],
d['noise_level'], d['pix_size_arcmin'])
final_map = conv_map + noise_map

cluster['noise_map'] = noise_map
Expand All @@ -460,7 +458,7 @@ def simulate_submap(M200_dist, z_dist, id_dist=None,
utils.save_sim_to_h5(f, f"sim_{cluster['ID']}", cluster)

f.close()
shutil.copyfile(settings_yaml, os.path.join(savedir, f'params_{run_id}.yaml'))
shutil.copyfile(os.path.join(os.path.dirname(__file__), "Settings", "inputdata.yaml"), os.path.join(savedir, f'params_{run_id}.yaml'))

return clusters

Expand Down
2 changes: 1 addition & 1 deletion simsz/read_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class YAMLOperator(object):

def __init__(self, file_path= Union[None, str]):
def __init__(self, file_path=os.path.join(os.path.dirname(__file__), "Settings", "inputdata.yaml")):

self.file_path = file_path

Expand Down
2 changes: 1 addition & 1 deletion simsz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ def save_sim_to_h5(file, name, data, attributes={}, overwrite=False):
if name not in file:
file.create_group(name)
for aname, attr in attributes.items():
file[name].attrs[aname] = attr
file[name].attrs[aname] = attr
10 changes: 6 additions & 4 deletions tests/test_simtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from astropy import units as u
from pixell import enmap
import camb
from astropy.cosmology import FlatLambdaCDM


def get_mock_cosmology():
'''
Expand All @@ -21,9 +23,9 @@ def get_mock_cosmology():

class TestSimTools():
def test_f_sz(self):
freq = 100
freq = 1
(cosmo,sigma8,ns) = get_mock_cosmology()
T_CMB = cosmo.Tcmb0
fsz = simtools.f_sz(freq,T_CMB)
fsz_expected = 12.509
assert u.isclose(fsz,fsz_expected),
f"Expected {fsz_expected}, but got {fsz}"
fsz_expected = -1.999948
assert u.isclose(fsz,fsz_expected),f"Expected {fsz_expected}, but got {fsz}"
Loading

0 comments on commit 49f1cbb

Please sign in to comment.