diff --git a/calibration/python/bolopropertiesutils.py b/calibration/python/bolopropertiesutils.py index c82dba60..bfac8546 100644 --- a/calibration/python/bolopropertiesutils.py +++ b/calibration/python/bolopropertiesutils.py @@ -15,7 +15,7 @@ class SplitByProperty(object): G3TimestreamMap, G3MapInt, etc. ''' def __init__(self, input='CalTimestreams', property=None, property_list=None, - output_root=None, bpm='BolometerProperties'): + output_root=None, bpm='BolometerProperties', drop_empty=False): ''' Split the input map given by input into several output maps named output_root + key (e.g. CalTimestreams + str(property)) with @@ -40,6 +40,8 @@ def __init__(self, input='CalTimestreams', property=None, property_list=None, bpm : str The key name of the BolometerPropertiesMap from which to extract the requested `property` for splitting the input map. + drop_empty : bool + If True, drop output maps that don't contain any bolometers. ''' if property is None: core.log_fatal("Property is a required argument") @@ -54,6 +56,7 @@ def __init__(self, input='CalTimestreams', property=None, property_list=None, self.props = None self.bpmkey = bpm self.bpm = None + self.drop_empty = drop_empty @staticmethod def converter(prop): @@ -94,8 +97,10 @@ def __call__(self, frame): continue out[prop][b] = inmap[b] - for prop in out.keys(): - frame['%s%s' % (self.output_root, prop)] = out[prop] + for prop, outmap in out.items(): + if not len(outmap.keys()) and self.drop_empty: + continue + frame['%s%s' % (self.output_root, prop)] = outmap @core.indexmod @@ -108,7 +113,7 @@ class SplitByBand(SplitByProperty): G3TimestreamMap, G3MapInt, etc. ''' def __init__(self, input='CalTimestreams', output_root=None, - bands=None, bpm='BolometerProperties'): + bands=None, bpm='BolometerProperties', drop_empty=False): ''' Split the input map given by input into several output maps named output_root + band + GHz (e.g. CalTimestreams150GHz with @@ -120,7 +125,7 @@ def __init__(self, input='CalTimestreams', output_root=None, ''' super(SplitByBand, self).__init__( input=input, output_root=output_root, property_list=bands, - bpm=bpm, property='band') + bpm=bpm, property='band', drop_empty=drop_empty) @staticmethod def converter(band): @@ -137,10 +142,10 @@ def converter(band): class SplitTimestreamsByBand(SplitByBand): def __init__(self, input='CalTimestreams', output_root=None, - bands=None, bpm='BolometerProperties'): + bands=None, bpm='BolometerProperties', drop_empty=False): core.log_warn("SplitTimestreamsByBand is deprecated, use SplitByBand instead") super(SplitTimestreamsByBand, self).__init__( - input=input, output_root=output_root, bands=bands, bpm=bpm) + input=input, output_root=output_root, bands=bands, bpm=bpm, drop_empty=drop_empty) @core.indexmod @@ -153,7 +158,7 @@ class SplitByWafer(SplitByProperty): G3TimestreamMap, G3MapInt, etc. ''' def __init__(self, input='CalTimestreams', output_root=None, - wafers=None, bpm='BolometerProperties'): + wafers=None, bpm='BolometerProperties', drop_empty=False): ''' Split the input map given by input into several output maps named output_root + wafer (e.g. CalTimestreamsW172 with @@ -165,7 +170,7 @@ def __init__(self, input='CalTimestreams', output_root=None, ''' super(SplitByWafer, self).__init__( input=input, output_root=output_root, property_list=wafers, - bpm=bpm, property='wafer_id') + bpm=bpm, property='wafer_id', drop_empty=drop_empty) @staticmethod def converter(wafer): @@ -184,7 +189,7 @@ class SplitByPixelType(SplitByProperty): G3TimestreamMap, G3MapInt, etc. ''' def __init__(self, input='CalTimestreams', output_root=None, - types=None, bpm='BolometerProperties'): + types=None, bpm='BolometerProperties', drop_empty=False): ''' Split the input map given by input into several output maps named output_root + wafer (e.g. CalTimestreamsW172 with @@ -196,7 +201,7 @@ def __init__(self, input='CalTimestreams', output_root=None, ''' super(SplitByPixelType, self).__init__( input=input, output_root=output_root, property_list=types, - bpm=bpm, property='pixel_type') + bpm=bpm, property='pixel_type', drop_empty=drop_empty) @staticmethod def converter(pixel_type): diff --git a/maps/include/maps/maputils.h b/maps/include/maps/maputils.h deleted file mode 100644 index c8935ca8..00000000 --- a/maps/include/maps/maputils.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _MAPS_MAPUTILS_H -#define _MAPS_MAPUTILS_H - -#include - -#include - -#include -#include - -// Divide out map weights from the sky maps -void RemoveWeightsT(G3SkyMapPtr T, G3SkyMapWeightsConstPtr W, bool zero_nans = false); -void RemoveWeights(G3SkyMapPtr T, G3SkyMapPtr Q, G3SkyMapPtr U, G3SkyMapWeightsConstPtr W, - bool zero_nans = false); - -// Apply map weights to sky maps -void ApplyWeightsT(G3SkyMapPtr T, G3SkyMapWeightsConstPtr W); -void ApplyWeights(G3SkyMapPtr T, G3SkyMapPtr Q, G3SkyMapPtr U, G3SkyMapWeightsConstPtr W); - -// Return maps of RA and Dec coordinates for each pixel in the input map -boost::python::tuple GetRaDecMap(G3SkyMapConstPtr m); - -// Return a mask that is one for all pixels in the input map that are within the -// given ra and dec rectangular bounds, and zero otherwise -G3SkyMapMaskPtr GetRaDecMask(G3SkyMapConstPtr m, double ra_left, double ra_right, - double dec_bottom, double dec_top); - -// Reproject the input map onto the output map grid, optionally -// oversampling the output pixels by the rebin factor, and/or sampling the input map -// with interpolation -void ReprojMap(G3SkyMapConstPtr in_map, G3SkyMapPtr out_map, int rebin=1, bool interp=false); - -// Flatten or unflatten Q and U polarization maps using the polarization gradient across the map. -// The h parameter controls the pixel width over which a gradient is computed. -void FlattenPol(FlatSkyMapPtr Q, FlatSkyMapPtr U, G3SkyMapWeightsPtr W=NULL, double h=0.001, bool invert=false); - -// Compute map moments up to fourth order (mean, var, skewness, kurtosis) of the input map, -// optionally excluding any pixels that are zero in the input mask, or zero/nan/inf in the input map -std::vector GetMapMoments(G3SkyMapConstPtr m, G3SkyMapMaskConstPtr mask=NULL, int order=2, - bool ignore_zeros=false, bool ignore_nans=false, bool ignore_infs=false); - -// Compute the histogram of the input map pixels, grouping the values into bins -// defined by the array of bin edges, and optionally excluding any pixels that are -// zero in the input mask, or zero/nan/inf in the input map -std::vector GetMapHist(G3SkyMapConstPtr m, const std::vector &bin_edges, - G3SkyMapMaskConstPtr mask=NULL, bool ignore_zeros=false, bool ignore_nans=false, - bool ignore_infs=false); - -// Convolve the input flat sky map with a filter kernel -FlatSkyMapPtr ConvolveMap(FlatSkyMapConstPtr map, FlatSkyMapConstPtr kernel); - -// Point source masking -G3SkyMapMaskPtr -MakePointSourceMask(G3SkyMapConstPtr map, const std::vector & ra, - const std::vector & dec, const std::vector & radius); - -// Python bindings -void maputils_pybindings(void); - -#endif //_MAPS_MAPUTILS_H diff --git a/maps/src/maputils.cxx b/maps/src/maputils.cxx index 32d7abb0..72c9dbdd 100644 --- a/maps/src/maputils.cxx +++ b/maps/src/maputils.cxx @@ -8,7 +8,8 @@ #include #include -#include +#include +#include #include #include @@ -19,11 +20,6 @@ using namespace G3Units; -void RemoveWeightsT(G3SkyMapPtr T, G3SkyMapWeightsConstPtr W, bool zero_nans) -{ - RemoveWeights(T, NULL, NULL, W, zero_nans); -} - void RemoveWeights(G3SkyMapPtr T, G3SkyMapPtr Q, G3SkyMapPtr U, G3SkyMapWeightsConstPtr W, bool zero_nans) { @@ -100,9 +96,9 @@ void RemoveWeights(G3SkyMapPtr T, G3SkyMapPtr Q, G3SkyMapPtr U, G3SkyMapWeightsC } } -void ApplyWeightsT(G3SkyMapPtr T, G3SkyMapWeightsConstPtr W) +void RemoveWeightsT(G3SkyMapPtr T, G3SkyMapWeightsConstPtr W, bool zero_nans) { - ApplyWeights(T, NULL, NULL, W); + RemoveWeights(T, NULL, NULL, W, zero_nans); } void ApplyWeights(G3SkyMapPtr T, G3SkyMapPtr Q, G3SkyMapPtr U, G3SkyMapWeightsConstPtr W) @@ -139,6 +135,11 @@ void ApplyWeights(G3SkyMapPtr T, G3SkyMapPtr Q, G3SkyMapPtr U, G3SkyMapWeightsCo } } +void ApplyWeightsT(G3SkyMapPtr T, G3SkyMapWeightsConstPtr W) +{ + ApplyWeights(T, NULL, NULL, W); +} + boost::python::tuple GetRaDecMap(G3SkyMapConstPtr m) { @@ -525,8 +526,9 @@ MakePointSourceMask(G3SkyMapConstPtr map, const std::vector & ra, } -namespace bp = boost::python; -void maputils_pybindings(void){ +PYBINDINGS("maps") +{ + namespace bp = boost::python; bp::def("remove_weights_t", RemoveWeightsT, (bp::arg("T"), bp::arg("W"), bp::arg("zero_nans")=false), "Remove weights from unpolarized maps. If zero_nans is true, empty pixels " diff --git a/maps/src/python.cxx b/maps/src/python.cxx index 1c13e842..f2c7db77 100644 --- a/maps/src/python.cxx +++ b/maps/src/python.cxx @@ -1,5 +1,4 @@ #include -#include namespace bp = boost::python; @@ -7,7 +6,6 @@ BOOST_PYTHON_MODULE(maps) { bp::import("spt3g.core"); bp::docstring_options docopts(true, true, false); - maputils_pybindings(); G3ModuleRegistrator::CallRegistrarsFor("maps"); }