Calculation of Solar RV Variations¶
- calculate solar velocities: calculate solar velocities and save to csv
- get component lists: using pandas to get the lists of each relevant component
- calculate RVs and save to csv: calculate RVs using optimized parameters
NOTE: this is purely an example but requires ground-based Solar RV measurements for fitting
In [1]:
Copied!
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
Get ground-based 'sun-as-a-star' RVs.
In [ ]:
Copied!
# get csv with solar RVs
csv_file = 'file_name'
# create pandas dataframe
component_df = pd.read_csv(csv_file)
# get RV list
rv_sun = component_df.rv_sun.values
# get csv with solar RVs
csv_file = 'file_name'
# create pandas dataframe
component_df = pd.read_csv(csv_file)
# get RV list
rv_sun = component_df.rv_sun.values
Read in velocities from csv.
In [2]:
Copied!
# csv file with rv components
csv_file = 'file_name'
# csv file with rv components
csv_file = 'file_name'
Get component lists.
In [ ]:
Copied!
# create pandas dataframe
component_df = pd.read_csv(csv_file)
# create pandas dataframe
component_df = pd.read_csv(csv_file)
In [4]:
Copied!
# get velocities lists
v_phot = component_df.v_phot.values
v_conv = component_df.v_conv.values
# get velocities lists
v_phot = component_df.v_phot.values
v_conv = component_df.v_conv.values
Calculate scaling coefficient values -- using linear regression.
Setup data to plug into linear regression model/
In [ ]:
Copied!
# components
X = np.zeros(shape=(len(rv_sun), 2))
X[:, 0] = v_phot
X[:, 1] = v_conv
# data we are fitting to
y = rv_sun
# components
X = np.zeros(shape=(len(rv_sun), 2))
X[:, 0] = v_phot
X[:, 1] = v_conv
# data we are fitting to
y = rv_sun
Use sklearn linear regression to get coefficient values.
In [ ]:
Copied!
# apply regression
reg = LinearRegression().fit(X, y)
print('R^2 for prediction: ' + str(reg.score(X, y)))
# get scaling factors
A = reg.coef_[0]
B = reg.coef_[1]
RV0 = reg.intercept_
# print scaling factors
print("Scaling Factors:\n A:", A, "\nB:", B, "\nRV0:", RV0)
# apply regression
reg = LinearRegression().fit(X, y)
print('R^2 for prediction: ' + str(reg.score(X, y)))
# get scaling factors
A = reg.coef_[0]
B = reg.coef_[1]
RV0 = reg.intercept_
# print scaling factors
print("Scaling Factors:\n A:", A, "\nB:", B, "\nRV0:", RV0)
Calculate the Model RV Variation using these coefficients.
In [ ]:
Copied!
RV = A*v_phot + B*v_conv + RV0
RV = A*v_phot + B*v_conv + RV0
Add calculation to csv.
In [ ]:
Copied!
component_df["rv_model"] = RV
component_df.to_csv(csv_file, index=False)
component_df["rv_model"] = RV
component_df.to_csv(csv_file, index=False)