The first line starts with a D minor ninth arpeggio (D-F-A-C-E) from the Dorian mode. To build a minor ninth arpeggio, you just have to take the first, the minor third, the fifth and the minor seventh of any minor scale (The Dorian mode as it is the case here). Keep in mind that the Dorian mode is a minor type scale, this is the second mode of the major scale. It is built with a root (1), a second (2), a minor third (b3), a perfect fourth (4), a perfect fifth (5), a sixth (6) and a minor seventh (b3). This is surely the first choice when you want to improvise over a minor chord.

D Dorian mode D E F G A B C Formula 1 2 (9) b3 4 (11) 5 6 (13) b7 D minor ninth arpeggio D E F X A X C

The first four notes of the second measure make up a descending Db major triad (Db-F-Ab). This triad is from the G altered scale. It starts on the #11 (Db) of G7. The altered scale is the seventh mode of the melodic minor scale. It is also known as "super Locrian mode". It is generally used over dominant 7th chords (alt) when you want to add a sense of tension. Indeed, the altered scale contains all the altered notes that a scale can contain. Namely b9, #9, b13 and #11.