Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tiled_noise to seedgen #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion actsims/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def __init__(self):
self.NOISE = 3
self.POISSON = 4
self.COMPTONY = 5
self.TILED_NOISE = 6

#quick-srcfree is maxmally correlated with 15mJy sims
self.fgdict = {'15mjy': 0, '100mjy': 1, 'srcfree': 2, 'quick-srcfree':0,'comptony': 3}

self.dmdict = {'act_mr3':0,'act_c7v5':1,'planck_hybrid':2}
self.dmdict = {'act_mr3':0,'act_c7v5':1,'planck_hybrid':2,'dr5':3}

def get_cmb_seed(self, set_idx, sim_idx):
return (set_idx, 0, self.CMB, sim_idx)
Expand Down Expand Up @@ -46,6 +47,54 @@ def get_noise_seed(self, set_idx, sim_idx, data_model, season, patch, array, pat
def get_poisson_seed(self, set_idx, sim_idx):
return (set_idx, 0, self.POISSON, sim_idx)

def get_tiled_noise_seed(self, set_idx, sim_idx, data_model, qid, tile_idx, lowell_seed=False):
"""Return a seed for a tile in a tiled noise simulation scheme. Allows consistent
seeding for a given simulation set, map number, data model, qid (array), and tile
number, across users and platforms.

Parameters
----------
set_idx : int
sim_idx : int
data_model : object
A soapack.interfaces DataModel object
qid : str or iterable of str
If simulating 1 array, can pass 1 string or iterable of type string
and length 1. If simulating correlation between 2 arrays, pass iterable of
type str and length 2. Iterables are sorted, so order does not matter. Cannot
correlate more than 2 arrays.
tile_idx : int
lowell_seed : bool
If two tiling schemes are building one sim, you don't want correlated tiles.
The second integer in the seed tuple will be 1 if True.

Returns
-------
tuple of int
Seed to be passed to np.random.seed

Example
-------
>>> from actsims import util as u
>>> u.seed_tracker.get_tiled_noise_seed(3,963,u.dmint.DR5(),'s18_03',7_034)
>>> (3, 0, 6, 963, 3, 8326, 0, 7034)
>>> u.seed_tracker.get_tiled_noise_seed(3,963,u.dmint.DR5(),['s18_04','s18_03'],7_034)
>>> (3, 0, 6, 963, 3, 8326, 2839, 7034)

"""
ret = (set_idx, int(lowell_seed), self.TILED_NOISE, sim_idx)
dm = data_model
qid = np.sort(np.atleast_1d(qid)) # sorted qids
assert len(qid) <= 2, f'Can only seed for correlation of up to 2 arrays; {len(qid)} passed'

assert(dm.name in self.dmdict.keys())
dm_idx = self.dmdict[dm.name]

if len(qid) == 1:
qid_idx = (dmint.arrays(qid[0], 'hash'), 0)
else:
qid_idx = tuple(dmint.arrays(q, 'hash') for q in qid)
return ret + (dm_idx,) + qid_idx + (tile_idx,)
seed_tracker = _SeedTracker()


Expand Down