Here's the offending lines:
Ztemp=SunZen
Ztemp[SunZen > 87]=87
Ztemp references the same object as the input SunZen, so the 87 assignment rudely modifies the input object.
This can be fixed by using Ztemp=SunZen.copy().
Can be closed in the same PR as #6.