Let $k$ be a field of characteristic $p>0$. Let $D_m$ be a $BT_m$ over $k$ (i.e., an $m$-truncated Barsotti--Tate group over $k$). Let $S$ be abreak $k$-scheme and let $X$ be a $BT_m$ over $S$. Let $S_{D_m}(X)$ be the subscheme of $S$ which describes the locus where $X$ is locally for the fppf topology isomorphic to $D_m$. If $pge 5$, we show that $S_{D_m}(X)$ is pure in $S$ i.e., the immersion $S_{D_m}(X) hookrightarrow S$ is affine. For $pin{2,3}$, we prove purity if $D_m$ satisfies a certain property depending only on its $p$-torsion $D_m[p]$. For $pge 5$, we apply the developed techniques to show that all level $m$ stratifications associated to Shimura varieties of Hodge type are pure.