Imaginary part of expression involving complete elliptic integral Suppose an expression
$$
\tag 1 G(z) = \frac{1}{\sqrt{(z-1)^{3}(z+3)}}\text{K}\left( \sqrt{\frac{16z}{(z+3)(z-1)^{3}}}\right),
$$
where
$$
K(x) \equiv \int \limits_{0}^{\frac{\pi}{2}}\frac{dy}{\sqrt{1 - x^2\sin^{2}(y)}}
$$
is complete elliptic integral of the first kind.
My task: I need to compute the imaginary part of $(1)$ for $0<z<3$. 
What's the main challenge of the task? The region $0<z<3$ is divided on two sub-regions $0<z<1$ and $1<z<3$ because of a singularity in the factor $\frac{1}{\sqrt{(z-1)^{3}}}$, and it seems that I need to compute imaginary parts for these regions separately. Let's discuss behavior of the imaginary part of $(1)$ for these two regions.
In the region $0 < z < 1$ the prefactor in the front of $K(...)$ is purely imaginary, while $K(...)$ is real. In the region $1 < z < 3$ the prefactor is real, but the elliptic integral contains imaginary part, since its argument is real and larger than one. Therefore, naively the functional form of imaginary parts in two regions $0<z<1$ and $1<z<3$ must be different (at least I think so): they come from different functions.  
It's possible to compute the imaginary parts in two regions analytically by using functional identities involving elliptic integrals. Surprisingly it turns out (after using one of identities) that functional dependences of imaginary parts in different regions are the same:
$$
\text{Im }G(z) = -\frac{1}{2}\frac{1}{2\sqrt{z} + \frac{1}{2}\sqrt{(3-z)(z+1)^3}}\text{K}\left( \frac{2\left(z(3-z)(z+1)^{3}\right)^{\frac{1}{4}}}{2\sqrt{z}+\frac{1}{2}\sqrt{(3-z)(z+1)^{3}}}\right), \quad 0 < z < 3
$$
I can show this step-by-step, by evaluating the imaginary parts in the region $0<z<1$ and in the region $1<z<3$ and applying definite elliptic integrals functional identity to obtained relations. 
But is it possible to calculate the imaginary part directly from $(1)$, without intermediate step of dividing the region $0<z<3$ onto $0<z<1$ and $1<z<3$?
An edit
One can think about the problem in another way. Precisely, after few manipulations the expression $(1)$ can be converted to the form
$$
G(z) = \frac{i}{\sqrt{(3-z)(z+1)^{3}}}\text{K}\left( \sqrt{\frac{16z}{(3-z)(z+1)^{3}}}\right)
$$
Now the prefactor is always purely imaginary, and 
$$
\text{Im }G(z) =  \frac{1}{\sqrt{(3-z)(z+1)^{3}}}\text{Re }\text{K}\left( \sqrt{\frac{16z}{(3-z)(z+1)^{3}}}\right)
$$
How to derive $\text{Re}[\text{K}(...)]$ without dividing the region onto two regions? It's obvious that the imaginary part is continuous function of $(...)$ except the singularity $z = 1$, where $(...) = 1$.
 A: All elliptic integrals in this answer follow Mathematica/mpmath convention; their last argument is $m$, the parameter.
In your original expression
$$G(z)=\frac1{\sqrt{(z-1)^3(z+3)}}K\left(\frac{16z}{(z-1)^3(z+3)}\right)$$
the parameter of $K$ is in $(1,\infty)$ for $z\in(0,3)$. Now apply the reciprocal modulus transformation and decompose the resulting incomplete integral of the form $F\left(\sin^{-1}\frac1{\sqrt m},m\right)$ into real and imaginary parts (Byrd and Friedman 162.02, DLMF 19.7.3):
$$K(m)=\frac1{\sqrt m}\left(K\left(\frac1m\right)-iK\left(1-\frac1m\right)\right)$$
This gives
$$\operatorname{Im}(G(z))=-\frac1{4\sqrt z}\operatorname{Re}\left(K\left(\frac{(3-z)(z+1)^3}{16z}\right)\right)$$
The parameter in this new expression is in $(0,\infty)$ for $z\in(0,3)$. Apply an ascending Gauss transformation (B&F 164.02):
$$\operatorname{Re}(K(m))=\frac{1+h}2K(1-h^2),\quad h=\frac{1-\sqrt m}{1+\sqrt m}$$
For the specific $m$ in the expression for $\operatorname{Im}(G(z))$ above
$$h^*=\frac{1-\sqrt{\frac{(3-z)(z+1)^3}{16z}}}{1+\sqrt{\frac{(3-z)(z+1)^3}{16z}}}=
\frac{4\sqrt z-\sqrt{(3-z)(z+1)^3}}{4\sqrt z+\sqrt{(3-z)(z+1)^3}}$$
Returning to the actual problem at hand, we get
$$\operatorname{Im}(G(z))=-\frac{1+h^*}{8\sqrt z}K(1-(h^*)^2)$$
with the parameter now in $(0,1)$, so we now have a valid and fully real expression for $\operatorname{Im}(G(z))$. Simplifying gives the result you found:
$$\boxed{\operatorname{Im}(G(z))=-\frac1{4\sqrt z+\sqrt{(3-z)(z+1)^3}}K\left(\frac{16\sqrt{z(3-z)(z+1)^3}}{(4\sqrt z+\sqrt{(3-z)(z+1)^3})^2}\right)}$$
At no point in this answer did I split the domain of $z$ into parts.
