Given a modular form $f$ of weight $k$ for a congruence subgroup $\Gamma$, and a modular function $t$ 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$ as above 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 a pro-representable 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 a certain polynomial. This makes the logarithm satisfy a differential equation with rational functions as coefficients. Since the dimension is 1, the isomorphism back to "modular coordinates" will be a single modular function $t$, and this answers the question positively.

This was the original motivation for the question - a positive answer is weaker, but maybe suggests the existence of associated varieties to 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) might scramble them together. Maybe not, and this solves might the question. 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.