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

Support supplemental sky targets #241

Merged
merged 3 commits into from Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions py/fiberassign/assign.py
Expand Up @@ -34,7 +34,8 @@

from .utils import Logger, Timer, default_mp_proc

from .targets import (TARGET_TYPE_SKY, TARGET_TYPE_SAFE, desi_target_type,
from .targets import (TARGET_TYPE_SKY, TARGET_TYPE_SUPPSKY,
TARGET_TYPE_SAFE, desi_target_type,
default_target_masks, default_survey_target_masks)

from .hardware import (FIBER_STATE_UNASSIGNED, FIBER_STATE_STUCK,
Expand Down Expand Up @@ -730,22 +731,24 @@ def read_assignment_fits_tile(params):
fsciencemask = None
fstdmask = None
fskymask = None
fsuppskymask = None
fexcludemask = None
fcol = None
if survey is not None:
fsciencemask, fstdmask, fskymask, fsafemask, fexcludemask = \
default_survey_target_masks(survey)
fsciencemask, fstdmask, fskymask, fsuppskymask, fsafemask, \
fexcludemask = default_survey_target_masks(survey)
fcol = "FA_TARGET"
else:
fsurvey, fcol, fsciencemask, fstdmask, fskymask, fsafemask, \
fsurvey, fcol, fsciencemask, fstdmask, fskymask, \
fsuppskymask, fsafemask, \
fexcludemask = default_target_masks(fbtargets)
survey = fsurvey

for col in full_names:
if col == "FA_TYPE":
targets_data[col][:nrawtarget] = [
desi_target_type(x, fsciencemask, fstdmask, fskymask,
fsafemask, fexcludemask)
fsuppskymask, fsafemask, fexcludemask)
for x in fbtargets[fcol][:]]
elif col == "FA_TARGET":
targets_data[col][:nrawtarget] = fbtargets[fcol]
Expand Down Expand Up @@ -1266,8 +1269,8 @@ def merge_results(targetfiles, skyfiles, tiles, result_dir=".",
# Read data directly into shared buffer
tgview[:] = fd[1].read()
if survey is None:
(survey, col, sciencemask, stdmask, skymask, safemask,
excludemask) = default_target_masks(tgview)
(survey, col, sciencemask, stdmask, skymask, suppskymask,
safemask, excludemask) = default_target_masks(tgview)

# Sort rows by TARGETID if not already done
tgviewids = tgview["TARGETID"]
Expand Down
40 changes: 24 additions & 16 deletions py/fiberassign/qa.py
Expand Up @@ -71,27 +71,28 @@ def qa_parse_table(header, tgdata):

def qa_tile_with_gfa(hw, tile_id, tgs, tgprops, tile_assign, tile_avail, tile_gfa):
props = dict()

locs = np.array(hw.device_locations("POS"))
nassign = 0
nscience = 0
nstd = 0
nsky = 0
nsuppsky = 0
nsafe = 0
unassigned = list()
objtypes = dict()

# SE to add GFA info to props
petals = list(range(10))
petals_wgfa = list(tile_gfa.keys())
petals_wogfa = list(set(petals)-set(petals_wgfa))
petals_wogfa = list(set(petals)-set(petals_wgfa))
gfas_per_tile = [nsafe]*10
brightest_gfas = [nsafe]*10
faintest_gfas = [nsafe]*10
gfas_upto_18th = [nsafe]*10
gfas_upto_19th = [nsafe]*10
gfas_upto_20th = [nsafe]*10
gfas_upto_19th = [nsafe]*10
gfas_upto_20th = [nsafe]*10

for cam in petals_wgfa:
if (len(tile_gfa[cam])>0):
gfas_per_tile[cam] = len(tile_gfa[cam])
Expand All @@ -107,8 +108,8 @@ def qa_tile_with_gfa(hw, tile_id, tgs, tgprops, tile_assign, tile_avail, tile_gf
faintest_gfas[cam] = ['NaN']
gfas_upto_18th[cam] = [0]
gfas_upto_19th[cam] = [0]
gfas_upto_20th[cam] = [0]
gfas_upto_20th[cam] = [0]

for lid in locs:
if lid not in tile_assign:
unassigned.append(int(lid))
Expand All @@ -130,25 +131,28 @@ def qa_tile_with_gfa(hw, tile_id, tgs, tgprops, tile_assign, tile_avail, tile_gf
nstd += 1
if tg.is_sky():
nsky += 1
if tg.is_suppsky():
nsuppsky += 1
if tg.is_safe():
nsafe += 1
props["assign_total"] = nassign
props["assign_science"] = nscience
props["assign_std"] = nstd
props["assign_sky"] = nsky
props["assign_suppsky"] = nsuppsky
props["assign_safe"] = nsafe
# SE: added this key for the number of GFA stars per camera: list of 10 integers per tile
props["gfa_stars_percam"] = gfas_per_tile
# SE: added this key for the list of 10 magnitudes of the brightest GFA stars available per camera
props["brightest_gfa_star_percam"] = [np.round(b*(nsafe+1)/(nsafe+1),2) for b in list(brightest_gfas)]
# SE: Number of gfa stars <18 per camera
# SE: added this key for the list of 10 magnitudes of the brightest GFA stars available per camera
props["brightest_gfa_star_percam"] = [np.round(b*(nsafe+1)/(nsafe+1),2) for b in list(brightest_gfas)]
# SE: Number of gfa stars <18 per camera
props["gfa_stars_brighter_than_18th"] = [int(b*(nsafe+1)/(nsafe+1)) for b in list(gfas_upto_18th)]
props["gfa_stars_brighter_than_19th"] = [int(b*(nsafe+1)/(nsafe+1)) for b in list(gfas_upto_19th)]
props["gfa_stars_brighter_than_20th"] = [int(b*(nsafe+1)/(nsafe+1)) for b in list(gfas_upto_20th)]

# SE: added this key for the list of 10 magnitudes of the faintest GFA stars available per camera
# SE: added this key for the list of 10 magnitudes of the faintest GFA stars available per camera
props["faintest_gfa_star_percam"] = [np.round(b*(nsafe+1)/(nsafe+1),2) for b in list(faintest_gfas)]

for ot, cnt in objtypes.items():
props["assign_obj_{}".format(ot)] = cnt
props["unassigned"] = unassigned
Expand All @@ -167,10 +171,11 @@ def qa_tile(hw, tile_id, tgs, tgprops, tile_assign, tile_avail):
nscience = 0
nstd = 0
nsky = 0
nsuppsky = 0
nsafe = 0
unassigned = list()
objtypes = dict()

for lid in locs:
if lid not in tile_assign:
unassigned.append(int(lid))
Expand All @@ -192,12 +197,15 @@ def qa_tile(hw, tile_id, tgs, tgprops, tile_assign, tile_avail):
nstd += 1
if tg.is_sky():
nsky += 1
if tg.is_suppsky():
nsuppsky += 1
if tg.is_safe():
nsafe += 1
props["assign_total"] = nassign
props["assign_science"] = nscience
props["assign_std"] = nstd
props["assign_sky"] = nsky
props["assign_suppsky"] = nsuppsky
props["assign_safe"] = nsafe
for ot, cnt in objtypes.items():
props["assign_obj_{}".format(ot)] = cnt
Expand All @@ -214,7 +222,7 @@ def qa_tile_file(hw, params):

header, fiber_data, targets_data, avail_data, gfa_data = \
read_assignment_fits_tile((tile_id, tile_file))

# Target properties
tgs, tgprops = qa_parse_table(header, targets_data)

Expand All @@ -226,7 +234,7 @@ def qa_tile_file(hw, params):
if (x["LOCATION"] >= 0)}

tavail = avail_table_to_dict(avail_data)
if gfa_data is not None:
if gfa_data is not None:
tgfa = gfa_table_to_dict(gfa_data)

qa_data = qa_tile_with_gfa(hw, tile_id, tgs, tgprops, tassign, tavail, tgfa)
Expand Down
17 changes: 16 additions & 1 deletion py/fiberassign/scripts/assign.py
Expand Up @@ -23,7 +23,8 @@
from ..gfa import get_gfa_targets

from ..targets import (str_to_target_type, TARGET_TYPE_SCIENCE,
TARGET_TYPE_SKY, TARGET_TYPE_STANDARD,
TARGET_TYPE_SKY, TARGET_TYPE_SUPPSKY,
TARGET_TYPE_STANDARD,
TARGET_TYPE_SAFE, Targets, TargetsAvailable,
TargetTree, LocationsAvailable,
load_target_file)
Expand Down Expand Up @@ -355,15 +356,20 @@ def run_assign_full(args):
# Assign sky to unused fibers, up to some limit
asgn.assign_unused(TARGET_TYPE_SKY, args.sky_per_petal)

# Assign suppsky to unused fibers, up to some limit
asgn.assign_unused(TARGET_TYPE_SUPPSKY, args.sky_per_petal)

# Force assignment if needed
asgn.assign_force(TARGET_TYPE_STANDARD, args.standards_per_petal)
asgn.assign_force(TARGET_TYPE_SKY, args.sky_per_petal)
asgn.assign_force(TARGET_TYPE_SUPPSKY, args.sky_per_petal)

# If there are any unassigned fibers, try to place them somewhere.
# Assigning science again is a no-op, but...
asgn.assign_unused(TARGET_TYPE_SCIENCE)
asgn.assign_unused(TARGET_TYPE_STANDARD)
asgn.assign_unused(TARGET_TYPE_SKY)
asgn.assign_unused(TARGET_TYPE_SUPPSKY)

# Assign safe location to unused fibers (no maximum). There should
# always be at least one safe location (i.e. "BAD_SKY") for each fiber.
Expand All @@ -372,6 +378,7 @@ def run_assign_full(args):

# Assign sky monitor fibers
asgn.assign_unused(TARGET_TYPE_SKY, -1, "ETC")
asgn.assign_unused(TARGET_TYPE_SUPPSKY, -1, "ETC")
asgn.assign_unused(TARGET_TYPE_SAFE, -1, "ETC")

gt.stop("run_assign_full calculation")
Expand Down Expand Up @@ -450,17 +457,24 @@ def run_assign_bytile(args):
asgn.assign_unused(TARGET_TYPE_SKY, args.sky_per_petal, "POS",
tile_id, tile_id)

# Assign suppsky to unused fibers, up to some limit
asgn.assign_unused(TARGET_TYPE_SUPPSKY, args.sky_per_petal, "POS",
tile_id, tile_id)

# Force assignment if needed
asgn.assign_force(TARGET_TYPE_STANDARD, args.standards_per_petal,
tile_id, tile_id)
asgn.assign_force(TARGET_TYPE_SKY, args.sky_per_petal,
tile_id, tile_id)
asgn.assign_force(TARGET_TYPE_SUPPSKY, args.sky_per_petal,
tile_id, tile_id)

# If there are any unassigned fibers, try to place them somewhere.
# Assigning science again is a no-op, but...
asgn.assign_unused(TARGET_TYPE_SCIENCE, -1, "POS", tile_id, tile_id)
asgn.assign_unused(TARGET_TYPE_STANDARD, -1, "POS", tile_id, tile_id)
asgn.assign_unused(TARGET_TYPE_SKY, -1, "POS", tile_id, tile_id)
asgn.assign_unused(TARGET_TYPE_SUPPSKY, -1, "POS", tile_id, tile_id)

# Assign safe location to unused fibers (no maximum). There should
# always be at least one safe location (i.e. "BAD_SKY") for each
Expand All @@ -470,6 +484,7 @@ def run_assign_bytile(args):

# Assign sky monitor fibers
asgn.assign_unused(TARGET_TYPE_SKY, -1, "ETC", tile_id, tile_id)
asgn.assign_unused(TARGET_TYPE_SUPPSKY, -1, "ETC", tile_id, tile_id)
asgn.assign_unused(TARGET_TYPE_SAFE, -1, "ETC", tile_id, tile_id)

gt.stop("run_assign_bytile calculation")
Expand Down