Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Jul 22, 2022
1 parent dc87d49 commit a744c98
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 96 deletions.
84 changes: 19 additions & 65 deletions docs/hatyan/analysis_prediction.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1 class="title">Module <code>hatyan.analysis_prediction</code></h1>

from hatyan.hatyan_core import get_const_list_hatyan, sort_const_list, robust_timedelta_sec, robust_daterange_fromtimesextfreq
from hatyan.hatyan_core import get_freqv0_generic, get_uf_generic
from hatyan.timeseries import check_ts, check_rayleigh, Timeseries_Statistics
from hatyan.timeseries import check_ts, nyquist_folding, check_rayleigh, Timeseries_Statistics


class HatyanSettings:
Expand Down Expand Up @@ -303,7 +303,7 @@ <h1 class="title">Module <code>hatyan.analysis_prediction</code></h1>
elif len(kwargs)&gt;0:
raise Exception(&#39;both arguments hatyan_settings and other settings (e.g. nodalfactors) are provided, this is not valid&#39;)

print(&#39;-&#39;*50)
#print(&#39;-&#39;*50)
print(&#39;ANALYSIS initializing&#39;)
print(hatyan_settings)

Expand Down Expand Up @@ -331,6 +331,10 @@ <h1 class="title">Module <code>hatyan.analysis_prediction</code></h1>
const_list_counts = pd.DataFrame({&#39;constituent&#39;:const_list_uniq,&#39;occurences&#39;:const_list_uniq_counts})
raise Exception(&#39;remove duplicate constituents from const_list:\n%s&#39;%(const_list_counts.loc[const_list_counts[&#39;occurences&#39;]&gt;1]))

#check for length
if len(ts_pd)&lt;2:
raise Exception(&#39;provided timeseries is less than 2 timesteps long, analysis not possible&#39;)

#remove nans
ts_pd_nonan = ts_pd[~ts_pd[&#39;values&#39;].isna()]
if len(ts_pd_nonan)==0:
Expand All @@ -356,24 +360,9 @@ <h1 class="title">Module <code>hatyan.analysis_prediction</code></h1>
u_i_rad, f_i = get_uf_generic(hatyan_settings, const_list, dood_date_fu)
v_u = v_0i_rad.values + u_i_rad.values

check_rayleigh(ts_pd,t_const_freq_pd)

#TODO: nyquist stuk code generieker maken met Henrique
stats = Timeseries_Statistics(ts=ts_pd)
unique_timesteps = stats.stats[&#39;timeseries unique timesteps (minutes)&#39;]
if len(unique_timesteps)==1: #constant freq, so folding is possible
constant_freq_phr = list(unique_timesteps)[0]/60
fs = 1/constant_freq_phr
nyquist_freq = 0.5*fs
bool_isnyquist = t_const_freq_pd[&#39;freq&#39;]==nyquist_freq
if bool_isnyquist.any():
raise Exception(f&#39;there is a component on the Nyquist frequency ({nyquist_freq} [1/hr]), this not possible:\n{t_const_freq_pd.loc[bool_isnyquist]}&#39;)
bool_freqtoohigh = t_const_freq_pd[&#39;freq&#39;]&gt;nyquist_freq
t_const_freq_pd_folded = t_const_freq_pd.copy()
t_const_freq_pd_folded.loc[bool_freqtoohigh,&#39;freq&#39;] = np.abs(fs - t_const_freq_pd_folded.loc[bool_freqtoohigh,&#39;freq&#39;] ) #remainder is better: 0.408%(1/3)
t_const_freq_pd_folded = t_const_freq_pd_folded.sort_values(&#39;freq&#39;) #TODO: sorting also done in rayleigh check
print(&#39;check folded rayleigh&#39;)
check_rayleigh(ts_pd,t_const_freq_pd_folded)
#check rayleigh frequency after nyquist frequency folding process
freq_rem = nyquist_folding(ts_pd,t_const_freq_pd)
check_rayleigh(ts_pd,freq_rem) #TODO: maybe sometimes valuable to not fold with nyquist (eg with strongly varying time interval), in that case: check_rayleigh(ts_pd,t_const_freq_pd)

#### TIMESERIES ANALYSIS
N = len(const_list)
Expand All @@ -389,18 +378,6 @@ <h1 class="title">Module <code>hatyan.analysis_prediction</code></h1>
tic = dt.datetime.now()
xTxmat = np.dot(xTmat,xmat)

if 0:
#TODO
xTxmat2 = xTxmat/xTxmat[0,0]
xTxmat2[np.abs(xTxmat2)&lt;0.05] = 0
xTxmat2_condition = np.linalg.cond(xTxmat2)
svd_u,svd_s,svd_vh = np.linalg.svd(xTxmat2) # s zijn singuliere waarden van groot naar klein, u en v zijn gespiegeld over diagonaal
xTxmat2_check = [email protected](svd_s)@svd_vh #matrix multiplicatie geeft weer originele matrix (ongeveer)
xTxmat2_check = svd_u[:,:2]@np.diag(svd_s[:2])@svd_vh[:2,:] #helft van info weggooien, geeft approximatie van originele matrix

#samp freq is 3hr, freq [1/hr],dus fs is 1/3, nyquist freq is 1/6 (0.5*fs)
#probleem is freq van 3M2S10 (0.408201 [1/hr]) is groter dan 1/6

print(&#39;xTx matrix calculated&#39;)
if &#39;A0&#39; in const_list: #correct center value [N,N] for better matrix condition
xTxmat_condition = np.linalg.cond(xTxmat)
Expand Down Expand Up @@ -529,7 +506,7 @@ <h1 class="title">Module <code>hatyan.analysis_prediction</code></h1>
elif len(kwargs)&gt;0:
raise Exception(&#39;both arguments hatyan_settings and other settings (e.g. nodalfactors) are provided, this is not valid&#39;)

print(&#39;-&#39;*50)
#print(&#39;-&#39;*50)
print(&#39;PREDICTION initializing&#39;)
print(hatyan_settings)

Expand Down Expand Up @@ -857,7 +834,7 @@ <h2 id="returns">Returns</h2>
elif len(kwargs)&gt;0:
raise Exception(&#39;both arguments hatyan_settings and other settings (e.g. nodalfactors) are provided, this is not valid&#39;)

print(&#39;-&#39;*50)
#print(&#39;-&#39;*50)
print(&#39;ANALYSIS initializing&#39;)
print(hatyan_settings)

Expand Down Expand Up @@ -885,6 +862,10 @@ <h2 id="returns">Returns</h2>
const_list_counts = pd.DataFrame({&#39;constituent&#39;:const_list_uniq,&#39;occurences&#39;:const_list_uniq_counts})
raise Exception(&#39;remove duplicate constituents from const_list:\n%s&#39;%(const_list_counts.loc[const_list_counts[&#39;occurences&#39;]&gt;1]))

#check for length
if len(ts_pd)&lt;2:
raise Exception(&#39;provided timeseries is less than 2 timesteps long, analysis not possible&#39;)

#remove nans
ts_pd_nonan = ts_pd[~ts_pd[&#39;values&#39;].isna()]
if len(ts_pd_nonan)==0:
Expand All @@ -910,24 +891,9 @@ <h2 id="returns">Returns</h2>
u_i_rad, f_i = get_uf_generic(hatyan_settings, const_list, dood_date_fu)
v_u = v_0i_rad.values + u_i_rad.values

check_rayleigh(ts_pd,t_const_freq_pd)

#TODO: nyquist stuk code generieker maken met Henrique
stats = Timeseries_Statistics(ts=ts_pd)
unique_timesteps = stats.stats[&#39;timeseries unique timesteps (minutes)&#39;]
if len(unique_timesteps)==1: #constant freq, so folding is possible
constant_freq_phr = list(unique_timesteps)[0]/60
fs = 1/constant_freq_phr
nyquist_freq = 0.5*fs
bool_isnyquist = t_const_freq_pd[&#39;freq&#39;]==nyquist_freq
if bool_isnyquist.any():
raise Exception(f&#39;there is a component on the Nyquist frequency ({nyquist_freq} [1/hr]), this not possible:\n{t_const_freq_pd.loc[bool_isnyquist]}&#39;)
bool_freqtoohigh = t_const_freq_pd[&#39;freq&#39;]&gt;nyquist_freq
t_const_freq_pd_folded = t_const_freq_pd.copy()
t_const_freq_pd_folded.loc[bool_freqtoohigh,&#39;freq&#39;] = np.abs(fs - t_const_freq_pd_folded.loc[bool_freqtoohigh,&#39;freq&#39;] ) #remainder is better: 0.408%(1/3)
t_const_freq_pd_folded = t_const_freq_pd_folded.sort_values(&#39;freq&#39;) #TODO: sorting also done in rayleigh check
print(&#39;check folded rayleigh&#39;)
check_rayleigh(ts_pd,t_const_freq_pd_folded)
#check rayleigh frequency after nyquist frequency folding process
freq_rem = nyquist_folding(ts_pd,t_const_freq_pd)
check_rayleigh(ts_pd,freq_rem) #TODO: maybe sometimes valuable to not fold with nyquist (eg with strongly varying time interval), in that case: check_rayleigh(ts_pd,t_const_freq_pd)

#### TIMESERIES ANALYSIS
N = len(const_list)
Expand All @@ -943,18 +909,6 @@ <h2 id="returns">Returns</h2>
tic = dt.datetime.now()
xTxmat = np.dot(xTmat,xmat)

if 0:
#TODO
xTxmat2 = xTxmat/xTxmat[0,0]
xTxmat2[np.abs(xTxmat2)&lt;0.05] = 0
xTxmat2_condition = np.linalg.cond(xTxmat2)
svd_u,svd_s,svd_vh = np.linalg.svd(xTxmat2) # s zijn singuliere waarden van groot naar klein, u en v zijn gespiegeld over diagonaal
xTxmat2_check = [email protected](svd_s)@svd_vh #matrix multiplicatie geeft weer originele matrix (ongeveer)
xTxmat2_check = svd_u[:,:2]@np.diag(svd_s[:2])@svd_vh[:2,:] #helft van info weggooien, geeft approximatie van originele matrix

#samp freq is 3hr, freq [1/hr],dus fs is 1/3, nyquist freq is 1/6 (0.5*fs)
#probleem is freq van 3M2S10 (0.408201 [1/hr]) is groter dan 1/6

print(&#39;xTx matrix calculated&#39;)
if &#39;A0&#39; in const_list: #correct center value [N,N] for better matrix condition
xTxmat_condition = np.linalg.cond(xTxmat)
Expand Down Expand Up @@ -1126,7 +1080,7 @@ <h2 id="returns">Returns</h2>
elif len(kwargs)&gt;0:
raise Exception(&#39;both arguments hatyan_settings and other settings (e.g. nodalfactors) are provided, this is not valid&#39;)

print(&#39;-&#39;*50)
#print(&#39;-&#39;*50)
print(&#39;PREDICTION initializing&#39;)
print(hatyan_settings)

Expand Down
2 changes: 1 addition & 1 deletion docs/hatyan/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h2 id="getting-started">Getting Started</h2>

__author__ = &#34;&#34;&#34;Jelmer Veenstra&#34;&#34;&#34;
__email__ = &#39;[email protected]&#39;
__version__ = &#39;2.5.62&#39;
__version__ = &#39;2.5.64&#39;

from hatyan.analysis_prediction import *
from hatyan.astrog import *
Expand Down
Loading

0 comments on commit a744c98

Please sign in to comment.