<figure><img src="image_1.png" /></figure>

HAL
open science

# The role of the cosmic web in the scatter of the galaxy stellar mass-gas metallicity relation

Callum T. Donnan, Rita Tojeiro, Katarina Kraljic

► To cite this version:

Callum T. Donnan, Rita Tojeiro, Katarina Kraljic. The role of the cosmic web in the scatter of the galaxy stellar mass-gas metallicity relation. Nature Astronomy, 2022, 6 (5), pp.599-606. 10.1038/s41550-022-01619-w. hal-03560528

HAL Id: hal-03560528

https://hal.science/hal-03560528v1

Submitted on 7 Oct 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
<figure><img src="image_3.png" /></figure>

# The role of the cosmic web in the scatter of the galaxy stellar mass-gas metallicity relation

Callum T. Donnan<fnref n="1" />,²✉, Rita Tojeiro<fnref n="1" /> and Katarina Kraljic³

The large-scale structure of the Universe can be understood in terms of features such as filaments, nodes and walls, which we collectively term the cosmic web. Galaxies evolve within the cosmic web, naturally raising the question of its impact on that process. There are two main mechanisms by which the cosmic web can influence galaxies: one is by modulating the growth of haloes, and the other is by regulating the gas ecosystem around galaxies. Disentangling the two is difficult, but key to deriving a holistic picture of galaxy formation and observational constraints on the growth of haloes. Here we report a detection of the effect of the cosmic web on the galaxy stellar mass-gas-phase metallicity relation of low-redshift star-forming galaxies using data from the Sloan Digital Sky Survey. The proximity of a galaxy to a node, independently of stellar mass and overdensity, influences its gas-phase metallicity, with galaxies closer to nodes displaying higher chemical enrichment than those farther away. We find a similar, but notably weaker, effect with respect to filaments. We find qualitative agreement in the cosmological hydrodynamical simulation IllustrisTNG (TNG300). Using IllustrisTNG, our results can be explained by both halo assembly bias and gas supply combining in nodes in a way that markedly modulates the metallicity of the gas, contributing to the scatter of this fundamental relation in galaxy evolution.

Within the standard cosmological model, galaxy formation and evolution are understood in broad terms—driven by gravity, structure forms hierarchically, yielding the potential wells within which cold baryons gather and form stars. Modern models of the galaxy-halo connection attempt to link the evolution of haloes within the standard paradigm with the observed evolution of galaxies<fnref n="1" />. We know from observations that stellar mass is crucial to understanding the properties of different galaxies², and the statistical link between stellar mass and halo mass is now well established. However, even at low redshift—where observations are abundant—the details of the drivers of individual galaxy pathways are not resolved. Having successfully established meaningful mean empirical relationships in extragalactic observations, efforts can now be focused on explaining why galaxies deviate from mean trends.

Galaxies exist within the large-scale structure of the Universe, consisting of dense nodes connected by filaments that are separated by walls and underdense voids³, the so-called cosmic web. The effect of the cosmic web on the growth of haloes, at fixed halo mass (that is, halo assembly bias), is now well established in simulations⁴⁻⁷ and has been detected in observations⁸: at fixed halo mass, haloes closer to nodes or filaments assembled their mass earlier than those farther away. However, the questions of if, how and why the cosmic web impacts the baryonic properties of galaxies remain to be answered. Simple models of the galaxy-halo connection link the star-formation history of a galaxy to the mass assembly history of the halo; that is, gas accretion follows dark-matter accretion (with some efficiency), and the star-formation rate follows gas accretion. So, at the simplest level, one may argue that halo assembly bias regulates the stellar content of a galaxy indirectly by modulating the halo assembly history, and there is observational evidence in that direction: at fixed stellar mass, galaxies near filaments show redder colours and have reduced star-formation rates and higher stellar metallicities⁹⁻¹¹.

However, the gas ecosystem of galaxies is complex, and understanding how the cosmic web affects gas in and around galaxies is crucial to understanding its overall impact on the galaxy-halo connection. Some observational studies have focused on correlating the *HI* gas content in galaxies with some form of cosmic web estimate, with varying success and results¹²,¹³. Here we focus on the gas-phase metallicity, which describes the relative mass of elements heavier than helium in the interstellar medium (ISM) of a galaxy. Some insight into the environmental effects on gas-phase metallicity has been gained before¹⁴⁻¹⁶, but never within the full context of the cosmic web in a wide-area survey. The shape of the metallicity versus stellar mass relation (MZR) is a key observable in models of galaxy evolution, and offers important insight into baryonic evolutionary mechanisms in galaxies¹⁷. The metal content in the ISM is enriched by stellar evolution, and depleted by winds that carry metals away from a galaxy and by dilution through the accretion of lower-metallicity gas from the circumgalactic medium and the intergalactic medium, which in turn flow from the cosmic web. Gas-phase metallicity generally climbs steeply with stellar mass, with a scatter considerably larger than measurement uncertainties¹⁸. Understanding what drives this scatter—that is, why do galaxies at fixed stellar mass have different gas-phase metallicities?—is likely to drive our understanding of the physical processes that define the evolutionary paths of galaxies. In simulations, the scatter in the MZR has been linked to outflows and inflows¹⁹,²⁰, and in observations it has been shown to correlate with the star-formation rate²¹, but how much the factors that drive these are purely internal and stochastic, or external and modulated by the cosmic web, remains to be determined.

In this Article, we study the effect of the cosmic web on the gas-phase metallicity of low-redshift galaxies in observations and in simulations. Our goal is to establish whether the cosmic web contributes to the observed scatter in the MZR and to explore possible underlying physical mechanisms to that contribution using

<footnote n="1">¹School of Physics and Astronomy, University of St Andrews, St Andrews, UK. ²Institute for Astronomy, University of Edinburgh, Royal Observatory, Edinburgh, UK. ³Aix Marseille Univ, CNRS, CNES, LAM, Marseille, France. ✉e-mail: callum.donnan@ed.ac.uk</footnote>
<figure><img src="image_4.png" /></figure>

**Fig. 1** | Mass-metallicity relations in SDSS DR7 split by the distance to filaments and nodes. a, Mass-metallicity relation for the 10th and 90th percentiles of $d_{\text{skeel}}/\langle D_z \rangle$ (where $d_{\text{skeel}}$ is the distance to the nearest filament) for galaxies in SDSS DR7. b, Mass-metallicity relation for the 10th and 90th percentiles of $d_{\text{node}}/\langle D_z \rangle$ (where $d_{\text{node}}$ is the distance to the nearest node) for galaxies in SDSS DR7. Solid lines indicate the mean gas-phase metallicity calculated for stellar mass bins of width 0.1 dex. Error bars indicate the s.e.m. Coloured numbers indicate the number of galaxies in each MZR. The grey histograms show two-dimensional histograms of individual galaxies. Differences in gas-phase metallicities are present between the closest 10% and most distant 10% of galaxies from filament and nodes, such that galaxies closer to filaments and nodes have higher gas-phase metallicities compared with their more distant counterparts.

simulations. Specifically, we investigate how the cosmic web impacts the metal and gas contents of galaxies via (1) its modulation of halo assembly history and (2) its influence on the net gas supply to galaxies. We study these two potential mechanisms in one simulation alone (IllustrisTNG), acknowledging that different cosmological hydrodynamical models may show different results.

Gas-phase metallicity probes ionized, rather than neutral, gas. Ionized gas is less directly linked to gas supply and gas accretion, but it bears the imprint of past stellar evolution, galactic outflows and inflows. Studying it allows one to ask what the effect of the cosmic web on these mechanisms is. Gas-phase metallicity also has the advantage that it is more readily available and will be measurable up to $z \approx 1.4$ in surveys sufficiently dense and wide to reliably extract the cosmic web, such the forthcoming Dark Energy Spectroscopic Instrument survey$^{22}$. The Dark Energy Spectroscopic Instrument survey and other large-scale spectroscopic experiments will provide a step change in our understanding of the role of the cosmic web in the evolution of galaxies at low redshift, refining the results presented here.

## The MZR in observations

Our observational sample consists of emission-line galaxies from the Sloan Digital Sky Survey$^{23}$ (SDSS) DR7 Main Galaxy Sample$^{24,25}$, with a median redshift of 0.071 and median stellar mass of $10^{10}$ solar masses ($M_{\odot}$). Sample selection is detailed in the Methods, which also provides details of the catalogue of galaxy metallicities and estimates of the distance to cosmic web features. In this study, the term cosmic web will be used to refer to regions that are topologically different, and classified as filaments or nodes (see further details in the Methods). There is a sampling effect as a function of redshift, and therefore every distance to filaments or nodes is normalized by the redshift-dependent mean intergalaxy separation $\langle D_z \rangle$.

The MZR for this sample is shown in Fig. 1, as the background histogram. As a first illustration of the effect of the cosmic web on the MZR, we began by plotting the mean MZR in the 10% of galaxies closer and further from filaments (Fig. 1a) and nodes (Fig. 1b) as in coloured lines. At fixed stellar mass, galaxies closer to filaments have higher gas-phase metallicities compared with those more distant, particularly at low stellar mass. Galaxies closer to nodes show a higher average gas-phase metallicity, with an average difference of approximately 0.02 dex, at all stellar masses.

To further quantify the effect of the cosmic web on MZR, we first computed the gas-phase metallicity residuals with respect to the mean value of the full population, evaluated as a function of stellar mass: that is, for each galaxy we quantified its deviation from the mean MZR at the galaxy's stellar mass. Next, we determined whether these residuals were correlated with the distance to filaments or nodes. Figure 2a,b shows the overall distribution of the distance to filaments and distance to nodes. The 10th and 90th percentiles, used in Fig. 1, are indicated by the red dashed lines. Figure 2c,d shows that the metallicity residuals vary as a function of the distance to nodes and filaments (solid lines) in two slices of stellar mass, separated at $\log(M_{\star}/M_{\odot}) = 10$ (the median stellar mass of the sample). The correlation between gas-phase metallicity residuals and the distance to nodes is negative and statistically significant in both mass bins, meaning that the hypothesis that the two variables are uncorrelated is rejected at over $5\sigma$ (the significance of the correlation between the metallicity residual and distance was assessed via the Spearman's rank-order coefficient; see further details in the Methods): galaxies closer to nodes are more likely to have gas-phase metallicities above the average than those farther from nodes. We find a shallower dependence of the residuals on the distance to filaments, which is significant only at lower stellar masses. These observations are in agreement with the visual representation shown in Fig. 1.

**The role of overdensity.** Previous studies have shown that galaxies residing in overdensities have higher gas-phase metallicities$^{26–28}$, and have suggested that in overdense regions the ISM was pre-enriched at higher redshift. A relationship between gas-phase metallicity and overdensity is also seen in our data (Supplementary Fig. 3). As measurements of the cosmic web are typically correlated with overdensity$^{29}$, it was critical to assess how much our results were driven by the distance to the cosmic web, beyond the known effect of overdensity. We made this assessment by shuffling our data such that overdensity information is kept, but cosmic web distances were randomized before recomputing the residuals (see the Methods for full details). In this test, if the observed relationship between metallicity and shuffled distances remained, we could infer that it is overdensity, and not the distance to cosmic web, that drove the signal in the unshuffled data. The results are shown as the dashed
<figure><img src="image_5.png" /><figcaption>**Fig. 2** | Gas-phase metallicity residuals as function of the distance to filaments and nodes in SDSS DR7. **a,b,** One-dimensional histograms of the normalized distance to filaments (**a**) and nodes (**b**) for the selected SDSS DR7 galaxy sample. Dashed red lines indicate the 10th and 90th percentiles corresponding to the selection made in Fig. 1. **c,d,** Binned residuals of the mass-metallicity relation as a function of the normalized distance to filaments (**c**) and nodes (**d**) are shown by the solid lines. Binned residuals of the gas-phase metallicity shuffled by overdensity as a function of the normalized distance to filaments (**c**) and nodes (**d**) are shown by the dashed lines. Negative correlations between the gas-phase metallicity residuals and the distance to nodes and filaments (at low stellar mass) were removed when shuffling was performed. Error bars represent the s.e.m.</figcaption></figure>

lines in Fig. 2c,d. The gradients are visibly reduced, particularly for nodes. We therefore interpret the relationship between the metallicit-y residual and distance to cosmic web in our unshuffled data to be primarily driven by the cosmic web, and not by overdensity. Having established this, we turned to IllustrisTNG to help us interpret our results on a qualitative level.

## The MZR in simulations

Modern cosmological hydrodynamical simulations can resolve many baryonic processes on galactic scales, within a cosmological volume, and provide good matches to observations³⁰. Here, we use TNG300 of the IllustrisTNG project³¹,³² to: (1) attempt to reproduce the trends seen in our observational work, and (2) investigate the causes. The details of our sample selection and post-processing are given in the Methods. In summary, we selected galaxies in TNG300 by their colour, gas content and stellar mass at $z=0.1$. We did not make mock observations in this study—our goal was not to reproduce the observations exactly, but instead to check whether simulations show the same qualitative trends; and if so, to use simulations to understand what processes may be at play.

The mass-metallicity relation for the TNG300 sample, split by the 10th and 90th percentiles of the distance to the cosmic web, is shown by the solid lines in Fig. 3 (distance to filaments and nodes in Fig. 3a,b, respectively). There is a small difference in gas-phase metallicity with the distance to filaments, with a higher gas-phase metallicity found for the 10% closest galaxies. For nodes, a higher gas-phase metallicity for galaxies in their vicinity is clearly

identified at all stellar masses in the range $9 < \log(M_*/M_\odot) < 10.2$ with an average difference of approximately 0.1 dex between the 10% closest and 10% most distant galaxies.

We investigated the correlation between gas-phase metallicity residuals and distances to the cosmic web in the same way as we did in our observational sample, shown for TNG300 in Fig. 4. There is a strong negative correlation for nodes, with galaxies displaying a higher gas-phase metallicity than average closer to nodes. This is present at both stellar masses with similar strength, although the sample size is notably smaller at $\log(M_*/M_\odot) > 10$ due to the smaller maximum mass in the galaxy selection in Fig. 4. Once again, the hypothesis that the residuals and distance to node are uncorrelated is rejected at greater than $5\sigma$ significance using the Spearman's rank-order coefficient. When looking at distances from filaments, we observe a slight trend in residuals, which increases at very small distances from filaments.

To investigate the role of overdensity in the simulation, we performed the same shuffling technique that we did with the data (shown by the light dashed lines in Fig. 4c,d). As with the data, the correlations were not present in the shuffled simulated data, indicating that overdensity did not dominate the signal we see in the solid lines in Fig. 4c,d. In the case of TNG300, we also took a more straightforward approach, afforded by the larger number of galaxies and cleaner overdensity values (enabled by the higher number density and three-dimensional positions), and simply recomputed the MZR as a function of distance to the cosmic web. However, we used only galaxies within a small bin of overdensity, centred at the
<figure><img src="image_6.png" /><figcaption>**Fig. 3** | Mass-metallicity relations in IllustrisTNG split by the distance to filaments and nodes. **a.** Mass-metallicity relations of star-forming galaxies in TNG300 at $z=0.1$ separated into bins by the 10% closest to and 10% most distant from filaments. Galaxies at $d_{\text{node}} < 3.5$ Mpc are not included. **b.** Mass-metallicity relations of star-forming galaxies in TNG300 separated by the 10% closest to and 10% most distant from nodes. Solid lines indicate the MZR computed for galaxies in the full overdensity range. Dashed lines indicate the MZR computed for galaxies fixed to the median overdensity (±0.32σ) in the sample. Coloured numbers indicate the number of galaxies in each MZR, with the smaller number representing the number for fixed overdensity. Grey histograms show two-dimensional histograms of individual galaxies. Error bars indicate the s.e.m. Differences in gas-phase metallicities are present between the closest 10% and most distant 10% of galaxies from filament and nodes in TNG300, independently of overdensity.</figcaption></figure>

sample median ±0.32σ—this is shown by the solid lines in Fig. 3. The difference between the MZR computed using all overdensities and the MZR computed using a small bin of overdensity was small, and much smaller than the difference between the MZR computed at different distances from the cosmic web. We again interpret these results as evidence that the effect we observed with respect to the cosmic web was not dominated by overdensity. This conclusion holds when using overdensity computed with Gaussian kernels of 3 Mpc, 6 Mpc or 9 Mpc.

The simulation therefore showed a qualitative agreement with observations, in that the effect was larger with nodes than filaments, and in both cases the gas-phase metallicity of galaxies increased with decreasing distance. Quantitatively, we note that the role of filaments was similar in simulations, whereas the role of nodes was amplified. This discrepancy in the role of nodes can be partly explained by the fact that the number density was higher in our TNG300 sample, resulting in typically smaller values of $d_{\text{node}}$. As the strength of the signal increased with decreasing $d_{\text{node}}$, we then expected a stronger signal in our TNG300 sample. The horizontal scales of Figs. 2 and 4 are not directly comparable. However, taking the mean value of $(D_z) = 8$ Mpc, we see that in SDSS DR7 data, we have very few galaxies with $d_{\text{node}} \lesssim 0.8$ Mpc, which is where we cut off the plot. The amplitude of the residuals at that distance is consistent between the two figures. The agreement between observations and simulations suggests that there is insight to be gained from further investigating the nature of these trends in the simulation, and we turn to that next.

## The impact of the cosmic web on gas-phase metallicity

To understand how the cosmic web modulates the gas-phase metallicity, we explored different mechanisms that regulate gas-phase metallicity in galaxies. The metallicity of the gas in a galaxy is increased by star formation whereby stars produce metals through nuclear fusion and expel metals into the ISM through feedback such as stellar winds and supernovae. It is theorized that the metallicity of the gas could be lowered by the accretion of metal-poor gas from the circumgalactic medium and intergalactic medium. This dilutes the enriched gas in the galaxy, lowering the overall gas-phase metallicity of the ISM¹⁷.

### Gas mass fractions and the role of inflows.
We begin by looking at the gas fraction, $M_{\text{gas}}/M_*$, as a function of stellar mass for galaxies in the 10th and 90th percentiles of the distance to nodes and filaments. The gas mass and stellar mass were computed within the stellar mass half-radius. We thereby considered gas that has reached the ISM, rather than probing gas in the circumgalactic medium³³. Limiting the gas to the galaxies' half-light radius is also more comparable to our observational results, due to the SDSS fibre aperture. Figure 5 displays the gas fraction as a function of stellar mass for galaxies in opposing percentiles of the distance to filaments and nodes. Figure 5a shows that the difference between the gas fractions of galaxies close to filaments and those that are distant from filaments is very small; this is true at all stellar masses considered. In the scenario whereby gas-phase metallicity is lowered with increased gas accretion, the similarity in the gas fractions between the two samples is fully consistent with the similarity in their gas-phase metallicities. However, a small difference in the gas fraction of galaxies as a function of the distance to filament is observed if we restricted our analysis to $\log[d_{\text{skel}} (\text{Mpc})] < 0.2$ corresponding to the decline in gas-phase metallicity close to filaments in Fig. 4.

The gas mass fraction as a function of stellar mass for galaxies in different distances to nodes is shown in Fig. 5b. Galaxies closer to nodes have a lower gas fraction than those more distant from nodes, with the difference becoming more pronounced at low stellar mass. In the scenario above, whereby gas accretion decreases metallicity, once again the results in Figs. 3 and 5 are consistent: in that scenario, galaxies close to nodes have less access to an external gas supply, which is typically metal poor¹⁷, and therefore experience less metal dilution, explaining their higher gas-phase metallicity.

### Star-formation histories and the role of halo assembly.
Simulations show that the ages of dark-matter haloes are correlated with the age of the stellar populations of the galaxies they host, especially at low halo or stellar mass⁸, and that star-formation histories play a role in regulating the metallicity of the gas through chemical enrichment. To investigate the role of the cosmic web on the gas-phase metallicity, we therefore looked at the star-formation histories of the galaxies in two stellar mass bins (separated at $\log(M_*/M_\odot) = 10$) and in two bins of the distance to the cosmic web (the 10th and
<figure><img src="image_7.png" /></figure>

**Fig. 4** | Gas-phase metallicity residuals as function of the distance to filaments and nodes in IllustrisTNG. **a,b,** One-dimensional histograms of the distance to filaments (**a**) and nodes (**b**) for the selected TNG300 galaxy sample. Dashed red lines indicate the 10th and 90th percentiles corresponding to the selection made in Fig. 3. **c,d,** Binned residuals of the mass-metallicity relation as a function of the distance to filaments (**c**) and nodes (**d**) are shown by the solid lines. Binned residuals of the gas-phase metallicity shuffled by overdensity as a function of the distance to filaments (**c**) and nodes (**d**) are shown by the dashed lines. Negative correlations between the gas-phase metallicity residuals and distances to filaments (up to $d_{\text{skel}} \approx 10^{0.2}$ Mpc) and nodes were removed when shuffling was performed, pointing towards the role of the cosmic web, beyond overdensity. Error bars represent the s.e.m.

90th percentiles). We also analysed the stellar metallicity histories, to help interpret the role of star formation in the regulation of chemical enrichment of the galaxy. The results are shown in Fig. 6, with the redshift at which half of the stellar mass has been formed ($z_{1/2}$) indicated for each sample. Galaxies closer to nodes, on average, formed their stars earlier with more active star formation in the past, in direct agreement with studies that investigated halo assembly with cosmic web environment⁵. To characterize the significance of the result, we performed a Kolmogorov–Smirnov test on the distributions of $z_{1/2}$ between the two distance bins with a significance of 7.88σ and 3.42σ for $\log(M_*/M_\odot) < 10$ and $\log(M_*/M_\odot) > 10$, respectively. The impact of the earlier star-formation activity in galaxies closer to nodes on the stellar metallicity is evident in Fig. 6c,d, where galaxies closer to nodes have increased chemical enrichment. Therefore, the scenario whereby the cosmic web modulates gas-phase metallicity by modulating star-formation histories is fully consistent with our observations, provided that galaxies retain the enriched gas that is expelled from stars through supernovae and stellar winds.

Although not shown here, filaments have a very small impact on the star-formation histories and chemical enrichment, fitting well with the observed negligible effect of filaments on the gas-phase metallicity in Fig. 3a.

## Conclusions

This work has shown a connection between the cosmic web and the gas-phase metallicity of galaxies. Our observational analysis shows

that the scatter in the galaxy stellar mass–gas metallicity relation (indicated by the offset in gas-phase metallicity at fixed stellar mass from the median relation) is significantly correlated with the distance to nodes in the cosmic web, but notably less correlated for filaments. Crucially, we have shown that this is an effect that is specific to the anisotropic nature of the cosmic web, and not driven by overdensity. We conclude that nodes and filaments have different roles in the scatter of the mass–metallicity relation—information that is lost if one quantifies the environment by overdensity alone.

Our analysis of IllustrisTNG demonstrates that the relationship between gas-phase metallicity and the distance to nodes can be explained by galaxies closer to nodes having limited access to low-metallicity gas and, at the same time, having experienced a more active star-formation history in the past, meaning that they have enriched their interstellar medium with more metals than galaxies of the same mass in different cosmic web environments. The qualitative agreement between TNG300 and SDSS DR7—despite quantitative differences—is encouraging, and suggests that comparing TNG300 and SDSS DR7 was a worthwhile exercise. However, current limitations of cosmological hydrodynamical simulations, particularly with respect to baryonic physics, mean that quantitative agreement with observations is not yet always possible. Our current work, therefore, offers a valuable opportunity in terms of model constraints: it will be informative to contrast other current and future models with our observations.

Disentangling the contributions from different physical mechanisms, and unfolding the different roles of filaments and nodes, will
<figure><img src="image_8.png" /></figure>

**Fig. 5** | Gas fraction as function of the distance to filaments and nodes in IllustrisTNG. a,b, Gas fraction of galaxies (within stellar mass half-radius) separated into the 10% closest to and 10% most distant from filaments (a) and nodes (b). Error bars indicate the s.e.m. Coloured numbers represent the number of galaxies in each sample. Each line matches the samples shown in the respective panels of Fig. 3. No difference in the gas fraction was found for galaxies as function of the distance to filaments. Galaxies closer to nodes have lower gas fractions compared with galaxies of the same mass farther away from nodes.

<figure><img src="image_9.png" /></figure>

**Fig. 6** | Star-formation and stellar metallicity histories in IllustrisTNG. a,b, Mean fractional stellar mass formed as a function of lookback time in 400 bins for two galaxy samples at $z=0.1$, defined as the 10% closest and 10% most distant from nodes, at a stellar mass of $\log(M_*/M_\odot) < 10$ (a) and $\log(M_*/M_\odot) > 10$ (b). c,d, Mean mass-weighted stellar metallicity formed in each bin as a function of lookback time in 400 bins for two galaxy samples at $z=0.1$, defined as the 10% closest to and 10% most distant from nodes at a stellar mass of $\log(M_*/M_\odot) < 10$ (c) and $\log(M_*/M_\odot) > 10$ (d). At all stellar masses considered, galaxies closer to nodes assembled their stellar mass earlier than those more distant. Galaxies closer to nodes have higher stellar metallicities, particularly in their recent past.

soon be possible by combining forthcoming statistically powerful surveys such as the Dark Energy Spectroscopic Instrument survey with detailed analysis of various simulations and forward-modelled mock observations. Our work here is an important first step towards that goal.

## Methods

SDSS. The SDSS<sup>23</sup> is a large galaxy imaging<sup>24</sup> and spectroscopic<sup>35</sup> survey covering over 14,000 square degrees of sky at present. In this study, we used data from the DR7<sup>24</sup> Main Galaxy Sample<sup>25</sup>, which consists of a magnitude-limited sample to a petrosian r-band magnitude of $r_p = 17.77$. This sample is well suited to our work, as the survey provides a complete and dense sample of galaxies over a
large contiguous area for the determination of cosmic web features, as well as
high-quality spectra enabling the determination of detailed galaxy properties (such
as the stellar mass and gas-phase metallicity).

**IllustrisTNG.** IllustrisTNG is a cosmological magneto-hydrodynamical suite of simulations that models galaxy formation and evolution on cosmological scales<sup>11,12</sup> by solving the coupled evolution of dark matter and baryons. The IllustrisTNG collaboration provides simulation outputs from runs performed in different volumes and at different resolutions. We mainly utilized the TNG300-1 run, corresponding to a volume of 302.6³ cMpc³ (co-moving Mpc) with a gas particle resolution of $m_{\text{baryon}} = 7.6 \times 10^6 \text{M}_\odot \text{h}^{-1}$. This is the largest of the TNG300 simulations, providing a wider variety of environments and better statistics. The smaller, higher-resolution boxes were used only to check the robustness of the gas-phase metallicity relation in TNG300.

**Catalogues and sample selections.** We use the MPA/JHU catalogue from SDSS DR7<sup>24</sup>, which contains stellar masses<sup>36</sup> and gas-phase metallicities<sup>18</sup>. The stellar masses used are total stellar masses from photometry fits. The gas-phase metallicites in the catalogue were determined using a photoionization model with the measurements of multiple emission-line fluxes. The metallicities have a median $1\sigma$ error of 0.03 dex. In IllustrisTNG, we used the group catalogues provided by the simulation, which contain stellar masses, gas-phase metallicities and gas masses for each galaxy in snapshot 91. To better match the metallicities in SDSS DR7 data, we restricted our gas-phase metallicity measurements in TNG300 to gas that is actively forming stars. Galaxy colours for IllustrisTNG were provided by a supplementary catalogue<sup>10</sup>, from which we extracted colour-corrected colours and magnitudes.

To facilitate the comparison between observations and simulations, we
performed colour and magnitude cuts in TNG300. The goal here was to
approximate the two samples, acknowledging that matching samples exactly is not
possible nor desirable, given that simulations do not reproduce observed galaxies
precisely. We broadly addressed sample differences due to light-cone versus
snapshot, and the need to select galaxies in TNG that would have a measurable
gas-phase metallicity—in the SDSS, these are galaxies with emission lines strong
enough to be measured in individual spectra with the required signal-to-noise
ratio. Effectively, this means removing lower-mass and redder galaxies in TNG,
as well as those without gas. We selected galaxies with $-21.4 < r < -18.4$ and
$0.3 < g - r < 0.7$. The minimum stellar mass taken was $\log(M_*/M_\odot) = 9.25$,
although the magnitude and colour cuts above effectively remove most galaxies
with $\log(M_*/M_\odot) < 9.5$. Finally, a maximum stellar mass of $\log(M_*/M_\odot) = 10.2$
was chosen as we found discrepancies in the mass–metallicity relation between
TNG300, TNG100 and TNG50 that seemed to be associated with TNG300 failing
to resolve relevant physical processes at high stellar mass. This is a similar range
to that used in another study of the mass–metallicity relation in IllustrisTNG<sup>37</sup>,
which showed that the MZR in IllustrisTNG is a good match to observations below
that stellar mass cutoff. Our selection yielded a total sample of 97,679 galaxies in
TNG300 out of a total of 225,105 galaxies above the minimum stellar mass. No
cuts were made to SDSS DR7, other than the natural selection effect of requiring
gas-phase metallicity measurements. This selected 65,984 galaxies from the
302,312 in the full sample. Further information and plots on the resulting samples
are given in the Supplementary Information, with Supplementary Fig. 1 showing
the colour selection on a colour–magnitude diagram and Supplementary Fig. 2
showing the resultant stellar mass distributions.

This 302,312 galaxy sample was initially selected from the full catalogue of 927,552 galaxies in SDSS DR7 where the sample was selected to galaxies that were within a right ascension of 120° and 220° as this provided a contiguous area allowing Discrete Persistent Structures Extractor (DisPerSE) measurements of the distances to the cosmic web. The cuts described here generated a sample of 65,984 SDSS galaxies over approximately 6,700 deg².

**Classification of the cosmic web and distances to nodes and filaments.**

The cosmic web was extracted using DisPerSE<sup>18,39</sup>, which measures persistent, filamentary structures in three dimensions. This traces out the large-scale structure using the positions of galaxies, categorizing the structure into nodes, filaments, walls and voids. This allowed us to generate a catalogue of $d_{\text{skel}}$ and $d_{\text{node}}$ for every galaxy in SDSS DR7 using the procedure from a recent paper<sup>40</sup>. DisPerSE was also used to generate a catalogue of the same type for every galaxy in snapshot 91 of TNG300. DisPerSE measures the significance of the attachment between two points in the density field in terms of the number of standard deviations, $\sigma$. This is called the persistence level. A persistence level of $3\sigma$ was used to generate the catalogue for SDSS DR7 and a level of $4\sigma$ was used for TNG300.

In observations, there is a redshift dependence on the sampling of galaxies. If distances to the cosmic web were computed without accounting for this issue, redshifts with a higher number density $n(z)$ would have artificially lower distances to nodes and filaments. This issue is typically resolved simply by normalizing every distance by the mean intergalaxy separation, $\langle D_z \rangle$, as a function of $z$: $\langle D_z \rangle = n(z)^{-3}$. In SDSS DR7, $\langle D_z \rangle$ varies between approximately 4 Mpc and 12 Mpc.

When selecting the distance bins by the distance to filament in SDSS DR7, we excluded any galaxies at $d_{\text{node}} < 1$ Mpc to remove any influence from nodes and

therefore isolate the relationship between metallicity and distance to filaments. This distance has been shown to be a robust cutoff for removing the influence of nodes in SDSS DR7<sup>11</sup>. In TNG300, we excluded galaxies at $d_{\text{node}} < 2$ Mpc, which was determined using the method described in a previous paper<sup>10</sup>.

**Residuals as a function of the distance to filaments and nodes.** The mean mass–metallicity relations (Figs. 1 and 3) were determined using stellar mass bins of width 0.1 dex by taking the mean gas-phase metallicity in each stellar mass bin. The uncertainty of the metallicity in each bin was given as the standard error on the mean, $\sigma_{\text{mean}} = \frac{d_{\text{bin}}}{\sqrt{N}}$, where $\sigma_{\text{bin}}$ is the standard deviation of each bin and N is the number of galaxies in each bin. This procedure was performed for the SDSS DR7 and IllustrisTNG samples.

The residuals of the mass–metallicity relation (Figs. 2 and 4) were determined by taking the difference between the gas-phase metallicity of each galaxy and the mean metallicity for that stellar mass. The metallicity residuals were then binned and plotted as a function of distance to filament and node in bins of width 0.2 dex between a log(dᵢ)/(Dᵢ) of -1 and 1 for SDSS DR7 and between a log(dᵢ) of -1 and 1.2 in TNG300 (where k refers to filaments or nodes). The uncertainty is given as the error on the mean, $\frac{d_{\text{bin}}}{\sqrt{N}}$.

Our interpretation of the results shown in Fig. 2 rely on quantifying how
significant the correlation between gas metallicity residual and distance to the
cosmic web is. We used the Spearman's rank correlation coefficient, $r_s$, to quantify
the level of correlation between two variables in a non-parametric way, without
assuming a linear relationship between the two (only that the relationship is
monotonic). Associated with each $r_s$, we computed a *P* value that indicated the
probability that a given value of $r_s$ would occur from two uncorrelated variables.
$r_s$ and *P* values were computed using unbinned data.

We accounted for the effects of overdensity by shuffling the data with respect to overdensity. In this procedure, we constructed a new binned sample such that the distribution of overdensity of each original bin of log(dᵢ) was reproduced, but we drew galaxies from the full galaxy population. The result is that each bin of our shuffled sample had an overdensity distribution that matched, by construction, the original distribution, but log(dᵢ) values were no longer constrained. We then recomputed the metallicity residuals in each bin, and plotted them as a function of the log(dᵢ) of the bin that they were constructed to match. If the original correlations remained, we concluded that the original signal was driven by overdensity, rather than distance to cosmic web features. If, on the other hand, the original correlations were notably reduced, we concluded that overdensity did not play a major role in driving the original correlations.

Measurements of overdensity were computed using a Gaussian kernel of 3 Mpc for each galaxy in SDSS DR7 and TNG300. We also computed overdensities using kernel sizes of 6 Mpc and 9 Mpc to check for potential inconsistencies in our results when using different kernel sizes. As noted in the main text, our results held, independent of the size of Gaussian kernel. The 'shuffling' procedure was implemented in both SDSS DR7 and TNG300 metallicity residuals. In addition, in TNG300 we leveraged the larger sample size and more robust measurements of overdensity to also demonstrate the effect of distances to cosmic web in a very small bin of overdensity, as shown in Fig. 3.

**Star-formation and enrichment histories in IllustrisTNG.** In IllustrisTNG, we extracted the ages and metallicities of all stellar particles bound to each subhalo in our sample out to two effective radii. The star-formation histories were computed as the mass formed in each of 400 bins of lookback time, linearly spaced between 0 and the age of the Universe at $z=0.1$. The metallicity histories were computed by taking the mass-weighted metallicity in the same bins.

**Data availability**

Data for SDSS DR7 and IllustrisTNG are publicly available at https://www.mpa.mpa-garching.mpg.de/SDSS/DR7/ and https://www.tng-project.org/data/. DisPerSE catalogues are available from the corresponding author upon reasonable request.

**Code availability**

DisPerSE is publicly available at: http://www2.iap.fr/users/sousbie/web/html/indexba87.html?category/Install. All other code used in this project is available from the corresponding author upon reasonable request.

Received: 26 August 2021; Accepted: 31 January 2022;
Published online: 14 March 2022

**References**

1. Wechsler, R. H. & Tinker, J. L. The connection between galaxies and their dark matter halos. *Annu. Rev. Astron. Astrophys.* **56**, 435–487 (2018).

2. Blanton, M. R. & Moustakas, J. Physical properties and environments of nearby galaxies. *Annu. Rev. Astron. Astrophys.* **47**, 159–210 (2009).

3. Bond, J. R., Kofman, L. & Pogosyan, D. How filaments of galaxies are woven into the cosmic web. *Nature* **380**, 603–606 (1996).
4. Dalal, N., White, M., Bond, J. R. & Shirokov, A. Halo assembly bias in hierarchical structure formation. Astrophys. J. 687, 12–21 (2008).

5. Borzyszkowski, M., Porciani, C., Romano-Díaz, E. & Garaldi, E. ZOMG - I. How the cosmic web inhibits halo growth and generates assembly bias. Mon. Not. R. Astron. Soc. 469, 594–611 (2017).

6. Musso, M. et al. How does the cosmic web impact assembly bias? Mon. Not. R. Astron. Soc. 476, 4877–4906 (2018).

7. Paranjape, A., Hahn, O. & Sheth, R. K. Halo assembly bias and the tidal anisotropy of the local halo environment. Mon. Not. R. Astron. Soc. 476, 3631–3647 (2018).

8. Tojeiro, R. et al. Galaxy And Mass Assembly (GAMA): halo formation times and halo assembly bias on the cosmic web. Mon. Not. R. Astron. Soc. 470, 3720–3741 (2017).

9. Alpaslan, M. et al. Galaxy And Mass Assembly (GAMA): stellar mass growth of spiral galaxies in the cosmic web. Mon. Not. R. Astron. Soc. 457, 2287–2300 (2016).

10. Kraljic, K. et al. Galaxy evolution in the metric of the cosmic web. Mon. Not. R. Astron. Soc. 474, 547–571 (2018).

11. Winkel, N. et al. The imprint of cosmic web quenching on central galaxies. Mon. Not. R. Astron. Soc. 505, 4920–4934 (2021).

12. Kleiner, D., Pimbblet, K. A., Jones, D. H., Koribalski, B. S. & Serra, P. Evidence for H I replenishment in massive galaxies through gas accretion from the cosmic web. Mon. Not. R. Astron. Soc. 466, 4692–4710 (2017).

13. Crone Odekon, M. et al. The effect of filaments and tendrils on the H I content of galaxies. Astrophys. J. 852, 142 (2018).

14. Darvish, B. et al. Spectroscopic study of star-forming galaxies in filaments and the field at $z \sim 0.5$: evidence for environmental dependence of electron density. Astrophys. J. 814, 84 (2015).

15. Genel, S. How environment affects galaxy metallicity through stripping and formation history: lessons from the Illustris simulation. Astrophys. J. 822, 107 (2016).

16. Gupta, A. et al. Chemical pre-processing of cluster galaxies over the past 10 billion years in the IllustrisTNG simulations. Mon. Not. R. Astron. Soc. 477, L35–L39 (2018).

17. Maiolino, R. & Mannucci, F. De re metallica: the cosmic chemical evolution of galaxies. Astron. Astrophys. Rev. 27, 3 (2019).

18. Tremonti, C. A. et al. The origin of the mass-metallicity relation: insights from 53,000 star-forming galaxies in the Sloan Digital Sky Survey. Astrophys. J. 613, 898–913 (2004).

19. De Lucia, G., Xie, L., Fontanot, F. & Hirschmann, M. Gas accretion regulates the scatter of the mass-metallicity relation. Mon. Not. R. Astron. Soc. 498, 3215–3227 (2020).

20. van Loon, M. L., Mitchell, P. D. & Schaye, J. Explaining the scatter in the galaxy mass-metallicity relation with gas flows. Mon. Not. R. Astron. Soc. 504, 4817–4828 (2021).

21. Mannucci, F., Cresci, G., Maiolino, R., Marconi, A. & Gnerucci, A. A fundamental relation between mass, star formation rate and metallicity in local and high-redshift galaxies. Mon. Not. R. Astron. Soc. 408, 2115–2127 (2010).

22. Martini, P. et al. Overview of the Dark Energy Spectroscopic Instrument. In Ground-based and Airborne Instrumentation for Astronomy VII Vol. 10702 (eds Evans, C. J. et al.) 107021F (SPIE, 2018).

23. York, D. G. et al. The Sloan Digital Sky Survey: technical summary. Astrophys. J. 120, 1579–1587 (2000).

24. Abazajian, K. N. et al. The Seventh Data Release of the Sloan Digital Sky Survey. Astrophys. J. Suppl. 182, 543–558 (2009).

25. Strauss, M. A. et al. Spectroscopic target selection in the Sloan Digital Sky Survey: the main galaxy sample. Astrophys. J. 124, 1810–1824 (2002).

26. Peng, Y.-j & Maiolino, R. The dependence of the galaxy mass-metallicity relation on environment and the implied metallicity of the IGM. Mon. Not. R. Astron. Soc. 438, 262–270 (2014).

27. Chartab, N. et al. The MOSDEF Survey: environmental dependence of the gas-phase metallicity of galaxies at $1.4 \le z \le 2.6$. Astrophys. J. 908, 120 (2021).

28. Williams, R. J. et al. Dynamics and metallicity of far-infrared selected galaxies. Mon. Not. R. Astron. Soc. 443, 3780–3794 (2014).

29. Libeskind, N. I. et al. Tracing the cosmic web. Mon. Not. R. Astron. Soc. 473, 1195–1217 (2018).

30. Nelson, D. et al. First results from the IllustrisTNG simulations: the galaxy colour bimodality. Mon. Not. R. Astron. Soc. 475, 624–647 (2018).

31. Pillepich, A. et al. Simulating galaxy formation with the IllustrisTNG model. Mon. Not. R. Astron. Soc. 473, 4077–4106 (2018).

32. Springel, V. et al. First results from the IllustrisTNG simulations: matter and galaxy clustering. Mon. Not. R. Astron. Soc. 475, 676–698 (2018).

33. Tumlinson, J., Peeples, M. S. & Werk, J. K. The circumgalactic medium. Annu. Rev. Astron. Astrophys. 55, 389–432 (2017).

34. Gunn, J. E. et al. The Sloan Digital Sky Survey photometric camera. Astrophys. J. 116, 3040–3081 (1998).

35. Smee, S. A. et al. The Multi-object, fiber-fed spectrographs for the Sloan Digital Sky Survey and the Baryon Oscillation Spectroscopic Survey. Astrophys. J. 146, 32 (2013).

36. Salim, S. et al. UV star formation rates in the local Universe. Astrophys. J. Suppl. 173, 267–292 (2007).

37. Torrey, P. et al. The evolution of the mass-metallicity relation and its scatter in IllustrisTNG. Mon. Not. R. Astron. Soc. 484, 5587–5607 (2019).

38. Sousbie, T. The persistent cosmic web and its filamentary structure - I. Theory and implementation. Mon. Not. R. Astron. Soc. 414, 350–383 (2011).

39. Sousbie, T., Pichon, C. & Kawahara, H. The persistent cosmic web and its filamentary structure - II. Illustrations. Mon. Not. R. Astron. Soc. 414, 384–403 (2011).

40. Kraljic, K. et al. The impact of the connectivity of the cosmic web on the physical properties of galaxies at its nodes. Mon. Not. R. Astron. Soc. 491, 4294–4309 (2020).

## Acknowledgements

Part of this work made use of the Horizon cluster hosted by the Institut d'Astrophysique de Paris. We thank S. Rouberol for running it smoothly. K.K. acknowledges support from the DEEPDIP project (grant number ANR-19-CE31-0023). Funding for the Sloan Digital Sky Survey IV was provided by the Alfred P. Sloan Foundation, the US Department of Energy Office of Science and the Participating Institutions. The SDSS acknowledges support and resources from the Center for High-Performance Computing at the University of Utah. The SDSS web site is www.sdss.org. The SDSS is managed by the Astrophysical Research Consortium for the Participating Institutions of the SDSS Collaboration including the Brazilian Participation Group, the Carnegie Institution for Science, Carnegie Mellon University, Center for Astrophysics | Harvard & Smithsonian (CFA), the Chilean Participation Group, the French Participation Group, Instituto de Astrofísica de Canarias, The Johns Hopkins University, Kavli Institute for the Physics and Mathematics of the Universe (IPMU)/University of Tokyo, the Korean Participation Group, Lawrence Berkeley National Laboratory, Leibniz Institut für Astrophysik Potsdam (AIP), Max-Planck-Institut für Astronomie (MPI Heidelberg), Max-Planck-Institut für Astrophysik (MPA Garching), Max-Planck-Institut für Extraterrestrische Physik (MPE), National Astronomical Observatories of China, New Mexico State University, New York University, University of Notre Dame, Observatório Nacional/MCTI, The Ohio State University, Pennsylvania State University, Shanghai Astronomical Observatory, United Kingdom Participation Group, Universidad Nacional Autónoma de México, University of Arizona, University of Colorado Boulder, University of Oxford, University of Portsmouth, University of Utah, University of Virginia, University of Washington, University of Wisconsin, Vanderbilt University and Yale University.

## Author contributions

C.T.D. performed the main analysis of the data. C.T.D., R.T. and K.K. interpreted the results and contributed to the writing of the manuscript. K.K. generated the DisPerSE catalogues.

## Competing interests

The authors declare no competing interests.

## Additional information

**Supplementary information** The online version contains supplementary material available at https://doi.org/10.1038/s41550-022-01619-w.

**Correspondence and requests for materials** should be addressed to Callum T. Donnan.

**Peer review information** Nature Astronomy thanks the anonymous reviewers for their contribution to the peer review of this work

**Reprints and permissions information** is available at www.nature.com/reprints.

**Publisher's note** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

© The Author(s), under exclusive licence to Springer Nature Limited 2022