|
15 | 15 | "InjectMaps", |
16 | 16 | "ReplicateMaps", |
17 | 17 | "CoaddMaps", |
| 18 | + "RebinMaps", |
18 | 19 | "ReprojectMaps", |
19 | 20 | "coadd_map_files", |
20 | 21 | ] |
@@ -835,6 +836,49 @@ def coadd_map_files( |
835 | 836 | return coadder.coadd_frame |
836 | 837 |
|
837 | 838 |
|
| 839 | +@core.indexmod |
| 840 | +def RebinMaps(frame, scale=1, weighted=True, norm=False): |
| 841 | + """ |
| 842 | + Rebin any maps in the input frame into larger pixels by summing scale-x-scale |
| 843 | + blocks of pixels together. Map dimensions must be a multiple of the rebinning |
| 844 | + scale. |
| 845 | +
|
| 846 | + Arguments |
| 847 | + --------- |
| 848 | + scale : int |
| 849 | + Rebinning scale factor, such that scale-x-scale blocks of pixels are summed |
| 850 | + into larger pixels. Must divide evenly into all map pixel dimensions. |
| 851 | + weighted : bool |
| 852 | + If True (default), ensure that maps have had weights applied before |
| 853 | + rebinning. Otherwise, rebin maps without checking the weights. |
| 854 | + norm : bool |
| 855 | + If False (default), sum all of the sub-pixels into each larger output pixel. |
| 856 | + If True, normalize the output pixel by the number of sub-pixels each |
| 857 | + encloses. Only applies to Stokes parameters T/Q/U, not weights or hits. |
| 858 | + """ |
| 859 | + if scale <= 1: |
| 860 | + return |
| 861 | + |
| 862 | + if weighted: |
| 863 | + ApplyWeights(frame) |
| 864 | + |
| 865 | + for k in ["T", "Q", "U", "Wunpol", "Wpol", "H"]: |
| 866 | + if k in frame: |
| 867 | + m = frame.pop(k) |
| 868 | + if k in "TQU": |
| 869 | + frame[k] = m.rebin(scale, norm=norm) |
| 870 | + elif k == "H": |
| 871 | + frame[k] = m.rebin(scale, norm=False) |
| 872 | + else: |
| 873 | + if weighted and norm: |
| 874 | + core.log_warn( |
| 875 | + "Rebinning weighted frames with norm=True may result " |
| 876 | + "in inconsistent maps and weights", |
| 877 | + unit="RebinMaps", |
| 878 | + ) |
| 879 | + frame[k] = m.rebin(scale) |
| 880 | + |
| 881 | + |
838 | 882 | @core.indexmod |
839 | 883 | class ReprojectMaps(object): |
840 | 884 | """ |
|
0 commit comments