Created
October 16, 2021 17:34
-
-
Save ejherran/1f3b4e2f7d89b3c1e0eb4de90fdf7f89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import math | |
import time | |
# General data accumulator. | |
BUFFER = [] | |
# Sets decimal precision to 10 digits, using truncation. | |
def fix(v): | |
return np.around(v, decimals=10) | |
# Run math calculations to perform sinusoidal reduction | |
def interna(ti, nu, a, phi, TWOPI): | |
nu = np.double(nu * 0.000001) | |
a = np.double(a) | |
phi = np.double(phi) | |
v = (TWOPI * nu * ti) + phi | |
v = np.sin(v) | |
v = a * v | |
return fix(v) | |
# Carry out the step-by-step summation of the calculations generated by the "internal" function and accumulate its results in BUFFER | |
def sumatoria(param, TWOPI): | |
j = 0 | |
for l in param: | |
FT = time.time() | |
j = j+1 | |
nu = l[0] | |
a = l[1] | |
phi = l[2] | |
res = "#time,flux,flux_err\n" | |
for i in range(len(BUFFER)): | |
z = interna(BUFFER[i][0], nu, a, phi, TWOPI) | |
BUFFER[i][2] = fix(BUFFER[i][2] + z) | |
FI = BUFFER[i][1] - BUFFER[i][2] | |
res = res + str(BUFFER[i][3]) + ',' + str(fix(FI)) + ",1.0\n" | |
makeFile(j, res) | |
print(j, time.time()-FT) | |
# Generates the output light curve file for each execution of the summation. | |
def makeFile(j, res): | |
f = open("output/lc" + str(j) + ".csv", 'w') | |
f.write(res) | |
f.close() | |
# Prepare the initial data for the execution of the processes. | |
def ejecutar(flux, param): | |
# Mathematical constant 2PI | |
TWOPI = np.pi * 2 | |
i = 0 | |
for l in flux: | |
ti = np.double(l[0]) | |
di = fix(ti / 86400.0) | |
fi = np.double(l[1]) | |
BUFFER.append([ti, fi, np.double(0), di]) | |
sumatoria(param, TWOPI) | |
return 0 | |
def main(args): | |
f = open("input/flux.csv", 'r') | |
flux = f.read() | |
f.close() | |
f = open("input/param.csv", 'r') | |
param = f.read() | |
f.close() | |
flux = flux.split("\n") | |
mflux = [] | |
for l in flux: | |
if(l != ''): | |
tmp = [] | |
for p in l.split(','): | |
tmp.append(float(p)) | |
mflux.append(tmp) | |
del(flux) | |
param = param.split("\n") | |
mparam = [] | |
for l in param: | |
if(l != ''): | |
tmp = [] | |
for p in l.split(','): | |
tmp.append(float(p)) | |
mparam.append(tmp) | |
del(param) | |
ejecutar(mflux, mparam) | |
return 0 | |
if __name__ == '__main__': | |
import sys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment