Skip to content

Commit

Permalink
test for estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
facusapienza21 committed Oct 3, 2023
1 parent f71a43c commit d66016c
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion smpsite/smpsite/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def estimate_pole(df_sample, params, ignore_outliers):



def simulate_estimations(params, n_iters=100, ignore_outliers=False, seed=None):
def simulate_estimations(params, n_iters=100, ignore_outliers="False", seed=None):
'''
Given a sampling strategy (samples per site and total number of samples)
returns a DF with results of n_iters simulated poles.
Expand Down
51 changes: 51 additions & 0 deletions smpsite/smpsite/test/data/df1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
,sample_site,vgp_long,vgp_lat,vgp_dec,vgp_inc,is_outlier
0,0,219.13330481569574,81.26082305832416,354.4888357847315,6.351383145022099,0
1,0,237.74717618213316,66.85382686386579,340.5615969983794,-5.365834506825029,0
2,0,192.711474408199,79.36339904242857,357.6722343122069,-0.7626174117950171,0
3,0,213.8387689568436,74.37789364520403,351.3633126291201,-6.064222264978353,0
4,0,296.98902000463045,33.764886440746494,303.04112738724984,46.64939083492478,1
5,1,243.73625218829494,80.8214209264816,351.73256176698,11.579164264807307,0
6,1,280.42933080429617,71.70316874959207,341.54443485371735,24.363500822120454,0
7,1,230.4788453844742,85.19890481348794,356.2709932758645,13.65521061595589,0
8,1,99.88502789355302,3.0068304979169693,85.26849628337541,-17.93150862219616,1
9,1,42.65365480998903,-55.24497456953516,156.34778489033346,29.307049169851197,1
10,2,97.0615820505266,70.82814024365085,19.175165536777058,14.060894965312187,0
11,2,147.15478420420132,81.25380937998214,4.735640321296188,5.241455350347652,0
12,2,90.35617051394006,69.31459011574015,20.9686440176458,17.99287037607214,0
13,2,113.42608204711446,72.1158741797574,16.383576370522775,5.150531078481537,0
14,2,101.80817882405739,71.6223862054569,18.071325282625423,11.505708190308939,0
15,3,353.0213847012938,70.36117170613686,357.31146458524506,48.50518352134069,0
16,3,335.0080476288843,78.15384411387532,354.6807312774738,37.05397904398577,0
17,3,46.60452987812272,72.72343355380315,13.412531604297016,38.25370220359266,0
18,3,29.375970348082237,80.57286770555638,4.8509764905785175,33.28391791296636,0
19,3,23.857879518844253,81.63842317477004,3.5382304651325285,32.43082978237877,0
20,4,316.0277772064835,65.65157721762687,341.29984761029846,45.255234669445514,0
21,4,321.9301858689908,72.85486441186181,348.59059370661134,40.649362033716244,0
22,4,324.44599781252964,78.11403389373059,352.6977229604082,35.41121301073734,0
23,4,302.3368540741673,67.68801299542302,339.88436092207087,37.71508838008895,0
24,4,185.17670049435225,64.8185553372273,357.72133134223714,-28.319900116930505,1
25,5,305.73802862239955,82.46716442483972,353.6946398805071,27.067849007784137,0
26,5,341.7332710354796,79.94586521562428,356.6715761188276,35.34736705729971,0
27,5,2.5295280849800044,85.06155695210555,0.22529452994513122,28.076034919024067,0
28,5,340.93761183179936,79.877446693818,356.5079284502881,35.37412879771137,0
29,5,17.53335607461966,78.7659008434254,3.596878182780358,37.06107768699812,0
30,6,98.18150868669491,70.53883680140027,19.393788984871236,13.261949751897834,0
31,6,106.08295929096683,71.15006917736781,18.140622923161516,8.688893862038048,0
32,6,110.2215268740124,74.72384473611093,14.358261587572258,8.873818596469382,0
33,6,82.15126280150365,75.67391401241669,14.492695455765585,22.36678792694117,0
34,6,94.04437260375809,77.25476551834072,12.869162067354267,17.318220336626407,0
35,7,295.5593003361987,79.88829113634073,350.596341884356,26.867056444448803,0
36,7,286.73501819313776,80.48590716921939,350.6656542353553,24.085935544636758,0
37,7,288.35052170919556,82.66191410585289,352.8744592476786,23.43623378890866,0
38,7,280.6295897055199,71.97075496552158,341.82450389258975,24.415669413288366,0
39,7,262.10537724648555,72.10764200102851,342.14115966523593,13.99844498948782,0
40,8,352.1100676804693,84.52847864690229,359.22203980719553,28.880840630061492,0
41,8,309.3510029772657,75.97433802716435,348.5918835633614,34.0220182579263,0
42,8,10.176222570142908,75.14783920307329,2.854973818110466,42.48164812467167,0
43,8,321.4106181095484,80.01068167389938,353.47760202801817,32.59724801941754,0
44,8,318.6204418812604,67.47173232310028,343.5854124274588,44.70338391673065,0
45,9,60.719855724102786,69.75700713602085,18.642120942541112,34.921027591595205,0
46,9,77.15890160112627,71.06727789834594,18.994604254919693,25.83282896636268,0
47,9,341.7104171985521,86.95183748031964,359.01910212067173,24.597833775742476,0
48,9,72.88337267387455,74.2611694052295,15.512022310014629,26.888210271381755,0
49,9,249.96946085012448,46.81388689225083,319.722159655811,-11.838709337890075,1
54 changes: 54 additions & 0 deletions smpsite/smpsite/test/test_estimate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import smpsite as smp
import numpy as np
import pandas as pd
from numpy.testing import assert_allclose

params0 = smp.Params(N=10,
n0=5,
kappa_within_site=100,
site_lat=10,
site_long=0,
outlier_rate=0.10,
secular_method="G",
kappa_secular=None)

def test_robust_fisher_mean_single():
_res = smp.robust_fisher_mean([10.0], [20.0])
assert _res['vgp_dec'] == 10.0
assert _res['vgp_inc'] == 20.0
assert _res['n_samples'] == 1
assert _res['resultant_length'] == 1.0

def test_robust_fisher_mean_multiple():
_res = smp.robust_fisher_mean([10.0, 20.0], [0.0, 0.0])
assert_allclose(_res['vgp_dec'], 15.0, 1e-6)

def test_estimate():

# Read sample data created with these params
df = pd.read_csv('./smpsite/test/data/df1.csv')

_res = smp.estimate_pole(df, params0, ignore_outliers="True")

assert_allclose(_res['pole_dec'], 350.20065867362314)
assert_allclose(_res['pole_inc'], 86.75081527833235)
assert_allclose(_res['S2_vgp'], 182.60923786776738)

_res = smp.estimate_pole(df, params0, ignore_outliers="False")

assert_allclose(_res['pole_dec'], 18.215514011721595)
assert_allclose(_res['pole_inc'], 86.81743210088786)
assert_allclose(_res['S2_vgp'], 99.71484820447859)

_res = smp.estimate_pole(df, params0, ignore_outliers="vandamme")

assert_allclose(_res['pole_dec'], 18.215514011721595)
assert_allclose(_res['pole_inc'], 86.81743210088786)
assert_allclose(_res['S2_vgp'], 99.71484820447859)


def test_simulate():
_df = smp.simulate_estimations(params0, n_iters=10, ignore_outliers="True", seed=666)
assert _df.shape == (10,17)
for col in ['plong', 'plat', 'S2_vgp', 'error_angle']:
assert col in _df.columns

0 comments on commit d66016c

Please sign in to comment.