How can we find a expression for the following sum $$ S=\sum_{n\in\mathbb{Z}} \left ( q^{(8n+1)^2}-q^{(8n+3)^2}\right ) $$ where $q=e^{-\pi{K^\prime(k)}/{K(k)}}$ and $K(x)=\int_{0}^{1} \frac{1}{\sqrt{1-t^2}\sqrt{1-x^2t^2} } \text{d}t,K^\prime(x)=K\left(\sqrt{1-x^2}\right)$ is the complete elliptic integral of the first kind?
Motivation.
We observe that
$$
\sum_{n\in\mathbb{Z}}q^{\left ( 4n+1\right )^2 }=\frac12\vartheta_2(q^4),\\
\sum_{n\in\mathbb{Z}}\left ( 4n+1\right ) q^{\left ( 4n+1\right )^2 }=\eta(4ix)^3.
$$
I have some good reasons to generalize those two formulae. In fact,
$$
S=\frac{1}{2} \sum_{n\in\mathbb{Z}/\{0\}}\left ( \frac{8}{n} \right )
q^{n^2}
$$
and $\left(\frac{m}{n}\right)$ is the Kronecker symbol.
I am very thankful for all your help and advice.
Your function is
$$\sum_{n\in \Bbb{Z}}\frac1{32} \sum_{k=0}^{15}(e^{-2i\pi k/16}-e^{-2i\pi k9/16}) e^{2i\pi kn^2/16} q^{n^2}=\frac1{32} \sum_{k=0}^{15}(e^{-2i\pi k/16}-e^{-2i\pi k9/16})\theta(e^{2i\pi k/16} q)$$