Skip to content

Commit 1d27a6e

Browse files
committed
Add automated skyproj map making if desired.
1 parent 7cf55a4 commit 1d27a6e

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

decasu/decasu_hpix_mapper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def main():
2828
required=False, help='Keep intermediate files')
2929
parser.add_argument('-q', '--query', required=False,
3030
help='Additional query string; will replace lsst_db_additional_selection config.')
31+
parser.add_argument('-m', '--make_map_images', action='store_true', required=False,
32+
help='Automatically make skyproj map images?')
3133

3234
args = parser.parse_args()
3335

@@ -55,4 +57,5 @@ def main():
5557
else:
5658
mapper = MultiHealpixMapper(config, args.outputpath, ncores=args.ncores)
5759
mapper(args.infile, bands=bands, pixels=pixels,
58-
clear_intermediate_files=not args.keep_intermediate_files)
60+
clear_intermediate_files=not args.keep_intermediate_files,
61+
make_map_images=args.make_map_images)

decasu/healpix_consolidator.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,45 @@ class HealpixConsolidator:
1313
clear_intermediate_files : `bool`
1414
Clear input files when done?
1515
"""
16-
def __init__(self, config, clear_intermediate_files):
16+
def __init__(self, config, clear_intermediate_files, make_map_images=False):
1717
self.config = config
1818
self.clear_intermediate_files = clear_intermediate_files
19+
self.make_map_images = make_map_images
1920

20-
def __call__(self, fname, mapfiles):
21+
def __call__(self, fname, mapfiles, descr):
2122
"""
2223
Consolidate a list of mapfiles, and delete input mapfiles
2324
if clear_intermediate_files is True.
2425
2526
Parameters
2627
----------
2728
fname : `str`
28-
Output filename
29+
Output filename
2930
mapfiles : `list`
30-
Input list of files
31+
Input list of files
32+
descr : `str`
33+
Description string.
3134
"""
3235
print("Consolidating %d maps into %s" % (len(mapfiles), fname))
3336
healsparse.cat_healsparse_files(mapfiles, fname)
3437

38+
if self.make_map_images:
39+
from matplotlib.backends.backend_agg import FigureCanvasAgg
40+
from matplotlib.figure import Figure
41+
import skyproj
42+
43+
m = healsparse.HealSparseMap.read(fname)
44+
45+
fig = Figure(figsize=(10, 6))
46+
FigureCanvasAgg(fig)
47+
ax = fig.add_subplot(111)
48+
49+
sp = skyproj.McBrydeSkyproj(ax=ax)
50+
sp.draw_hspmap(m, zoom=True)
51+
sp.draw_colorbar(label=descr)
52+
skyprojfile = fname.replace(".hsp", "_skyproj.png")
53+
fig.savefig(skyprojfile)
54+
3555
if self.clear_intermediate_files:
3656
for f in mapfiles:
3757
os.unlink(f)

decasu/multi_healpix_mapper.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@ def __init__(self, config, outputpath, ncores=1):
3535
if not os.path.isdir(outputpath):
3636
raise RuntimeError("Outputpath %s does not exist." % (outputpath))
3737

38-
def __call__(self, infile, bands=[], pixels=[], clear_intermediate_files=True):
38+
def __call__(self, infile, bands=[], pixels=[], clear_intermediate_files=True, make_map_images=False):
3939
"""
4040
Compute maps for a combination of bands/pixels
4141
4242
Parameters
4343
----------
4444
infile : `str`
45-
Name of input file with wcs and map information
45+
Name of input file with wcs and map information
4646
bands : `list`, optional
47-
List of bands to run. If blank, run all.
47+
List of bands to run. If blank, run all.
4848
pixels : `list`, optional
49-
List of pixels to run (nside=`config.nside_run`).
50-
If blank, run all.
49+
List of pixels to run (nside=`config.nside_run`).
50+
If blank, run all.
5151
clear_intermediate_files : `bool`, optional
52-
Clear intermediate files when done?
52+
Clear intermediate files when done?
53+
make_map_images : `bool`, optional
54+
Make map images?
5355
"""
5456
# First build the wcs's
5557
print('Reading input table...')
@@ -125,6 +127,7 @@ def __call__(self, infile, bands=[], pixels=[], clear_intermediate_files=True):
125127
print('Consolidating maps...')
126128
fname_list = []
127129
mapfiles_list = []
130+
descr_list = []
128131
for map_type in self.config.map_types.keys():
129132
for operation in self.config.map_types[map_type]:
130133
op_code = op_str_to_code(operation)
@@ -147,10 +150,15 @@ def __call__(self, infile, bands=[], pixels=[], clear_intermediate_files=True):
147150
fname_template)))
148151
fname_list.append(fname)
149152
mapfiles_list.append(mapfiles)
153+
descr_list.append(f'{band}_{map_type}_{operation}')
150154

151-
hpix_consolidator = HealpixConsolidator(self.config, clear_intermediate_files)
155+
hpix_consolidator = HealpixConsolidator(
156+
self.config,
157+
clear_intermediate_files,
158+
make_map_images=make_map_images,
159+
)
152160

153-
values = zip(fname_list, mapfiles_list)
161+
values = zip(fname_list, mapfiles_list, descr_list)
154162

155163
t = time.time()
156164
mp_ctx = multiprocessing.get_context("fork")

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ fitsio>=1.0.5
66
esutil>=0.6.5
77
LSSTDESC.Coord
88
pyyaml>=5.0
9+
skyproj
10+
matplotlib

tests/decasu_test_base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def check_expected_maps_hpix(self, expected_dict, nside, hpix, band, check_amp=F
220220

221221
return mod_times
222222

223-
def check_expected_maps_consolidated(self, expected_dict, band, time_bin=-1):
223+
def check_expected_maps_consolidated(self, expected_dict, band, time_bin=-1, images=False):
224224
"""
225225
Check for expected consolidated maps, ranges, types.
226226
@@ -232,6 +232,8 @@ def check_expected_maps_consolidated(self, expected_dict, band, time_bin=-1):
232232
Band name
233233
time_bin : `int`, optional
234234
Bin of time to be processing.
235+
images : `bool`, optional
236+
Check for images?
235237
"""
236238
if time_bin < 0:
237239
outbase = 'testing'
@@ -263,4 +265,9 @@ def check_expected_maps_consolidated(self, expected_dict, band, time_bin=-1):
263265
self.assertLess(np.max(m[valid_pixels]),
264266
expected_dict[em][1])
265267

268+
if images:
269+
image_name = os.path.join(self.test_dir, '%s_%s_%s_skyproj.png'
270+
% (outbase, band, em))
271+
self.assertTrue(os.path.isfile(image_name))
272+
266273
return mod_times

tests/test_hpix_lsst.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def test_hpix_lsst(self):
3939

4040
mapper = decasu.MultiHealpixMapper(config, self.test_dir, ncores=1)
4141
mapper(dbfile, bands=[band],
42-
clear_intermediate_files=False)
42+
clear_intermediate_files=False,
43+
make_map_images=True)
4344

4445
# Look at 549
4546
expected_dict = OrderedDict()
@@ -60,7 +61,7 @@ def test_hpix_lsst(self):
6061
expected_dict['exptime_sum'] = [29.0, 61.0, 'float64']
6162
expected_dict['nexp_sum'] = [0, 3, 'int32']
6263

63-
self.check_expected_maps_consolidated(expected_dict, 'r', time_bin=0)
64+
self.check_expected_maps_consolidated(expected_dict, 'r', time_bin=0, images=True)
6465

6566

6667
if __name__ == '__main__':

0 commit comments

Comments
 (0)