TITLE: A Rokhlin lemma with a prescribed height function?
QUESTION [15 upvotes]: Let $T$ be a ergodic automorphism of a non-atomic Lebesgue probability space $(X, \mathcal{A}, \mu)$.
The celebrated Rokhlin tower lemma says that given an integer $n>0$ and $0 < \epsilon < 1$, there exists $B \in \mathcal{A}$ such that the sets $B$, $TB$, ..., $T^{n-1} B$ are disjoint and their union (called a tower of height $n$) has measure $>1-\epsilon$.
Here's an equivalent formulation of the conclusion of Rokhlin's lemma: the return time function $R_B \colon B \to \{1,2,\dots, \infty\}$ satisfies:

$R_B \ge n$;
$\int_B (R_B - n) d\mu < \epsilon$.

(To see that the integral is the measure of the complement of the Rokhlin tower, thing about the Kakutani skyscraper with base $B$.)

My question is: Can we replace the constant $n$ above by a function $N$? 
More precisely: Given an arbitrary measurable function $N : X \to \{1,2,\dots\}$, and $0 < \epsilon < 1$, is there a set $B \in\mathcal{A}$ such that:

$R_B(x) \ge N(x)$ for all $x\in B$;
$\int_B (R_B - N) d\mu < \epsilon$ ?


Note that the integral is the measure of the error set $\{T^i(x) \mid x\in B, N(x) \le i < R_B(x) \}$.
If $N$ is assumed to be bounded then the answer is yes. Here's the proof, an easy adaptation of the usual proof of the Rokhlin lemma. Suppose $N$ is bounded by a constant $n$. Take $m > n/\epsilon$. Since the set of periodic points has zero measure, we can take a positive measure set $E$ such that the return time $R_E$ is $\ge m$. Consider the Kakutani skyscraper with base $E$, which by ergodicity covers a full measure set. For each point $x_0$ in the base $E$, color blue each of the points $x_0$, $x_1:=T^{N(x_0)}(x_0)$ (which is at height $N(x_0)$), $x_2:=T^{N(x_1)}(x_1)$ (which is at height $N(x_0)+N(x_1)$), etc., stopping when the height becomes $\ge r_E(x_0) - n$ (i.e., when we first reach the floors of the skyscraper $n$-away from the top). Let $B$ be the set of blue points, which is measurable and satisfies $R_B \ge N$. The error set is contained in the region within height $n$ from the top of the skyscraper, and therefore has measure $<n/m<\epsilon$, as we wanted to show.
I haven't checked, but a similar construction seems to work if the function $N$ is integrable over $X$.

So the main question is: Is this generalized Rokhlin lemma true for non-integrable $N$, or is there a counter-example?

Rem.: Since $R_B$ is always integrable (Kac's lemma), the restriction of $N$ to $B$ should be integrable.

REPLY [5 votes]: So I've changed my mind! I think the answer is "yes". Suppose $X$ and $N$ are given. Let $\epsilon>0$ be given and let $M$ be such that $\mu({x:N(x)>M})<\epsilon$. Now build a Rokhlin tower with height $M/\epsilon$ and error set of size at most $\epsilon/M$. Let $A$ denote the base of the tower (so that $\mu(A)<\epsilon/M$). For each $x\in A$, let $n_1(x)$ be the least integer (up to $M/\epsilon-M$) such that $N(T^{n_1(x)}x)\le M$ (or $n_1(x)=\infty$ if there is no such finite integer). Then let $n_2(x)$ be the least integer greater than $n_1(x)+N(T^{n_1(x)}x)$ (up to $M/\epsilon-M$) such that $N(T^{n_2(x)})\le M$ etc. For each $x\in A$, let there be $k(x)\ge 0$ finite values of $n_j(x)$. 
Let $B_x=\{T^{n_j(x)}x:j\le k(x)\}$ and let $B=\bigcup_{x\in A} B_x$. This is a measurable set. I claim it has the properties that you want. 
Let $F=\{x\colon N(x)>M\}\cup E\cup \bigcup_{j=1}^{M-1}T^{-j}(E\cup A)$. This set has measure at most $4\epsilon$. Now for $x\in B$, notice that
$$
R_B(x)-N(x)\le 
\sum_{j=0}^{R_B(x)-1}\mathbf 1_F(T^jx).
$$
In particular, it follows that 
$$
\int_B (R_B-N)\,d\mu\le \mu(F)<4\epsilon,
$$
as required.
COMMENT: It was pointed out to me by Jairo Bochi, the poser of the question, that it is not necessary to use Rokhlin's lemma in the proof: it suffices to take $A$ to be any set such that $\mu(A\cap T^{-j}A)=0$ for all $1\le j<M/\epsilon$. In an ergodic system, one can find such a set by taking $A_0$ to be any set of measure less than $\epsilon/M$ and defining $A=A_0\setminus\bigcup_{j=1}^{M/\epsilon}T^{-j}A_0$ (this set is not of measure 0, as otherwise every point of $A_0$ would return to $A_0$ within $M/\epsilon$ steps, so that the measure of $A_0$ would exceed $\epsilon/M$ by ergodicity.)