import numpy as np
import pandas as pd

import os
import sys

import matplotlib.pyplot as plt

solar_original = os.path.join("..", "data", "solar_forcing_cmip7.csv")
solar_extended = os.path.join("..", "data", "solar_forcing_cmip7_extended.csv")

solar_original_df = pd.read_csv(solar_original)
print(solar_original_df.head())
print(solar_original_df.loc[2299-1750, :])
print(solar_original_df.loc[2300-1750, :])
print(solar_original_df.loc[2038-1750, :])
print(solar_original_df.loc[2038-1750, "erf"])
solar_extended_df = solar_original_df.copy()

# Extensions are done by duplicating solar cycles from 24th of August 2038
frac_year0 = 129/365
frac_year1 = 236/365
solar_extended_df.loc[2300-1750:, "erf"] = [solar_original_df.loc[i-1750 , "erf"]*frac_year0 +  solar_original_df.loc[i + 1 -1750 , "erf"]*frac_year1 for i in range(2038, 2239)]

plt.plot(solar_original_df["year"], solar_original_df["erf"], label="original")
plt.plot(solar_extended_df["year"], solar_extended_df["erf"], label="extended")
plt.legend()
plt.savefig("solar_forcing_comparison.png")
solar_extended_df.to_csv(solar_extended, index=False)