{'fraction_non_alphanumeric': 0.0352809840761648, 'fraction_numerical': 0.04376948352851967, 'mean_word_length': 4.61592145729832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Novelty detection and multiple timescale integration drive Drosophila 1 orientation dynamics in temporally diverse olfactory environments

16 17 To survive, insects must effectively navigate odors plumes to their source. In natural plumes, 18 turbulent winds break up smooth odor regions into disconnected patches, so navigators encounter 19 brief bursts of odor interrupted by bouts of clean air. The timing of these encounters plays a 20 critical role in navigation, determining the direction, rate, and magnitude of insects’ orientation 21 and speed dynamics. Still, disambiguating the specific role of odor timing from other cues, such 22 as spatial structure, is challenging due to natural correlations between plumes’ temporal and 23 spatial features. Here, we use optogenetics to isolate temporal features of odor signals, examining 24 how the frequency and duration of odor encounters shape the navigational decisions of freely- 25 walking Drosophila . We find that fly angular velocity depends on signal frequency and 26 intermittency – fraction of time signal can be detected – but not directly on durations. Rather than 27 switching strategies when signal statistics change, flies smoothly transition between signal 28 regimes, by combining an odor offset response with a frequency-dependent novelty-like 29 response. In the latter, flies are more likely to turn in response to each odor hit only when the hits 30 are sparse. Finally, the upwind bias of individual turns relies on a filtering scheme with two distinct 31 timescales,

ABSTRACT 16 17 To survive, insects must effectively navigate odors plumes to their source. In natural plumes, 18 turbulent winds break up smooth odor regions into disconnected patches, so navigators encounter 19 brief bursts of odor interrupted by bouts of clean air. The timing of these encounters plays a 20 critical role in navigation, determining the direction, rate, and magnitude of insects' orientation 21 and speed dynamics. Still, disambiguating the specific role of odor timing from other cues, such 22 as spatial structure, is challenging due to natural correlations between plumes' temporal and 23 spatial features. Here, we use optogenetics to isolate temporal features of odor signals, examining 24 how the frequency and duration of odor encounters shape the navigational decisions of freely-25 walking Drosophila. We find that fly angular velocity depends on signal frequency and 26 intermittency -fraction of time signal can be detected -but not directly on durations. Rather than 27 switching strategies when signal statistics change, flies smoothly transition between signal 28 regimes, by combining an odor offset response with a frequency-dependent novelty-like 29 response. In the latter, flies are more likely to turn in response to each odor hit only when the hits 30 are sparse. Finally, the upwind bias of individual turns relies on a filtering scheme with two distinct 31 timescales, allowing rapid and sustained responses in a variety of signal statistics. A quantitative 32 model incorporating these ingredients recapitulates fly orientation dynamics across a wide range 33 of environments. Heisenberg, 1982; Gaudry et al., 2013). In stronger airflows, further away from boundaries, and 49 above rough terrain such as rocks or trees, complex airflows break up smooth odor regions into 50 discrete packets and filaments swept along by the wind ( Yee et al., 1993). As a result, animals experience discrete encounters with odor 53 packets separated by blanks (moments when odor concentration is below detection threshold). 54 The durations of these encounters can span a wide range of timescales (Celani et al., 2014). 55 Under such conditions, insects navigate by orienting upwind within the odor and moving 56 crosswind or downwind when the odor is lost, in an attempt to regain the plume (Kennedy and 57 Marsh, 1974). Similar behaviors (with some variations between species) are observed in 58 laboratory experiments where walking and flying moths  2014) are made to navigate straight odor ribbons. We recently discovered that flies can also detect 63 the direction of motion of odor signals, by resolving inter-antennal concentrations differences over 64 time. Odor motion provides a directional cue complementary to the wind, and is especially useful 65 in turbulent plume navigation (Kadakia et al., accepted). In sum, despite variations between 66 species and locomotive regimes, the general picture of insect odor navigation is that the wind 67 (along with recently-discovered odor motion) indicate the direction in which to reorient, while the 68 timing of odor encounters indicate when to reorient.

70
Careful analyses of moth turning responses following odor encounters have implicated the 71 frequency of odor encounters as a key driver of upwind progress (Kanzaki et al., 1992;Mafra-72 Neto and Cardé, 1994;Vickers and Baker, 1994). Frequency-driven turning is also observed in 73 walking flies navigating complex odor plumes when odor encounters are brief (~100 ms) and Still, how these multiple features are precisely weighted within a single navigation strategy, and 82 whether the strategy itself modulates as signal statistics change, remains unclear. 83 84 In this study, we address these questions using an optogenetic assay developed in previous 85 studies (Demir et al., 2020;Kadakia et al., accepted). We present spatially uniform but temporally-86 structured fictive odor stimuli to freely-walking blind Drosophila melanogaster in a steady laminar 87 flow. In addition to decoupling odor signal from wind, the spatially uniform stimulus removes both 88 the effect of behavioral feedback on the received odor signal, and any bilateral differences 89 between antennae in timing or intensity from the odor encounters (Borst and Heisenberg, 1982;90 Gaudry et al., 2013; Kadakia et al., accepted). Thus, flies must navigate using the temporal 91 features of the odor signals and the fixed wind direction alone.

93
Our main findings are the following. i) Fly angular velocity is controlled by the frequency and 94 intermittency of odor encounters, but not their duration. ii) Flies demonstrated "novelty detection" 95 in turn rate and turn speed: they responded more strongly to signal onset when the prior period 96 without stimulus was longer than ~2 seconds. As in previous studies (Alvarez-Salvado et al., 97 2018) we also observed an "offset response" in turning behavior, which peaks both at the end of 98 a long odor encounter or a block of many encounters at high frequency or high intermittency. 99 Importantly these two features combine to smoothly transition the behavioral response of the flies 100 between low and high frequency regimes. iii) The upwind bias of turns (likelihood to orient upwind 101 when turning) was independently modulated by frequency and intermittency of the signal. This 102 dependency resulted from a rapid increase in upwind bias at the onset of odor pulses, followed 103 by a slower decay at the offset, and allowed for strong upwind responses across a wide range of 104 temporally diverse odor environments. We incorporated these findings into a model combining 105 novelty and offset responses together with a two-timescale integrator. towards the fictive odor source) to a very similar degree ( Figure 1C).

140
To confirm that Orco>Chr mutants were orienting upwind due to the fictive plume stimuli and not 141 some other confounding factor, such as ambient lighting in the experimental arena, we obtained 142 the mean orientation of all trajectories during the ON block (3-12 s) for each environment (CS in 143 EA, CS in smoke, Orco>Chr in fictive plume), along with the parental controls of the 144 optogenetically active line (w;+;Orco-GAL4, w;gmr-hid;20XUAS-Chrimson). Orco>Chr mutant 145 responses were additionally measured in the absence of all-trans-retinal (ATR). We compared 146 the mean orientation in these environments to the mean of uniformly distributed headings (which 147  (Kadakia et al., accepted)) is projected from above as fictive odor stimuli, uniformly illuminating the entire arena with high temporal (< 6 ms) precision. Wind speed is 150 mm/s like in (Demir et al., 2020). B. Four sequential ON and OFF blocks are presented to flies (15 s per block). During the ON block, flashes of red light are presented with a given duration and frequency. No flashes are presented during the OFF block. C. Orientation of flies during the ON and OFF block, for odor plumes of ethyl acetate (EA; left column, orange) and smoke (middle column, blue) with turbulent wind (data from Demir et al. 2020) and fictive odor plume presentation at 2 Hz, 0.1 s (right column, red) with laminar wind. Black: mean response over all trajectories. Grey shade indicates SEM. Only walking flies (ground speed > 2 mm/s) were included. Canton-S flies were used for both smoke (114-282 trajectories per frame) and EA (243-582 trajectories per frame) plume presentation. w;gmr-hid/+;Orco-GAL4/UAS-20XChrimson mutants (60-99 trajectories per frame) were used for fictive odor plume presentation. We reflected flies orientation greater than 180° orientations were always between 0° (directly downwind) and 180° (directly upwind). Thus, a uniform spread of orientations results in an average orientation of 90°. D. Mean  due to the way we reflect orientations results in a mean of 90°-see Figure 1 caption) in both 148 laminar and turbulent wind environments (Figure 1-Figure Supplement 1 Orco>Chr: 119.9°±2.9°, pval < 1e -6 ) ( Figure 1D). In comparison, the orientation of both the UAS-152 parental control line and the Orco>Chr mutant line without ATR did not differ from uniform 153 orientation (UAS: 92.4°±3.5°, pval = 0.491, NO ATR: 92.2°±2.4°, pval = 0.343), (Figure 1D, grey, 154 Figure Supplement 2). Interestingly, the GAL4-parental control line oriented more downwind 155 than expected (79.1°±2.9°, pval = 0.0002), which we attributed to a mild influence of background 156 visual stimuli, since this parent was not blind.

158
The similarity in gross behaviors between wildtype flies navigating real odors and optogenetically 159 stimulated flies navigating fictive odors indicate that spatially uniform, dynamic optogenetic stimuli 160 can drive upwind naturalistic plume navigation. This is consistent with previous results that used 161 real odors (Alvarez-Salvado et al., 2018), though an added benefit here is that bilateral information 162 is entirely removed by using full-field optogenetic flashes. Temporal signal variation alone is 163 enough to drive persistent upwind navigation, emphasizing the importance of temporal stimuli 164 features in the absence of spatially-variable concentrations or local gradients.

166
Upwind heading correlates with signal frequency and intermittency, but not duration 167 168 Next, we asked how frequency, duration and intermittency modulate upwind heading. We 169 generated 45 fictive odor environments with pulse durations between 0.02s and 1s, and pulse 170 frequency between 0.2 Hz and 5 Hz ( Figure 1E). Intermittency -the fraction of time signal is 171 present -is equal to frequency multiplied by duration (Jayaram et al., 2022), and varied between 172 0.004 and 0.875 (intermittency is bounded between 0 (signal is never present) and 1 (signal is 173 always present)). Combinations that produced indeterminable encounters (i.e. intermittency ≥ 1) 174 were excluded.

176
Average upwind heading exhibited common trends across environments (Figure 2A). At ON 177 block onset, flies oriented toward the upwind direction (180 o ) when the odor was present, and 178 went downwind at odor offset, similar to behavior in real odor plumes (see Figure 1). To quantify how the frequency, duration, and intermittency of odor encounters influence upwind 191 bias, we calculated the instantaneous angular velocity as a function of orientation at each time 192 point during the ON block (Materials and Methods) ( Figure 2B). Here, angular velocity was signed 193 such that upwind turns were positive and downwind turns were negative. Average angular velocity 194 was nearly zero when flies were oriented upwind or downwind, but became increasingly positive 195 with signal frequency for those oriented crosswind, up to around 3 Hz. Similar trends were found 196 with intermittency, but not duration ( frequency and intermittency to drive upwind motion, prompting us to examine behavioral models 206 that respond to these particular signal features.

208
Turn dynamics exhibit novelty-response and offset-response 209 210 Fly orientation results from the cumulative effect of individual turns. To understand how temporal 211 features of the odor signal drive turn dynamics, we first explored how the average angular speed 212 (the magnitude of the angular velocity) was modulated during the signal block across 213 environments ( Figure 3A). For clarity, we focus on four example odor environments chosen from 214 the 45 environments shown in Figure 2. We chose these 4 cases to illustrate the different signal 215 and response regimes present in the full dataset ( remained roughly steady for the remainder of the ON block. We first wondered whether this was 223 because in higher frequency environments, flies had maintained their upwind orientation upon 224 receiving new pulses and hence did not need to reorient upwind. However, we found that in higher 225 frequency environments, even flies facing crosswind or downwind at the onset of later pulses did 226 not show large changes in mean angular speed (Figure 3, Figure Supplement 2).This suggests 227 a type of "novelty response", where angular speed will spike at the onset of a new encounter 228 provided the previous odor encounter was in the sufficiently distant past. In high intermittency 229 environments e.g. 3 Hz, 0.25 s, we observed a second large, sharp peak in angular speed at the 230 end of the ON block, which was also seen at the end of individual, long duration encounters (e.g. 231 heading to the direction of interest. We defined turn events by setting a threshold on angular 246 speed. Events above threshold were called "turns", those below threshold were called "fixations". 247 The threshold (25 deg/s) was chosen to remove small fluctuations that contribute little to the 248 overall change in heading, but keep large angular changes that drive navigation behaviors. We 249 also set a minimum turn duration of 0.18s to remove very short fluctuations in angular speed that 250 were potentially artefacts of the tracking ( Having defined turn and fixation events, we examined how the rate, duration, and angular speed 254 of these discrete events, which modulate total angular speed, are influenced by signal statistics. 255 To obtain the turn rate, we note that >95 % of fixation events (times between turns) lasted less 256 than 1.5 s ( with time ( Figure 3C). It was high at the onset (4.92 ± 0.18 turns/s) and offset (4.18 ± 0.09 turns/s) 260 of ON blocks, but lower (3.19 ± 0.02 turns/s) during OFF blocks. Turn durations also appeared 261 exponentially distributed, but with a rate that varied less over time ( Figure 3D). Finally, the mean 262 turn speed exhibited a unimodal distribution that resembled a Gamma distribution with mean that 263 strongly depended on the signal ( Figure 3E): higher at the onset and offset of the ON block, and 264 lower otherwise. Together, this suggested that angular speed dynamics depended more on 265 changes in turn rate and turn speed than on temporal variations in turn duration.

267
To get a qualitative understanding of how turn rate and speed depend on the signal, we plotted 268 them as a function of time ( Figure 4A). We observed a similar novelty response and offset 269 responses as we observed for angular speed ( Figure  grey). We conclude that turn dynamics are mainly controlled by signal-driven modulations of the 274 turn rate and turn speed, which exhibit both a novelty-response and offset-response. 275 276 To model turn rate and turn speed at signal offset, we defined an intermittency-dependent offset 277 response OFF(t) analogous to the OFF response reported by (Alvarez-Salvado et al., 2018), who 278 used real odors to stimulate flies in a setup similar to ours. The OFF(t) function computes the 279 difference between two integrative filters which decay at different timescales, one long and one 280 short, producing a transient spike after long duration encounters or higher intermittency signals 281 ( Figure 4B) (Materials and Methods). This makes it a good candidate for modeling the observed 282 offset behavior in turn rate and angular speed.

284
For the frequency-dependent novelty detection, we defined the function N(t) that would spike at 285 pulse onsets and then decay until the next pulse onset. The height of a spike increases with the 286 time since the last pulse onset (i.e. when a pulse has more "novelty" to it): 287 where " is the time of the latest pulse onset, and # is the decay timescale of the response to 290 individual odor pulse. ( ) controls the height of the response to each pulse. It is maximal (= 1) 291 for the initial odor encounter but decays for successive encounters that occur within a novelty 292 timescale $ (see Materials and Methods). Odor encounters that occur after a time $ are treated 293 as novel signals and elicit maximal response again ( Figure 4B). 294 295 (1)

310
Given these two response functions, ( ) and ( ), we attempted to capture the dynamics of 311 both the turn rate and turn speed by simple linear combination. We modeled the turn rate ( ) as 312 313 314 315 and the mean turn speed ( ) as 318 319 where ( and ( for = 0, 1, 2 are constant parameters. We note that turn duration was weakly 322 modulated by the signal statistics (Figure 4, Figure Supplement 3), but the modulation was 323 much smaller compared to modulations in turn rate and turn speed. Thus, for simplicity, we treated 324 turn duration as exponentially-distributed with fixed parameters determined from data ( Figure  325 3D). We first estimated the parameters for ( ) using maximum likelihood estimation (see  Upwind bias responds to odor signal with two timescales: a fast rise time and a slow decay 359 360 Up until now, we are able to describe fly angular speed dynamics well, through a dynamic turn 361 rate and turn speed. In order to describe fly orientation, we must also understand the direction of 362 these turns, controlled by the upwind bias -the probability that a given turn is upwind (Demir et  (2) and turn speed, upwind bias also depended on fly orientation, and was largest for crosswind-367 facing flies ( Figure 5B). 368 369 Following our previous work (Demir et al., 2020), we model upwind bias ( ) as a sigmoid ( Figure  370 5C): 371 372 where % represents a baseline bias (i.e. when no signal is present), and the sin ' term ensures 375 that the bias is maximal at crosswind angles ( Figure 5C). ( ) is the output of a signal processing 376 model and is a gain factor controlling how much the signal affects upwind bias. To best capture 377 the upwind bias, we consider four simple signal processing models ( ) = ( ), ( ), ( ), ( ) 378 hereafter called: intermittency sensing ( ), frequency sensing ( ), dual-frequency-intermittency 379 sensing ( ) and two-timescale integrator ( ). The intermittency sensing model exponentially 380 filters the binary signal ( ) with timescale : 381 382 By construction, ( ) responds uniquely to signal intermittency (Jayaram et al., 2022). The 385 frequency sensing model ( ) was proposed in (Demir et al., 2020). Here, the duration of the 386 signal is ignored, and the signal is converted to a time-series ( ) of delta function spikes at the 387 onset of each odor encounter. The onsets are exponentially filtered to produce the output, which 388 is effectively a running estimate of odor encounter frequency: 389 390 The third model examined was a dual frequency and intermittency sensing model ( ), outlined 393 in (Jayaram et al., 2022). This model linearly combines I(t) and F(t), but the contributions of F(t) 394 and I(t) are independently weighted: Here . and / are gain factors. In this case the gain in Equation (4) is set to be 1 and the same 399 timescale is assumed for and . Finally, in the two-timescale integrator model, the response 400 ( ) adapted to the signal with one timescale 0 when the signal turned on, but another timescale 401 # when the signal was lost. This is expressed mathematically as:  To find out which of these 4 models best describes fly behavior, we fit all of them to data. To 439 constrain % we took advantage of the fact that the upwind bias returns to baseline within a couple 440 of seconds following the offset of the ON block ( Figure 5A  1 grey). Accordingly, we estimate % by using the last 10s of the OFF block (Figure 5D, black) to 442 fit Equation (4) with ( ) = 0 (Figure 5A, purple). To estimate the remaining parameters we 443 simulated stochastic agents. Turn initiation, speed and duration were simulated as explained 444 above using the best fit parameter values extracted from the analysis in the previous section. Turn 445 bias parameters were estimated using Equation (4) to generate a stochastic turn direction for 446 each turn executed by the agents. For each environment, 240 sample trajectories were 447 generated. We constrained the parameters by minimizing the mean squared error between the 448 mean orientation of agents and flies (Materials and Methods).

450
We found that the two-timescale integrator model ( ) best fit the data across all environments 451 ( Figure 5D). For the intermittency sensing model ( ( ), overall NR = 0.27, the optimal 452 parameters . = 0.04s, = 12.6) predicted well the response for long encounters or lower 453 frequencies, but underestimated responses at higher frequencies or lower durations, and 454 overestimated the response at the highest intermittencies ( Figure 5D, yellow). Conversely, the 455 frequency sensing model ( ( ), overall NR = 0.29; best fit parameters / = 0.08s, = 9.3) 456 exhibited the opposite trend: satisfactory fits for frequencies > ~1.5 Hz, but clear underestimates 457 for lower frequencies (Figure 5D, blue). This suggested that a simple sum of these models might 458 resolve these individual failure modes. Indeed, the dual-frequency-intermittency model was more 459 accurate overall ( ( ), NR = 0.25), and with optimally fit gains . = 2.7, / = 3.2 and timescale 1 460 = 0.1s, captured the mean and dynamics the orientation response across a range of odor 461 environments (Figure 5D, green). Still, it underestimated the response at low frequencies < 1.5 462 Hz. The two-timescale integrator model, however, predicted the mean orientation responses 463 across all panels better ( ( ), NR = 0.20) than the than the dual-frequency-intermittency model. 464 The optimally fit rise time for the response at signal onset was almost instantaneous ( 0 = 0.01s-465 -Materials and Methods for details about this value), whereas the decay timescale was much 466 longer ( # = 1s). We also verified that the two-timescale integrator models with best-fit parameter 467 values reproduces upwind bias in the data (Figure 5A, purple).

469
We conclude that models that combine frequency and intermittency sensing to determine upwind 470 bias perform better than single-sensor models (Jayaram et al., 2022). However, a linear 471 combination of the frequency and intermittency sensors is not sufficient. The data is better 472 reproduced by sensor that responds to these features through integrating the odor signal over 473 two different timescales.

475
A single model captures general trends in angular speed and orientation across a broad 476 spectrum of temporally diverse fictive odor environments 477 478 To better examine the limits of our model, we now plot mean angular speed and orientation 479 predictions on top of the data across all 45 environments. As mentioned above, angular speed is 480 predicted well across most environments (Figure 6A  The model also captures the general trend in orientation (Figure 6B NR=0.20), albeit less well 486 than for angular speed. This is to be expected given the cumulative effect that errors in the 487 prediction of angular speed and turning bias have on orientation. Maxima in mean fly orientation 488 were underestimated at low frequencies, but overall general trends across all 45 panels were 489 captured.

491
We conclude that flies navigate diverse temporal statistics by: 1) modulating their turn decisions 492 and turn speed via a frequency-dependent novelty detector and an intermittency-dependent offset 493 detector of odor signals; and 2) biasing the orientation of these turns using a response function 494 that integrates the signal over two timescales, a very fast rise timescale (tens of ms) and a slow 495 decay timescale (seconds). regimes. To isolate temporal features from spatial information such as the spatial structure of 507 odor encounters, local odor gradients, and turbulent wind structure, we used optogenetics. This 508 allowed us to probe a broad range of odor frequency and durations.

510
A key finding of this study is that a model incorporating both a frequency-dependent novelty 511 response (this study) and a previously observed intermittency-driven offset response (Alvarez-512 Salvado et al., 2018) can successfully describe the dynamics of turns across the spectrum of 513 temporally diverse environments studied. This single model predicts that in environments with 514 high odor intermittency, the turn rate is dynamic and spikes at the encounter offset, as seen in 515 The novelty response reveals that after ~2s of no stimulus a fly is very likely to execute a large 546 turn in response to a new odorant encounter, whereas more frequent encounters are not as likely 547 to trigger such a deterministic response. In turbulent odor plumes, times between encounters 548 (blank times) are power-law distributed and odor packets tend to arrive in clumps (Celani et al., novelty response and how these observed timescales emerge from the neural circuitry could be 556 a fruitful avenue for future study. It would also be insightful to investigate theoretically the 557 optimality of varying turn rate and turn speed in such a way--whether modulation with this novelty 558 response and offset response is optimal for navigation success across a range of temporally 559 diverse environments. 560 561 In addition to the modulation of turn rate and turn speed, another important finding of this study is 562 that the likelihood for a turn to be oriented upwind increases with a very fast timescale (fit to be 563 roughly 10ms) at signal onset and decays with a slower timescale of roughly 1s. We show 564 (Materials and Methods) that as a result, upwind bias increases independently with both signal 565 frequency and intermittency, thus allowing for a sustained upwind bias across environments. The 566 response to both frequency and intermittency is largely consistent with previous findings that 567 intermittency dominates upwind motion in high-duration, low frequency environments whereas turning exhibit similar fast and slow timescales: the turning bias increases rapidly ~10ms at odor 583 onset but decays slowly ~1s at odor offset. Moreover, our analysis shows that, for a simple 584 integrating response to increase independently with frequency and intermittency, it is necessary 585 for the rise timescale to be faster than the decay timescale. 2011). In a previous paper that used the exact same experimental setup and light intensity, we 594 verified that the type of stimuli used here drives ORN responses within their physiological range 595 and that fly behavior resembles that in real odor plumes (Kadakia et al., accepted). Since the odor 596 encounters in this study neither fluctuated in intensity nor lasted longer than 1 second, it is 597 perhaps unsurprising that we did not need to include ORN adaptive dynamics in our model. 598 However, in experimental paradigms with longer light stimuli or varying intensity, adaptation could 599 play an important role in navigational behavior. 600 601 Other aspects of olfactory navigation have not been considered in this study. As we wanted to 602 focus solely on orientation dynamics, we did not factor changes in ground speed or transitions 603 between stops and walk bouts into our predictive models, although these locomotory behaviors collective behavior that could improve odor environment recognition (Sehdev et al., 2019a).

619
We have demonstrated that processing odor signals over multiple timescales allows for 620 temporally driven navigational behaviors across diverse environments. to avoid ATR degradation. For control experiments without ATR ( Figure 1D, Figure 1-644 Supplement 2), flies were instead given 1 mM deionized water.

646
Behavioral apparatus 647 648 The fly walking arena in this study is identical to that used in ( Experiments were recorded at 60 frames per second with a camera (FLIR Grasshopper USB 3.0) 665 with an IR-pass filter. Optogenetic stimuli were delivered using a projector (DLP LightCrafter 666 4500) mounted above the arena, with resolution 912 x 1140 pixels, which illuminated the entire 667 walking arena with pixels of size 292 µm (along wind axis) x 292 µm (perpendicular to wind axis). 668 Only the red LED (central wavelength 627 nm) was used throughout this study. All experiments 669 used a 60 Hz stimulus update rate. The projector and camera were aligned by minimizing the 670 least square difference between the two coordinate systems, as described in detail in (Kadakia et  671 al., accepted). 672 673 674 675 676 Stimulus protocol 677 678 All stimuli were written using custom scripts in Python 3.6.5. All stimuli were delivered to the 679 projector using the Python package PsychoPy, version 2020.2.4.post1. Fly tracking/data acquisition 720 721 All tracking scripts were custom written by Nirag Kadakia in Python 3.7.4 and are described in 722 detail in (Kadakia et al., accepted).

724
Briefly, fly centroids were determined using the SimpleBlobDetector function in OpenCV, and 725 assigned to a trajectory identity by matching to other nearby centroids. Centroids that could not 726 be connected to existing trajectories within 30 frames were excluded, and subsequent detected 727 centroids were thus marked as a new trajectory. Orientation was obtained using the canny 728 function in scikit-image to determine fly "edges", defined between 0 and 360. Measurement noise 729 was removed using a Savitsky-Golay filter (4 th order polymonial, window size of 21 frames (0. where the fly moved less than 2mm/s were additionally removed to ensure equal treatment of 740 data for comparison with data taken from (Demir et al., 2020).

742
Defining turns 743 744 To define a turn event, we sought to determine a threshold angular speed and minimum duration, 745 above which the reorientation event would be classified as a turn. This method is robust against 746 artificial detections of spurious events that may occur due to measurement fluctuations. However, 747 arbitrarily setting the angular speed threshold too high will neglect large angular changes that 748 likely drive changes in the overall heading. To determine a suitable minimum angular speed 749 threshold for this dataset, we pooled trajectories across all 45 odor environments, and examined 750 how changing the threshold angular speed for a turn event affected the distribution of the angular 751 change for "fixation" events, i.e. the change in orientation for events where the angular speed was 752 below threshold. We set the threshold at between 5 deg/s and 150 deg/s. For each of the 17 753 tested thresholds, we obtained the distribution of angular change magnitudes during fixation 754 events, and extracted the 95 th percentile to obtain a comparable measure representing the 755 majority of angular changes made (Figure 3, Figure Supplement 3A).

757
A suitable threshold would have smaller angular changes during fixations, and larger changes 758 during turns. We found that initially, as the threshold increased, smaller angular changes that are 759 likely caused by trivial reorientations were classed as "fixations", and thus would be disregarded 760 as a turn event. Increasing the turn speed threshold beyond 25 deg/s led to much greater changes 761 in orientation during fixation events, (Figure 3, Figure Supplement 3A) (see also Figure 3B).

762
Thus we set the minimum angular speed threshold for a turn event at 25 deg/s.

764
We observed that the distribution of angular change magnitude for events above the 25 deg/s 765 threshold angular speed was bimodal (Figure 3, Figure Supplement 3B). The first peak indicates 766 a proportion of events with small angular changes; the second peak centralized around much 767 larger angular changes. We reckoned that the distribution of smaller angular changes could be 768 from very short, sharp changes in orientation, which were potentially artefacts of the tracking to 769 be removed.

771
We fit a Gaussian mixture to the distribution and found that the standard deviation of the low-772 mean Gaussian was approximately 4.5°. A navigating agent is more likely to regulate the duration 773 of its turn, rather than the magnitude of the angular change and thus we instead set a minimum 774 duration for turn events. With a minimum angular speed of 25°/s, and a minimum angular change 775 of 4.5°, we get a minimum turn duration of 0.18 s. We removed all above angular speed threshold 776 events with an event duration of less than 0.18 s; the resultant angular change distribution for turn 777 events was no longer bimodal (Figure 3, Figure Supplement 3C).

779
Plotting turn quantities as a function of time 780 781 To estimate the turn rate as a function of time, at any time point we considered trajectories where 782 flies were in a fixation state or had just transitioned from fixation to turn at that time point. 783 Assuming an inhomogeneous Poisson process, the probability to transition from fixation to turn 784 at a timepoint is given by ( ) ⋅ Δ , where Δ is the time-step resolution of our data, 1/60s. Thus 785 the fraction of all considered trajectories that had just transitioned from fixation to turn, divided by 786 Δ , provides an estimate of ( ). We smoothed this estimate with a rectangular smoothing window 787 of width 0.25s, sliding the window across each time step, and plotted the results in Figure  We estimated mean turn speed, mean turn duration and upwind bias as a function of time in the 792 following way. We defined a 0.25s wide window and considered all turns that started in this 793 window. For each turn, we then computed its mean angular speed, its duration and whether it 794 was upwind (+1) or downwind (0). We then averaged these quantities to get an estimate of the 795 mean turn speed, mean turn duration or upwind bias, respectively, for that window. As for the turn 796 rate, we slid the window across each time step and plotted our results against the center of the 797 time window. Error bars were estimated by resampling the data 1000 times at each time point.

799
Modeling fly turning behavior 800 801 The OFF function is defined as Parameter Estimation 826 827 To estimate parameters for turn rate (Equation 2), we considered time points where flies were in 828 fixations (i.e. not turning) or had just transitioned from fixation to turn. We excluded fixations that 829 lasted longer than 1.5s, as more than 95% of fixations were shorter than 1.5s and beyond this 830 duration, fixation durations were no longer exponentially distributed (Figure 3 Figure  831 Supplement 2). For a time point , the probability to not initiate a turn at that time point is !9 ! :* 832 where Δ is our sampling time (1/60s) and * denotes the turn rate from Equation 2 at that time 833 point. The probability to initiate a turn at that time point is 1 − !9 ! :* . We then constructed a 834 likelihood function: and minimized the negative log of this likelihood using scipy.optimize.minimize with the standard 839 L-BFGS-B method for minimization with bounds. All subsequent log-likelihood functions were 840 minimized similarly. Note that for all timescales we estimated the log of the inverse timescale, i.e. 841 the log of the 'rate' and then converted that back into a timescale.

843
To estimate turn speed parameters, we calculated the mean angular speed for each turn and 844 subtracted our minimum turn speed of 25 deg/s (this is added back later when simulating the 845 turns). The distribution of the resultant mean angular speeds was assumed to be a Gamma 846 distribution with fixed shape parameter 2, based off the observations in Figure 3. The mean of 847 this Gamma distribution was assumed to depend on the signal and is given by Equation 3. 848 Assuming individual turns are independent, we could then construct a likelihood function as the 849 product of the likelihood of each mean turn speed: 850 851 where * is the observed mean angular speed (after subtracting 25 deg/s) for the turn and * is 853 the predicted mean angular speed for a given set of parameters, using Equation 3. As the 854 timescales for the N and OFF responses were already estimated from the turn rate analysis, only 855 the three coefficients were estimated from this likelihood function, by minimizing its negative 856 logarithm.

858
For turn duration, for each turn we calculated its duration and subtracted the minimum turn 859 duration, 0.18s (this is added back later when simulating turns). We then assumed an exponential 860 distribution for these resultant turn durations and computed a likelihood function as 861 862 = Π ?DEAB #IJ (!G ! 9 %-. )

864
where here * denotes the turn duration (after subtracting 0.18s). We found the constant #IJ that 865 minimized the negative log-likelihood. The inverse of this constant is reported as #IJ in Materials 866 and Methods, Table 1. that minimized the mean squared error were used.

886
Analysis of two-timescale integrating model 887 888 Following our analysis of a single timescale integrator ( ) in (Jayaram et al., 2022), we consider 889 the response ( ) to a binary square-wave signal with frequency and duration . If we let M 890 denote the value of ( ) at the onset of the nth pulse, then by straightforwardly integrating 891 Equations 8 and 9, we get the relation 892 893 Expanding and simplifying, we get 896 897 We can then see that in general 900 901 We can then compute the asymptotic average value of ( ) over one period of the signal, which 909 we denote as f as 910 911 If we note that ⋅ = , the intermittency of the signal, we get 914 915 We can see here that the response depends independently on both the intermittency and 920 frequency of the signal. Since the response is integrating the signal (Equations 8 and 9), f 921 increases with signal intermittency. To see how it depends on frequency, we consider the 922 difference between the timescales. Firstly, note that if 0 = # then we just have a single 923 timescale integrator and f = , as we would expect from (Jayaram et al., 2022). For the case 924 where 0 ≪ # and can be approximated as 0 (as in our fits), one can readily compute f , noting 925 that ( ) is 1 when the signal is present and decays with timescale # when the signal is absent. 926 We get 927 928 which we can see grows with until ≫ 1/ # at which point it levels off. 931 932 On the other hand, if # ≪ 0 and is taken to be 0 instead, we get 933 934 coincidentally was also fit to 0.18s. 949 950 **Note that the found value of 10ms for 0 was on the edge of the minimization bounds. We did 951 not probe shorter timescales as the time-resolution of our data was ~16ms. However we verified 952 that even for an instantaneous rise timescale the cost was higher than the cost for 10ms but within 953 3% of its value. The same was true for a 0 of 20ms. For values greater than 20ms the cost started 954 to grow more significantly. Hence we concluded that the rise timescale was between 0-20ms.

956
Simulating Fly Turning Dynamics 957 958 To simulate flies executing our turn model, we first determined whether a simulated fly would 959 initiate a turn or not by taking the probability to initiate a turn in a time step Δ as ( ) ⋅ Δ , where 960 ( ) is given by Equation 2. If a fly was not turning its angular velocity was assumed to be 0. If a 961 turn was initiated, its duration in excess of 0.18s was sampled from an exponential distribution 962 with timescale #IJ , and added to 0.18s to get the total turn duration. The mean angular speed of 963 the turn in excess 25 deg/s was sampled from a Gamma distribution with shape parameter 2 and 964 mean given by Equation 3, then added to 25 deg/s to get the total mean angular speed. We 965 assumed a turn had a parabolic angular speed profile (see Figure 3B). Given the mean value and 966 duration (i.e. time between two zeros) of this parabola, we could compute || for the duration of 967 the turn as |6 / ' ( − 2*7J* )( − ( 2*7J* + ))| where 2*7J* is the start time of the turn, is the 968 mean angular speed of the turn, is the duration of the turn and the factor in front ensures that 969 the average angular speed over the turn is equal to . To determine the sign of the turn, we 970 determined whether it was upwind or downwind by simulating a Bernoulli variable with probability 971 given by Equation 4. Once ̇ was specified for the whole turn, we could use Euler integration with 972 timestep Δ = 1/60s (the frame rate of our experiments) to evolve a simulated agent's heading. 973 Values for response functions ( ) except for ( ) were computed by Euler integration with a 974 step-size of 1/10 th our sampling rate and then resampled for agent simulation. ( ) was computed 975 as in (Jayaram et al., 2022). Agents were initialized with headings sampled from the distribution 976 of experimental flies' initial headings for that environment and initialized to all not be turning for 977 simplicity (thus the first 0.1s of our simulated total angular speed is not shown in Figure 5C and 978 6A as the comparison with data would not be fair). 979 Canton-S: wildtype (same as in Demir 2020). Recorded at 60 fps, but presented by subsampling every 5 frames. Dashed line indicates orienting crosswind (90°). All flies that moved less than 2mm/s on average for their entire trajectory were removed. Orco>Chr: laminar, n=5-69 trajectories per time point across the entire 5 minute recording; complex, n=8-56. GAL4 PARENT: laminar, n=1-18; complex, n=1-17. UAS PARENT: laminar, n=1-13;complex, n=1-12. Canton-S: laminar, n=1-13; complex, n=1-12. B. Population orientation mean and SEM across all trajectories for laminar (green) and complex (purple) wind without odor stimulus over 5 minute recording. Any time points where the fly moved less than 2 mm/s were removed. Orco>Chr: laminar, 91.1° ± 1.1°, n = 678 trajectories; complex, 91.9° ± 1.4°, n = 519. GAL4 parent: laminar, 84.1° ± 2.9°, n = 152, complex, 82.2° ± 3.3°, n = 119. UAS parent: laminar, 87.2° ± 3.7°, n = 102, complex, 89.8° ± 3.0°, n=114. Canton-S: laminar, 90.2° ± 4.4°, n = 120, complex, 90.3° ± 4.3°, n = 111.   Mean turn speed is also dynamic and well-predicted by the combination of novelty and offset responses. Experimental population mean angular speed given turning estimated with a sliding 0.25s window (grey line) and bootstrapped error (grey shading) (see Materials and Methods) for all 45 fictive odor environments as well as model predictions (pink) and simulated error (pink shading) using Equation 3 and fit with one fixed set of parameters to all 45 environments using Maximum Likelihood Estimation (see Materials and Methods), and using timescales for and responses extracted from the turn rate parameter estimates. Angular speed given turning is dynamic and reasonably well-approximated by the model. To generate model predictions and error, artificial turns were simulated occurring at the same times as the real turns. The speed of these turns in excess of the 25 deg/s threshold was sampled from a gamma distribution with time varying mean, given by Equation 3. Average turn speed on this simulated data was then calculated with the same sliding 0.25s window. We repeated this process 10000 times, taking the mean of all these as the model turn angular speed and the standard deviation as the model error. For more details see Materials and Methods. Ns are the same as in Figure 4 Supplement 1.

Figure 4 Supplement 3: Mean turn duration is roughly constant in time for high frequency environments
but shows a small signal dependency for low frequency long duration signal: Mean turn duration (grey) and estimated error (grey shading) vs. time for all 45 environments considered as well as the MLE estimate of a constant duration (pink line) and uncertainty (pink shading) (see Materials and Methods). We do see some signal modulation of turn duration, particularly at lower frequencies and often see an increase in turn duration at the offset of the ON block. However, the strength of this modulation is rather mild overall and the response at block offset is somewhat unpredictable and not well fit with the off response timescales found for turn rate. Thus, to keep our model as simple as possible we neglected modulations in turn duration. To generate model predictions and error, artificial turns were simulated occurring at the same times as the real turns. The duration of these turns in excess of the 0.18s threshold was sampled from an exponential distribution with fixed parameter. Average turn speed on this simulated data was then calculated with the same sliding 0.25s window. We repeated this process 10000 times, taking the mean of all these as the model turn duration and the standard deviation as the model error. For more details see Materials and Methods. Ns are the same as in Figure 4 Supplement 1.
Figure 5 Supplement 1: Turn bias is dynamic and well approximated by a two-timescale integrator with an instantaneous rise timescale. Probability to turn upwind given turning (i.e. upwind bias) vs time (grey) and estimated error (grey shading) for all 45 fictive odor environments along with model predictions (purple) and estimated error (purple shading) for a two-timescale integrating response (Equations 8-9) with instantaneous rise timescale and finite decay timescale (see Materials and Methods). Upwind bias was estimated by calculating the fraction of turns that were upwind in a sliding 0.25s window. We see that upwind bias generally rises during signal presence and otherwise is slightly less than 0.5, suggesting that in the absence of signal flies display a preference for downwind orientation. To generate model predictions and error, artificial turns were simulated occurring at the same times as the real turns, with the same initial orientations. The direction of these turns (upwind or downwind) was assigned according to the probability given by the time varying bias, Equation 4. Turn bias on this simulated data was then calculated with the same sliding 0.25s window. We repeated this process 10000 times, taking the mean of all these as the model turn bias and the standard deviation as the model error. For more details see Materials and Methods. N = 8-103 turn events per time point for all 45 environments.