Commit d28ee394 authored by David P. Mayer's avatar David P. Mayer Committed by GitHub
Browse files

Merge pull request #35 from acpaquette/ipf

Ipf Reader
parents e16e3498 dec2e3f1
Loading
Loading
Loading
Loading
+1959 −82

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
point_id,stat,known,lat_Y_North,long_X_East,ht,sigma0,sigma1,sigma2,res0,res1,res2
point_id,stat,known,lat_Y_North,long_X_East,ht,sig0,sig1,sig2,res0,res1,res2
1,1,1,0.08538133869186999,2.38013146162178,-2697.2374469465,0.0,0.0,1.707214,16.348041000000002,-13.917623,-0.151001
2,1,1,0.08508542650082002,2.3808135855714703,-2702.0,0.0,0.0,1.0,15.983285999999998,-16.869508,0.103341
3,1,1,0.08626480095809,2.3870838392611,-2714.16003756809,0.0,0.0,3.828854,12.831839,-34.360639,-2.2058459999999998
+122 −0
Original line number Diff line number Diff line
pt_id,val,fid_val,no_obs,l.,s.,sig_l,sig_s,res_l,res_s,fid_x,fid_y
1_8344_8845_4r,1,0,0,-4058.982422,-2318.0107420000004,0.0,0.0,-0.062556,-0.21471300000000001,0.0,0.0
2_8344_8845_4r,1,0,0,-3969.065186,-606.849243,0.0,0.0,0.22866,0.105249,0.0,0.0
3_8344_8845_4r_mt_z,1,0,0,-1019.7390140000001,-2300.877197,0.0,0.0,-0.025129,-0.002447,0.0,0.0
4_8344_8845_4r_mt_z,1,0,0,-1037.0991210000002,-548.180237,0.0,0.0,-0.0007559999999999999,0.227752,0.0,0.0
5_8344_8845_4r,1,0,0,2438.9841309999997,-2304.8435059999997,0.0,0.0,0.062022,-0.10997699999999999,0.0,0.0
6_8344_8845_4r,1,0,0,2397.826904,-562.432861,0.0,0.0,-0.07267799999999999,-0.056103999999999994,0.0,0.0
7_8344_8845_4r_mt_z,1,0,0,-2510.927734,-1267.364868,0.0,0.0,0.21525,-0.040427,0.0,0.0
8_8344-8845_4r_mt_z,1,0,0,840.825317,-1028.345337,0.0,0.0,-0.24192199999999997,0.382924,0.0,0.0
9_8344_8845_4r,1,0,0,-4070.962158,2465.817139,0.0,0.0,-0.140837,0.00598,0.0,0.0
10_8344_8845_4r,1,0,0,-4044.69751,1008.950928,0.0,0.0,0.063678,0.6612939999999999,0.0,0.0
11_8344_8845_4r,1,0,0,-761.216064,2303.787109,0.0,0.0,-0.24730700000000003,-0.587299,0.0,0.0
12_8344_8845_4r,1,0,0,-889.364441,966.5339970000001,0.0,0.0,-0.251753,0.00817,0.0,0.0
13_8344_8845_4r,1,0,0,-2559.871338,1777.522827,0.0,0.0,-0.13126500000000002,-0.305102,0.0,0.0
14_8344_8845_4r,1,0,0,2385.27832,2476.032227,0.0,0.0,0.389532,-0.29925799999999997,0.0,0.0
15_8344_8845_4r_mt_z,1,0,0,2395.869385,1038.165405,0.0,0.0,-0.17085,0.372485,0.0,0.0
16_8344_8845_4r,1,0,0,756.099792,1785.4947510000002,0.0,0.0,0.165338,-0.327408,0.0,0.0
17_8344_8845_2r_mt_z,1,0,0,-3138.269531,442.515503,0.0,0.0,-0.02337,-0.24864299999999998,0.0,0.0
18_8344_8845_2r,1,0,0,-1773.8649899999998,354.084259,0.0,0.0,-0.002223,-0.000684,0.0,0.0
19_8344_8845_2r_mt_z,1,0,0,-92.482826,723.305237,0.0,0.0,-0.214498,0.14519200000000002,0.0,0.0
20_8344_8845_2r_mt_z,1,0,0,1434.079712,742.064026,0.0,0.0,-0.058132,-0.171782,0.0,0.0
21_8344_8845_4r_xyz,1,0,0,-838.9910279999999,-614.524109,0.0,0.0,-0.131313,0.9971200000000001,0.0,0.0
22_8344_8845_4r_mt_z,1,0,0,-3994.073975,-2160.606445,0.0,0.0,0.21777399999999997,-0.141372,0.0,0.0
23_8344_8845_4r_mt_z,1,0,0,-3851.86499,2088.046875,0.0,0.0,-0.07844,-0.22165,0.0,0.0
24_8344_8845_4r_mt_z,1,0,0,2343.634033,-2073.817871,0.0,0.0,-0.27434400000000003,0.06779099999999999,0.0,0.0
25_8344_8845_4r_mt_z,1,0,0,2350.053711,2168.792236,0.0,0.0,-0.311081,-0.152226,0.0,0.0
26_8344_8845_4r_mt_z,1,0,0,-1844.550781,-996.0164789999999,0.0,0.0,-0.108472,0.122981,0.0,0.0
27_8344_8845_2r_mt_z,1,0,0,-1618.0053710000002,700.699158,0.0,0.0,-0.020846,0.073456,0.0,0.0
28_8344_8845_4r_mt_z,1,0,0,521.921509,-1602.4414060000001,0.0,0.0,-0.009861,0.363227,0.0,0.0
29_8344_8845_4r_mt_z,1,0,0,820.691284,1469.345459,0.0,0.0,-0.664959,-0.06624400000000001,0.0,0.0
30_8344_8845_3r_mt_z,1,0,0,-326.405365,-283.346985,0.0,0.0,-0.20681100000000002,0.180573,0.0,0.0
61_8344_8845_4r_mt_z,1,0,0,-4067.466064,-2193.302002,0.0,0.0,-0.017458,-0.229608,0.0,0.0
62_8344_8845_4r_mt_z,1,0,0,2040.637939,2052.019043,0.0,0.0,0.187054,-0.19953900000000002,0.0,0.0
63_8344_8845_4r_mt_z,1,0,0,2267.361328,-1402.6448970000001,0.0,0.0,-0.25967399999999996,-0.350489,0.0,0.0
65_8344_8845_4r_mt_z,1,0,0,-675.820618,1659.5936279999999,0.0,0.0,0.285702,-0.673177,0.0,0.0
P19_008344_1894_XN_09N203W_3,1,0,1,-3543.180176,-2052.497559,0.09999,0.09999,-0.271723,0.046268000000000004,0.0,0.0
P19_008344_1894_XN_09N203W_5,1,0,1,-3693.414551,118.131378,0.191225,0.191225,-0.007534999999999999,3e-06,0.0,0.0
P19_008344_1894_XN_09N203W_8,1,0,1,-3529.115479,1634.99353,0.010654,0.010654,-0.11299000000000001,0.190108,0.0,0.0
P19_008344_1894_XN_09N203W_9,1,0,1,-1530.085083,-2021.120728,0.025998,0.025998,-0.28780100000000003,-0.05082,0.0,0.0
P19_008344_1894_XN_09N203W_10,1,0,1,-1163.659546,-2110.94873,0.054246,0.054246,-0.209774,-0.028914999999999996,0.0,0.0
P19_008344_1894_XN_09N203W_11,1,0,1,-649.603027,-291.606293,0.144968,0.144968,0.179422,0.48035,0.0,0.0
P19_008344_1894_XN_09N203W_12,1,0,1,-1879.1154789999998,1650.314575,0.044342,0.044342,0.194544,-0.551285,0.0,0.0
P19_008344_1894_XN_09N203W_13,1,0,1,1195.076782,-2043.631714,0.081316,0.081316,-0.184309,0.153021,0.0,0.0
P19_008344_1894_XN_09N203W_14,1,0,1,1826.979736,-2180.584961,0.185789,0.185789,0.208304,-0.026378,0.0,0.0
P19_008344_1894_XN_09N203W_15,1,0,1,1833.592407,-1740.516968,0.23812199999999997,0.23812199999999997,0.652892,-0.509659,0.0,0.0
P19_008344_1894_XN_09N203W_16,1,0,1,1370.180664,-273.589996,0.11324100000000001,0.11324100000000001,0.296132,-0.060485000000000004,0.0,0.0
P19_008344_1894_XN_09N203W_17,1,0,1,1198.482544,-429.786133,0.055307,0.055307,-0.091967,0.10811400000000002,0.0,0.0
P19_008344_1894_XN_09N203W_18,1,0,1,1516.067993,1830.024048,0.009269,0.009269,-0.002093,-0.264173,0.0,0.0
P19_008344_1894_XN_09N203W_19,1,0,1,1338.967651,1679.986084,0.004901,0.004901,-0.030115,-0.306342,0.0,0.0
P19_008344_1894_XN_09N203W_20,1,0,1,1350.758423,1952.026978,0.019969999999999998,0.019969999999999998,-0.011408,-0.409686,0.0,0.0
P20_008845_1894_XN_09N203W_1,1,0,0,-3224.0,-2003.0,0.0,0.0,0.055124,0.018517,0.0,0.0
P20_008845_1894_XN_09N203W_2,1,0,0,-3389.0,-2155.0,0.0,0.0,-0.07315,-0.271173,0.0,0.0
P20_008845_1894_XN_09N203W_3,1,0,0,-2913.0,-2000.0,0.0,0.0,-0.08818,-0.049593,0.0,0.0
P20_008845_1894_XN_09N203W_4,1,0,1,-3226.0,167.0,0.0,0.0,-0.195774,-6.6e-05,0.0,0.0
P20_008845_1894_XN_09N203W_5,1,0,1,-2934.0,-6.0,0.0,0.0,-0.049005,0.437424,0.0,0.0
P20_008845_1894_XN_09N203W_6,1,0,3,-3378.0,1532.0,0.0,0.0,0.026541000000000002,0.063346,0.0,0.0
P20_008845_1894_XN_09N203W_7,1,0,3,-3378.0,1672.0,0.0,0.0,0.055623,0.013456000000000001,0.0,0.0
P20_008845_1894_XN_09N203W_8,1,0,3,-2793.0,1837.0,0.0,0.0,-0.11748299999999999,-0.22933699999999999,0.0,0.0
P20_008845_1894_XN_09N203W_9,1,0,0,-780.0,-1953.0,0.0,0.0,0.298743,-0.045963,0.0,0.0
P20_008845_1894_XN_09N203W_10,1,0,2,423.0,-1995.0,0.0,0.0,0.067585,0.401377,0.0,0.0
P20_008845_1894_XN_09N203W_11,1,0,1,-21.0,196.0,0.0,0.0,0.06955,-0.000458,0.0,0.0
P20_008845_1894_XN_09N203W_12,1,0,1,2885.0,-2124.0,0.0,0.0,0.25413600000000003,-0.273798,0.0,0.0
P20_008845_1894_XN_09N203W_13,1,0,1,2746.0,-2253.0,0.0,0.0,-0.407167,-0.176964,0.0,0.0
P20_008845_1894_XN_09N203W_14,1,0,0,2728.0,-1980.0,0.0,0.0,-0.885848,0.137668,0.0,0.0
P20_008845_1894_XN_09N203W_15,0,0,0,2942.0,58.0,0.0,0.0,0.0,0.0,0.0,0.0
P20_008845_1894_XN_09N203W_16,1,0,2,2865.0,2024.0,0.0,0.0,-0.053859000000000004,0.035981,0.0,0.0
P20_008845_1894_XN_09N203W_17,1,0,2,3175.0,1974.0,0.0,0.0,-0.064058,0.044374000000000004,0.0,0.0
P20_008845_1894_XN_09N203W_18,1,0,2,2872.0,1565.0,0.0,0.0,0.256228,0.21886,0.0,0.0
P03_002371_1888_XI_08N204W_49,1,0,1,-2629.182861,1085.034424,0.012761,0.012761,0.20840300000000003,-0.004282,0.0,0.0
P03_002371_1888_XI_08N204W_54,1,0,1,-1095.4067380000001,1127.088013,0.274421,0.274421,0.019106,-0.331897,0.0,0.0
P03_002371_1888_XI_08N204W_55,1,0,1,-941.496277,1247.825806,0.05563099999999999,0.05563099999999999,0.152919,-0.306029,0.0,0.0
P03_002371_1888_XI_08N204W_56,1,0,1,-1098.9589839999999,1441.816895,0.11484200000000001,0.11484200000000001,-0.297223,-0.308728,0.0,0.0
P03_002371_1888_XI_08N204W_63,1,0,1,119.94445800000001,1116.177612,0.023727,0.023727,-0.104057,-0.034587,0.0,0.0
P03_002371_1888_XI_08N204W_64,1,0,1,-19.255381,1270.651611,0.007022,0.007022,-0.29496999999999995,-0.13664600000000002,0.0,0.0
P03_002371_1888_XI_08N204W_65,1,0,1,-271.636139,1030.2692869999998,0.14131400000000002,0.14131400000000002,-0.007378,0.127183,0.0,0.0
P03_002371_1888_XI_08N204W_71,1,0,1,1793.756836,1419.46814,0.070811,0.070811,0.008126999999999999,-0.059650999999999996,0.0,0.0
P03_002371_1888_XI_08N204W_77,1,0,1,3770.185547,1056.4335939999999,0.051015,0.051015,-0.344149,0.7918810000000001,0.0,0.0
P01_001540_1889_XI_08N204W_3,1,0,0,-819.994568,-476.940125,0.0,0.0,-0.010086,0.238933,0.0,0.0
P01_001540_1889_XI_08N204W_4,1,0,0,-1038.7459720000002,-225.617737,0.0,0.0,-0.10251500000000001,0.293944,0.0,0.0
P01_001540_1889_XI_08N204W_5,1,0,0,-1043.086548,-229.29058799999999,0.0,0.0,-0.103618,0.22217399999999998,0.0,0.0
P01_001540_1889_XI_08N204W_6,1,0,0,-1016.6671140000001,-212.669418,0.0,0.0,0.098336,0.182504,0.0,0.0
P01_001540_1889_XI_08N204W_7,1,0,0,-1089.852539,-179.61308300000002,0.0,0.0,-0.09901499999999999,0.24748699999999998,0.0,0.0
P01_001540_1889_XI_08N204W_43,1,0,1,231.430023,1286.035034,0.179721,0.179721,0.043216000000000004,0.007601999999999999,0.0,0.0
P01_001540_1889_XI_08N204W_44,1,0,1,53.3703,1130.200195,0.035373,0.035373,-0.239021,0.05197,0.0,0.0
P01_001606_1897_XI_09N203W_20,1,0,1,-3490.634277,-1071.889893,0.074986,0.074986,-0.10951300000000001,0.027899,0.0,0.0
P01_001606_1897_XI_09N203W_21,1,0,1,-3489.029297,-1344.598267,0.117221,0.117221,0.11984000000000002,-0.07396599999999999,0.0,0.0
P01_001606_1897_XI_09N203W_26,1,0,1,-2843.921875,-1365.05249,0.066368,0.066368,0.053526,-0.129321,0.0,0.0
P01_001606_1897_XI_09N203W_27,1,0,1,-2872.278076,-1055.845581,0.044944,0.044944,0.014887000000000001,-0.175307,0.0,0.0
P01_001606_1897_XI_09N203W_32,1,0,1,-702.726318,-1309.760742,0.097152,0.097152,-0.12127,0.083388,0.0,0.0
P01_001606_1897_XI_09N203W_33,1,0,1,-425.8797,-1332.264404,0.141272,0.141272,0.27812,0.018378,0.0,0.0
P01_001606_1897_XI_09N203W_39,1,0,1,957.507324,-1314.205933,0.214219,0.214219,-0.08834600000000001,0.135983,0.0,0.0
P01_001606_1897_XI_09N203W_40,1,0,1,1286.863525,-1325.946045,0.022701,0.022701,0.025672000000000004,-0.015907,0.0,0.0
P01_001606_1897_XI_09N203W_41,1,0,1,1415.3436279999999,-1585.812134,0.062944,0.062944,0.17824700000000002,0.100219,0.0,0.0
P01_001606_1897_XI_09N203W_42,1,0,1,-713.122681,-1899.2719730000001,0.10971099999999999,0.10971099999999999,-0.24755700000000003,0.240463,0.0,0.0
P01_001606_1897_XI_09N203W_48,1,0,1,2357.769287,-1605.21167,0.142259,0.142259,-0.046652,-0.341859,0.0,0.0
P01_001606_1897_XI_09N203W_49,1,0,1,2368.67749,-1310.2536619999998,0.084816,0.084816,0.16844800000000001,-0.178884,0.0,0.0
P01_001606_1897_XI_09N203W_50,1,0,1,2938.904541,-1286.650635,0.268181,0.268181,0.22215,-0.28928200000000004,0.0,0.0
P03_002226_1895_XI_09N203W_41,1,0,1,-2964.822021,-752.72998,0.130511,0.130511,0.19989500000000002,0.18193199999999998,0.0,0.0
P03_002226_1895_XI_09N203W_42,1,0,1,-2676.941162,-549.997925,0.015522999999999999,0.015522999999999999,-0.189075,0.282047,0.0,0.0
P03_002226_1895_XI_09N203W_43,1,0,1,-2503.68457,-1243.333618,0.091619,0.091619,-0.183131,-0.034143,0.0,0.0
P03_002226_1895_XI_09N203W_46,1,0,1,-984.080139,-1301.115845,0.02843,0.02843,-0.10387,-0.014166,0.0,0.0
P03_002226_1895_XI_09N203W_47,1,0,1,-1119.626953,-926.1320800000001,0.195907,0.195907,-0.217611,0.08741499999999999,0.0,0.0
P03_002226_1895_XI_09N203W_53,1,0,1,3304.79834,-528.821411,0.090225,0.090225,-0.12703599999999998,-0.24331999999999998,0.0,0.0
P03_002226_1895_XI_09N203W_54,1,0,1,3597.587646,-608.987488,0.18746300000000002,0.18746300000000002,0.13215,-0.402642,0.0,0.0
P03_002226_1895_XI_09N203W_55,1,0,1,3277.619873,-1106.364136,0.141123,0.141123,-0.258301,-0.48746300000000004,0.0,0.0
P03_002226_1895_XI_09N203W_64,1,0,1,-1488.9279789999998,306.37027,0.141123,0.141123,0.11354000000000002,0.000408,0.0,0.0
P03_002226_1895_XI_09N203W_67,1,0,1,-1501.843384,294.863434,0.141123,0.141123,-0.038216,-0.001066,0.0,0.0
P03_002226_1895_XI_09N203W_68,1,0,1,-1487.291992,301.690338,0.141123,0.141123,-0.16136,0.000601,0.0,0.0
P03_002226_1895_XI_09N203W_71,1,0,1,-1476.8244630000002,421.30285599999996,0.141123,0.141123,0.045458,0.000436,0.0,0.0
P03_002226_1895_XI_09N203W_66,1,0,1,-1473.926636,445.16494800000004,0.141123,0.141123,-0.039173,-6.1e-05,0.0,0.0
P03_002226_1895_XI_09N203W_72,1,0,1,-1478.19104,398.059052,0.141123,0.141123,0.03951,-0.0005690000000000001,0.0,0.0
P03_002226_1895_XI_09N203W_74,1,0,1,-1463.276489,270.004364,0.141123,0.141123,0.097608,0.000572,0.0,0.0
P03_002226_1895_XI_09N203W_76,1,0,1,-1399.385376,210.815338,0.141123,0.141123,-0.021339,-0.000335,0.0,0.0
P03_002226_1895_XI_09N203W_82,1,0,1,-1110.612061,-112.804382,0.141123,0.141123,-0.179249,0.431591,0.0,0.0
P19_008344_1894_XN_09N203W_2,1,0,1,-3987.0656740000004,-1756.185791,0.141123,0.141123,0.018394,-0.141215,0.0,0.0
P19_008344_1894_XN_09N203W_7,1,0,1,-3991.17334,1967.117554,0.141123,0.141123,0.242488,-0.04689,0.0,0.0
P03_002371_1888_XI_08N204W_76,1,0,1,4066.5737299999996,1038.447998,0.141123,0.141123,-0.272976,0.9673510000000001,0.0,0.0
P03_002371_1888_XI_08N204W_78,1,0,1,4083.8732909999994,1277.689209,0.141123,0.141123,-0.328486,0.8362860000000001,0.0,0.0
P01_001606_1897_XI_09N203W_19,1,0,1,-3917.203125,-1175.195679,0.141123,0.141123,-0.022262999999999998,-0.15115599999999998,0.0,0.0
P01_001606_1897_XI_09N203W_65,1,0,1,4070.48584,-2315.9921879999997,0.141123,0.141123,-0.12137,-0.47907,0.0,0.0
P03_002226_1895_XI_09N203W_1,1,0,0,-1197.647949,-569.925598,0.0,0.0,-0.070627,0.194853,0.0,0.0
P03_002226_1895_XI_09N203W_2,1,0,0,-1241.685791,-499.006836,0.0,0.0,-0.066482,0.270447,0.0,0.0
+97 −12
Original line number Diff line number Diff line
import json
import re
from functools import singledispatch

import numpy as np
import pandas as pd
@@ -52,6 +53,77 @@ def socetset_keywords_to_json(keywords, ell=None):
        parse(ell)
    return json.dumps(stream)

@singledispatch
def read_ipf(arg): # pragma: no cover
    return str(arg)

@read_ipf.register(str)
def read_ipf_str(input_data):
    """
    Read a socet ipf file into a pandas data frame

    Parameters
    ----------
    input_data : str
                 path to the an input data file

    Returns
    -------
    df : pd.DataFrame
         containing the ipf data with appropriate column names and indices
    """

    # Check that the number of rows is matching the expected number
    with open(input_data, 'r') as f:
        for i, l in enumerate(f):
            if i == 1:
                cnt = int(l)
            elif i == 2:
                col = l
                break

    columns = np.genfromtxt(input_data, skip_header=2, dtype='unicode',
                            max_rows = 1, delimiter = ',')

    # TODO: Add unicode conversion
    d = [line.split() for line in open(input_data, 'r')]
    d = np.hstack(np.array(d[3:]))

    d = d.reshape(-1, 12)

    df = pd.DataFrame(d, columns=columns)

    assert int(cnt) == len(df), 'Dataframe length {} does not match point length {}.'.format(int(cnt), len(df))

    # Soft conversion of numeric types to numerics, allows str in first col for point_id
    df = df.apply(pd.to_numeric, errors='ignore')

    return df

@read_ipf.register(list)
def read_ipf_list(input_data_list):
    """
    Read a socet ipf file into a pandas data frame

    Parameters
    ----------
    input_data_list : list
                 list of paths to the a set of input data files

    Returns
    -------
    df : pd.DataFrame
         containing the ipf data with appropriate column names and indices
    """
    frames = []

    for input_file in input_data_list:
        frames.append(read_ipf(input_file))

    df = pd.concat(frames)

    return df

def read_gpf(input_data):
    """
    Read a socet gpf file into a pandas data frame
@@ -76,22 +148,35 @@ def read_gpf(input_data):
                col = l
                break

    default_columns = np.genfromtxt(input_data, skip_header=2, dtype='unicode',
                                    max_rows = 1, delimiter = ',')

    columns = []

    for column in default_columns:

        if '(' in column and ')' in column:
            column_name ,suffix = column.split('(')
            num = int(suffix.split(')')[0])

            for column_num in range(int(num)):
                new_column = '{}{}'.format(column_name, column_num)
                columns.append(new_column);

        else:
            columns.append(column)

    # Mixed types requires read as unicode - let pandas soft convert
    d = np.genfromtxt(input_data, skip_header=3, dtype='unicode')
    d = d.reshape(-1, 12)

    #TODO: cols should be used to dynamically generate the column names

    df = pd.DataFrame(d, columns=['point_id', 'stat', 'known',
                              'lat_Y_North', 'long_X_East','ht',
                              'sigma0', 'sigma1', 'sigma2',
                              'res0', 'res1', 'res2'])
    df = pd.DataFrame(d, columns=columns)

    # Soft conversion of numeric types to numerics, allows str in first col for point_id
    df = df.apply(pd.to_numeric, errors='ignore')

    # Validate the read data with the header point count
    assert int(cnt) == len(df)
    assert int(cnt) == len(df), 'Dataframe length {} does not match point length {}.'.format(int(cnt), len(df))

    return df

@@ -132,7 +217,7 @@ def save_gpf(df, output_file):
        #Output coordinates to gpf file
        outGPF.write('{0} {1} {2}\n'.format(row['point_id'], row['stat'], row['known']))
        outGPF.write('{0}         {1}         {2}\n'.format(row['lat_Y_North'], row['long_X_East'], row['ht']))
        outGPF.write('{0} {1} {2}\n'.format(row['sigma0'], row['sigma1'], row['sigma2']))
        outGPF.write('{0} {1} {2}\n'.format(row['sig0'], row['sig1'], row['sig2']))
        outGPF.write('{0} {1} {2}\n\n'.format(row['res0'], row['res1'], row['res2']))

    outGPF.close()
+24 −10
Original line number Diff line number Diff line
import json

import numpy as np
import pandas as pd
from pandas.util.testing import assert_frame_equal

from plio.io.io_bae import socetset_keywords_to_json, read_gpf, save_gpf
from plio.io.io_bae import socetset_keywords_to_json, read_gpf, save_gpf, read_ipf
from plio.examples import get_path

import pytest
@@ -13,27 +14,40 @@ def insight_gpf():
    return get_path('InSightE08_XW.gpf')

@pytest.fixture()
def insight_expected():
def insight_expected_gpf():
    return pd.read_csv(get_path('InSightE08_XW.csv'))

@pytest.mark.parametrize('gpf, expected', [(insight_gpf(),insight_expected())])
@pytest.fixture
def insight_ipf():
    return get_path('P20_008845_1894_XN_09N203W.ipf')

@pytest.fixture()
def insight_expected_ipf():
    return pd.read_csv(get_path('P20_008845_1894_XN_09N203W.csv'))

@pytest.mark.parametrize('gpf, expected', [(insight_gpf(),insight_expected_gpf())])
def test_read_gfp(gpf, expected):
    df = read_gpf(gpf)
    assert_frame_equal(df, expected)

@pytest.mark.parametrize('gpf', [(insight_gpf())])
def test_write_gpf(gpf):
@pytest.mark.parametrize('ipf, expected', [([insight_ipf()],insight_expected_ipf())])
def test_read_ifp(ipf, expected):
    df = read_ipf(ipf)
    assert_frame_equal(df, expected)

@pytest.mark.parametrize('gpf, file', [(insight_gpf(), 'out.gpf')])
def test_write_gpf(gpf, file):
    """
    We test by manually comparing files and not using filecmp so that we
    are not testing float point precision differences, e.g. 0.0 == 0.00000000.
    """
    df = read_gpf(gpf)
    save_gpf(df, 'out.gpf')
    save_gpf(df, file)

    with open(gpf) as f:
        fl = f.readlines()

    with open('out.gpf') as f:
    with open(file) as f:
        fs = f.readlines()

    # Check that the header is the same
@@ -41,7 +55,7 @@ def test_write_gpf(gpf):
        assert fl[i] == fs[i]

    truth_arr = np.genfromtxt(gpf, skip_header=3)
    test_arr = np.genfromtxt('out.gpf', skip_header=3)
    test_arr = np.genfromtxt(file, skip_header=3)
    np.testing.assert_array_almost_equal(truth_arr, test_arr)

def test_create_from_socet_lis():