# Deep Transfer Learning on Satellite Imagery Improves Air Quality Estimates
in Developing Nations

Nishant Yadav,1,2 Meytar Sorek-Hamer,2,3∗ Michael Von Pohle,2,3
Ata Akbari Asanjan,2,3 Adwait Sahasrabhojanee,2,3 Esra Suel,4
Raphael Arku,5 Violet Lingenfelter,1,2 Michael Brauer,7 Majid Ezzati,4
Nikunj Oza,3 Auroop R. Ganguly1

1Sustainability and Data Sciences Laboratory, Northeastern University, Boston,
USA
2University Space Research Association (USRA), Mountain View, USA
3NASA Ames Research Center, Mountain View, USA
4Imperial College London, London, UK
5University of Massachusetts, Amherst, USA
7University of British Columbia, Vancouver, Canada

∗To whom correspondence should be addressed; E-mail<EMAIL_ADDRESS>
> Urban air pollution is a public health challenge in low- and middle-income
> countries (LMICs). However, LMICs lack adequate air quality (AQ) monitoring
> infrastructure. A persistent challenge has been our inability to estimate AQ
> accurately in LMIC cities, which hinders emergency preparedness and risk
> mitigation. Deep learning-based models that map satellite imagery to AQ can
> be built for high-income countries (HICs) with adequate ground data. Here we
> demonstrate that a scalable approach that adapts deep transfer learning on
> satellite imagery for AQ can extract meaningful estimates and insights in
> LMIC cities based on spatiotemporal patterns learned in HIC cities. The
> approach is demonstrated for Accra in Ghana, Africa, with AQ patterns
> learned from two US cities, specifically Los Angeles and New York.

## One Sentence Summary

Estimating air quality in low-resourced developing cities with limited
observations is feasible with deep transfer learning.

## Introduction

Accurately estimating urban air quality (AQ) is vital for effective policy and
research. However, not all parts of the world are equally equipped with an
adequate ground monitoring network (see figure 1). Cities in low- and middle-
income countries (LMICs), such as in sub-Saharan Africa and South-East Asia,
severely lack the infrastructure required to monitor AQ (?). For instance, of
the approximately 15,000 AQ stations reporting to the World Air Quality Index
(WAQI) Project , less than 300 stations are located in Africa. Only 7 out of
54 countries in Africa have real-time AQ monitoring stations (?). In contrast,
satellite imagery at increasingly high resolution (HR) is now available
globally from governmental and commercial resources. There is, thus, an
emerging argument that satellite imagery combined with the latest advances in
machine learning (ML) methods - particularly computer vision - may offer a
promising alternative approach when traditional methods prove inadequate (?,
?, ?). Computer vision is a subfield of ML that enables computers to derive
meaningful information from digital images and other visual inputs.

Traditional methods for developing city-wide AQ maps can be categorized into
physical and empirical approaches. Physical models, such as CMAQ (?), can
provide detailed insights into the physical-chemical processes of the
diffusion and transformation of multiple pollutants and present the direct
linkage between pollutant emission and air pollution. However, these chemical
transport models are coarse-grained (4-12 km spatial resolution) and dependent
on a priori knowledge with regard to emissions, which may not be available.
Moreover, the underlying physics driving the emissions may not be known
understood. On the other hand, empirical models demonstrate the relationships
between dependent and multiple independent variables based on historical data.
One of the most widely used regression methods in environmental health studies
is land-use regression (LUR) modeling (?, ?). LUR models solve multiple
regression equations that map sample locations and different environmental
variables. It requires gathering locally measured data on traffic, weather,
land use, and population density, among others. The resulting models can
predict AQ levels at unmeasured locations with a high spatial resolution
($\sim$ 100 m). However, data collection for LUR models is time-consuming and
may even be prohibitive if requisite data is unavailable. Thus, LUR models are
available for only a handful of urban regions and developed on an annual
basis.

Although satellite-based data-products (e.g., Aerosol Optical Depth) have been
used to calculate AQ indicators in the past (?, ?), in this work, we posit a
different approach to inferring air quality from satellite data. We
hypothesize that with the availability of sub-meter resolution satellite
imagery, next-generation data-driven AQ models might infer pollution
information directly from the images using computer vision techniques. The
visual features in HR satellite imagery (e.g., parks, roads, industries)
indicative of air quality can be distinguished and learned. For example, a
satellite image containing a dense road network may indicate a high
concentration of air pollutants such as NO2; an image comprising a green cover
may suggest the opposite. The latest advances in ML, especially Deep Learning
(DL) (?, ?), make such a task particularly amenable. Convolutional neural
networks (CNN) can learn to identify such features from large training data
and have shown promising results in this regard (?, ?). Within remote sensing,
too, DL methods have been applied to problems such as land use and land cover
classification (?), predicting economic indicators from nightlight imagery
(?), and crop estimation (?).

## DeepAQ Model - Unsupervised Transfer Learning

Although DL models, which are data-intensive by design, perform well on
regions and problems where large training data is available, generalization to
newer, often data-poor areas remains challenging (?). It limits the direct
application of ML/DL techniques to satellite imagery over regions - usually
high-income and developed - with abundant ground-level data for model training
and validation. We overcome this challenge using a transfer learning approach
(?). In ML, transfer learning is the idea that knowledge gained while solving
one problem can be applied to a different but related problem. Depending on
how much (labeled) training data is available over the actual area of
interest, transfer methods can be divided into supervised or unsupervised (see
Supplementary Material for more details).

In this work, we propose an unsupervised transfer learning approach (DeepAQ
hereafter) and demonstrate it for the city of Accra in Ghana, Africa. The
DeepAQ model performs two steps: first, a CNN-based model is trained to
estimate air quality at 200 $m$ resolution (in terms of annual average NO2
levels) over cities with sufficient training data. Los Angeles and New York
City (NYC) are chosen as two candidate cities. The two cities are chosen
because of 1) availability of labeled data, and, more importantly, 2) a wide
distribution of $NO_{2}$ levels and associated patterns. In the second step,
the DeepAQ model is transferred to Accra in a completely unsupervised setting
(see Methodology). Our team collected AQ data in Accra for model validation
across 130 stations for a year (?). As an initial proof-of-concept, we also
demonstrate the performance of our DeepAQ model by transferring a trained
model from LA to NYC, where sufficient labeled data is available for both
cities for model validation.

Satellite Imagery: Over 300 raw satellite images from MAXAR WorldView2 (WV2)
are used in this study to train and validate the DeepAQ model. WV2 was
launched in 2009 as part of the MAXAR satellite constellation. It is a sun-
synchronous satellite located 770 km from Earth. Images are produced in eight
spectral bands in the VIS–NIR range (400 nm–1040 319 nm) with a spatial
resolution of 2 $m$ (rescaled to $\sim$ 2.5 $m$ to better match the target
data resolution). A single raw image roughly spans an area of 400 $km^{2}$. In
this work, only the visible (RGB) bands are used. From each image, multiple 80
x 80 patches are extracted, such that each patch covers a 200 $m$ x 200 $m$
region on the region to match the target data resolution. In total, approx.
40,000, 16,000, 28,000 image patches are generated for LA, NYC and Accra
respectively based on the availability of satellite imagery.

Target Data: The mean annual $NO_{2}$ target data ($\mu g/m^{3}$) at 200 $m$
resolution is available from (2010) LUR models for LA and NYC (?). LUR models
solve multiple regression equations that map sample locations and various
environmental variables. It requires gathering locally measured data on
traffic, weather, land use, and population density, among others. LUR data is
only available for select few cities as LUR models require substantial time
and effort. They commonly serve as inputs for environmental policy and
research as it is not possible to obtain station data at such high resolution.

For Accra, a team of researchers associated with this work collected $NO_{2}$
ground level data across 135 different locations for a year (?). Although in
DeepAQ, no labeled data from Accra is used, the 135 datapoints collected serve
to validate the predictions over Accra.

Road Network: Locations near (major) roads have higher $NO_{2}$ levels because
of the strong correlation with vehicular emission. Based on this
understanding, the distance of each target data point from a major road is
calculated and fed as an input to the DeepAQ model. The road network
information for the three cities is obtained from OpenStreetMap, which is a
provider of freely available global geographic database.

Data Pre-Processing: Raw satellite data need to be processed before use. In
this work, radiometric correction, followed by filtering for cloud cover was
performed on the satellite images. Finally, the images were normalized between
the range of $(-1,1)$ before patch extraction.

The problem is formulated as a regression task. The goal is to predict the
mean annual $NO_{2}$ level ($\mu g/m^{3}$) over an urban region given the
corresponding satellite imagery. At each time, the DeepAQ model takes as input
two image patches - one from the source city (labeled) and another from the
target city (unlabeled). During training, the model learns to generate domain-
invariant features for the target city image patches (see section 2.3 for
details) while learning to predict $NO_{2}$ levels for the source city. At the
inference, the trained model is used to predict the $NO_{2}$ levels over the
target city using the domain-invariant feature embeddings learned.

We perform two experiments. The first proof-of-concept demonstrates the
utility of the DeepAQ model by considering only LA and NYC as the source and
target cities, respectively. The goal is to the validate how the model
performs by evaluating against the large labeled data available for NYC (not
used during training). Once the model efficacy is established, the actual
analysis is performing using both LA and NYC as (labeled) source cities and
Accra as the (unlabeled) target city. A standard ResNet-34 (?) based
convolutional neural network (CNN) is used as a baseline with no domain
adaptation. Two metrics are used to evaluate to performances - standard
deviation normalized root mean squared error ($\sigma-rmse$) and coefficient
of determination ($R^{2}$).

## Results

The main results are presented in figures 2 and 3. In terms of point metrics,
the DeepAQ model substantially outperforms the baseline CNN (Table 1). In the
case of NYC, we observe the baseline model fails to capture the spatial
distribution of $NO_{2}$ values, especially over the Manhattan region with
high $NO_{2}$ levels (figure 2). The DeepAQ models not only captures the
regions of high $NO_{2}$ values much better, but is also able to localize
distinct regions near roads. However, DeepAQ, too, misses out on areas with
extremely high $NO_{2}$ values. A possible explanation is that such high
values ($\geq$ 100 $\mu g/m^{3}$) are not observed in LA and the model is
bounded by the maximum observed value. The DeepAQ model achieves a
substantially lower $\sigma-nrmse$ (38%) and roughly 3 times higher $R^{2}$
score compared to the baseline (supplementary figure S4). It shows the DeepAQ
model is able to successfully transfer features from the source city to the
target city. We further analyze this aspect during model interpretation.

City | NYC | Accra
---|---|---
Method | $\sigma-nrmse$ | $R^{2}$ | $\sigma-nrmse$ | $R^{2}$
DeepAQ | 0.525 | 0.642 | 0.665 | 0.492
Baseline | 0.844 | 0.243 | 0.981 | 0.275
Table 1: Results. DeepAQ compares favorably to the baseline model which is a
simple CNN (resnet-34) without domain adaptation. $\sigma-rmse$ refers to root
mean squared error normalized by the standard deviation $\sigma$.

For Accra, the baseline CNN trained on LA and NYC (without transfer learning)
resulted in an $R^{2}$ score of 0.0. In other words, it fails to capture any
distribution over the region. In comparison, DeepAQ results in an $R^{2}$
score of 0.49 and the predicted distribution overlaps with the actual
distribution except for regions of extremely high $NO_{2}$ values
(supplementary figures S5 and S6).

To summarize, the DeepAQ model succeeds in making reasonably well prediction
over unseen regions. However, extremely high and low values are not predicted
well. It may be possible to overcome this limitation by using a diverse set of
source cities with different AQ distributions. In that case, the model may
learn to associate a broader range of values with the urban features
identified.

### Model Interpretation

The goal of the DeepAQ model is to learn high-level features that are
indicative of the $NO_{2}$ levels, for example, roads, freeways, parks. To
interpret the model output, we use a pixel attribution method called Grad-CAM
(?). The method outputs a relevance score for the input image pixels that
maximally contributed to the DeepAQ output against the input image. We select
two sets of images corresponding to high and low levels of $NO_{2}$ and
generate the pixel-level saliency maps using Grad-CAM for each image (figure
4). We observe that the model is able to identify semantically meaningful
features such as freeways in case of high $NO_{2}$, i.e., the ’freeway’ pixels
contribute more to the DeepAQ output. Similarly in areas of low $NO_{2}$, the
model is able to identify green areas such as forests and parks. The ability
to learn semantically meaningful, and potentially generalizable, features is
critical for domain adaptation.

## Conclusion

Traditional methods for high-resolution AQ mapping are built manually using
locally available data. It is difficult to scale them beyond the regions they
are built for. Low- and middle-income countries (LMIC) that include some of
the most polluted cities lack the resources for direct AQ monitoring.
Increasingly fine satellite imagery combined with deep learning methods offer
a scalable, automated approach to AQ monitoring making them particularly
appealing for LMICs lacking ground data. This work proposes a new approach
that entails developing data-driven AQ models using sub-meter satellite
imagery that can be transferred to LMIC cities using patterns and insights
learned from data-rich cities in the developed parts of the world. Such high-
resolution AQ models / maps can facilitate informed decision-making in
environmental health policy and research at local scale in the fastest growing
urban regions (in LMICs). However, we must not lose sight of the importance of
installing high-quality AQ sensors in LMIC cities as the validity of input-
output relationship in deep learning models is critically dependent on
accurate and reliable estimates of the pollutants of interest.

## References

  * 1. R. V. Martin, et al., Atmospheric Environment: X 3, 100040 (2019).
  * 2. S. suffocation in Africa: Air pollution is a growing menace, UNICEF (2019).
  * 3. X. X. Zhu, et al., IEEE Geoscience and Remote Sensing Magazine 5, 8 (2017).
  * 4. Q. Yuan, et al., Remote Sensing of Environment 241, 111716 (2020).
  * 5. E. Rolf, et al., Nature communications 12, 1 (2021).
  * 6. O. US EPA, CMAQ: The Community Multiscale Air Quality Modeling System (2016).
  * 7. M. Lee, et al., Science of the Total Environment 592, 306 (2017).
  * 8. L. Jin, et al., Environmental research 177, 108597 (2019).
  * 9. A. Van Donkelaar, R. V. Martin, R. J. Park, Journal of Geophysical Research: Atmospheres 111 (2006).
  * 10. A. C. Just, et al., Environmental science & technology 49, 8576 (2015).
  * 11. Y. Guo, et al., Neurocomputing 187, 27 (2016).
  * 12. Y. LeCun, Y. Bengio, G. Hinton, nature 521, 436 (2015).
  * 13. J. Gu, et al., Pattern Recognition 77, 354 (2018).
  * 14. W. H. L. Pinaya, S. Vieira, R. Garcia-Dias, A. Mechelli, Machine learning (Elsevier, 2020), pp. 173–191.
  * 15. C. Zhang, et al., Remote sensing of environment 221, 173 (2019).
  * 16. N. Jean, et al., Science 353, 790 (2016).
  * 17. A. Koirala, K. B. Walsh, Z. Wang, C. McCarthy, Computers and electronics in agriculture 162, 219 (2019).
  * 18. B. Neyshabur, S. Bhojanapalli, D. Mcallester, N. Srebro, Advances in Neural Information Processing Systems, I. Guyon, et al., eds. (Curran Associates, Inc., 2017), vol. 30.
  * 19. F. Zhuang, et al., Proceedings of the IEEE 109, 43 (2020).
  * 20. S. N. Clark, et al., BMJ open 10, e035798 (2020).
  * 21. M. J. Bechle, D. B. Millet, J. D. Marshall, Environmental science & technology 49, 12297 (2015).
  * 22. K. He, X. Zhang, S. Ren, J. Sun, Deep residual learning for image recognition. corr abs/1512.03385 (2015) (2015).
  * 23. R. R. Selvaraju, et al., Proceedings of the IEEE International Conference on Computer Vision (ICCV) (2017).
  * 24. S. J. Pan, Q. Yang, IEEE Transactions on knowledge and data engineering 22, 1345 (2010).
  * 25. Y. Ganin, V. Lempitsky, International conference on machine learning (PMLR, 2015), pp. 1180–1189.

## Acknowledgments

This work was supported by the Pathways to Equitable Healthy Cities grant from
the Wellcome Trust [209376/Z/17/Z], NASA ARC ARIA Award, USRA IRAD Award, NSF
CRISP 2.0 Type 2 INQUIRE Award (1735505) and the NSF INTERN Award. We thank
the Pathways to Equitable Healthy Cities team and Wellcome Trust, NASA, USRA,
and NSF for the financial and professional support, the NEX group at NASA ARC
for supporting our work, Prof. Michael Jerrett (UCLA) for the data and Dr.
Jason Su (UC Berkeley) who helped develop the land use regression model in LA,
as well as Maxar for providing access to their satellite imagery.

## Author Contributions

Conceptualization: NY, MSH, MVP, AAA, AS, ARG
Methodology: NY, MSH, MVP, AAA
Investigation: NY, MSH, MVP, AAA
Visualization: NY, VL, ES
Funding acquisition: NY, MSH, NO, ARG
Supervision: MSH, NO, ARG
Data Acquisition: MSH, RA, MB, ME
Writing – original draft: NY, MSH, ARG
Writing – review and editing: NY, MSH, MVP, AAA, AS, ES, RA, VL, MB, ME, NO,
ARG

Figure 1: Skewed distribution of air quality (AQ) monitoring stations across
the globe. The figure show 681 cities reporting AQ data to the World Air
Quality Index (WAQI) Project through public, private and citizen efforts. Out
of approximately 15,000 stations, less than 300 are located in Africa. The
third most polluted city in Africa - Accra, Ghana - has only one monitoring
station contributing to WAQI compared to 20+ stations for New York City, as an
example. Figure 2: Mean annual $NO_{2}$ levels ($\mu g/m^{3}$) over New York
City (NYC) as estimated by DeepAQ, and compared with the baseline Resnet-34
model (trained only on Los Angeles (LA) data with no transfer learning). In
this case, LA acts as the source city (domain). Compared to the baseline, the
DeepAQ model is able to better identify regions of high $NO_{2}$ levels, such
as in the Manhattan area of NYC (upper left). The road network is superimposed
on top (red lines) for reference. See supplementary figure S3 for the case
when no road network information is provided to the model. Figure 3: Mean
annual $NO_{2}$ levels ($\mu g/m^{3}$) over Accra, Ghana, as predicted by
DeepAQ.The square dots point to the fixed monitoring stations measuring
$NO_{2}$ levels across Accra. The DeepAQ model is able to capture the spatial
distribution of $NO_{2}$ over Accra with higher levels observed in the city
center and near the highways. See supplementary figure S2 for the case when no
road network information is provided to the model. Figure 4: Interpreting the
DeepAQ model. Using the Grad-CAM method, regions of the input that are
considered important by the model for prediction are visualized. The top row
in (A) and (B) contains four satellite image patches from Los Angeles with
high and low $NO_{2}$ levels ($\mu g/m^{3}$), respectively. The bottom row
contains the pixel-importance maps generated using Grad-CAM. Pixels in yellow
refer to the pixels that maximally contributed to the DeepAQ output against
that image patch. The DeepAQ models is able to learn meaningful high-level
features such as freeways and green cover and relate them to different levels
of $NO_{2}$.

## Supplementary Materials

## Methodology

### Transfer Learning

We define transfer learning using the framework in (?). A domain
$\mathcal{D}=\\{\mathcal{X},\mathcal{P(X}\\}$ consists of a feature space
$\mathcal{X}$ and a marginal probability distribution $\mathcal{P(X)}$. Given
a domain, a task $\mathcal{T}=\\{\mathcal{Y},f(\cdot)\\}$ consists of a label
space $\mathcal{Y}$ and a predictive function $f(\cdot)$ which models
$\mathcal{P}(y|x)$ for $y\in\mathcal{Y}$ and $x\in\mathcal{X}$. Given a source
domain $\mathcal{D_{S}}$ and learning task $\mathcal{T_{S}}$, and a target
domain $\mathcal{D_{T}}$ and learning task $\mathcal{T_{T}}$ , transfer
learning aims to improve the learning of the target predictive function
$f_{T}(\cdot)$ in $\mathcal{T_{T}}$ using the knowledge from $\mathcal{D_{S}}$
and $\mathcal{T_{S}}$.

### Domain Adaptation

Based on whether
$\mathcal{D_{S}}\neq\mathcal{D_{T}},\mathcal{T_{S}}\neq\mathcal{T_{T}}$ or
both, transfer learning can be categorized into different sub-types. A
comprehensive overview of transfer learning approaches is presented in (?). A
common use case arises from the phenomenon known as dataset shift or domain
shift, where the marginal probability distribution of the feature space
$\mathcal{X}$ in source domain $\mathcal{P_{S}(X)}$ is different from the
target domain, $\mathcal{P_{T}(X)}$. As a result, the models trained on the
feature representations from one domain do not generalize well on novel
(target) datasets (domains). The typical solution is to use a pre-trained
model and fine-tune using task-specific datasets. However, it might be
prohibitively difficult to obtain enough labeled data to properly fine-tune
the large number of parameters employed by DL models. Unsupervised Domain
adaptation (UDA) is the problem for overcoming such a domain shift and
facilitate improved generalization of DL models to novel ’unlabeled’ datasets.
The more successful UDA methods attempt to learn feature representations that
are domain-invariant. In other words, the DA model maps the source and target
features into a common feature space to ensure that the model cannot
distinguish between the training and test domain data samples. By doing so,
the model is expected to perform (generalize) better on feature embeddings,
and ultimate the downstream task, of the target domain.

### Proposed Model

The proposed UDA model (DeepAQ) is based on an adversarial training approach,
first proposed by Ganin et al (?). The model (see Fig. S1) comprises of three
components – a convolutional feature encoder (G), a fully connected classifier
or regression decoder (D) and an auxiliary domain classifier (critic, C). In
the first step, the encoder takes the labeled source and unlabeled target
domain images as inputs and generates feature embeddings. The critic C then
takes the feature embeddings generated by G and attempts to classify them as
coming either from source or target-domain. The encoder G is then trained with
an additional adversarial loss (with gradient reversal) that maximizes C’s
mistakes and thus aligns features across domains. Further, during training
only the labeled source images are fed through to the decoder D which predict
the mean annual $NO_{2}$ level over that satellite image patch using a
Euclidean loss. At inference, the domain-invariant features for the target
domain learned by the feature encoder G are passed through decoder D for
prediction the mean annual $NO_{2}$ levels for the target domain image
patches. We adapt the original approach in Ganin et al. by adding a strong
regularization in the encoder (G), which substantially improved the
performance (over 10% for synthetic datasets such as MNIST). Empirically, we
observed that the regularization allows for learning more robust and
potentially more generalizable features that are equally discriminative at the
same time.

### Baseline

In DeepAQ, a pre-trained ResNet-34 model is used as the feature encoder
component (G). For the baseline model, the critic (C) responsible for
transferring or adapting the features across domains is not considered. Simply
put, all components except C, remain the same in the baseline model. The
baseline, thus, evaluates the model performance in the absence of domain
adaptation.

Figure S1: Schematic Architecture for DeepAQ - Unsupervised Domain Adaptation.
The three main components include: a ResNet-34 feature encoder; an auxiliary
domain classifier and a fully-connected decoder. Figure S2: Mean annual
$NO_{2}$ levels ($\mu g/m^{3}$) over Accra, Ghana, as predicted by DeepAQ. In
this case, no road network information is provided to the model. The DeepAQ
model is still able to capture the spatial distribution of $NO_{2}$ levels
compared to the case where road network information is explicitly provided to
the model. Figure S3: Mean annual $NO_{2}$ levels ($\mu g/m^{3}$) over New
York City (NYC) as predicted by DeepAQ, and compared with the baseline
Resnet-34 model (no domain adaptation). In this case, no road network
information is provided to the model. The DeepAQ model is able to better
identify regions of high $NO_{2}$ levels, such as in the Manhattan area of NYC
(upper left); however, the performance is poorer compared to the case where
road network information is provided explicitly. A possible explanation could
be that $NO_{2}$ levels are highly correlated with proximity to roads in a
large city like NYC where vehicular emission might be the predominant source
of $NO_{2}$. Figure S4: DeepAQ Predicted vs Target mean annual $NO_{2}$ ($\mu
g/m^{3}$) distribution over New York City. Figure S5: DeepAQ Predicted vs
Target mean annual $NO_{2}$ ($\mu g/m^{3}$) distribution over Accra, Ghana.
Figure S6: DeepAQ Predicted vs Targeted mean annual $NO_{2}$ ($\mu g/m^{3}$)
distribution over Accra, Ghana when no road network information is provided to
the DeepAQ model. For direct comparison, see figure S5.


[1]organization=Physik-Institut, University of Zurich,
addressline=Winterthurerstrasse 190, postcode=8057, city=Zurich,
country=Switzerland [2]Dipartimento di Fisica, Università di Roma “La
Sapienza”, Piazzale Aldo Moro 2, I-00185 Roma, Italy [3]INFN, Sezione di Roma,
Piazzale Aldo Moro 2, I-00185 Roma, Italy

# PycWB: A User-friendly, Modular, and Python-based Framework for
Gravitational Wave Unmodelled Search

Yumeng Xu  Shubhanshu Tiwari  Marco Drago

###### Abstract

Unmodelled searches and reconstruction is a critical aspect of gravitational
wave data analysis, requiring sophisticated software tools for robust data
analysis. This paper introduces PycWB, a user-friendly and modular Python-
based framework developed to enhance such analyses based on the widely used
unmodelled search and reconstruction algorithm Coherent Wave Burst (cWB). The
main features include a transition from C++ scripts to YAML format for user-
defined parameters, improved modularity, and a shift from complex class-
encapsulated algorithms to compartmentalized modules. The PycWB architecture
facilitates efficient dependency management, better error-checking, and the
use of parallel computation for performance enhancement. Moreover, the use of
Python harnesses its rich library of packages, facilitating post-production
analysis and visualization. The PycWB framework is designed to improve the
user experience and accelerate the development of unmodelled gravitational
wave analysis.

## Metadata

Current code version | 0.17.1
---|---
Permanent link to code / repository | git.ligo.org/yumeng.xu/pycwb
Legal Code License | GNU General Public License
Code versioning system used | git
Software languages, tools, | Python, C++, Javascript, HTML
and services used
Compilation requirements | gcc, ROOT, wheel, setuptools
and dependencies
Link to developer | yumeng.xu.docs.ligo.org/pycwb
documentation / manual
Support email for questions |<EMAIL_ADDRESS>
Table 1: Code metadata

##  1 Motivation and Significance

The choice of programming language significantly influences the design and
usage of scientific software. The benefits of having a Python-based software
or Python interface for critical software in gravitational waves (GW) data
analysis are outlined in [1, 2]. Python, as of now, is on its way to becoming
the default programming language in GW data analysis. This statement can be
corroborated by the emergence of Python-based gravitational waveform models
like pySEOBNR[2], gwsurrogate[3], inference software like BILBY[4], PyCBC-
inference[5]. And the success and wide usage of GW data analysis algorithms
like PyCBC [6].

Despite these advancements, there remain several opportunities where Python-
based software can accelerate the usage and development of GW data analysis
algorithms. One specific example is the so-called unmodelled search and
waveform reconstruction algorithms in GW data analysis. The lack of readily
available Python-based open-source software restricts the development and
usage of un-modelled algorithms, limiting it primarily to researchers
proficient in languages like C/C++ which is a low-level programming language.
Creating Python-based solutions and interfaces will enhance participation and
development in the field.

The Coherent Wave Burst (cWB) algorithm has been at the forefront of
advancements in GW astrophysics [7]. The range of applicability of cWB for GW
transient data analysis is very wide as it is an all-sky morphology-
independent algorithm i.e. it does not rely on the waveform models or the sky
direction of the source. Instead cWB relies on the coherent energy produced by
the GW signal in the network of detectors. cWB has played a major role in the
discovery of the first detection of GW signal GW150914 [8] and more recently
it has proved itself to be a crucial method to detect interesting transient GW
signals that are not well modelled like GW190521 [9, 10]. cWB is routinely
used in a variety of GW transient searches for the LIGO-Virgo-KAGRA
collaborations like IMBH searches [11], eBBH searches [12] and generic
searches for transients with short [13] and long duration [14].

While cWB offers an extensive array of functionalities and scripts, however,
it falls short in facilitating user-specific modifications not inherently
supported by the framework. Although cWB does provide plugin support, these
plugins are required to access and manipulate global variables at the specific
point of invocation. This approach demands a comprehensive understanding of
the underlying code and risks unintentional disruptions or alterations to the
variables. Moreover, the lack of clear dependencies between the modules
further complicates the task for developers aiming to make modifications as
the understanding of the interaction between different components becomes
challenging. The PycWB framework addresses these issues and offers a more
straightforward and stable environment for customization and code alteration.

This paper introduces PycWB, a modularized Python package for the cWB
algorithm. This package will enable the easier integration of the future
machine learning algorithm and new Python-based waveform models. The remainder
of this paper is structured as follows: Section 2 provides an introduction to
the structure and features of PycWB. Then, in Section 3, we present several
use cases that demonstrate the user-friendliness and efficiency of PycWB,
comparing its application with the traditional cWB. Finally, we share our
conclusions and insights on the impact and potential of our new framework in
the concluding section.

##  2 Software Description

The software framework in focus is implemented in Python and leverages the
coherent Wave Burst (cWB) software originally developed on ROOT [15]. The
description of the core cWB algorithm and the code can be found here [16, 17].
The native pyROOT interface of ROOT has immensely facilitated this Python
implementation, saving the need for rewriting the entire suite of algorithms
used for cWB. Instead, the core cWB code is integrated, specifically the WAT
module, which is included in the package and automatically compiled upon
installation using pip. The installation process is streamlined to avoid the
usually intricate cWB setup.

To install the PycWB, we provide the easiest way which is to use conda due to
its dependencies on ROOT and HEALPix[18] for cWB core code

⬇

1conda create -n pycwb "python>=3.9,<3.11"

2conda activate pycwb

3conda install -c conda-forge root=6.26.10 healpix_cxx=3.81 nds2-client
python-nds2-client lalsuite setuptools_scm cmake pkg-config

4python3 -m pip install pycwb

In its design, the software takes a modular approach. This way, the core cWB
code is divided into different modules, providing a roadmap for future
transitions, where the existing C++ codes can be replaced seamlessly with
Python modules.

Figure 1: This figure shows the structure of the PycWB. The blue blocks
represent the Python modules and the orange blocks represent the Python class.
The green blocks show the external C/C++ code embedded in PycWB, while the
yellow blocks highlight the key variables.

###  2.1 User Configurations

The PycWB framework makes it simpler for users to set their own parameters.
Instead of using C++ scripts like before, PycWB uses YAML format, a more user-
friendly way that doesn’t need C++ knowledge. Users or developers can easily
set their own parameters using a Python dictionary. This dictionary is set up
like a JSON schema, allowing flexibility in defining parameters. This system
makes sure the user inputs are correct, checks them against the types and
ranges that are already set, and provides default values when needed.
Additionally it can automatically generate guides or instructions from this
schema, keeping users updated with the software’s requirements. This new
approach makes it simpler for users to work with the software, manage their
settings, and helps in faster development.

Listing 1: cWB user parameters

⬇

1 strcpy(analysis,"2G");

2

3 nIFO = 3;

4 cfg_search = ’r’;

5 optim=false;

6

7 strcpy(ifo[0],"L1");

8 strcpy(ifo[1],"H1");

9 strcpy(ifo[2],"V1");

10 strcpy(refIFO,"L1");

11

12 strcpy(channelNamesRaw[0],"L1:GWOSC-4KHZ_R1_STRAIN");

13 strcpy(channelNamesRaw[1],"H1:GWOSC-4KHZ_R1_STRAIN");

14 strcpy(channelNamesRaw[2],"V1:GWOSC-4KHZ_R1_STRAIN");

15

16 strcpy(frFiles[0],"input/L1_frames.in");

17 strcpy(frFiles[1],"input/H1_frames.in");

18 strcpy(frFiles[2],"input/V1_frames.in");

Listing 2: PycWB user parameters

⬇

1analysis: "2G"

2cfg_search: "r"

3

4optim: False

5

6ifo: ["L1","H1","V1"]

7refIFO: "L1"

8

9channelNamesRaw: [’L1:GWOSC-4KHZ_R1_STRAIN’, ’H1:GWOSC-4KHZ_R1_STRAIN’,
’V1:GWOSC-4KHZ_R1_STRAIN’]

10frFiles: ["input/L1_frames.in", "input/H1_frames.in", "input/V1_frames.in"]

###  2.2 Modular and Classes

The original cWB framework presented a challenging structure where class-based
constructions excessively encapsulated numerous methods and key algorithms.
This approach led to dense coding, which was difficult to comprehend and
modify due to its high interdependencies and complexity. However, in the PycWB
framework, a fundamental shift towards modularity and clarity is adopted.
Essential functions are transferred to Python classes, serving as standard
data formats or interfaces between different modules. Meanwhile, key
algorithms have been detached from their original class environments and
restructured into independent modules. This revamped architecture facilitates
efficient dependency management. The necessary variables are initialized
before each function call, and functions are called as pure procedures,
thereby significantly enhancing the software’s comprehensibility, usability,
and adaptability.

(a) Part of the workflow for cWB

(b) Part of the workflow for PycWB

Figure 2: This figure shows the modular design of PycWB. On the left, the
workflow appears streamlined, but the updates on shared variables are
scattered within the modules making it resemble a black box. On the right, we
demonstrate our approach to modularization in PycWB. We have isolated each
module to ensure it only depends on the input and subsequently delivers the
output to the next steps. This architecture enhances the transparency and
flexibility of the process, allowing for easier comprehension and
customization.

###  2.3 Parallelization

The modularization in Python facilitates easy parallelization of various
processes in PycWB, using Python’s multiprocessing library. As a result,
computations across layers are expedited, bringing about a speedup of 4 to 6
times in the pixel finding and clustering stage. Reading data and data
conditioning also enjoy speed improvements, leading to an overall speedup of 2
to 3 times.

A further enhancement of performance by PycWB can be envisaged by the
integration of GPU acceleration. With the increase in the number of GW events
and data the integration of GPU acceleration will become essential for cWB
algorithm. To this end PycWB interface provides a much more straightforward
solution with Numba[19].

###  2.4 Post production processing

With Python’s wealth of packages for data processing, visualization, and
machine learning, post-production data processing is seamless. The modular
framework lets users easily select and implement the post-processing modules
they need without requiring code modifications or recompilation. For instance,
integrating the autoencoder neural network for glitch detection [20] into
PycWB is as simple as interfacing a few lines of TensorFlow[21] code with the
framework. This ensures that advanced techniques such as machine learning can
be employed efficiently and effectively without the need for extensive code
modifications.

Figure 3: A selection of python packages that can be seamlessly integrated for
post-production in PycWB

###  2.5 Web interface

Similar to cWB, PycWB also provides a web interface. But the web interface in
PycWB is structured as a separate module. This module contains HTML, CSS and
Javascript frameworks as a web app, along with simple Python functions to copy
the static webpage files to the designated output directory. As a result,
there’s no need for HTML webpage generation. This separation of the web
interface and the Python code contributes to the modularity and usability of
PycWB.

##  3 Illustrative Examples

###  3.1 Real data analysis

To validate the performance of PycWB, we conducted identical analyses on real
LIGO-Virgo events GW150914[8], GW170809[22], and GW190521 [9] using both cWB
and PycWB. For the cWB analysis, we used the cwb_gwosc command to download
data from GWOSC [23, 24] and process them.

⬇

cwb_gwosc GW=EVENT_ID IFO=V1 TAG=TSTXY all

For PycWB, we utilized the same user configuration file and data, executing
the analysis via a simple command.

⬇

pycwb_search user_parameters.yaml

Table 3 outlines the events analyzed and the speed factors for both cWB and
PycWB. The speed factor, calculated as the ratio of computation time to the
length of the data, indicates a 2-3 times overall performance boost with
PycWB. This notable increase in speed is primarily attributed to effective
parallelization made very simple to implement due to the Python interface.

Event name |  cWB speed factor |  PycWB speed factor |  relative improvement
---|---|---|---
GW150914 |  10X |  20.1X |  2 times
GW170809 |  4.76X |  12.8X |  2.7 times
GW190521 |  8.5X |  24.5X |  2.9 times
Table 2: Performance comparison: PycWB shows 2-3 times of performance
improvement due to the parallelization compared to cWB on the selected events.

In addition, we highlight key parameters of the recovered events to showcase
the consistency in accuracy between cWB and PycWB. Given that both platforms
use the same algorithms and setups, similar accuracy levels are to be
expected. Any minor deviations could potentially be attributed to differences
in data types between Python and C++. These results affirm PycWB’s
capabilities in maintaining the robustness of the algorithm while enhancing
performance.

Event name | Software | rho[0] | likelihood | start time
---|---|---|---|---
GW150914 | cWB | 16.70109 | 634.7065 | 1126259462.125
PycWB | 16.76488 | 641.5996 | 1126259462.125
GW170809 | cWB | 6.045537 | 117.5504 | 1186302519.6875
PycWB | 6.045362 | 117.5518 | 1186302519.6875
GW190521 | cWB | 10.13721 | 215.8701 | 1242442967.125
PycWB | 10.64826 | 236.0143 | 1242442967.125
Table 3: The results obtained from the PycWB analysis are consistent with
those obtained from cWB, accommodating only the differences inherent in the
data types between Python and C++.

Figure 4 presents an example of an analysis conducted on GW150914 using PycWB.
The left panel displays the time-frequency map of the likelihood of selected
pixels, providing a visual representation of how the event’s signal changes
over time and frequency. The right panel illustrates the reconstructed
waveform of the event.

(a) Likelihood map

(b) Reconstructed waveform

Figure 4: A selection of the plots from the PycWB analysis on GW150914, the
first detected GW event. These plots were created using Matplotlib, a popular
data visualization library in Python, which takes the output from the
likelihood module. In comparison with C++, Python’s Matplotlib requires
significantly less code for plotting, demonstrating the efficiency and ease of
use provided by PycWB in visualizing analysis results.

###  3.2 Batch Injection with Python script

The PycWB framework simplifies the handling of batch injections involving
large parameter sets. In cWB, injecting complex GW signals (like binary black
holes populations) is achieved with cumbersome scripts which create XML files,
in particular the LIGO Light-Weight (LIGOLW) XML format [25] for parameters.
Moreover, one needs to modify the XML table manually when dealing with keys
not predefined in the LIGOLW XML table. On the other hand, PycWB provides the
option to generate an array of parameters directly through a Python function.
This function returns a list of parameters, offering significant flexibility
and efficiency. Recently search algorithms like PyCBC etc provide HDF5
injection file support to mitigate the issues with LIGO-LW XML file formats,
these injection files can be seemlessly integrated in PycWB to have consistent
injections between pipelines.

The parameters are passed directly to the waveform generator, thus allowing
users to employ their own waveform generators with additional parameters,
circumventing the need for any code modification within PycWB. The Python
function can be constructed as demonstrated in the code snippet 3.

Listing 3: generate_parameters.py: A simple example for batch injection script

⬇

1def get_injection_parameters():

2 return [{

3 ’mass1’: 20,

4 ’mass2’: 20,

5 ’spin1z’: spin1z,

6 ’spin2z’: 0,

7 ’distance’: 200,

8 ’inclination’: 0,

9 ’polarization’: 0,

10 ’gps_time’: 1126259462.4,

11 ’coa_phase’: 0,

12 ’ra’: 0,

13 ’dec’: 0

14 } for spin1z in [0, 0.3, 0.6]]

To implement this, the parameters_from_python keyword can be used in place of
the parameters keyword in the YAML file containing user parameters. The
example shows in code snippet 4.

Listing 4: Example user parameter file for generating injection parameters
from script

⬇

1injection

2 segment # ....

3 parameters_from_python

4 file "generate_parameters.py"

5 function "get_injection_parameters"

6 approximant #...

7 generator #...

###  3.3 Injection with third-party Python waveform models

While PycWB uses PyCBC as the default for waveform generation during
injection, users may wish to utilize their own models or adopt new ones that
have yet to be implemented in PyCBC. To accommodate this, PycWB features an
option within its read_data module that allows for the integration of any
waveform generator. The only requirement is for the user to write a wrapper
function that accepts input from their injection parameters and returns the
’+’ (plus) and ’×’ (cross) polarization. This flexible approach enables
seamless integration of a diverse array of waveform models, thereby expanding
the analytical capabilities of the PycWB framework.

We demonstrated this ability by running a data injection with the cutting-edge
waveform model, pyseobnr. This model, only implemented in Python, utilizes the
effective-one-body method and numerical relativity (NR) calibration, serving
as a testament to the framework’s compatibility and flexibility.

Listing 5: Example code using the pySEOBNR waveform model for injection

⬇

1from pyseobnr.generate_waveform import GenerateWaveform

2

3def waveform_generator(mass1, mass2, spin1x, spin1y, spin1z, spin2x, spin2y,
spin2z, distance, inclination, polarization, coa_phase, f_lower, delta_t,
**kwargs):

4 parameters = {

5 ’mass1’: mass1,

6 ’mass2’: mass2,

7 ’spin1x’: spin1x,

8 ’spin1y’: spin1y,

9 ’spin1z’: spin1z,

10 ’spin2x’: spin2x,

11 ’spin2y’: spin2y,

12 ’spin2z’: spin2z,

13 ’distance’: distance,

14 ’inclination’: inclination,

15 ’polarization’: polarization,

16 ’coa_phase’: coa_phase,

17 ’f_ref’: f_lower,

18 ’f22_start’: f_lower,

19 ’deltaT’: delta_t,

20 "approximant": "SEOBNRv5HM",

21 }

22 wfm_gen = GenerateWaveform(parameters)

23 hp, hc = wfm_gen.generate_td_polarizations_conditioned_2()

24

25 return hp, hc

To integrate a third-party waveform model that’s not natively supported in
PycWB, the user only needs to write a wrapper function, as demonstrated in
code snippet 5. Then, to incorporate this into a run, the user simply adds a
generator key to the user parameter file, specifying the location and function
name, as shown in code snippet 6.

Listing 6: Example for using the waveform model wrapper in user parameter file

⬇

1injection

2 segment # ...

3 parameters_from_python # ...

4 approximant "SEOBNRv5HM"

5 generator

6 module "PATH_TO_THE_CODES"

7 function waveform_generator

##  4 Conclusions

The Coherent WaveBurst (cWB) is playing a key role in the discovery and
analysis of gravitational waves. Despite its importance, the accessibility and
user-friendliness of its interface have been a challenge, primarily due to the
complex and highly technical nature of the C++ language it was originally
written in.

In addressing this challenge, we present PycWB, a Python-based modular
adaptation of the cWB. This transformation not only makes cWB more accessible
to the scientific community but also unlocks the potential for numerous
innovations in the field. By leveraging the power and simplicity of Python,
PycWB makes complex analyses in gravitational wave research more manageable
and user-friendly. The capability to use PycWB within interactive Jupyter
Notebooks simplifies the learning process for new users, making it
significantly more approachable. Moreover, the seamless compatibility with
PyCBC and other Python-based waveform models such as pyseobnr and gwsurrogate
greatly simplifies injection studies. Data post-processing is much easier. Its
Python-based data output from each module makes data manipulation more
intuitive. Additionally, users have the flexibility to choose the specific
data they wish to save at each stage of the process.

Furthermore, the PycWB framework allows seamless integration with machine
learning libraries in Python, paving the way for more sophisticated and
automated analyses. This adaptability extends to developers, who can easily
design new modules or add GPU-accelerated capabilities with Python packages
like numba, without an in-depth understanding of the entire PycWB structure.

In conclusion, PycWB provides user-friendly, flexible, and powerful
architecture, which opens new avenues for research and discovery in the realm
of gravitational waves. The ease of use and adaptability of PycWB empowers
both experienced researchers and newcomers alike to contribute to this
exciting field of research.

##  5 Conflict of Interest

We wish to confirm that there are no known conflicts of interest associated
with this publication and there has been no significant financial support for
this work that could have influenced its outcome.

## Acknowledgements

We are grateful to Giovanni Andrea Prodi, Francesco Salemi, Sophie Bini,
Dixeena Lopez, Michael Ebersold, Edoardo Milotti and Gabriele Vedovato for
their helpful comments and encouragement throughout this project. Y. Xu is
supported by China Scholarship Council. S. Tiwari is supported by the Swiss
National Science Foundation (SNSF) Ambizione Grant Number: PZ00P2-202204. M.
Drago acknowledges the support from the Amaldi Research Center funded by the
MIUR program ’Dipartimento di Eccellenza’ (CUP:B81I18001170001) and the
Sapienza School for Advanced Studies (SSAS). The authors are grateful for
computational resources provided by the LIGO Laboratory and supported by
National Science Foundation Grants PHY-0757058 and PHY-0823459. This paper has
document number LIGO-P2300267.

This research has made use of data or software obtained from the Gravitational
Wave Open Science Center (gwosc.org), a service of the LIGO Scientific
Collaboration, the Virgo Collaboration, and KAGRA. This material is based upon
work supported by NSF’s LIGO Laboratory which is a major facility fully funded
by the National Science Foundation, as well as the Science and Technology
Facilities Council (STFC) of the United Kingdom, the Max-Planck-Society (MPS),
and the State of Niedersachsen/Germany for support of the construction of
Advanced LIGO and construction and operation of the GEO600 detector.
Additional support for Advanced LIGO was provided by the Australian Research
Council. Virgo is funded, through the European Gravitational Observatory
(EGO), by the French Centre National de Recherche Scientifique (CNRS), the
Italian Istituto Nazionale di Fisica Nucleare (INFN) and the Dutch Nikhef,
with contributions by institutions from Belgium, Germany, Greece, Hungary,
Ireland, Japan, Monaco, Poland, Portugal, Spain. KAGRA is supported by
Ministry of Education, Culture, Sports, Science and Technology (MEXT), Japan
Society for the Promotion of Science (JSPS) in Japan; National Research
Foundation (NRF) and Ministry of Science and ICT (MSIT) in Korea; Academia
Sinica (AS) and National Science and Technology Council (NSTC) in Taiwan.

##  Appendix A Full user parameter file example

Listing 7: Run the search with python

⬇

1###### project ######

2

3outputDir "output"

4nproc 6

5###### search ######

6

7analysis "2G"

8cfg_search "r"

9

10optim False

11

12###### network configuration ######

13ifo ["L1","H1"]

14refIFO "L1"

15

16# lags

17lagSize 1

18lagStep 1.

19lagOff 0

20lagMax 0

21

22# superlags

23slagSize 1 # number of super lags (simulation=1) - if slagSize=0 -> Standard
Segments

24slagMin 0

25slagMax 0

26slagOff 0

27

28# job

29segLen 1200

30segMLS 600

31segTHR 200

32segEdge 10

33

34# frequency

35fLow 16.

36fHigh 1024.

37

38

39levelR 3

40l_low 4 # low frequency resolution level // std (sthr = 2)

41l_high 10 # high frequency resolution level // std (sthr = 8)

42

43wdmXTalk "wdmXTalk/OverlapCatalog16-1024.bin"

44

45healpix 7

46

47###### cWB production thresholds & regulators ######

48

49bpp 0.001

50subnet 0.5

51subcut -1.0

52netRHO 5.0

53cedRHO 5.0

54netCC 0.5

55Acore 1.7

56Tgap 0.2

57Fgap 128.0

58delta 0.5

59cfg_gamma -1.0

60LOUD 300

61

62pattern 10

63

64iwindow 100

65

66# simulation

67simulation "all_inject_in_one_segment"

68nfactor 1

69

70injection

71 segment

72 start 1126258862.4

73 end 1126260062.4

74 noise

75 seeds [0, 1]

76 parameters

77 mass1 20

78 mass2 20

79 spin1z 0

80 spin2z 0

81 distance 500

82 inclination 0

83 polarization 0

84 gps_time 1126259462.4

85 coa_phase 0

86 ra 0

87 dec 0

88 approximant "IMRPhenomXHM"

##  Appendix B Example Python codes for PycWB

Listing 8: Run the search with python

⬇

1from pycwb.search import search

2

3search(’./user_parameters.yaml’)

Listing 9: Run the search with python step by step

⬇

1import os

2

3import pycwb

4from pycwb.config import Config

5from pycwb.modules.logger import logger_init

6

7if not os.environ.get(’HOME_WAT_FILTERS’):

8 pyburst_path = os.path.dirname(os.path.abspath(pycwb.__file__))

9 os.environ[’HOME_WAT_FILTERS’] = f"{os.path.abspath(pyburst_path)}/vendor"

10

11logger_init()

12

13config = Config(’./user_parameters_injection.yaml’)

14

15from pycwb.modules.read_data import generate_injection

16from pycwb.modules.job_segment import create_job_segment_from_injection

17

18# generate injected data for each detector with given parameters in config

19

20job_segments = create_job_segment_from_injection(config.ifo,
config.simulation, config.injection)

21

22data = generate_injection(config, job_segments[0])

23

24# apply data conditioning to the data

25from pycwb.modules.data_conditioning import data_conditioning

26from pycwb.modules.plot import plot_spectrogram

27

28strains, nRMS = data_conditioning(config, data)

29

30# calculate coherence

31from pycwb.modules.coherence import coherence

32

33fragment_clusters = coherence(config, strains, nRMS)

34

35# supercluster

36from pycwb.modules.super_cluster import supercluster

37from pycwb.types.network import Network

38

39network = Network(config, strains, nRMS)

40pwc_list = supercluster(config, network, fragment_clusters, strains)

41

42# likelihood

43from pycwb.modules.likelihood import likelihood

44

45events, clusters = likelihood(config, network, pwc_list)

46from pycwb.modules.plot import plot_event_on_spectrogram

47

48# plot statistics

49from gwpy.spectrogram import Spectrogram

50

51for cluster in clusters:

52 merged_map, start, dt, df = cluster.get_sparse_map("likelihood")

53 plt = Spectrogram(merged_map, t0=start, dt=dt, f0=0, df=df).plot()

54 plt.colorbar()

55

56from gwpy.spectrogram import Spectrogram

57

58for cluster in clusters:

59 merged_map, start, dt, df = cluster.get_sparse_map("null")

60 plt = Spectrogram(merged_map, t0=start, dt=dt, f0=0, df=df).plot()

61 plt.colorbar()

## References

  * Wette [2020] K. Wette, SoftwareX 12, 100634 (2020), arXiv:2012.09552 [astro-ph.IM] .
  * Mihaylov  _et al._ [2023] D. P. Mihaylov, S. Ossokine, A. Buonanno, H. Estelles, L. Pompili, M. Pürrer, and A. Ramos-Buades, (2023), arXiv:2303.18203 [gr-qc] .
  * Field  _et al._ [2018] S. Field, C. Galley, and J. Blackman, in  _APS April Meeting Abstracts_ , APS Meeting Abstracts, Vol. 2018 (2018) p. G14.005.
  * Ashton  _et al._ [2019] G. Ashton _et al._ , Astrophys. J. Suppl. 241, 27 (2019), arXiv:1811.02042 [astro-ph.IM] .
  * Biwer  _et al._ [2019] C. M. Biwer, C. D. Capano, S. De, M. Cabero, D. A. Brown, A. H. Nitz, and V. Raymond, Publ. Astron. Soc. Pac. 131, 024503 (2019), arXiv:1807.10312 [astro-ph.IM] .
  * Usman  _et al._ [2016] S. A. Usman _et al._ , Class. Quant. Grav. 33, 215004 (2016), arXiv:1508.02357 [gr-qc] .
  * Klimenko  _et al._ [2016] S. Klimenko _et al._ , Phys. Rev. D 93, 042004 (2016), arXiv:1511.05999 [gr-qc] .
  * Abbott  _et al._ [2016] B. P. Abbott _et al._ (LIGO Scientific, Virgo), Phys. Rev. D 93, 122003 (2016), arXiv:1602.03839 [gr-qc] .
  * Abbott  _et al._ [2020] R. Abbott _et al._ (LIGO Scientific, Virgo), Phys. Rev. Lett. 125, 101102 (2020), arXiv:2009.01075 [gr-qc] .
  * Szczepańczyk  _et al._ [2021] M. Szczepańczyk _et al._ , Phys. Rev. D 103, 082002 (2021), arXiv:2009.11336 [astro-ph.HE] .
  * Abbott  _et al._ [2022] R. Abbott _et al._ (LIGO Scientific, VIRGO, KAGRA), Astron. Astrophys. 659, A84 (2022), arXiv:2105.15120 [astro-ph.HE] .
  * Abbott  _et al._ [2019a] B. P. Abbott _et al._ (LIGO Scientific, Virgo), Astrophys. J. 883, 149 (2019a), arXiv:1907.09384 [astro-ph.HE] .
  * Abbott  _et al._ [2021a] R. Abbott _et al._ (KAGRA, VIRGO, LIGO Scientific), Phys. Rev. D 104, 122004 (2021a), arXiv:2107.03701 [gr-qc] .
  * Abbott  _et al._ [2021b] R. Abbott _et al._ (KAGRA, VIRGO, LIGO Scientific), Phys. Rev. D 104, 102001 (2021b), arXiv:2107.13796 [gr-qc] .
  * Brun and Rademakers [1997] R. Brun and F. Rademakers, Nucl. Instrum. Meth. A 389, 81 (1997).
  * Drago  _et al._ [2021] M. Drago, S. Klimenko, C. Lazzaro, E. Milotti, G. Mitselmakher, V. Necula, B. O’Brian, G. A. Prodi, F. Salemi, M. Szczepanczyk, S. Tiwari, V. Tiwari, G. V, G. Vedovato, and I. Yakushin, SoftwareX 14, 100678 (2021).
  * Klimenko  _et al._ [2021] S. Klimenko, G. Vedovato, V. Necula, F. Salemi, M. Drago, R. Poulton, E. Chassande-Mottin, V. Tiwari, C. Lazzaro, B. O’Brian, M. Szczepanczyk, S. Tiwari, and V. Gayathri, “cwb pipeline library: 6.4.1,”  (2021).
  * Górski  _et al._ [2005] K. M. Górski, E. Hivon, A. J. Banday, B. D. Wandelt, F. K. Hansen, M. Reinecke, and M. Bartelmann, The Astrophysical Journal 622, 759 (2005).
  * Lam  _et al._ [2015] S. K. Lam, A. Pitrou, and S. Seibert (2015).
  * Bini  _et al._ [2023] S. Bini, G. Vedovato, M. Drago, F. Salemi, and G. A. Prodi, Class. Quant. Grav. 40, 135008 (2023), arXiv:2303.05986 [gr-qc] .
  * Abadi  _et al._ [2016] M. Abadi _et al._ , (2016), arXiv:1603.04467 [cs.DC] .
  * Abbott  _et al._ [2019b] B. P. Abbott _et al._ (LIGO Scientific, Virgo), Phys. Rev. X 9, 031040 (2019b), arXiv:1811.12907 [astro-ph.HE] .
  * Abbott  _et al._ [2021c] R. Abbott _et al._ (LIGO Scientific, Virgo), SoftwareX 13, 100658 (2021c), arXiv:1912.11716 [gr-qc] .
  * Abbott  _et al._ [2023] R. Abbott _et al._ (KAGRA, VIRGO, LIGO Scientific), Astrophys. J. Suppl. 267, 29 (2023), arXiv:2302.03676 [gr-qc] .
  * The LIGO Scientific Collaboration [2022] The LIGO Scientific Collaboration, “LIGO Light-Weight XML I/O library for Python,”  (2022).


# Quantifying separability in RAAGs via representations

Olga Kharlampovich , Alina Vdovina CUNY, Graduate Center and Hunter
CollegeCUNY, Graduate Center and City College

###### Abstract

We answer the question in [8] and prove the following statement. Let $L$ be a
RAAG, $H$ a word quasiconvex subgroup of $L$, then there is a finite
dimensional representation of $L$ that separates the subgroup $H$ in the
induced Zariski topology. As a corollary, we establish a polynomial upper
bound on the size of the quotients used to separate $H$ in $L$. This implies
the same statement for a virtually special group $L$ and, in particular, a
fundamental groups of a hyperbolic 3-manifold.

##  1 Introduction

A subgroup $H<G$ is separable if for any $g\in G-H$ there exist a homomorphism
$\phi:G\rightarrow K$, where $K$ is finite and $\phi(g)\not\in\phi(H).$
Alternatively, $H=\cap_{H\leq L\leq G,[G:L]<\infty}L$. Residual finiteness
means that the trivial subgroup $1<G$ is separable. It was shown in [6,
Theorem F] that every word quasiconvex subgroup of a finitely generated right-
angled Artin group (RAAG) is a virtual retract, and hence is separable. If $B$
is a virtually special compact cube complex such that $\pi_{1}(B)$ is word-
hyperbolic, then every quasiconvex subgroup of $\pi_{1}(B)$ is separable [7].
For both these cases we will quantify separability. Namely, we answer the
question in [8] and prove the following statement. Let $L$ be a RAAG, if $H$
is a cubically convex-cocompact subgroup of $L$, then there is a finite
dimensional representation of $L$ that separates the subgroup $H$ in the
induced Zariski topology. As a corollary, we establish a polynomial upper
bound on the size of the quotients used to separate $H$ in $L$. This implies
the same statement for a virtually special group $L$ and, in particular, a
fundamental groups of hyperbolic 3-manifold.

######  Definition 1.

A subset $S$ of a geodesic metric space $X$ is $K$-quasiconvex if for every
geodesic $\gamma$ in $X$ whose endpoints lie in $S,$ the $K$-neighborhood of
$S$ contains $\gamma$. We say that $S$ is convex if it is $0$-quasiconvex. A
subcomplex $Y$ of a CAT(0) cube complex $X$ is convex provided $Y$ is
connected and for each vertex $v$ of $Y$ the link of $Y$ at $v$ is a full
subcomplex of the link of $X$ at $v.$ The combinatorial convex hull of a
subcomplex $Y\subset X$ is the intersection of all convex subcomplexes
containing $Y$ .

A group $H$ acting on a geodesic metric space $X$ is quasiconvex if the orbit
$Hx$ is a $K$-quasiconvex subspace of $X$ for some $K>0$ and some $x\in X.$ If
$H$ preserves a convex closed subset $C$ and is cocompact on $C$ we say that
$H$ is convex cocompact. Convexity clearly implies quasiconvexity.

We will use the previous notions in the following context: either $X$ is a
CAT(0) cube complex equipped with its CAT(0) metric, or $X$ is the set of
vertices of a cube complex equipped with the combinatorial distance (here a
geodesic is the sequence of vertices of a combinatorial geodesic of the
1-skeleton). In the first case we say that $H$ is CAT(0) quasiconvex, in the
second that $H$ is combinatorially quasiconvex (or word quasiconvex). For
special cube complexes (in particular, Salvetti complexes) these notions
coincide.

Convex cocompact subgroups of RAAGs are virtual retracts. A subgroup $H$ of a
RAAG is word quasi-convex if and only if it is convex cocompact [6]. For
hyperbolic groups all definitions of quasiconvexity coincide and do not depend
on a generating set.

A local isometry $\phi:Y\rightarrow X$ of cube complexes is a locally
injective combinatorial map with the property that, if $e_{1},\ldots,e_{n}$
are 1-cubes (edges) of $Y$ all incident to a $0$-cube (vertex) $y$, and the
(necessarily distinct) 1-cubes $\phi(e_{1}),\ldots,\phi(e_{n})$ all lie in a
common $n$-cube $c$ (containing $\phi(y)$), then $e_{1},\ldots,e_{n}$ span an
$n$-cube $c_{0}$ in $Y$ with $\phi(c_{0})=c$. If $\phi:Y\rightarrow X$ is a
local isometry and $X$ is nonpositively-curved, then $Y$ is as well. Moreover,
$\phi$ lifts to an embedding $\tilde{\phi}:\tilde{Y}\rightarrow\tilde{X}.$ of
universal covers, and $\tilde{Y}$ is convex in $\tilde{X}$.

######  Theorem 1.

Let $L$ be a RAAG. If $H$ is a word quasiconvex subgroup of $L$, then there is
a faithful representation $\rho_{H}:L\rightarrow GL(V)$ such that
$\overline{\rho_{H}(H)}\cap\rho_{H}(L)=\rho_{H}(H)$, where
$\overline{\rho_{H}(H)}$ is the Zariski closure of $\rho_{H}(H).$

######  Theorem 2.

Let $L$ be a virtually special group. If $H$ is a word quasiconvex subgroup of
$L$, then there is a faithful representation $\rho_{H}:L\rightarrow GL(V)$
such that $\overline{\rho_{H}(H)}\cap\rho_{H}(L)=\rho_{H}(H)$, where
$\overline{\rho_{H}(H)}$ is the Zariski closure of $\rho_{H}(H).$

######  Theorem 3.

Let $L$ be a hyperbolic virtually special group. If $H$ is a quasiconvex
subgroup of $L$, then there is a faithful representation
$\rho_{H}:L\rightarrow GL(V)$ such that
$\overline{\rho_{H}(H)}\cap\rho_{H}(L)=\rho_{H}(H)$, where
$\overline{\rho_{H}(H)}$ is the Zariski closure of $\rho_{H}(H).$

######  Corollary 4.

Let $L$ and $H$ be as in the theorems above. Then there exists a constant
$N>0$ such that for each $g\in L-H,$ there exist a finite group $Q$ and a
homomorphism $\varphi:L\longrightarrow Q$ such that
$\varphi\left(g\right)\notin\varphi\left(H\right)$ and
$\left|Q\right|\leq\left|\left|g\right|\right|_{S}^{N}.$ If $K=H\ker\varphi,$
then $K$ is a finite-index subgroup of $L$ whose index is at most
$\left|Q\right|\leq\left|\left|g\right|\right|_{S}^{N}$ with $H\leq K$ and
$g\notin K.$ Moreover, the index of the normal core of the subgroup $K$ is
bounded above by $\left|Q\right|$.

The groups covered by this corollary include fundamental groups of hyperbolic
3-manifolds, $C^{\prime}(1/6)$ small cancellation groups and, therefore,
random groups for density less than $1/12$.

Our Theorems and Corollary 4 generalize results for free groups, surface
groups from [8] and for limit groups [4]. We use [8] to deduce Corollary 4
from the theorems. Corollary 4 establishes polynomial bounds on the size of
the normal core of the finite index subgroup used in separating $g$ from $H$.
The constant $N$ explicitly depends on the subgroup $H$ and the dimension of
$V$ in Theorem 1. For a general finite index subgroup, the upper bound for the
index of the normal core is factorial in the index of the subgroup. It is for
this reason that we include the statement about the normal core of $K$ at the
end of the corollary.

Recently, several effective separability results have been established; see
[1]-[8], [9]-[11], [12]-[16]. Most relevant here are papers [8], [5]. The
methods used in [5] give linear bounds in terms of the word length of $|g|$ on
the index of the subgroup used in the separation but do not produce polynomial
bounds for the normal core of that finite index subgroup.

##  2 Fundamental group of the canonical completion

######  Proposition 5.

[2, Theorem 2.6] Let $\Gamma$ be a finite graph, $S(\Gamma)$ Salvetti complex,
$Y$ a compact cube complex that has a local isometric embedding in $S(\Gamma)$
with respect to Cat(0) metric (So $\pi_{1}(Y)\leq\pi_{1}(S(\Gamma)).$Then $Y$
can be embedded in $C(Y)$ that is a finite cover of $S(\Gamma)$ by canonically
completing the 1-skeleton and then adding cubes everywhere where there is a
boundary of a cube.

###### Proof.

We define the canonical completion from [2] because we need this construction
to analyse fundamental groups of $Y$ and $C(Y)$. Since $Y$ has a local
isometric embedding in $S(\Gamma)$, each edge in $Y$ is naturally equipped
with a direction and labelling is induced by a generator of
$\pi_{1}(S(\Gamma))$. Each vertex $v$ of $Y$ either has an edge $x$ incoming
and outgoing, or does not have $x$ adjacent to it at all, or has $x$ either
incoming or outgoing. For each label $x$ we consider connected paths with all
the edges labelled by $x$. If such a path $p$ is a cycle, we leave it alone.
If the initial vertex $v$ of the path $p$ has valency 1 with respect to $x$,
then the final vertex $u$ has valency 1 as well because of $y$ being
isometrically embedded in $S(\Gamma)$. In this case we add an edge labelled by
$x$ with the initial vertex $u$ and the final vertex $v$. If a vertex $w$ does
not have edges with label $x$ adjacent to it, we add a loop with the label $x$
to the vertex $w$. Now we add cubes everywhere where there is a boundary of a
cube. See the example in Fig 1, we basically borrowed it from N. Lazarovich’s
talk in Montreal.

∎

Figure 1: Example

This proposition implies the following.

######  Proposition 6.

Let $L$ be a RAAG, $H$ a word quasiconvex subgroup. Then there exists a finite
index subgroup $K$ obtained from $H$ by adding some conjugates of powers of
standard generators of $L$. Algebraically, $K$ is obtained from $H$ by a
series of the following operations: 1) free product with infinite cyclic
group, 2) HNN-extension such that associated subgroups are the same and with
identical isomorphism.

###### Proof.

Let $L=A_{\Gamma}$ be a RAAG, $S_{\Gamma}$ its Salvetti complex. It is
explained in the proof of Corollary B in [5] that $H=\pi_{1}(Y)$, where $Y$ is
a compact connected cube complex, based at a 0-cube $x$, with a based local
isometry $f:Y\rightarrow S_{\Gamma}$.

When constructing the canonical completion $C(Y)$ in the proof of Proposition
5 we add edges that create loops that correspond to conjugates of $x^{k}$,
where $x$ is a generator of $L$.

Now we will prove the second statement of the Proposition by induction on the
number of steps needed to complete the one-skeleton of $Y$. We will only work
with 2-skeletons since they determine fundamental groups. We take an
incomplete vertex $v$ of $Y$. A step is the following transformation.

Case 1. $v$ has valency 0 in $x$. Then we add a loop labelled by $x$ in $v$
and to all vertices connected to $v$ by a path with label that commutes with
$x$.

Case 2. Vertex $v$ has valency 1 in $x$. Suppose $v$ has an outgoing edge
labelled by $x$. Let $u$ be the endpoint of the path from $v$ with edges
labelled by $x$. Then we connect $u$ with $v$ by an edge labelled by $x$ and
do the same in all vertices connected to $v$ by a path with label that
commutes with $x$. We can do this because $f$ is a local isometry.

Case 3. Vertex $v$ has valency 2 in $x$. If there is no loop labelled by
$x^{k}$ starting at $v$, we complete the path labelled by a power of $x$ and
passing through $v$. We also do the same in all vertices connected to $v$ by a
path with label that commutes with $x$. We can do this because $f$ is a local
isometry.

Case 4. If $deg_{x}(v)=2$ and there is a loop labelled by $x^{k}$ starting at
$v$, then we do nothing.

By [2, Lemma 2.7], if in the obtained extension of $Y$ (denoted $Y_{1}$) we
have a lift of the boundary of 2-cube, then this lift is a closed path. To
complete the step, we fill in newly obtained lifts of boundaries of 2-cubes by
2-cubes. Denote the obtained complex by $Y_{2}$.

In case 4 $\pi_{1}(Y)=\pi_{1}(Y_{2}).$ In all other cases we added an extra
generator $t=hx^{k}h^{-1}$, where $h\in A(\Gamma).$

Now we claim that in Cases 1-3 $\pi_{1}(Y_{2})$ is an HNN-extension of
$\pi_{1}(Y)$ with stable letter $t$. We can move the base point $v$ to $hv$,
then $t=x^{k}$. Both $\pi_{1}(Y),\pi_{1}(Y_{2})$ have a local isometry into
$S(\Gamma)$. Suppose there is a relation in $\pi_{1}(Y_{2})$

$x^{\pm k}g_{1}x^{\pm k}g_{2}\ldots g_{t}=1,$

where $g_{1},\ldots,g_{t}\in\pi_{1}(Y).$ We will show by induction on $t$ that
it follows from relations $[x^{k},g]=1,$ where $g\in\pi_{1}(Y)$ and $g$ does
not contain $x$. For some $i$ it should be $[g_{i},x]=1$. Then
$g_{i}=x^{k_{1}}g$, where $g\in A(\Gamma),$ $[g,x]=1$ and $g$ does not contain
$x$. Suppose $k_{1}\neq 0$. Then, since $x^{k}\in\pi_{1}(Y_{2})$, for some
$k_{2}$ (in particular, $k_{2}=k_{1}k$) , $g^{k_{2}}\in\pi_{1}(Y_{2})$.
Therefore $g^{k_{2}}\in\pi_{1}(Y)$ (indeed, making a step we do not glue
together different vertices). But then $x^{k_{1}k_{2}}\in\pi_{1}(Y),$
contradiction with the assumption that we are in Cases 1-3 and that $k_{1}\neq
0$. Therefore $k_{1}=0$ and $g\in\pi_{1}(Y)$. Relation $[x^{k},g]=1$ is an
HNN-extension relation. We can apply it, decrease $t$ and use induction.

Therefore, if $x^{k}$ appears in a relation of $\pi_{1}(Y_{2})$, then this
relation is a consequence of relations $[x^{k},g]=1$ for some $g\in\pi_{1}(Y)$
such that $[g,x]=1.$ This proves the claim. Since the canonical completion is
constructed by a sequence of such steps, the proposition is proved.

∎

##  3 Representations

######  Definition 2.

[8] Let $G$ be a finitely generated group and $H$ a finitely generated
subgroup of $G.$ For a complex affine algebraic group $\bf{G}$ and any
representation $\rho_{0}\in Hom(G,\bf{G}),$ we have the closed affine
subvariety

$R_{\rho_{0},H}(G,{\bf{G}})=\left\\{\rho\in Hom(G,{\bf
G}):\rho_{0}(h)=\rho(h)\text{ for all }h\in H\right\\}$

The representation $\rho_{0}$ is said to strongly distinguish $H$ in $G$ if
there exist representations $\rho,\rho^{\prime}\in R_{\rho_{0},H}(G,\bf{G})$
such that $\rho(g)\neq\rho^{\prime}(g)$ for all $g\in G-H.$

######  Lemma 7.

[8, Lemma 3.1] Let $G$ be a finitely generated group, ${\bf G}$ a complex
algebraic group, and $H$ a finitely generated subgroup of $G.$ If $H$ is
strongly distinguished by a representation $\rho\in Hom(G,{\bf G})$, then
there exists a representation $\varrho:G\longrightarrow{\bf G}\times{\bf G}$
such that $\varrho(G)\cap\overline{\varrho(H)}=\varrho(H),$ where
$\overline{\varrho(H)}$ is the Zariski closure of $\varrho(H)$ in ${\bf
G}\times{\bf G}.$

######  Proposition 8.

Let $L$ be a RAAG and $H$ a word quasiconvex finitely generated subgroup.
There exist a finite-index subgroup $K\leq L$ and a faithful representation
$\rho_{\omega}:K\rightarrow\bf G$ that strongly distinguishes $H$ in $K$.

###### Proof.

Let $K$ be a finite index subgroup from Proposition 6. Let $\rho$ be a
faithful representation of $K$ in $\bf G$. Since $K$ is obtained from $H$ as
in Proposition 6, we can write

$H=K_{0}<\ldots K_{i}<\ldots K_{n}=K,$

where $K_{i}=\langle K_{i-1},t_{i}|[H_{i-1},t_{i}]=1\rangle.$ Then $H$ is
strongly distinguished in K by the representation $\rho$ because we can take
$\rho$ and $\rho^{\prime}$ to be the same on $H$ and
$\rho^{\prime}(t_{i})=\rho(t_{i})^{k},$ for $k>1$, $i=1,\ldots,n.$ ∎

Let us prove Theorem 1. The proof of [8, Theorem 1.1] shows that it is
sufficient to have a representation of $K$ that strongly distinguishes $H$.
Indeed, like in [8, Corollary 3.4], we can construct a representation
$\Phi:K\rightarrow GL(2,{\mathbb{C}})\times GL(2,{\mathbb{C}})$ such that
$\Phi(g)\in Diag(GL(2,{\mathbb{C}}))$ if and only if $g\in H$. Setting
$d_{H}=[L:K]$, we have the induced representation

${Ind_{K}}^{G}(\Phi):L\rightarrow GL(2d_{H},{\mathbb{C}})\times
GL(2d_{H},{\mathbb{C}}).$

Recall, that when $\Phi$ is represented by the action on the vector space $V$
and $L=\cup_{i=0}^{t}g_{i}K$, then the induced representation acts on the
disjoint union $\sqcup_{i=0}^{t}g_{i}V$ as follows

$g\Sigma g_{i}v_{i}=\Sigma g_{j(i)}\Phi(k_{i})v_{i},$

where $gg_{i}=g_{j(i)}k_{i},$ for $k_{i}\in K.$ Taking
$\rho={Ind_{K}}^{G}(\Phi)$, it follows from the construction of $\rho$ and
definition of induction that $\rho(g)\in\overline{(\rho(H))}$ if and only if
$g\in H$. If we set $\rho=\rho_{H},$ then Theorem 1 is proved.

Since a special group is a subgroup of a RAAG and we can extend a
representation from a finite index subgroup to the whole group, Theorem 1
implies Theorem 2.

All definitions of quasiconvexity coincide in hyperbolic groups and Theorem 3
follows from Theorem 2.

##  4  Proof of Corollary 4

Given a complex algebraic group $\textbf{G}<GL(n,\mathbb{C})$, there exist
polynomials $P_{1},\ldots,P_{r}\in\mathbb{C}\left[X_{i,j}\right]$ such that

$\textbf{G}=\textbf{G}\left(\mathbb{C}\right)=V\left(P_{1},\ldots,P_{r}\right)=\left\\{X\in\mathbb{C}^{n^{2}}\mid
P_{k}(X)=0,k=1,\ldots,r\right\\}$

We refer to the polynomials $P_{1},\ldots,P_{r}$ as defining polynomials for
G. We will say that G is $K$-defined for a subfield $K\subset\mathbb{C}$ if
there exists defining polynomials $P_{1},\ldots,P_{r}\in
K\left[X_{i,j}\right]$ for G. For a complex affine algebraic subgroup
$\textbf{H}<\textbf{G}<GL(n,\mathbb{C})$, we will pick the defining
polynomials for H to contain a defining set for G as a subset. Specifically,
we have polynomials
$P_{1},...,P_{r_{\textbf{G}}},P_{r_{\textbf{G}}+1},...,P_{r_{\textbf{H}}}$
such that

$\textbf{G}=V\left(P_{1},\ldots,P_{r_{\textbf{G}}}\right)\text{ and
}\textbf{H}=V\left(P_{1},\ldots,P_{r_{\textbf{H}}}\right)$ (1)

If G is defined over a number field $K$ with associated ring of integers
$\mathcal{O}_{K}$, we can find polynomials
$P_{1},\ldots,P_{r}\in\mathcal{O}_{K}\left[X_{i,j}\right]$ as a defining set
by clearing denominators. For instance, in the case when $K=\mathbb{Q}$ and
$\mathcal{O}_{K}=\mathbb{Z}$, these are multivariable integer polynomials.

For a fixed finite set $X=\left\\{x_{1},\ldots,x_{t}\right\\}$ with associated
free group $F(X)$ and any group $G,$ the set of homomorphisms from $F(X)$ to
$G,$ denoted by $Hom\left(F\left(X\right),G\right),$ can be identified with
$G^{t}=G_{1}\times\ldots\times G_{t}.$ For any point
$\left(g_{1},\ldots,g_{t}\right)\in G^{t},$ we have an associated homomorphism
$\varphi_{\left(g_{1},\ldots,g_{t}\right)}:F\left(X\right)\longrightarrow G$
given by $\varphi_{\left(g_{1},\ldots,g_{t}\right)}\left(x_{i}\right)=g_{i}.$
For any word $w\in F(X),$ we have a function
Eval${}_{w}:Hom(F(X),G)\longrightarrow G$ defined by
Eval${}_{w}(\varphi_{\left(g_{1},\ldots,g_{t}\right)})(w)=w(g_{1},\ldots,g_{t}).$
For a finitely presented group $\Gamma,$ we fix a finite presentation
$\langle\gamma_{1},\ldots,\gamma_{t}\mid r_{1},\ldots,r_{t^{\prime}}\rangle,$
where $X=\left\\{\gamma_{1},\ldots,\gamma_{t}\right\\}$ generates $\Gamma$ as
a monoid and $\left\\{r_{1},\ldots,r_{t^{\prime}}\right\\}$ is a finite set of
relations. If G is a complex affine algebraic subgroup of
$Gl_{n}(n,\mathbb{C}),$ the set $Hom(\Gamma,\textbf{G})$ of homomorphisms
$\rho:\Gamma\longrightarrow\textbf{G}$ can be identified with an affine
subvariety of $G^{t}.$ Specifically,

$Hom(\Gamma,\textbf{G})=\left\\{\left(g_{1},\ldots,g_{t}\right)\in\textbf{G}^{t}\mid
r_{j}\left(g_{1},\ldots,g_{t}\right)=I_{n}\text{ for all }j\right\\}$ (2)

If $\Gamma$ is finitely generated, $Hom(\Gamma,\textbf{G})$ is an affine
algebraic variety by the Hilbert Basis Theorem.

The set $Hom(\Gamma,\textbf{G})$ also has a topology induced by the analytic
topology on $G^{t}.$ There is a Zariski open subset of
$Hom(\Gamma,\textbf{G})$ that is smooth in the this topology called the smooth
locus, and the functions
Eval${}_{w}:Hom(\Gamma,\textbf{G})\longrightarrow\textbf{G}$ are analytic on
the smooth locus. For any subset $S\in G$ and representation $\rho\in
Hom(\Gamma,\textbf{G})$, $\overline{\rho(S)}$ will denote the Zariski closure
of $\rho(S)$ in G.

######  Lemma 9.

([8, Lemma 5.1]) Let ${\bf G}\leq GL\left(n,\mathbb{C}\right)$ be a
$\overline{\mathbb{Q}}$-algebraic group, $L\leq{\bf G}$ be a finitely
generated subgroup, and $\textbf{A}\leq{\bf G}$ be a
$\overline{\mathbb{Q}}$-algebraic subgroup. Then, $H=L\cap\textbf{A}$ is
closed in the profinite topology.

###### Proof.

Given $g\in L-H$, we need a homomorphism $\varphi:L\longrightarrow Q$ such
that $|Q|<\infty$ and $\varphi\left(g\right)\notin\varphi\left(H\right).$ We
first select polynomials
$P_{1},...,P_{r_{\textbf{G}}},...,P_{r_{\textbf{A}}}\in\mathbb{C}\left[X_{i,j}\right]$
satisfying (1). Since G and A are $\overline{\mathbb{Q}}$-defined, we can
select $P_{j}\in\mathcal{O}_{K_{0}}\left[X_{i,j}\right]$ for some number field
$K_{0}/\mathbb{Q}.$ We fix a finite set
$\left\\{l_{1},\ldots,l_{r_{L}}\right\\}$ that generates $L$ as a monoid. In
order to distinguish between elements of $L$ as an abstract group and the
explicit elements in ${\bf G},$ we set $l=M_{l}\in{\bf G}$ for each $l\in L.$
In particular, we have a representation given by
$\rho_{0}:L\longrightarrow{\bf G}$ given by $\rho_{0}(l_{t})=M_{l_{t}}$. We
set $K_{L}$ to be the field generated over $K_{0}$ by the set of matrix
entries $\left\\{\left(M_{t}\right)_{i,j}\right\\}_{t,i,j}$. It is
straightforward to see that $K_{L}$ is independent of the choice of the
generating set for $L.$ Since $L$ is finitely generated, the field $K_{L}$ has
finite transcendence degree over $\mathbb{Q}$ and so $K_{L}$ is isomorphic to
a field of the form $K(T)$ where $K/\mathbb{Q}$ is a number field and
$T=\left\\{T_{1},\ldots,T_{d}\right\\}$ is a transcendental basis (See [8]).
For each, $M_{l_{t}},$ we have $(M_{l_{t}})_{i,j}=F_{i,j,t}(T)\in K_{L}$. In
particular, we can view the $(i,j)$-entry of the matrix $M_{l_{t}}$ as a
rational function in $d$ variables with coefficients in some number field $K$.
Taking the ring $R_{L}$ generated over $\mathcal{O}_{K_{0}}$ by the set
$\left\\{\left(M_{l_{t}}\right)_{i,j}\right\\}_{t,i,j}$, $R_{L}$ is obtained
from $\mathcal{O}_{K_{0}}\left[T_{1},\ldots,T_{d}\right]$ by inverting a
finite number of integers and polynomials. Any ring homomorphism
$R_{L}\longrightarrow R$ induces a group homomorphism
$GL(n,R_{L})\longrightarrow GL(n,R)$, and since $L\leq GL(n,R_{L})$, we obtain
$L\longrightarrow GL(n,R)$ . If $g\in L-H$ then there exists
$r_{\mathbf{G}}<j_{g}\leq r_{\mathbf{A}}$ such that
$Q_{g}=P_{j_{g}}\left(\left(M_{l}\right)_{1,1},\ldots,\left(M_{l}\right)_{n,n}\right)\neq
0$. Using Lemma 2.1 in [3], we have a ring homomorphism
$\psi_{R}:R_{L}\longrightarrow R$ with $|R|<\infty$ such that
$\psi_{R}(Q_{g})\neq 0$. Setting, $\rho_{R}:GL(n,R_{L})\longrightarrow
GL(n,R)$ we assert that $\rho_{R}(g)\notin\rho_{R}(H)$. To see this, set
$\overline{M}_{\eta}=\rho_{R}(\eta)$ for each $\eta\in L$, and note that
$\psi_{R}(P_{j}((M_{\eta})_{1,1},\ldots,M_{\eta})_{n,n}))=P_{j}((\overline{M}_{\eta})_{1,1},\ldots,(\overline{M}_{\eta})_{n,n})$
. For each $h\in H$, we know that $P_{j_{l}}\left((M_{h})_{i,j}\right)=0$ and
so $P_{j}((\overline{M}_{\eta})_{1,1},\ldots,(\overline{M}_{\eta})_{n,n})=0$ .
However, by selection of $\psi_{R}$, we know that $\psi_{R}(Q_{g})\neq 0$ and
so $\rho_{R}(g)\notin\rho_{R}(H)$ . ∎

Theorems 1, 2, 3 and Lemma 9 imply Corollary 4.

###### Proof.

Since $H\leq L$ is word quasiconvex, by Theorems 1, 2, 3 there is a faithful
representation

$\rho_{H}:L\longrightarrow GL\left(n,\mathbb{C}\right)$

such that $\overline{\rho_{H}(H)}\cap\rho_{H}(L)=\rho_{H}(H)$. We can
construct the representation in Theorem 1 so that
$\textbf{G}=\overline{\rho_{H}(L)}$ and $\textbf{A}=\overline{\rho_{H}(H)}$
are both $\overline{\mathbb{Q}}$-defined. So, by Lemma 9, we can separate $H$
in $L.$ Next, we quantify the separability of $H$ in $L.$ Toward that end, we
need to bound the order of the ring $R$ in the proof of Lemma 9 in terms of
the word length of the element $g.$ Lemma 2.1 from [3] bounds the size of $R$
in terms of the coefficient size and degree of the polynomial $Q_{g}.$ It
follows from a discussion on pp 412-413 of [3] that the coefficients and
degree can be bounded in terms of the word length of $g,$ and that the
coefficients and degrees of the polynomials $P_{j}.$ Because the $P_{j}$ are
independent of the word $g,$ there exists a constant $N_{0}$ such that
$|R|\leq\left|\left|g\right|\right|^{N_{0}}.$ By construction, the group $Q$
we seek is a subgroup of $GL(n,R).$ Thus,
$|Q|\leq|R|^{n^{2}}\leq\left|\left|g\right|\right|^{N_{0}n^{2}}.$ Taking
$N=N_{0}n^{2}$ completes the proof.

∎

Acknowledgement: We are thankful to N. Lazarovich and M. Hagen for the useful
discussions about canonical completions during the Workshop on Cube Complexes
and Combinatorial Geometry (Montreal 2023) that inspired this work. We thank
Dolciani foundation, Simons foundation and PSC CUNY for the support.

## References

  * [1] K. Bou-Rabee, Quantifying residual finiteness. J. Algebra 323, 729-737 (2010)
  * [2] K. Bou-Rabee, M.F Hagen, P. Patel, Residual finiteness growths of virtually special groups. Math. Z. 279, 297-310 (2015)
  * [3] K. Bou-Rabee, D.B. McReynolds, Extremal behavior of divisibility functions on linear groups.Geom. Dedicata 175, 407-415 (2015).
  * [4] K. Brown, O. Kharlampovich, Quantifying separability in limit groups via representations, arXiv:2303.03644, 2023.
  * [5] M.F. Hagen, P. Patel, Quantifying separability in virtually special groups. Pacific J. Math. 284, 103-120 (2016)
  * [6] F. Haglund, Finite index subgroups of graph products, Geom Dedicata (2008) 135:167-209
  * [7] F. Haglund, D. Wise, SPECIAL CUBE COMPLEXES, GAFA, Geom. funct. anal. Vol. 17 (2008) 1551-620.
  * [8] L. Louder, D. B. McReynolds, P.Patel, Zariski closures and subgroup separability, Sel. Math. New Ser. (2017) 23, 2019-2027.
  * [9] M. Kassabov, F. Matucci, Bounding the residual finiteness of free groups. Proc. Am.Math. Soc. 139, 2281-2286 (2011)
  * [10] G. Kozma, A. Thom, Divisibility and laws in finite simple groups. Math. Ann. 364, 79-95 (2016)
  * [11] O. Kharlampovich, A. Myasnikov, M. Sapir, Algorithmically complex residually finite groups, Bulletin of Mathematical Sciences 7 (2017), no. 2, 309-352.
  * [12] P. Patel, On a Theorem of Peter Scott. Proc. Am. Math. Soc. 142, 2891-2906 (2014)
  * [13] P. Patel, On the residual finiteness growths of particular hyperbolic manifold groups. Geom. Dedicata 186(1), 87-103 (2016)
  * [14] M. Pengitore, Effective conjugacy separability of finitely generated nilpotent groups. http://arxiv.org/ abs/1502.05445 (2015)
  * [15] I. Rivin, Geodesics with one self-intersection, and other stories. Adv. Math. 231, 2391-2412 (2012)
  * [16] B. Solie, Quantitative residual properties of $\Gamma$\- imit groups. (English summary) Internat. J. Algebra Comput. 24 (2014), no. 2,207-231.