def Dgrade(nside_in, nside_out): """Keras layer performing a downgrade of input maps Parameters ---------- nside_in : integer Nside parameter for the input maps. Must be a valid healpix Nside value nside_out: integer Nside parameter for the output maps. Must be a valid healpix Nside value """ file_in = os.path.join( os.path.dirname(__file__), "..", "ancillary_files", "dgrade_from{}_to{}.npy".format(nside_in, nside_out), ) try: pixel_indices = np.load(file_in) except: pixel_indices = nnh.dgrade(nside_in, nside_out) def f(x): y = OrderMap(pixel_indices)(x) pool_size = int((nside_in / nside_out)**2.0) y = tf.keras.layers.AveragePooling1D(pool_size=pool_size)(y) return y return f
def Pooling(nside_in, nside_out, layer1D, *args, **kwargs): """Keras layer performing a downgrade+custom pooling of input maps Args: * nside_in (integer): ``NSIDE`` parameter for the input maps. * nside_out (integer): ``NSIDE`` parameter for the output maps. * layer1D (layer object): a 1-D layer operation, like :code:`keras.layers.MaxPooling1D` * args (any): Positional arguments to be passed to :code:`layer1D` * kwargs: keyword arguments to be passed to :code:`layer1D`. The keyword :code:`pool_size` should not be included, as it is handled automatically. """ file_in = os.path.join( os.path.dirname(__file__), "..", "ancillary_files", "dgrade_from{}_to{}.npy".format(nside_in, nside_out), ) try: pixel_indices = np.load(file_in) except: pixel_indices = nnh.dgrade(nside_in, nside_out) def f(x): y = OrderMap(pixel_indices)(x) pool_size = int((nside_in / nside_out)**2.0) kwargs["pool_size"] = pool_size y = layer1D(*args, **kwargs)(y) return y return f
def DegradeAndConvNeighbours(nside_in, nside_out, filters, use_bias=False, trainable=True): """Keras layer performing a downgrading and convolution of input maps. Args: * nside_in (integer): ``NSIDE`` parameter for the input maps. * nside_out (integer): ``NSIDE`` parameter for the output maps. * filters (integer): Number of filters to use in the convolution * use_bias (bool): Whether the layer uses a bias vector or not. Default is ``False``. * trainable (bool): Wheter this is a trainable layer or not. Default is ``True``. """ file_in = os.path.join( os.path.dirname(__file__), "..", "ancillary_files", "dgrade_from{}_to{}.npy".format(nside_in, nside_out), ) try: pixel_indices = np.load(file_in) except: pixel_indices = nnh.dgrade(nside_in, nside_out) def f(x): y = OrderMap(pixel_indices)(x) kernel_size = int((nside_in / nside_out)**2.0) y = Conv1D( filters, kernel_size=kernel_size, strides=kernel_size, use_bias=use_bias, trainable=trainable, kernel_initializer="random_uniform", )(y) return y return f