Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoughlin committed May 28, 2024
1 parent 7200eeb commit bbd534b
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 867 deletions.
7 changes: 1 addition & 6 deletions gwemopt/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def parse_args(args):

parser.add_argument("--Ndet", default=1, type=int)
parser.add_argument("--nside", default=256, type=int)
parser.add_argument("--DScale", default=1.0, type=float)
parser.add_argument("--Tobs", default="0.0,1.0")

parser.add_argument("--mindiff", default=0.0, type=float)
Expand Down Expand Up @@ -111,8 +110,6 @@ def parse_args(args):
parser.add_argument("--doSingleExposure", action="store_true", default=False)
parser.add_argument("--filters", default="r,g,r")
parser.add_argument("--doAlternatingFilters", action="store_true", default=False)
parser.add_argument("--doRASlices", action="store_true", default=False)
parser.add_argument("--nside_down", default=2, type=int)
parser.add_argument("--max_filter_sets", default=4, type=int)
parser.add_argument("--iterativeOverlap", default=0.0, type=float)
parser.add_argument("--maximumOverlap", default=1.0, type=float)
Expand All @@ -137,10 +134,8 @@ def parse_args(args):
parser.add_argument("--doBlocks", action="store_true", default=False)
parser.add_argument("--Nblocks", default=4, type=int)

parser.add_argument("--doRASlice", action="store_true", default=False)
parser.add_argument("--raslice", default="0.0,24.0")

parser.add_argument("--absmag", default=-15.0, type=float)
parser.add_argument("--raslice", default=None)

parser.add_argument(
"--galactic_limit", help="Galactic limit.", default=0.0, type=float
Expand Down
44 changes: 7 additions & 37 deletions gwemopt/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def combine_coverage_structs(coverage_structs):
coverage_struct_combined = {}
coverage_struct_combined["data"] = np.empty((0, 8))
coverage_struct_combined["filters"] = np.empty((0, 1))
coverage_struct_combined["ipix"] = []
coverage_struct_combined["patch"] = []
coverage_struct_combined["FOV"] = np.empty((0, 1))
coverage_struct_combined["area"] = np.empty((0, 1))
coverage_struct_combined["moc"] = []
coverage_struct_combined["telescope"] = np.empty((0, 1))
coverage_struct_combined["galaxies"] = []
coverage_struct_combined["exposureused"] = []
Expand All @@ -45,17 +42,8 @@ def combine_coverage_structs(coverage_structs):
coverage_struct_combined["filters"] = np.append(
coverage_struct_combined["filters"], coverage_struct["filters"]
)
coverage_struct_combined["ipix"] = (
coverage_struct_combined["ipix"] + coverage_struct["ipix"]
)
coverage_struct_combined["patch"] = (
coverage_struct_combined["patch"] + coverage_struct["patch"]
)
coverage_struct_combined["FOV"] = np.append(
coverage_struct_combined["FOV"], coverage_struct["FOV"]
)
coverage_struct_combined["area"] = np.append(
coverage_struct_combined["area"], coverage_struct["area"]
coverage_struct_combined["moc"] = (
coverage_struct_combined["moc"] + coverage_struct["moc"]
)
coverage_struct_combined["telescope"] = np.append(
coverage_struct_combined["telescope"], coverage_struct["telescope"]
Expand Down Expand Up @@ -173,7 +161,7 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):

coverage_structs = []
n_scope = 0
full_prob_map = map_struct["prob"]
full_prob_map = map_struct["skymap"]

for jj, telescope in enumerate(params["telescopes"]):
if params["splitType"] is not None:
Expand Down Expand Up @@ -233,16 +221,7 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):
previous_coverage_struct,
)

if params["doRASlices"]:
coverage_struct = gwemopt.scheduler.schedule_ra_splits(
params,
config_struct,
map_struct_hold,
tile_struct,
telescope,
previous_coverage_struct,
)
elif params["doBalanceExposure"]:
if params["doBalanceExposure"]:
if (
params["max_nb_tiles"] is None
): # optimize max tiles (iff max tiles not already specified)
Expand Down Expand Up @@ -435,7 +414,7 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):
if params["doIterativeTiling"]:
map_struct_hold = slice_map_tiles(params, map_struct_hold, coverage_struct)

map_struct["prob"] = full_prob_map
map_struct["skymap"] = full_prob_map

return tile_structs, combine_coverage_structs(coverage_structs)

Expand Down Expand Up @@ -508,16 +487,7 @@ def absmag(params, map_struct, tile_structs, previous_coverage_struct=None):
tile_struct,
previous_coverage_struct,
)
if params["doRASlices"]:
coverage_struct = gwemopt.scheduler.schedule_ra_splits(
params,
config_struct,
map_struct_hold,
tile_struct,
telescope,
previous_coverage_struct,
)
elif params["doBalanceExposure"]:
if params["doBalanceExposure"]:
if params["max_nb_tiles"] is None:
# optimize max tiles (iff max tiles not already specified)
optimized_max, coverage_struct, tile_struct = optimize_max_tiles(
Expand Down
5 changes: 1 addition & 4 deletions gwemopt/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from gwemopt.io.export_tiles import (
export_tiles_coverage_hist,
export_tiles_coverage_int,
)
from gwemopt.io.export_tiles import export_tiles_coverage_int
from gwemopt.io.schedule import export_schedule_xml, read_schedule, summary
from gwemopt.io.skymap import get_skymap, read_skymap
10 changes: 0 additions & 10 deletions gwemopt/io/export_tiles.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
def export_tiles_coverage_hist(params, diffs):
"""
Export the histogram of the tiles coverage.
"""
filename = params["outputDir"].joinpath("tiles_coverage_hist.dat")
with open(filename, "w") as fid:
for ii in range(len(diffs)):
fid.write("%.10f\n" % diffs[ii])


def export_tiles_coverage_int(filename, tts, cum_probs, cum_areas):
with open(filename, "w") as fid:
for ii in range(len(tts)):
Expand Down
47 changes: 22 additions & 25 deletions gwemopt/io/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,10 @@ def export_schedule_xml(xmlfile, map_struct, coverage_struct, config_struct):
Field(name="priority", ucd="", unit="", dataType="int", Description=[""])
)
table_field = utilityTable(table)
table_field.blankTable(len(coverage_struct["ipix"]))
table_field.blankTable(len(coverage_struct["moc"]))

for ii in range(len(coverage_struct["ipix"])):
for ii in range(len(coverage_struct["moc"])):
data = coverage_struct["data"][ii, :]
ipix = coverage_struct["ipix"][ii]

prob = np.sum(map_struct["prob"][ipix])

ra, dec = data[0], data[1]
observ_time, exposure_time, field_id, prob, airmass = (
Expand Down Expand Up @@ -198,15 +195,6 @@ def export_schedule_xml(xmlfile, map_struct, coverage_struct, config_struct):


def summary(params, map_struct, coverage_struct, catalog_struct=None):
idx50 = len(map_struct["cumprob"]) - np.argmin(np.abs(map_struct["cumprob"] - 0.50))
idx90 = len(map_struct["cumprob"]) - np.argmin(np.abs(map_struct["cumprob"] - 0.90))

mapfile = params["outputDir"].joinpath("map.dat")
with open(mapfile, "w") as fid:
fid.write(
"%.5f %.5f\n"
% (map_struct["pixarea_deg2"] * idx50, map_struct["pixarea_deg2"] * idx90)
)

filts = list(set(coverage_struct["filters"]))
for jj, telescope in enumerate(params["telescopes"]):
Expand All @@ -225,15 +213,12 @@ def summary(params, map_struct, coverage_struct, catalog_struct=None):
totexp = 0

with open(schedulefile, "w") as fid:
for ii in range(len(coverage_struct["ipix"])):
for ii in range(len(coverage_struct["filters"])):
if not telescope == coverage_struct["telescope"][ii]:
continue

data = coverage_struct["data"][ii, :]
filt = coverage_struct["filters"][ii]
ipix = coverage_struct["ipix"][ii]

prob = np.sum(map_struct["prob"][ipix])

ra, dec = data[0], data[1]
observ_time, mag, exposure_time, field_id, prob, airmass = (
Expand Down Expand Up @@ -307,6 +292,8 @@ def summary(params, map_struct, coverage_struct, catalog_struct=None):
fid.write("\n")

summaryfile = params["outputDir"].joinpath("summary.dat")
cummoc = None

with open(summaryfile, "w") as fid:
gpstime = params["gpstime"]
event_mjd = Time(gpstime, format="gps", scale="utc").mjd
Expand All @@ -322,26 +309,36 @@ def summary(params, map_struct, coverage_struct, catalog_struct=None):
if params["tilesType"] == "galaxy":
galaxies = np.empty((0, 2))

for ii in range(len(coverage_struct["ipix"])):
for ii in range(len(coverage_struct["filters"])):
data = coverage_struct["data"][ii, :]
filt = coverage_struct["filters"][ii]
ipix = coverage_struct["ipix"][ii]
moc = coverage_struct["moc"][ii]

prob = np.sum(map_struct["prob"][ipix])
ra, dec = data[0], data[1]
observ_time, mag, exposure_time, field_id, prob, airmass = (
data[2],
data[3],
data[4],
data[5],
data[6],
data[7],
)

if data[2] > event_mjd + tt:
continue

ipixs = np.append(ipixs, ipix)
ipixs = np.unique(ipixs).astype(int)
cum_prob = np.sum(map_struct["prob"][ipixs])
if cummoc is None:
cummoc = moc
else:
cummoc = cummoc + moc
cum_prob = 0 ## FIXME

if params["tilesType"] == "galaxy":
galaxies = np.append(galaxies, coverage_struct["galaxies"][ii])
galaxies = np.unique(galaxies).astype(int)
cum_prob = np.sum(catalog_struct[params["galaxy_grade"]][galaxies])

cum_area = len(ipixs) * map_struct["pixarea_deg2"]
cum_area = 0 ## FIXME
mjds.append(data[2])
mjds_floor.append(int(np.floor(data[2])))

Expand Down
Loading

0 comments on commit bbd534b

Please sign in to comment.