def mask(self, image, nan_to_num=True, layers=None, in_global_mask=False):
self.set_mask(layers)<EOL>image = self.get_image(image, output='<STR_LIT>')<EOL>if in_global_mask:<EOL><INDENT>masked_data = image[self.global_mask]<EOL>masked_data[~self.get_mask(in_global_mask=True)] = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>masked_data = image[self.current_mask]<EOL><DEDENT>if nan_to_num:<EOL><INDENT>masked_data = np.nan_to_num(masked_data)<EOL><DEDENT>return masked_data<EOL>
Vectorize an image and mask out all invalid voxels.

        Args:
            images: The image to vectorize and mask. Input can be any object
                handled by get_image().
            layers: Which mask layers to use (specified as int, string, or
                list of ints and strings). When None, applies the conjunction
                of all layers.
            nan_to_num: boolean indicating whether to convert NaNs to 0.
            in_global_mask: Whether to return the resulting masked vector in
                the globally masked space (i.e., n_voxels =
                len(self.global_mask)). If False (default), returns in the full
                image space (i.e., n_voxels = len(self.volume)).
        Returns:
          A 1D NumPy array of in-mask voxels.