Copied code from WFPalmer2013 PSP data analysis