Skip to content

Commit

Permalink
skyportal connection updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoughlin committed May 29, 2024
1 parent 30531c6 commit a409a12
Showing 1 changed file with 5 additions and 35 deletions.
40 changes: 5 additions & 35 deletions gwemopt/skyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,6 @@ def create_galaxy_from_skyportal(params, map_struct, catalog_struct, regions=Non


def create_moc_from_skyportal(params, map_struct=None, field_ids=None):
nside = params["nside"]
npix = hp.nside2npix(nside)

if params["doMinimalTiling"]:
prob = map_struct["prob"]

n, cl, dist_exp = (
params["powerlaw_n"],
params["powerlaw_cl"],
params["powerlaw_dist_exp"],
)
prob_scaled = copy.deepcopy(prob)
prob_sorted = np.sort(prob_scaled)[::-1]
prob_indexes = np.argsort(prob_scaled)[::-1]
prob_cumsum = np.cumsum(prob_sorted)
index = np.argmin(np.abs(prob_cumsum - cl)) + 1
prob_indexes = prob_indexes[: index + 1]

if "doUsePrimary" in params:
doUsePrimary = params["doUsePrimary"]
Expand All @@ -261,13 +244,6 @@ def create_moc_from_skyportal(params, map_struct=None, field_ids=None):
else:
doUseSecondary = False

npix = hp.nside2npix(nside)
pixarea = hp.nside2pixarea(nside)

theta, phi = hp.pix2ang(nside, np.arange(npix))
ra = np.rad2deg(phi)
dec = np.rad2deg(0.5 * np.pi - theta)

moc_structs = {}
for telescope in params["telescopes"]:
config_struct = params["config"][telescope]
Expand All @@ -279,7 +255,8 @@ def create_moc_from_skyportal(params, map_struct=None, field_ids=None):
if tess.field_id not in field_ids[telescope]:
mocs.append(MOC.new_empty(29))
continue
mocs.append(skyportal2FOV(tess, nside))
moc = moc_from_tiles([tile.healpix for tile in tess.tiles], 2**29)
mocs.append(moc)
for ii, tess in enumerate(tesselation):
index = tess.field_id

Expand All @@ -301,21 +278,20 @@ def create_moc_from_skyportal(params, map_struct=None, field_ids=None):
moc_struct_new = copy.copy(moc_struct)
if params["tilesType"] == "galaxy":
tile_probs = gwemopt.tiles.compute_tiles_map(
params, moc_struct_new, prob, func="center"
params, moc_struct_new, map_struct["skymap"], func="center"
)
else:
tile_probs = gwemopt.tiles.compute_tiles_map(
params, moc_struct_new, prob, func="np.sum(x)"
params, moc_struct_new, map_struct["skymap"], func="np.sum(x)"
)

keys = moc_struct.keys()

sort_idx = np.argsort(tile_probs)[::-1]
csm = np.empty(len(tile_probs))
csm[sort_idx] = np.cumsum(tile_probs[sort_idx])
moc_keep = np.where(csm <= cl)[0]
moc_keep = np.where(csm <= params["powerlaw_cl"])[0]

probs = []
moc_struct = {}
cnt = 0
for ii, key in enumerate(keys):
Expand All @@ -328,12 +304,6 @@ def create_moc_from_skyportal(params, map_struct=None, field_ids=None):
return moc_structs


def skyportal2FOV(tess, nside):
moc = moc_from_tiles([tile.healpix for tile in tess.tiles], 2**29)

return moc


def moc_from_tiles(rangeSet, nside):
depth = int(np.log2(nside))
segmentlist = segments.segmentlist()
Expand Down

0 comments on commit a409a12

Please sign in to comment.