Main

To study hippocampal memory engrams during long-term learning, we designed a goal-oriented learning task for head-fixed mice. Mice ran on a spherical treadmill to collect soy milk rewards on a 4-m-long virtual linear track displayed on monitors around the animal. After at least 10 days of familiarization to this track (familiar context), imaging sessions started in which mice ran alternatingly on this familiar and a visually different, novel track with different reward sites (Fig. 1a, b, Supplementary Video 1). Animals consistently licked more often inside than outside reward zones on both tracks (Fig. 1d). Initially, overall licking and reward-related licking were lower in the novel context than in the familiar context (Extended Data Fig. 1c, d). These differences vanished with learning. On the novel track, the ratio of rewarded to erroneous licks increased markedly on the second training day (Fig. 1d), indicating that mice remembered the rewarded locations.

Fig. 1: Two-photon calcium imaging of hippocampal place cell activity in a virtual environment.
figure 1

a, Experimental schematic. b, Behaviour timeline (see Methods). c, Left, CA1 and DG (top) and CA2/3 (bottom) implantation sites. GCaMP6f (white) and td-Tomato (tdT; red) in parvalbumin (PV)-expressing interneurons. Dotted lines, imaging planes. Right, GCaMP6f and tdT fluorescence in vivo. d, Ratio between rewarded and non-rewarded licks in the familiar (fam, filled circles) and novel (nov, open circles) contexts (n = 15 mice; two-sided signed rank-sum test). e, Calcium traces (grey) with significant transients (red; see Methods) of a GC and linear-track position (blue) over time. Right, calcium activity over track distance of the same GC. f, Top, fraction of active (more than 0.05 transients per s) cells among all neurons. Test for population overlap (χ2 test). Bottom, cells with place fields among active cells. g, Spatial information for all familiar-track-active neurons (ANOVA on ranks, Dunn’s test). Boxes, 25th to 75th percentiles; bars, median; whiskers, 99% range. NS, not significant; ***P < 0.001. Error bars denote s.e.m. For exact P values see Supplementary Table 1.

To measure hippocampal neuronal activity, mice were injected with adeno-associated viruses designed to express the fluorescent calcium indicator GCaMP6f pan-neuronally in CA1 and the dentate gyrus (DG) or CA3 (Fig. 1c). A chronic transcortical imaging window was implanted above CA1 to perform two-photon imaging of CA1 or DG neurons13 (Supplementary Video 2). Implantation did not impair spatial learning in a Barnes maze (Extended Data Fig. 1h, i). CA1 and DG neurons were imaged at depths of around 150 µm and around 700 µm, respectively. To image CA3, we implanted a more lateral window14 (Fig. 1c). Data were obtained predominantly from CA3 (Extended Data Fig. 2d), but some CA2 cells may also have been included14. In all cases, we used fast volumetric scanning to simultaneously record about 500 neurons (see Methods, Supplementary Videos 35).

We first analysed neuronal activity in the familiar and novel contexts (Fig. 1). Consistent with previous findings11,12,15,16, pyramidal cells (PYRs) in CA1–CA3 were substantially more active than granule cells (GCs) (Fig. 1f, Extended Data Fig. 3a, b). We also determined the fraction of cells that was active in the familiar, novel or both contexts with more than 0.05 calcium transients per second. Activation of hippocampal neurons might be predetermined by intrinsic properties17. In line with this idea, we found a marked overlap of active neuronal ensembles between contexts (Fig. 1f, upper row). About 35% of these active neurons had a clearly defined place field (see Methods) on the first recording day in either the novel or the familiar context, or both (Fig. 1f, lower row). Because many neurons were active in both contexts, we investigated whether active neurons were more likely to have a place field in both contexts. However, the familiar- and novel-context place cells appeared to form independent subgroups within the active cell population (Fig. 1f, lower row) indicating that a separate place-coding group or ‘engram’ might exist for each context. Further comparison of spatial coding properties revealed lower average spatial information (see Methods) per active cell (Fig. 1g) and wider place fields (Extended Data Fig. 3c) in GCs compared to CA1–3 PYRs. Thus, GC activity is sparse and has broader and less precise spatial tuning than PYR activity.

Next, we compared neuronal activity between contexts (Fig. 2). Consistent with a previous study15 and their inputs from the entorhinal cortex18, mean activity in GCs decreased in the novel context, whereas mean activity of CA1 and CA2/3 PYRs increased (Fig. 2a). Similarly, novel-context spatial information was markedly lower in the DG, but higher in both CA regions (Fig. 2b). Additionally, there was a trend towards higher place cell numbers on the familiar track than on the novel track, particularly in the DG (n = 30.50 versus 16.42 place cells per experiment, 12 experiments, P = 0.066, paired t-test; Extended Data Fig. 3f). We next investigated the cause of these activity differences between contexts. Hippocampal γ-aminobutyric acid (GABA) interneurons contribute to separation of memory engrams19 and formation of place fields13. We therefore analysed the activity of parvalbumin (PV)-expressing interneurons (PVIs; Extended Data Fig. 4), the most abundant subtype of interneurons in the hippocampus. PVI activity in CA1 and the DG correlated positively with running speed13,20 (Extended Data Fig. 4c–h). PVIs in the DG, but not in CA1, showed decreased activity in the novel context (Extended Data Fig. 4i–l), contrasting with reports from unidentified DG interneurons15. Thus, our data argue against suppression of GCs by enhanced PVI activity, and are instead consistent with predominant recruitment of DG PVIs by local GC inputs.

Fig. 2: Pyramidal cells in CA1 and CA2/3 discriminate between contexts.
figure 2

a, Activity difference scores (see Methods) between novel and familiar contexts for all cells (two-sided signed rank-sum test: novel versus familiar activity). b, Mean spatial information of active cells (two-sided rank-sum test). c, Familiar-track place cell activity plotted for the first (left) and second (middle) block of familiar-context runs and for the novel context (right). d, Mean activity correlations of place cells within familiar (left) and novel context (middle) runs and between contexts (right bars; ANOVA on ranks, Dunn’s test). e, PoV correlations (see Methods) for all experiments within familiar-context runs and between contexts (thin lines). Thick lines denote mean ± s.e.m. (two-sided paired t-test). Boxes, 25th to 75th percentiles; bars, median; whiskers, 99% range. *P < 0.05, **P < 0.01, ***P < 0.001; NS, not significant. For exact P values see Supplementary Table 1.

To probe neuronal discrimination between contexts, we first determined the consistency of place cell firing on the same track between the first and the second block of five consecutive runs. Place cell consistency in the familiar context was high in all hippocampal subfields (Fig. 2c, d; F–F′). The same measure and trial-to-trial reliability were generally lower for novel-context runs, indicating an initially less reliable representation (Fig. 2c, d; N–N′; Extended Data Fig. 3i). Next, we quantified place cell remapping between the familiar and novel contexts. Unexpectedly, activity map correlations between contexts were substantially higher for DG place cells than in CA1 and CA2/3 (Fig. 2c, d; F–N). We confirmed this finding separately in two mice by imaging neuronal activity in CA1 and DG of the same mice (Extended Data Fig. 5). Thus, DG place cell activity was similar between contexts, whereas that of CA1–3 place cells was highly discriminative. We also calculated population vectors (PoVs) for both contexts from the mean calcium activity maps of all cells. PoVs were significantly more dissimilar between contexts as compared to independent runs within the familiar context in CA1 and CA2/3 (P = 0.004, both regions, paired t-test), but not in the DG (P = 0.051, Fig. 2e). Indeed, activity map correlations between contexts were markedly lower in CA1 and CA2/3 than in the DG, indicating stronger remapping in CA1–3. GCs might encode travelled distance and therefore show low context-selectivity. To test this possibility, we let mice run on a simplified linear track with striped walls but no further contextual information (Extended Data Fig. 6a). Under these conditions, GC activity and spatial information were low, and GCs did not show consistent place fields (Extended Data Fig. 6b, c), indicating that they encode the general task layout rather than mere distance. Thus, GCs show reliable place representations and low context discrimination, whereas CA2/3 PYRs and CA1 PYRs prominently encode contextual differences.

To investigate place field stability throughout learning, we imaged the same cells in both contexts on two subsequent days (Fig. 3, Extended Data Fig. 7). Whereas GCs maintained their place field locations in the same context, CA1 PYRs and CA2/3 PYRs displayed substantial remapping (Fig. 3b–d). This was characterized by lower activity map correlations (Fig. 3d, e) and larger shifts of the preferred firing location (Extended Data Fig. 7c). Despite the generally high GC place field stability, activity map correlations between days were lower for GCs encoding the novel context than for those encoding the familiar context. By contrast, hippocampal PYRs showed similarly low stability in both contexts (Fig. 3e). Thus, GCs have stable place fields, whereas place fields in other hippocampal subfields change over days.

Fig. 3: GC place fields are highly stable across days.
figure 3

a, Illustrative example of CA1 cells imaged on subsequent days. b, Activity of familiar-track place cells sorted for day 1. c, As in b for novel-track place cells. d, Left, experimental schematic. Right, activity map correlations between days for all day 1 (d1) place cells (ANOVA on ranks, Dunn’s test). e, Activity map correlations between days for familiar-context (left) and novel-context (right) place cells. f, Mean trial-to-trial reliability of novel-track place cell responses on days 1 and 2. g, Activity map correlations between contexts of day 1 (left) and day 2 (right) place cells. eg, Two-sided rank-sum test. Boxes, 25th to 75th percentiles; bars, median; whiskers, 99% range. *P < 0.05, ***P < 0.001; NS, not significant. For exact P values see Supplementary Table 1.

Place cell stability in CA1 may depend on environmental complexity9. We therefore repeated our experiments in a virtual context without distal visual cues (‘poor’) and a highly enriched, multisensory track (‘rich’; Supplementary Video 6). Notably, the number of place cells was similar between all tracks, but their firing rate, spatial information and day-to-day stability were markedly reduced on the ‘poor’ track (Extended Data Fig. 8). We observed no differences between the ‘rich’ track and our standard contexts, indicating that CA1 place cell representations are also dynamic over days in complex environments.

Next, we investigated learning-induced changes in spatial coding. From day 1 to day 2, there was a substantial increase in the trial-to-trial reliability of place cells in CA1–3, but not in the DG (Fig. 3f, Extended Data Fig. 7d). The DG is required for context discrimination5,6. We therefore tested whether neuronal activity became more distinct between contexts with learning. Unexpectedly, activity correlations between contexts were unchanged in GCs from day 1 to day 2 but were lower for CA1 place cells on day 2 and remained negative in CA2/3 (Fig. 3g). Thus, improved behavioural context discrimination was accompanied by a decorrelation of place cell activity in CA1, but not in the DG.

In light of recent findings20, we compared place coding between the deep and superficial sublayers of CA1. Notably, place field stability across days was slightly higher in deep-layer PYRs (45% difference, P = 0.046; Extended Data Fig. 9i), albeit at generally low levels. Place field reliability and context discrimination were comparable between sublayers (Extended Data Fig. 9g, h).

To investigate the development of spatial representations over the time-course of hippocampus-dependent memory2, we continued imaging sessions for five subsequent days (Fig. 4, Extended Data Fig. 10). Whereas the number of place cells was similar for each context and day (Fig. 4c, white numbers), their firing locations changed markedly in some hippocampal sub-areas. Familiar-context place fields of GCs remained stable throughout all days (Fig. 4a–c) and novel-context place cells showed gradually increasing stability (Fig. 4b, c, Extended Data Fig. 10b). By contrast, CA1 and CA2/3 activity in the same contexts became rapidly more dissimilar over days. For CA2/3 cells, activity map correlations over more than two days dropped below chance levels (Fig. 4d), demonstrating that these neurons constantly remap their place fields.

Fig. 4: Stable coding of GCs persists throughout multiple days, whereas CA2/3 PYRs constantly remap over time.
figure 4

a, Activity maps of all familiar-context place cells sorted by day 3. b, Development of activity map correlations between subsequent days for familiar- (dark) and novel-context (light) place cells (numbers show n; ANOVA on ranks, Dunn’s test; mean ± s.e.m.). c, Mean activity map correlations (colour coded; Pearson’s R) over 5 days and two contexts as indicated on the x-axis. Each row shows mean correlation values for cells that had a place field on the day and track indicated on the y-axis (white numbers show n). d, Mean activity map correlations for familiar-context place cells over days passed. Blue dotted line, chance level correlations for CA2/3 cells obtained by shuffling cell IDs (two-sided rank-sum test, actual versus shuffled correlations, Bonferroni correction; mean ± s.e.m.). e, Schematic: GCs show a highly stable environment representation with low spatial and context selectivity. By contrast, PYRs form highly context-, place- and time-specific ensembles. *P < 0.05; **P < 0.01; ***P < 0.001. For exact P and n values in d see Supplementary Table 1.

Dynamic coding has been described in CA17,8,9,21, CA210 and other associative areas22,23. A gradual variation of active CA1 ensembles links contextual memories acquired close in time7,8,21 and remapping of individual PYRs is driven by synaptic plasticity13,24. By contrast, neuronal ensemble activity in motor areas stabilizes throughout learning25. In the hippocampus, temporally stable coding of GCs may induce heterosynaptic plasticity at CA3 PYR dendrites by associating their activity with temporally dynamic inputs from the entorhinal cortex23 or other CA3 PYRs26. This hypothesis would explain why CA3 ensembles can trigger memory recall independent of GC input even when the DG is required for initial task learning27,28. Our results, together with previous findings8,10, indicate that CA3 coding can be dynamic or stable, potentially depending on the behaviour, proximo-distal location within CA3 (Extended Data Fig. 2e), virtual versus real-world navigation or species differences in entorhinal cortex innervation29. When CA3 is stable, a mechanism similar to that described above may apply at CA3–CA1 synapses.

Traditionally, similar memories are thought to be represented by largely non-overlapping populations of GCs4. However, recent findings indicate that GCs remap only between widely dissimilar environments11, while other cell types (for example, mossy cells) discriminate between similar contexts12. Accordingly, CA2/3 PYR activity was most discriminative between our virtual contexts (Fig. 2d, e). The high similarity of our—mostly mature6—GC activity between contexts may explain why mature GCs mediate generalization between similar contexts rather than pattern separation5.

Our results further suggest that the hippocampus combines stable and dynamic coding and reunites findings of temporally varying neuronal ensembles encoding the same environment7,8 with reports of stable behavioural output upon DG engram reactivation over weeks2,27. Given that the DG is required for the extinction or modification of existing memories acquired in the same scenery28,30, our data support the hypothesis that GCs provide a simplistic but stable representation of the global environment11,12 that serves as a blueprint for spatially and contextually precise, but temporally varying, CA1–3 engrams (Fig. 4e). Such an encoding scheme would enable one to associate memories acquired in the same global environment but still to discriminate between slightly different or temporally separate instances of these memories.

Methods

Mice

All experiments involving animals were carried out according to national and institutional guidelines and approved by the ‘Tierversuchskommission’ of the Regierungspräsidium Freiburg (license no. G16/037) in accordance with national legislation. B6;129P2-Pvalbtm1(cre)Arbr/J mice (PV-Cre; The Jackson laboratory) crossed with B6.Cg-Gt(ROSA)26Sortm9(CAG-tdTomato)Hze/J mice (Ai9-reporter; The Jackson laboratory) were used for all experiments at an age of 7–15 weeks (n = 6 for DG, 5 for CA2/3, 11 for CA1 and 7 for the ‘poor–rich–novel’ (Extended Data Figs. 6, 8) recordings). Age-matched C57/Bl6 mice injected with GFP virus were used as control group for Barnes maze experiments. Mice were housed on a 12-h light–dark cycle in groups of 2–5 mice. After the start of the post-window-implantation training and food restriction, mice were housed individually. No statistical methods were used to predetermine sample size. The experiments were not randomized and the investigators were not blinded to allocation during experiments and outcome assessment.

Virus injections and head plate implantation

All surgical procedures were performed in a stereotactic apparatus (Kopf instruments) under anaesthesia with 1–2% isoflurane and analgesia using 0.1 mg kg−1 buprenorphine. A small (~0.5–1 mm diameter) craniotomy was made over the hippocampus and 500 nl AAV1.Syn.GCaMP6f.WPRE.SV4 (titre 4.65 × 1013 vg (viral genomes) per ml; University of Pennsylvania Vector Core) were injected into CA3 (A/P −1.7 mm; M/L 1.9 mm; D/V −1.9 mm) or DG and CA1 (A/P −2.0 mm; M/L 2.0 mm; D/V −2.0 and/or −1.4 mm). GFP controls were injected with equal amounts of AAV1.CAG.GFP (titre 3.2 × 1012 vg per ml; University of North Carolina Vector core) with the same coordinates. In the same surgery session, mice were implanted with a stainless-steel head plate (25 × 10 × 0.8 mm with an 8-mm central aperture). The head plate was oriented horizontally for CA1 and DG imaging implantations and with a 20° lateral angle for CA3 imaging implantations. Mice were allowed to recover from surgery for at least 5 days before training sessions commenced. Postoperative analgesic treatment was continued with carprofen (5 mg kg−1 body weight) for 3 days after surgery.

Imaging window implantation

Cortical excavation and imaging window implantation were performed more than 10 days after the initial virus injection, according to published protocols14,31. A craniotomy (diameter 3 mm) was made centred at A/P −1.5 mm, M/L −1.5 mm for CA1/DG imaging and A/P −1.5 mm, M/L −2.5 mm for CA3 recordings. For implantations over CA3, the head of the mouse was tilted by 20°, so that the implantation plane was parallel to the lateral part of the pyramidal cell layer. Parts of the somatosensory cortex and posterior parietal association cortex were gently aspirated while being irrigated with chilled saline. We continued aspiration until the external capsule was exposed. The outer part of the external capsule was then gently peeled away using fine forceps, leaving the inner capsule and the hippocampus itself undamaged. The imaging window implant consisted of a 3-mm diameter coverslip (CS-3R, Warner Instruments) glued to the bottom of a stainless steel cannula (3-mm diameter, 1.2–1.5-mm height). The window was gradually lowered into the craniotomy using forceps until the glass was in contact with the external capsule. The implant was then fixed to the skull using cyanoacrylate. Mice were allowed to recover from window implantation for 2–3 days.

Barnes maze

To test for potential detrimental effects of our implantation on normal hippocampal function, we compared animals implanted for our imaging experiments with GFP-injected control mice (n = 8, each) in a Barnes maze paradigm. The mice were tested on three consecutive days on a 1-m diameter Barnes maze (Noldus) with 20 equally spaced holes at the perimeter in a sound-isolated chamber with distal visual cues on the walls. One session with four runs interleaved by approximately 30 s was carried out per day. The location of the escape hole in relation to the visual cues was kept constant throughout experiments. The mouse was placed onto a starting point in a different quadrant of the maze for each trial. A trial ended after 2 min or when the mouse’s body had completely entered the escape hole. Mice were tracked using video tracking software (Ethovision, Noldus) and the distance travelled (m) was analysed.

Virtual environment setup and behavioural training

Our custom virtual environment setup consisted of an air-supported polystyrene ball (20-cm diameter), similar to other published designs13,31,32,33,34,35. A small metal axle was attached to the side of the ball to constrain the ball motion to the forward–backward direction. The motion of the ball was monitored with an optical sensor (G-500, Logitech) and translated into forward motion through the virtual environment. The forward gain was adjusted so that 4 m of distance travelled along the circumference of the ball equalled one full traversal along the linear track. When the mouse had reached the end of the track, screens were blanked for 5–10 s and the mouse was ‘teleported’ back to the start of the linear track. The virtual environment was displayed on four TFT monitors (19″ screen diagonal, Dell) arranged in a hexagonal arc around the mouse and placed ~25 cm away from the head, thereby covering ~260° of the horizontal and ~60° of the vertical visual field of the mouse, similar to ref. 35. The virtual environment was created and simulated using the open-source 3D rendering software Blender33. The track consisted of textured walls, floors and other 3D rendered objects at the tracks sides as visual cues (Extended Data Fig. 1g). Potential reward locations were marked with visual and acoustic cues, and 4 µl of soy milk was gradually dispensed through a spout in front of the mouse as long as the mouse waited in a rewarded location (see Supplementary Video 1). The simplified (‘poor’) track used for the experiments shown in Extended Data Fig. 8 was derived from the standard familiar context, but all rendered cues and objects were removed, except for a homogenous texture on the walls to both sides of the mouse. The context for the experiments in Extended Data Fig. 6 was essentially the same, but the first three reward locations were additionally removed to limit positional information to idiothetic cues alone. For the multisensory ‘rich’ context (Extended Data Fig. 8, Supplementary Video 6) a large number of 3D animated objects was added to the standard track. Furthermore, a brief (400-ms) 4-kHz tone was played as auditory background at 1 Hz repetition rate and a vanilla-scented piece of cardboard was placed into the behavioural setup. Finally, small cloth objects were attached to a foam disk (10-cm diameter), which was mounted on the axis of a stepper motor. The motor was controlled by an Arduino-board and programmed to move the objects into the range of the mouse’s whiskers according to its position on the virtual track (Supplementary Video 6).

Five days after head plate implantation, mice were placed in the virtual environment for 10–30 min daily, with gradually increasing timespans. During this time, only the familiar context was available to the mice. After 4–5 days of habituation, mice showed consistent running and reward-related licking. The mice were thereafter implanted with the cortical window and allowed to recover from the surgery. After recovery, food scheduling was initiated with a goal of 85–90% of the ad libitum body weight. Simultaneously, training in the virtual environment was re-initiated for 30–60 min daily in the familiar context until consistent reward licking was observed in all animals and familiarization to the context had been achieved for at least 10 days in total before start of the imaging sessions.

From the first day of the imaging session, mice were introduced to a novel context, which had different visual cues and floor and wall textures, but had the same dimensions as the familiar context including the four marked reward locations. On the novel track, two of these reward sites were disabled (that is, the auditory cue was still given, but no reward was dispensed). Licking by the mice was monitored with a capacitive sensor attached to the metal lick spout. For some of the initial animals, no lick data were recorded. Mice alternatingly ran on the two tracks for a total of 15–30 runs on each track and day. The mice made 1–5 runs on one track and then an equal number of runs on the other. The length of these trial blocks was randomly varied. Imaging was performed with the same set of contexts for at least two (up to five) subsequent days. In many of the mice, the visible area under the imaging window was sufficiently large to select another imaging field of view that contained a different population of neurons. In these cases, we repeated the entire imaging experiment after the first experiment had been completed and used the new field of view and a different novel context (see Extended Data Fig. 5). In this manner, we performed a total of twelve experiments in six animals for the DG, seven experiments in five animals for CA3, and fifteen experiments in eleven animals for CA1 in the familiar–novel paradigm, as well as six experiments in three mice for DG imaging in the simplified environment, and seven experiments in six animals for the poor–normal–rich paradigm in CA1.

In vivo two-photon calcium imaging

Imaging was performed using a resonant/galvo high-speed laser scanning two-photon microscope (Neurolabware) with a frame rate of 30 Hz for bidirectional scanning. The microscope was equipped with an electrically tunable, fast z-focusing lens (optotune, Edmund Optics) to switch between z-planes within less than a millisecond. Images were acquired through a 16× objective (Nikon, 0.8 N.A., 3 mm WD), which was tilted at an angle of 20° for CA3 imaging. GCaMP6f was excited at 930 nm with a femtosecond-pulsed two photon laser (Mai Tai DeepSee, Spectra-Physics). We scanned three imaging planes (~25 µm z-spacing between planes) in rapid alternation so that each plane was sampled at 10 Hz. The planes spanned 300–500 µm in the x/y-direction and were placed so that as many principal cells as possible were depicted. An early subset of the CA1 imaging experiments was performed with a galvo/galvo laser scanning microscope (Femto 2D, Femtonics) and a Chameleon Ultra II two-photon laser (Coherent) using only a single plane for imaging. To block ambient light from the photodetectors, the animal’s head plate was attached to the bottom of an opaque imaging chamber before each experiment, and the chamber was fixed in the behavioural apparatus together with the animal. A ring of black foam rubber between the imaging chamber and the microscope objective blocked any remaining stray light.

Histology and imaging area detection

At the end of experiments, mice were deeply anaesthetized using ketamine/xylazine (Sigma Aldrich) and image stacks of the area underneath the imaging window were acquired in vivo in the two-photon microscope (see Supplementary Video 2). Mice were then perfused transcardially with 4% paraformaldehyde in PBS. Brains were cut into 100-µm coronal slices and sections containing the area underneath the imaging window were collected. Image stacks of GCaMP6f and tdT fluorescence in the sections were acquired with a confocal microscope (LSM 710, Zeiss) and the imaged region was re-identified by comparing these stacks with the ones obtained in vivo, as described above (Fig. 1c, Extended Data Fig. 2c). For CA2/3 imaging experiments, the location of the imaged areas in CA3 and CA2 was confirmed for all mice by referencing sections to an anatomical atlas36.

Imaging data processing, segmentation and data extraction

Motion correction of all imaging data was performed line-by-line using the SIMA software package37 with a 2D hidden Markov model38. When necessary, a pre-alignment step was performed using Matlab (version R2015b, MathWorks) built-in functionality (rigid transformation). Motion artefacts were estimated on either the red tdT or the green GCaMP6f fluorescence channel, whichever gave the better result for a given dataset. If no decent motion correction could be achieved, the data were discarded. Next, the motion-corrected and time-averaged image of tdT for each run was used to align recordings from the same field of view relative to each other and their displacements were stored with the dataset.

For obtaining data from principal cells, regions of interest (ROIs) were drawn manually around cell bodies (segmentation) in the principal cell layers of the three hippocampal subfields using ImageJ (NIH). Cell bodies were identified based on the motion-corrected, time-averaged GCaMP6f fluorescence images and re-inspected for each run to make sure that segmented cells were clearly visible throughout the experiment. We disambiguated GCs from other cell types by their small soma size and their location in the granule cell layer of the DG. We did not segment or include any neurons into this GC dataset that had unusually large somata or were located in the hilar region. Thereby, we made sure that our data represent the activity of GCs rather than hilar mossy cells or GABAergic DG interneurons39,40. In CA1 and CA2/3, only neurons in the pyramidal cell layers were segmented and included in the PYR dataset. Neurons in the pyramidal cell layer that co-expressed tdT were excluded from this dataset. For the disambiguation of superficial- and deep-layer CA1 PYRs (Extended Data Fig. 9), we referenced our imaging planes with the 3D stacks of the entire hippocampal formation from the respective mice and manually selected PYR somata in regions that were close (~50 µm) to the oriens border for the deep and somata close to the radiatum border for the superficial group. PVI somata were identified in the red tdT channel and ROIs were drawn around their somata in stratum oriens, pyramidale and radiatum in CA1 and in the granule cell layer as well as the hilar region in the DG.

The obtained ROIs were transformed according to the displacement between the mean GCaMP6f fluorescence images as described above, and the average calcium signal over time was obtained from each ROIs for all runs. We restricted further analysis on running periods with a speed of at least 5 cm s−1. We identified significant calcium transients, which reflect the firing of principal cells, as described31,38. In brief, calcium traces were corrected for slow changes in fluorescence by subtracting the eighth percentile value of the fluorescence-value distribution in a window of ~8 s around each time point from the raw fluorescence trace. We obtained an initial estimate on baseline fluorescence and standard deviation (s.d.) by calculating the mean of all points of the fluorescence signal that did not exceed 3 s.d. of the total signal and would therefore be likely to be part of a significant transient. We divided the raw fluorescence trace by this value to obtain a ΔF/F trace. We used this trace to determine the parameters for transient detection that yielded a false positive rate (defined as the ratio of negative to positive oriented transients) <5% and extracted all significant transients from the raw ΔF/F trace. Definitive values for baseline fluorescence and baseline s.d. were then calculated from all points of this trace that did not contain significant transients. For further analysis, all values of this ΔF/F trace that did not contain significant calcium transients were masked and set to zero.

For PVIs, rigorous identification of spike or burst-related calcium transients was prevented by their high firing rates, which exceeds the acquisition rate of our imaging system and the kinetics of the calcium indicator41,42,43,44,45,46. However, the calcium signal from PVIs can still be used to approximate PVI firing rate over time13,20,45,46. To obtain baseline-normalized ΔF/F calcium traces from PVIs, we extracted their raw fluorescence signals and divided them by their mean fluorescence in periods in which the virtual environment screens were blanked between the runs. Therefore, the ΔF/F trace of PVIs reports the change in activity rates of the cells due to exposure to one of the contexts.

Activity differences and spatial information

Activity difference scores in Fig. 2a were calculated for each cell using the following formula: (activityfamiliar – activitynovel)/(activityfamiliar + activitynovel). To calculate a measure for spatial information (SI) content for principal cells, we adapted a traditional method of SI assessment47 to calcium imaging data. To calculate SI, the average calcium activity (mean ΔF/F) was computed for each 10-cm-wide bin along the linear track and used as an approximation for the neurons’ average firing rate in that location. SI was then calculated for each cell as \({\rm{S}}{\rm{I}}=\sum _{i=1}^{N}{\lambda }_{i}{\rm{l}}{\rm{n}}\frac{{\lambda }_{i}}{\lambda }{p}_{i}\) in which λ i and p i are the average calcium activity and fraction of time spent in the i-th bin, respectively, λ is the overall calcium activity averaged over the entire linear track and N is the number of bins on the track (40 in our case). Therefore, the amount of spatial information is inferred from differences in the calcium activity and reported as bits per s.

Place field identification

Place fields were identified according to published methods31,35. In brief, the mean ΔF/F was calculated from significant calcium transients for 80 position bins (each 5-cm wide) and this mean fluorescence over distance plot was then smoothed by averaging over the three points adjacent to each bin. Potential place fields were initially identified as contiguous regions of this ΔF/F over distance plot in which all of the points were greater than 25% of the difference between the bin with the highest ΔF/F value and the baseline value (mean of the lowest 20 out of 80 bins’ ΔF/F values). In addition, the candidate place fields had to fulfil the following criteria: (1) the potential field had to have a width of at least 3 bins (corresponds to 15 cm running distance on the ball circumference); (2) the mean ΔF/F value inside the field had to be at least seven times the mean of the ΔF/F value outside the field; and (3) significant calcium transients had to be present at least 20% (for CA1–3 PYRs) and 10% (for GCs) of the time in which the mouse was moving in the field. Potential place fields that fulfilled these criteria were accepted if their P value from bootstrapping exceeded 0.05. For bootstrapping, the ΔF/F trace for each experiment was broken into segments of at least 50 consecutive imaging frames and randomly shuffled. This was repeated 1,000 times for each cell. Then the place field detection procedure, as described above, was performed on each of the shuffled ΔF/F traces. The P value of the place field was then defined as the number of these randomly shuffled traces on which a place field was detected according to the outlined criteria divided by the number of shuffles (1,000). Overall, the criteria for place cell identification were relatively conservative and may underestimate the fraction of detected place cells among the active cells (Fig. 1f). The best parameters for place field detection were determined on the first obtained datasets by systematic variation and optimized to detect the maximum number of significant place fields.

Place field stability, consistency and discrimination between contexts

To assess the similarity of a place cell’s spatial representation on different contexts or days, we first divided the track into 40 bins and calculated the mean ΔF/F value for each bin on the track, based on all significant calcium transients (activity map) for each individual cell. One of these maps was computed for each context and day in all cells. The stability of place field of a cell was measured as the cross-correlation of the mean activity maps for runs in the same context on two different days. To assess whether the mean place field stability of cells in a region between a given day and a target day was above chance (Fig. 4d; Extended Data Fig. 10c), we generated chance distributions by correlating each cell’s activity on the selected day with that of a randomly chosen cell on the target day. The consistency of place field firing was determined as the cross-correlation between the average activity of the first and the second block of five consecutive runs on the same track and session. Finally, the similarity between contexts was determined as the correlation of mean activity maps for runs in the familiar context and runs in the novel context on the same day (Figs. 2d, 3g, Extended Data Fig. 3g). To calculate the trial-to-trial reliability (Fig. 3f, Extended Data Figs. 3i, 7e), we calculated the pairwise cross-correlations between the calcium signals of all individual runs in one session on the same track and averaged the obtained values for each cell. We computed PoVs from the activity of all imaged cells in a session by stacking their average activities over distance on top of each other. PoV correlations between days or contexts were then determined as the cross-correlation of these cellular activities in each 10-cm bin along the linear track between two different contexts or days10,48.

Place field shift and centre of mass

To assess the shift of place fields (Extended Data Fig. 7c), we first calculated the centre of mass (COM) for each place field based on the mean activity map over track distance according to the following equation: \({\rm{COM}}=\frac{{\sum }_{i}^{N}{\rm{\Delta }}{F}_{i}{x}_{i}}{{\sum }_{i}^{N}{\rm{\Delta }}{F}_{i}}\) in which N is the number of bins covered by the place field, ΔF i is the fluorescence in the i-th bin of the place field and x i is the distance of the i-th bin from the start of the track. For all cells that had a defined place field on the same linear track on two consecutive days, the place field relocation distance was defined as the distance between the two COMs of the place fields.

Statistics

All statistical tests are described in the corresponding figure legends. All comparisons were two-sided. Unless indicated otherwise, statistical comparisons were made between cells fulfilling the individual criteria as specified in the figure legend. The reported n numbers exclude missing (‘NaN’) values. All ANOVA tests are one-way tests.

Reporting summary

Further information on experimental design is available in the Nature Research Reporting Summary linked to this paper.

Code availability

Any custom written code is available upon request.

Data availability

The data that support the findings of this study are available from the corresponding author upon reasonable request.