Skip to content
Snippets Groups Projects
Commit 502e8ba5 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Add in option to use the pickle file

parent c7c8c5f8
No related branches found
No related tags found
1 merge request!478Rework of the skymap utilities
Pipeline #60300 failed
...@@ -188,7 +188,7 @@ class CompactBinaryCoalesenceResult(CoreResult): ...@@ -188,7 +188,7 @@ class CompactBinaryCoalesenceResult(CoreResult):
self, maxpts=None, trials=5, jobs=1, enable_multiresolution=True, self, maxpts=None, trials=5, jobs=1, enable_multiresolution=True,
objid=None, instruments=None, geo=False, dpi=600, objid=None, instruments=None, geo=False, dpi=600,
transparent=False, colorbar=False, contour=[50, 90], transparent=False, colorbar=False, contour=[50, 90],
annotate=True, cmap='cylon'): annotate=True, cmap='cylon', load_pickle=False):
""" Generate a fits file and sky map from a result """ Generate a fits file and sky map from a result
Code adapted from ligo.skymap.tool.ligo_skymap_from_samples and Code adapted from ligo.skymap.tool.ligo_skymap_from_samples and
...@@ -223,6 +223,9 @@ class CompactBinaryCoalesenceResult(CoreResult): ...@@ -223,6 +223,9 @@ class CompactBinaryCoalesenceResult(CoreResult):
Annotate image with details Annotate image with details
cmap: str cmap: str
Name of the colormap to use Name of the colormap to use
load_pickle: bool, str
If true, load the cached pickle file (default name), or the
pickle-file give as a path.
""" """
try: try:
...@@ -242,23 +245,34 @@ class CompactBinaryCoalesenceResult(CoreResult): ...@@ -242,23 +245,34 @@ class CompactBinaryCoalesenceResult(CoreResult):
logger.info('Taking random subsample of chain') logger.info('Taking random subsample of chain')
data = data.sample(maxpts) data = data.sample(maxpts)
try: default_obj_filename = os.path.join(self.outdir, '{}_skypost.obj'.format(self.label))
pts = data[['ra', 'dec', 'luminosity_distance']].values
cls = kde.Clustered2Plus1DSkyKDE if load_pickle is False:
distance = True try:
except KeyError: pts = data[['ra', 'dec', 'luminosity_distance']].values
logger.warning("The results file does not contain luminosity_distance") cls = kde.Clustered2Plus1DSkyKDE
pts = data[['ra', 'dec']].values distance = True
cls = kde.Clustered2DSkyKDE except KeyError:
distance = False logger.warning("The results file does not contain luminosity_distance")
pts = data[['ra', 'dec']].values
logger.info('Initialising skymap class') cls = kde.Clustered2DSkyKDE
skypost = cls(pts, trials=trials, multiprocess=jobs) distance = False
obj_filename = os.path.join(self.outdir, '{}_skypost.obj'.format(self.label)) logger.info('Initialising skymap class')
logger.info('Pickling skymap to {}'.format(obj_filename)) skypost = cls(pts, trials=trials, multiprocess=jobs)
with open(obj_filename, 'wb') as out: logger.info('Pickling skymap to {}'.format(default_obj_filename))
pickle.dump(skypost, out) with open(default_obj_filename, 'wb') as out:
pickle.dump(skypost, out)
else:
if isinstance(load_pickle, str):
obj_filename = load_pickle
else:
obj_filename = default_obj_filename
logger.info('Reading from pickle {}'.format(obj_filename))
with open(obj_filename, 'rb') as file:
skypost = pickle.load(file)
skypost.multiprocess = jobs
logger.info('Making skymap') logger.info('Making skymap')
hpmap = skypost.as_healpix() hpmap = skypost.as_healpix()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment