Moving grating stimuli were generated using the Psychophysics Toolbox58,59 in MATLAB. Each stimulus trial consisted of a 4 s blank period (uniform gray at mean luminance) followed by a 4 s drifting sinusoidal grating (0.05 cycles per degree, 1 Hz temporal frequency). Typically, 8 drifting directions were used (separated by 45 degrees) and 5 trials were recorded for each direction, giving a total of 40 stimulus trials per recording session (320 s recording time). The gratings were presented with an LCD monitor (30 × 40 cm), placed 25 cm in front of the center of the right eye of the mouse. The monitor subtended an angle of ±38° horizontally and -20° to +38° vertically around the eye of the mouse. For experiments with cell-attached recording (Fig. 3), pipette access required the use of a smaller LCD monitor (12 × 16 cm) placed ∼10 cm in front of the right eye. During simultaneous imaging and electrophysiology, the optimal grating stimulus was repeatedly played (duration 2 s, separated by a 4 s blank period), but the contrast of the stimulus grating was adjusted online to maintain moderate spike rates.