From 60b8936dca1eb66a9c958a7f0ada06b0e81eda7b Mon Sep 17 00:00:00 2001 From: adrien-laposta Date: Tue, 19 Dec 2023 06:28:50 -0800 Subject: [PATCH] create html file in source sub --- .../python/planck/check_src_subtraction.py | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/project/data_analysis/python/planck/check_src_subtraction.py b/project/data_analysis/python/planck/check_src_subtraction.py index d6def457..e13538b0 100644 --- a/project/data_analysis/python/planck/check_src_subtraction.py +++ b/project/data_analysis/python/planck/check_src_subtraction.py @@ -4,8 +4,10 @@ of the residual map (i.e. the source subtracted map) """ from pspy import so_map, pspy_utils, so_map -import sys +import numpy as np import pandas as pd +import os +import pspipe from pspipe_utils import log from pspy import so_mpi @@ -36,7 +38,7 @@ n = len(ra_list) log.info(f"Display {n} sources with 150 GHz flux >= {flux_cut:.1f} mJy and SNR >= {snr_cut:.1f}") -release = "npipe" +release = "legacy" map_dir = "planck_projected" if release == "legacy": map_root = "HFI_SkyMap_2048_R3.01_halfmission-{}_f{}_map.fits" @@ -75,9 +77,56 @@ sub.plot(file_name=f"{out_dir}/{release}_f{freq}_{split}_{task:03d}", color_range=[250, 100, 100], - ticks_spacing_car=0.3 + ticks_spacing_car=0.6 ) sub_srcfree.plot(file_name=f"{out_dir}/{release}_srcfree_f{freq}_{split}_{task:03d}", color_range=[250, 100, 100], - ticks_spacing_car=0.3 - ) \ No newline at end of file + ticks_spacing_car=0.6 + ) + + +# Generate HTML file for visualization +ids_src = np.arange(n) +multistep_path = os.path.join(os.path.dirname(pspipe.__file__), "js") +os.system(f"cp {multistep_path}/multistep2.js {out_dir}/") + +maps = [f"{freq}_{split}" for freq in map_freqs for split in map_splits] + +filename = f"{out_dir}/{release}_sources.html" +g = open(filename, mode='w') +g.write('\n') +g.write('\n') +g.write(f' Source subtraction for Planck {release} \n') +g.write(f'\n') +g.write(' \n') +g.write(' \n') +g.write(' \n') +g.write(' \n') +g.write(' \n') +g.write(f'

Source subtraction for Planck {release}

') +g.write('

This webpage display the 100 brightest sources at 150 GHz, with a flux higher than 150mJy detected with a SNR > 5.

\n') +g.write('

You can switch between sources (c/v), between the map and source free map (j/k) and between the maps (a/z).

\n') +g.write('
\n') +for src_id in ids_src: + + + g.write('
\n') + for type in ["", "_srcfree"]: + + prefix = f"{release}{type}" + g.write('
\n') + for map_name in maps: + + freq, split = map_name.split("_") + file_name = f"{prefix}_f{freq}_{split}_{src_id:03d}_T.png" + g.write(f'

{freq} GHz split {split} - {prefix} [Source no {src_id:03d}]

\n') + g.write(' \n') + g.write('

\n') + + g.write('
\n') +g.write('
\n') +g.write(' \n') +g.write(' \n') +g.close() + +