Pull the ```_gdal_write_array``` out of the if block, and expose an intermediate ```data``` variable which changes according to the if. i.e.

```
data = cube.data
if y_points[0] < y_points[-1]:
    # Flip the data so North is at the top of the data
    data = data[::-1, :]
_gdal_write_array(data, padf_transform, fname, ftype)
```