Skip to content

Instantly share code, notes, and snippets.

@ejherran
Created October 16, 2021 17:14
Show Gist options
  • Save ejherran/b1d15eb05b21afca556c42c0bb6764fe to your computer and use it in GitHub Desktop.
Save ejherran/b1d15eb05b21afca556c42c0bb6764fe to your computer and use it in GitHub Desktop.
import numpy as np
# Sets decimal precision to 10 digits, using truncation.
def fix(v):
return np.around(v, decimals=10)
def main(args):
# Multiplying a number by this factor is the equivalent of dividing it by 10 ^ 6
FACTOR = 0.000001
# Open the target light curve file and save its data in the variable <d>
f = open('output/lc'+str(args[1])+'.csv', 'r')
d = f.read()
f.close()
# Open the residual light curve file and load its data into the variable <z>
# [-LAST-] should be replaced by the final number of generated light curves.
f = open('output/lc[-LAST-].csv', 'r')
z = f.read()
f.close()
# Converts <d> and <z> data to iterable lists
d = d.split('\n')
z = z.split('\n')
# Loops through each of the <d> and <z> rows. Note that <d> and <z> are lists of identical dimensions.
for i in range(1, len(d)-1):
# Break each row of <d> and <z> and separate it by columns into <lo> and <lf> respectively.
lo = d[i].split(',')
lf = z[i].split(',')
# Converts the second column of <lo> and <lf> to double precision decimal numbers and stores them in <vo> and <vf> respectively.
vo = np.double(lo[1])
vf = np.double(lf[1])
# Multiply <vo> by the FACTOR and add 1 to it
vo = fix((vo * FACTOR)) + 1
# Multiply <vf> by the FACTOR
vf = fix(vf * FACTOR)
# Replace <vo> and <vf> as second and third column in <lo>. In text format.
lo[1] = str(vo)
lo[2] = str(vf)
# Combine <lo> as a row of text in <d>
d[i] = ','.join(lo)
# Combine all the <d> rows into a single block of text.
d = "\n".join(d)
# Create the output file in the post / directory
f = open('post/post_lc'+str(args[1])+'.csv', 'w')
f.write(d)
f.close()
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment