Mechanical drift in the imaging plane was corrected using the TurboReg plug-in in ImageJ61. All remaining analyses were performed in MATLAB. Regions-of-interest (ROIs) corresponding to visually identifiable cell bodies were selected using a semi-automated algorithm (Supplementary Fig. 14). For GCaMP, ring-shaped ROIs were placed at the cytosolic regions of the cells (excluding the nucleus; GCaMP expression is typically restricted to the cytoplasm11). For OGB1-AM, circular ROIs covering the whole soma were used. For long-term GCaMP imaging, baseline fluorescence images of multiple sessions were inspected manually, and only the cells that could be clearly identified in all imaged sessions were included in the analysis. The fluorescence time course of each cell was measured by averaging all pixels within the ROI, with a correction for neuropil contamination41. The fluorescence signal of a cell body was estimated as Fcell_true(t)=Fcell_measured(t)-r*Fneuropil(t), with r=0.7. The neuropil signal Fneuropil(t) surrounding each cell was measured by averaging the signal of all pixels within a 20 μm region from the cell center (excluding all selected cells). Cell-attached recordings confirmed that neuropil-compensated fluorescence changes reflect action potentials in single neurons