Given a modular form $f$ of weight $k$ for a congruence subgroup $\Gamma$, and a modular function $t$ for $\Gamma$ with $t(i\infty)=0$, we can form a function $F$ such that $F(t(z))=f(z)$ (at least locally), and we know that this $F$ must now satisfy a linear ordinary differential equation $$P_{k+1}(T)F^{(k+1)} + P_{k}(T)F^{(k)} + ... + P_{0}(T)F = 0$$

Where $F^{(i)}$ is the i-th derivative, and the $P_i$ are algebraic functions of $T$, and are rational functions of $T$ if $t$ is a Hauptmodul for $X(\Gamma)$.

My question is the following:

given a modular form $f$, what are necessary and sufficient conditions for the existence of a modular function $t$ such that the $P_i(T)$ are rational functions?

For example, the easiest sufficient condition is that $X(\Gamma)$ has genus 0, by letting $t$ be a Hauptmodul. But, this is not necessary, as the next condition will show.

Another sufficient condition is that $f$ is a rational weight 2 eigenform. I can show this using Shimura's construction* of an associated elliptic curve, and a computation of a logarithm for the formal group in some coordinates (*any choice in the isogeny class will work).

Trying to generalise, I have thought of the following: if $f$ is associated to a motive $h^i(V)$ of a variety $V$, with Artin-Mazur formal group $\Phi^i(V)$ of dimension 1, then we can construct formal group law a-la Stienstra style, and get a logarithm using the coefficients of powers of certain polynomials. Since the dimension is 1, there will actually be a single polynomial that we take powers of, making the coefficients have a rather simple recurrence relation, forcing our $P_i$ to be rational.

Now, some people, without naming names, believe that rational eigenforms should correspond to the middle cohomology of certain rational Calabi-Yai varieties. I'm not entirely certain that such people exist. Probably. If this is true, then this should answer my question for rational eigenforms.

Putting non-eigenforms aside, since I'm not interested as much in them, we are left with non-rational eigenforms. We can try to perform the same Stienstra construction, but this time we get that the galois orbit of $f$ is associated to a "formal group law" of a motive with dimension greater than one. This will make for an interesting recurrence for the vector of the galois orbit, but not necessarily for each form individually, as the isomorphism of formal groups laws (between Stienstra's and those with the modular forms as logarithm) will scramble them together. I realise this last paragraph might be difficult to understand, for the wording is clumsy, and the mathematical notions are even worse. If you're really interested in this, I'd be happy to elaborate.