Authorship for papers not completed before leaving, where I am major contributor? I am a senior freelance software engineer, with about 10 years' experience. I've been working in a university setting for the past year, as a contractor. Usually I work in a commercial environment. 

During the year, I've done 15-20 days' work on each of 2 different projects that should have turned into papers, but didn't due to lack of time from the PI. These projects are more or less complete from a coding point of view: they just haven't been written up by the PI. I believe the time required to write up should be 2-4 days each. 

I've now decided to move on from the team (partly due to frustration at projects like these being blocked, which means I don't have much visible output) and am documenting and handing over my projects. 

My question is this. On these projects, is it reasonable to ask for authorship on any paper that is written based on my work after I leave? And - assuming that my estimate of 2-4 days' work remaining above is correct - is it reasonable to ask for first authorship? (Our field is epidemiology / life sciences, so I believe that authorship order reflects overall contribution.)

We weren't doing traditional scientific experiments - these are data-driven research projects. So the hierarchy is probably more like the wider digital world, in which execution is generally acknowledged to be more important than ideas. Specifically, my code would have collected the data; my coding decisions would have driven 95% of the design; and I would have written an iPython notebook forming the basis of the methods and results sections of the paper. The PI would write the intro and conclusions and pull together the paper. For example, one project was to do comparison of datasets in the scientific literature, and the PI's idea was pretty much "hey, let's look at dataset A, see if we could match it with dataset B, and draw some conclusions". My contribution was to see if that was possible, learn about datasets C and D and E and F, decide F was the best match, do the actual matching of A and F, and draw the conclusions. The PI will literally just write up the conclusions. 

In both cases the original idea was the PI's, and they have provided guidance as I worked, but probably not more than 0.5-1 day in total. 

I'm not sure how authorship works after I've left. The ICMJE's author definition says that authors should be involved in drafting and approving the paper, but I won't be involved in that (well, unless I work for free). 

However, it's very important for my commercial reputation that I can point to visible work done during the year, so I would like to be named as an author, rather than all the work just vanishing under the PI's name.

One other point: the PI previously put me down as second author on a project where I'd done 99% of the work, and when I queried this, claimed there was no convention on authorship order in our field. Fortunately, I was able to resolve this amicably. But given that experience, I'm now keen to clarify the position about authorship before I leave, and I'd welcome advice on convention and etiquette in this situation.
If you only did programming support for a project, and did not design or collect data, or design the experiment, and did not have a role in writing the manuscript, you probably qualify for only an acknowledgement, and not full authorship. I'm not clear what you mean by "feasibility research" - it's possible that work would qualify if it went beyond normal software design processes (i.e., are you determining whether the idea was feasible for YOU to accomplish in a certain time frame, or feasible at all, and what was the extent of other approaches that you considered...given the time frame you state of 15-20 days work, I am very skeptical there was extensive feasibility research necessary).

15-20 days work is a miniscule amount of time for a typical scientific publication - I would say the normal range is 6 months to 2 years. This range counts all of the failures and false starts inherent in science, refining ideas, etc. Though it is possible all of the data and analysis that goes into a paper takes place on a shorter time frame, it is unfair to exclude all of the productive failure along the way.

Programming by itself isn't really a direct contribution to a scientific project, regardless of the time spent, unless you are developing algorithms, or doing something novel (for example, optimizing a program to the extent that a previously computationally intractable question can be solved in a reasonable timeframe).

I doubt your PI actually does not know the conventions of authorship in the field; it seems more likely that they knew you were overestimating your role in the project, gave you the appropriate credit, and didn't want to argue with you over it further.

More generally, and not speaking to your situation specifically, leaving a lab should not affect your claim to authorship on any work you did while you were a member. However, meeting all the requirements for authorship will indeed require further, unpaid work. At a minimum, this would include review of the manuscript before submission and publication, and in most cases would include substantial writing/editing support, preparation of final figures, etc.