double K_getPhasedRVLine(ok_kernel* k, int planet, int row, int column) { static gsl_matrix* phasedRVLine = NULL; if (planet >= 1) { if (k->ndata == 0) return -1; int np = K_getNplanets(k); double masses[np + 1]; double periods[np + 1]; for (int i = 1; i <= np; i++) { masses[i] = K_getElement(k, i, MASS); periods[i] = K_getElement(k, i, PER); if (i != planet) { K_setElement(k, i, MASS, 0.); K_setElement(k, i, PER, 10000.); } }; double period = K_getElement(k, planet, PER); int samples = -row; if (phasedRVLine != NULL) { gsl_matrix_free(phasedRVLine); phasedRVLine = NULL; } double** comp = K_getCompiled(k); phasedRVLine = K_integrateStellarVelocity(k, comp[0][0], comp[k->ndata - 1][0], samples, NULL, NULL); double mint = MGET(phasedRVLine, 0, T_TIME); for (int i = 0; i < MROWS(phasedRVLine); i++) { double t = fmod((MGET(phasedRVLine, i, 0) - mint), period); MSET(phasedRVLine, i, 0, t); } ok_sort_matrix(phasedRVLine, 0); for (int i = 1; i <= np; i++) { K_setElement(k, i, MASS, masses[i]); K_setElement(k, i, PER, periods[i]); } return 1; } else { return MGET(phasedRVLine, row, column); } }
double K_getPhasedDataForPlanet(ok_kernel* k, int planet, int row, int column) { static gsl_matrix* phased_data = NULL; if (planet >= 1) { if (phased_data != NULL) { gsl_matrix_free(phased_data); phased_data = NULL; } double chi2 = k->chi2; double rms = k->rms; double jitter = k->jitter; double chi2_rvs = k->chi2_rvs; planet = MIN(planet, K_getNplanets(k)); double mass = K_getElement(k, planet, MASS); double period = K_getElement(k, planet, PER); K_setElement(k, planet, MASS, 0); K_calculate(k); phased_data = K_getCompiledDataMatrix(k); double mint = MGET(phased_data, 0, T_TIME); for (int i = 0; i < MROWS(phased_data); i++) { double t = fmod((MGET(phased_data, i, T_TIME) - mint), period); double v = MGET(phased_data, i, T_SVAL) - MGET(phased_data, i, T_PRED); MSET(phased_data, i, T_TIME, t); MSET(phased_data, i, T_VAL, v); } ok_sort_matrix(phased_data, T_TIME); K_setElement(k, planet, MASS, mass); K_calculate(k); k->chi2 = chi2; k->rms = rms; k->jitter = jitter; k->chi2_rvs = chi2_rvs; return 1; } else { return MGET(phased_data, row, column); } }
gsl_matrix* ok_periodogram_full(ok_kernel* k, int type, int algo, bool circular, unsigned int sample, const unsigned int samples, const double Pmin, const double Pmax) { k = K_clone(k); K_calculate(k); // Input data for LS periodogram gsl_matrix* data = ok_buf_to_matrix(K_compileData(k), K_getNdata(k), DATA_SIZE); if (type == PS_TYPE_RESIDUALS) { // If residuals periodogram, subtract signal from data for (int i = 0; i < data->size1; i++) MSET(data, i, T_SVAL, MGET(data, i, T_SVAL) - MGET(data, i, T_PRED)); } else if (type == PS_TYPE_DATA) { // If full periodogram, then start with no planets K_removePlanet(k, -1); } // Calculate LS periodogram gsl_matrix* ret = ok_periodogram_ls(data, samples, Pmin, Pmax, 0, T_TIME, T_SVAL, T_ERR, NULL); int np = K_getNplanets(k) + 1; // Number of minimizable offsets int no = 0; for (int i = 0; i < DATA_SETS_SIZE; i++) if (VIGET(k->parFlags, i) & MINIMIZE) { no++; } // Calculate baseline chi^2 (Chi^2_H) double Chi2_H = _kminimize(k, algo); // Normalizing factor for power double nd = 0.5 * (K_getNdata(k) - no); #pragma omp parallel for for (int r = 0; r < samples; r++) { double P = MGET(ret, r, PS_TIME); double K = sqrt(MGET(ret, r, PS_Z)); ok_kernel* k2 = K_clone(k); K_calculate(k2); double args[] = {PER, P, DONE}; K_addPlanet(k2, args); K_setElement(k2, np, SEMIAMP, K); K_setElementFlag(k2, np, PER, ACTIVE); if (circular) { K_setElementFlag(k2, np, ECC, ACTIVE); K_setElementFlag(k2, np, LOP, ACTIVE); } double Chi2_K = _kminimize(k2, algo); double z = nd * (Chi2_H - Chi2_K) / Chi2_H; MSET(ret, r, PS_Z, z); fflush(stdout); } return ret; }