From 7c82fd73a18435c897fb4b876b84437a0542ee3b Mon Sep 17 00:00:00 2001 From: Lachlan Phillips Date: Sun, 22 Aug 2021 17:11:30 +1000 Subject: [PATCH 1/4] Reader for CastAway CSV format --- ctd/read.py | 44 +++++++++ tests/data/castaway_data.csv | 170 +++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100755 tests/data/castaway_data.csv diff --git a/ctd/read.py b/ctd/read.py index 4f2533e..095cf3e 100644 --- a/ctd/read.py +++ b/ctd/read.py @@ -488,3 +488,47 @@ def rosette_summary(fname): ros["nbf"] = ros["nbf"].astype(int) ros.set_index("nbf", drop=True, inplace=True, verify_integrity=False) return ros + +def from_castaway_csv(fname): + """ + DataFrame constructor to open CastAway CSV format. + + Example + -------- + >>> import ctd + >>> cast = ctd.from_castaway_csv('tests/data/castaway_data.csv') + >>> downcast, upcast = cast.split() # upcast often prefiltered + >>> fig, ax = plt.subplots() + >>> ax = downcast['temperature'].plot_cast() + >>> fig.show() + + """ + with open(fname) as file: + f = file.readlines() + + # Strip newline characters + f = [s.strip() for s in f] + + # separte meta data and CTD profile + meta = [s for s in f if s[0] == '%'][0:-1] + data = [s.split(',') for s in f if s[0] != '%'] + df = pd.DataFrame(data[1:-1], columns=data[0]) + + # convert to numeric + for col in df.columns: + df[col] = pd.to_numeric(df[col]) + + # normlise column names and extract units + units = [s[s.find("(")+1:s.find(")")] for s in df.columns] + df.columns = [_normalize_names(s.split('(')[0]).lower().replace(' ','_') for s in df.columns] + df.set_index("pressure", drop=True, inplace=True, verify_integrity=False) + + # Add metadata + meta = [s.replace('%','').strip().split(',') for s in meta] + metadata = {} + for l in meta: + metadata[l[0]] = l[1] + metadata['units'] = units + setattr(df, "_metadata", metadata) + + return df diff --git a/tests/data/castaway_data.csv b/tests/data/castaway_data.csv new file mode 100755 index 0000000..81cc03e --- /dev/null +++ b/tests/data/castaway_data.csv @@ -0,0 +1,170 @@ +% Device,CC1449004 +% File name,CC1449004_20170822_023911 +% Cast time (UTC),2017-08-22 02:39:11 +% Cast time (local),2017-08-22 12:39:11 +% Sample type,Cast +% Cast data,Processed +% Location source,GPS +% Default latitude,32 +% Default altitude,0 +% Start latitude,-36.2199169 +% Start longitude,150.2301061 +% Start altitude,-11.510000228881836 +% Start GPS horizontal error(Meter),3.3499999046325684 +% Start GPS vertical error(Meter),2.8199999332427979 +% Start GPS number of satellites,5 +% End latitude,-36.2209792 +% End longitude,150.2303978 +% End altitude,17.149999618530273 +% End GPS horizontal error(Meter),3.7699999809265137 +% End GPS vertical error(Meter),3.0699999332427979 +% End GPS number of satellites,5 +% Cast duration (Seconds),191.4 +% Samples per second,5 +% Electronics calibration date,0001-01-01 +% Conductivity calibration date,2017-07-10 +% Temperature calibration date,2017-07-08 +% Pressure calibration date,2017-06-13 +% +Pressure (Decibar),Depth (Meter),Temperature (Celsius),Conductivity (MicroSiemens per Centimeter),Specific conductance (MicroSiemens per Centimeter),Salinity (Practical Salinity Scale),Sound velocity (Meters per Second),Density (Kilograms per Cubic Meter) +0.15,0.14918969207604846,16.44616462140171,45033.875,54328.157275071106,35.607839890028522,1511.8595379477067,1026.1134459830698 +0.44999999999999996,0.4475594436187802,16.338550527745483,45016.243174780633,54448.260280155162,35.688421488779753,1511.6302654471911,1026.2018541754821 +0.74999999999999989,0.745917521168835,16.318359541774043,44964.884109873245,54412.717020399206,35.660764631948126,1511.5418830254562,1026.1866110037611 +1.05,1.0442773544836836,16.306742507616722,44952.61091070062,54413.163786047306,35.660150700018228,1511.5107680006493,1026.1901669839594 +1.35,1.3426356697470967,16.292997956917986,44942.9115730025,54419.53090920228,35.663733044379306,1511.4779983514277,1026.1974441343039 +1.65,1.6409937035694138,16.284870465223147,44922.915116326476,54406.026481502333,35.653117254621741,1511.4459603757432,1026.1924935993031 +1.9500000000000002,1.9393524242776337,16.278004298744751,44912.759319604804,54402.7746527593,35.650121077155042,1511.4265500961376,1026.1931097083511 +2.25,2.2377111141341204,16.270587163531417,44900.943250482305,54398.236536550707,35.646140717025375,1511.404320191685,1026.1930964406547 +2.55,2.5360696835221885,16.264983127137331,44893.392747030375,54396.475346559477,35.644328397803768,1511.3901161627346,1026.1943290152785 +2.85,2.8344274897958521,16.260511354704352,44892.006963315725,54400.691471553131,35.646986070014904,1511.3845198534937,1026.1987364756424 +3.15,3.1327840068044455,16.256351198985545,44891.690055619089,54405.7929882114,35.6503159155875,1511.3806482061991,1026.2035884619872 +3.4499999999999997,3.431139786726034,16.254626641177548,44888.456704356082,54404.148527127247,35.648865084503825,1511.3786902315192,1026.2041975236075 +3.75,3.7294954474345863,16.253840347192504,44886.476655865743,54402.785629290454,35.647687917549604,1511.3799101148204,1026.20479915087 +4.05,4.0278508104475037,16.252878042390414,44886.063786484687,54403.554268820837,35.648063536141777,1511.3823844192332,1026.2066360078927 +4.35,4.3262056651020986,16.251994101861818,44886.068975450522,54404.72630803645,35.648740971669106,1511.3854459418228,1026.2086868062318 +4.6499999999999995,4.624560737549869,16.251722554954377,44879.290403302723,54396.86832897197,35.642830821616727,1511.3827754898396,1026.2055284070545 +4.9499999999999993,4.92291560622033,16.249080241982448,44881.1628593355,54402.622550667678,35.64674771982709,1511.3842094213062,1026.2104792313039 +5.2499999999999991,5.2212694086837148,16.247411794991351,44881.168051899913,54404.82941689666,35.648129034411156,1511.3856890406569,1026.2132535851181 +5.55,5.5196232747433545,16.244026311085385,44870.688510879409,54396.59088135542,35.64171726040091,1511.3729372769667,1026.2104323585108 +5.85,5.8179764657510482,16.242058566247096,44877.71118147541,54407.700223533175,35.649614458276844,1511.3810209569501,1026.2182880203768 +6.1499999999999995,6.1163284611473765,16.2399673425783,44874.20498086929,54406.208191317863,35.648249137924495,1511.3780402689345,1026.2190478067889 +6.4499999999999993,6.41468070494374,16.239313500602755,44868.491035288418,54400.143002662524,35.643628354316235,1511.3756897433509,1026.2169698357616 +6.7499999999999991,6.713032321994433,16.237859901926093,44874.634875147181,54409.509831342177,35.65028250908221,1511.3839079376646,1026.2237499794728 +7.0499999999999989,7.0113834294534891,16.237800326489172,44868.544668490969,54402.204183123686,35.644793293798266,1511.3823689101318,1026.2208660529757 +7.35,7.3097343459485788,16.236370982443429,44871.520460250751,54407.6980966087,35.648605139653377,1511.3873813609746,1026.225454297783 +7.6499999999999995,7.6080842306475933,16.236148529279845,44873.657085939485,54410.582324482624,35.650586933835015,1511.393965785725,1026.2283547193085 +7.9499999999999993,7.9064336203117147,16.233976135401864,44870.240353001922,54409.3058181674,35.649373931588812,1511.3909119368757,1026.2292504325963 +8.25,8.20478230473952,16.233688163652932,44874.399983116375,54414.7297775229,35.653215994978609,1511.3994429604204,1026.2335969387509 +8.5499999999999989,8.5031304050944847,16.23302437422241,44871.798123302862,54412.450704629,35.6513746621222,1511.4002686595566,1026.2336591221356 +8.85,8.8014788433741611,16.233444328505385,44867.650331649806,54406.866879941961,35.647184199136177,1511.401691715387,1026.2316628279225 +9.1499999999999986,9.0998270311496263,16.232009272342143,44869.920183336995,54411.513015247496,35.650372945368225,1511.4059673597324,1026.235773069262 +9.45,9.3981744503391269,16.230419840388663,44868.270038518691,54411.609452696437,35.650209735585136,1511.4059036794297,1026.2373408873068 +9.75,9.6965215803585565,16.2284911666757,44865.059856295287,54410.261674284811,35.648961722028659,1511.4035522936511,1026.2381530233513 +10.049999999999999,9.9948681841227565,16.226870683730841,44865.749151336247,54413.236327734907,35.650909681302352,1511.4058295547941,1026.2413518802748 +10.35,10.293214621831423,16.226573138708115,44861.118119532526,54408.012483351289,35.646932303629825,1511.4053078879606,1026.2396860169311 +10.649999999999999,10.591560843989752,16.226532035097595,44864.431401570131,54412.0851147211,35.649799574431569,1511.4134677612169,1026.2432253846043 +10.95,10.889907011663023,16.226223943581726,44858.168499921907,54404.895972658705,35.644378427221291,1511.4112477736269,1026.2404514609461 +11.25,11.188253079283268,16.225773928924848,44861.388856300655,54409.3956048512,35.647529901201935,1511.4184871636683,1026.2443043210294 +11.549999999999999,11.486598006918928,16.224521565963332,44864.2986958478,54414.577770248296,35.651125068416327,1511.4237888907583,1026.248684684648 +11.85,11.784942648033466,16.225627304786236,44861.0425226974,54409.169072230332,35.647112569913823,1511.4275110421249,1026.2466660811508 +12.149999999999999,12.08328738048087,16.223897360133293,44859.514510512141,54409.599022889539,35.6471840608543,1511.4272881894945,1026.2484469631804 +12.45,12.381631352335475,16.224382902449886,44863.979201023336,54414.37329357471,35.650604221629763,1511.4376941558778,1026.2522892991731 +12.75,12.679974899305096,16.224097664871088,44861.025031566416,54411.166735851344,35.648109049037359,1511.4389203530993,1026.2517606348893 +13.049999999999999,12.978318627989781,16.223841911981893,44858.39931279829,54408.319594006585,35.645879935533586,1511.4405435930148,1026.2514297730997 +13.35,13.276661878838306,16.223589706345621,44862.113682637551,54413.157614621618,35.649293987983704,1511.4486899654685,1026.2554386145423 +13.649999999999999,13.575005058300206,16.223355464481948,44855.434829004851,54405.36599167953,35.643435930746357,1511.4461909842912,1026.252311500923 +13.95,13.873348049955746,16.223080097990731,44860.287317289156,54411.615059637072,35.647884340709396,1511.4554603025529,1026.2571212849148 +14.249999999999998,14.171689999498456,16.2217125602814,44860.662452729972,54413.8751963872,35.649325561935996,1511.4579243715891,1026.2598715615152 +14.549999999999999,14.470031432557219,16.220598641181319,44859.106714802911,54413.458554173631,35.648819508351451,1511.4589155060689,1026.2610651850118 +14.85,14.768373054949951,16.219952936580633,44853.365433009683,54407.346730865116,35.644165404791735,1511.4565492103643,1026.2589595999582 +15.149999999999999,15.066714151473702,16.216262522072,44855.523088117043,54414.835726669975,35.649279074473952,1511.4561574147717,1026.2650736803196 +15.45,15.365054134892425,16.214649732938788,44854.37716472023,54415.574868846408,35.649585754783743,1511.4565623862138,1026.2670081669508 +15.749999999999998,15.663394388034407,16.212912376631358,44845.278371622677,54406.830026711417,35.642920099037411,1511.4485397273588,1026.2636086415605 +16.05,15.961734882360286,16.210476028823074,44843.310659084957,54407.65914438969,35.643233650019262,1511.4464365397816,1026.2657394688572 +16.35,16.260074507907994,16.209881972628189,44846.896658363461,54412.7943488785,35.646841052214647,1511.4537619720475,1026.2699763280525 +16.650000000000002,16.558413856627052,16.209002408182027,44841.081023752224,54406.899467735049,35.6423295624976,1511.4508447811718,1026.2680346226791 +16.95,16.856752977205257,16.208995982656937,44844.969208153881,54411.625591445089,35.64567878729175,1511.459667186344,1026.2719365307496 +17.25,17.155091539237425,16.208260268303746,44842.664788805763,54409.800968105294,35.644166037193919,1511.4606503484411,1026.2722679775229 +17.55,17.453429725283282,16.208823495703417,44845.486830167494,54412.481388656059,35.646054238850738,1511.4695265968089,1026.2749139091807 +17.85,17.75176754278079,16.209044524215919,44844.395696450127,54410.865641519478,35.644763603916346,1511.4736886262183,1026.2751941834451 +18.150000000000002,18.050105128273348,16.209312907079685,44845.449868673677,54411.790327338007,35.645341561014213,1511.4801519728128,1026.2769007102149 +18.45,18.348442408004324,16.209696238618925,44845.317829874875,54411.123986700113,35.644759654900405,1511.4856277654976,1026.2776884298678 +18.75,18.646779580218798,16.210247612641314,44844.76235806325,54409.722042421119,35.643649756899258,1511.4910074669435,1026.2780310342241 +19.05,18.94511598079885,16.208617921070481,44848.588884781406,54416.516674598017,35.648400992861781,1511.496489605214,1026.2833879178872 +19.35,19.243451900540293,16.209061621203418,44844.968589007425,54411.538172387322,35.644657469678165,1511.4985007652022,1026.2817298283319 +19.650000000000002,19.541787912762384,16.208836435361796,44844.929114721366,54411.787609027706,35.644704198191441,1511.5028433133418,1026.2831422549502 +19.95,19.8401234706912,16.20820396391106,44845.350318952231,54413.133800039519,35.645526867349091,1511.5068372866203,1026.2852460118663 +20.25,20.138458777908333,16.20888518302106,44844.486870004366,54411.186654087469,35.644026063783066,1511.5121625061763,1026.2852577827778 +20.55,20.436793603878925,16.208922332980848,44848.124556238909,54415.551314169519,35.647112988116525,1511.5208153209469,1026.2889476590769 +20.85,20.735127831502751,16.20914017726334,44847.813189481662,54414.885868239879,35.646519874939251,1511.5257726947311,1026.289765095956 +21.150000000000002,21.033461903036841,16.207845381872005,44845.216722251665,54413.445190681821,35.645248845827773,1511.5253269411705,1026.2904121909648 +21.45,21.331795578390938,16.208093188125559,44847.356591167816,54415.714391864822,35.646812456791572,1511.5328651116843,1026.2928814956379 +21.75,21.630129289549473,16.208254653572148,44842.38281949683,54409.466254365689,35.64211665417573,1511.5329150238511,1026.2905564586595 +22.05,21.928462470953015,16.206784568529727,44847.889084316645,54418.08861563987,35.648221018351883,1511.5404462439583,1026.296916940817 +22.35,22.226795227219128,16.206221676832861,44840.889787372595,54410.338976290121,35.64237078041716,1511.5369507866567,1026.2938720922448 +22.650000000000002,22.525127427706447,16.205622635879323,44848.880383591932,54420.825987641168,35.649906712492673,1511.5487952437845,1026.3011314660434 +22.95,22.823459282815808,16.206232026348207,44841.346622205718,54410.879637736762,35.642528070375349,1511.5471168943002,1026.2966389786745 +23.25,23.1217915305294,16.206033216164844,44842.4657362486,54412.500107699292,35.643583254497223,1511.5527039037954,1026.2988208436432 +23.55,23.420123058913251,16.20425480586902,44842.882829997936,54415.354726437909,35.645430828038563,1511.5543797312125,1026.3019787789792 +23.85,23.718454436962077,16.205845268638967,44840.697130630317,54410.602231666591,35.641936031451891,1511.560181434056,1026.3002457983707 +24.150000000000002,24.016785797708796,16.205518685462614,44841.732955694795,54412.2903754577,35.643031697370859,1511.5654248090561,1026.30248843121 +24.45,24.3151169261703,16.205294894910885,44839.263576083205,54409.589459850147,35.640912555379572,1511.5672716440784,1026.3022345984105 +24.75,24.613447622490291,16.204209054708841,44841.284209972582,54413.475271949304,35.643566967548722,1511.5719945012186,1026.3058523216926 +25.05,24.911777679903569,16.203315929104825,44839.990101082658,54413.084347671393,35.64309550176052,1511.5736981017205,1026.3070211073004 +25.35,25.21010766415765,16.202988085403568,44837.350139633971,54410.313697027595,35.640917693417705,1511.5751592049592,1026.3067462907411 +25.650000000000002,25.508437296658133,16.202790264765813,44839.78959344847,54413.535230638015,35.643148306712767,1511.5821059230216,1026.3098319200503 +25.95,25.806766643162153,16.201296985323641,44834.920544761859,54409.598514256177,35.640030559273676,1511.5789211916572,1026.3091046644101 +26.25,26.105095797772826,16.202192140372947,44837.886346152416,54412.015498341592,35.641749209340034,1511.5886164668041,1026.3115428353608 +26.55,26.403424510547364,16.20271398179792,44838.239747133142,54411.755214645913,35.641475536121291,1511.594871451573,1026.312535292896 +26.85,26.701752291736177,16.202164443293498,44844.178725396821,54419.688056820196,35.647139535381555,1511.6047065438888,1026.3183432044 +27.150000000000002,27.000079516536083,16.202079879992041,44839.948271992471,54414.665961762526,35.643326388791138,1511.6050232989408,1026.3167541212201 +27.45,27.298406941297291,16.200816144689973,44837.330850365783,54413.1585802876,35.642008597673751,1511.6046174085313,1026.3173579724241 +27.75,27.596734278834081,16.199514103766486,44834.345347000417,54411.254989657304,35.64039718726216,1511.6037553788585,1026.3177448754923 +28.05,27.8950612360949,16.199958608976239,44836.97018773554,54413.853437666934,35.642216596050488,1511.6121901528761,1026.3203650803757 +28.35,28.193387494842671,16.198695089688343,44837.232067004676,54415.840076239489,35.643463799258583,1511.6147453676983,1026.3229416378649 +28.65,28.491713869965686,16.198806841128558,44831.22641943724,54408.403855378718,35.637892745889907,1511.6136327112376,1026.3199549584522 +28.95,28.790040295811249,16.198281656502818,44833.141524390987,54411.421692528813,35.63995012738269,1511.6193791231053,1026.3229832424245 +29.25,29.088365934761477,16.198502701385188,44835.693832432415,54414.227329340465,35.641905518598222,1511.6272881045327,1026.3257598638684 +29.55,29.386691221748922,16.197415701704863,44832.485365436012,54411.769041596359,35.639902395755222,1511.6266307137721,1026.3257955636459 +29.85,29.685016409947472,16.197179809984767,44831.880398058318,54411.346365015772,35.639454959895239,1511.63036982125,1026.3268301981307 +30.15,29.983341299152439,16.197145623717809,44832.099462196435,54411.657389663822,35.639560667987759,1511.6353638043418,1026.3282434346345 +30.45,30.281665561134737,16.197650438507512,44835.787478251965,54415.466660137346,35.642273261828272,1511.6450140259171,1026.3315365135322 +30.75,30.579988912492023,16.196688629540024,44837.603604135315,54418.94129809329,35.644634474835691,1511.6497768829433,1026.3348997763467 +31.05,30.878312205714842,16.198089286509035,44833.9373415741,54412.641603084834,35.639990772087778,1511.6536732745183,1026.3323271226775 +31.35,31.176635706170721,16.197507895543453,44833.600969063868,54413.001246021668,35.640092727711782,1511.6569907625742,1026.3338644645087 +31.65,31.47495892116423,16.196461783169752,44831.588446446185,54411.9403778039,35.639118402275912,1511.6576456954758,1026.3346819132639 +31.950000000000003,31.773281894753541,16.19650903536294,44831.655891651746,54411.9598254896,35.639015954331477,1511.6626482730255,1026.3359161072626 +32.25,32.071604423076664,16.19486355861924,44830.883728775254,54413.196034721725,35.639684608996632,1511.6633679067081,1026.33813628643 +32.55,32.36992630111736,16.194065799550309,44831.872388762815,54415.44979671832,35.6411613412707,1511.6676109150506,1026.3407811649252 +32.85,32.66824798494136,16.194409845699312,44829.198743846879,54411.750176495174,35.63835026357868,1511.6703938722965,1026.3398632536487 +33.15,32.966569022160414,16.1942884932624,44835.640533817394,54419.729255853708,35.644078572034175,1511.6816118163422,1026.3456209608212 +33.45,33.264889381209443,16.192481196462346,44830.388005945832,54415.741300133086,35.640900567708336,1511.6773962322836,1026.3449202343372 +33.75,33.5632094418254,16.192848858058746,44833.6749266958,54419.245293257722,35.643379129183415,1511.6863574621996,1026.3480650518659 +34.05,33.861529134117738,16.192942685416742,44831.683320702476,54416.703927993389,35.641400239788688,1511.6893363056865,1026.3478452312625 +34.35,34.159848802873576,16.191631296030355,44829.248097398231,54415.480386325988,35.64028730190568,1511.6890199458776,1026.348617607262 +34.65,34.458168051498582,16.191673962324586,44831.16989481647,54417.756772668065,35.641841246745912,1511.6959205806361,1026.3511267252618 +34.95,34.75648697634881,16.192906794250419,44831.19185717043,54416.154801957113,35.640634186068596,1511.7032715730434,1026.3512360825837 +35.25,35.0548057750012,16.191823534455761,44829.61420312569,54415.670825579036,35.640080603313557,1511.7042981334009,1026.3523856895263 +35.55,35.353124250539679,16.190351639971169,44827.972749787325,54415.62279148669,35.63981894804845,1511.7044737028466,1026.3538500213724 +35.85,35.651442289449612,16.190685841756036,44829.44293142097,54416.965893265406,35.640708858003563,1511.711498893156,1026.3557807280836 +36.15,35.94975983172786,16.191031163910559,44830.850071710673,54418.2177587595,35.641532603554495,1511.718481685994,1026.3576579512987 +36.45,36.248077369078352,16.191533747692489,44827.60953090198,54413.620290860352,35.63807406223669,1511.7210017923455,1026.3562052366051 +36.75,36.546394866831321,16.190055278127403,44826.909955712632,54414.724201057892,35.638657495092168,1511.7221327191644,1026.3583210245129 +37.05,36.84471172452195,16.19051164797618,44829.63676497282,54417.431310513282,35.640557459636682,1511.7306973329487,1026.3610001372585 +37.35,37.143027853023185,16.1915263456943,44833.188181581252,54420.40166868885,35.642691002584968,1511.7412380724168,1026.3637292361852 +37.65,37.441343743953418,16.190874061968749,44829.486056560774,54416.769584833266,35.639857700371493,1511.7409500998949,1026.3630254853797 +37.95,37.739659745291782,16.190409503482634,44827.551965336628,54415.035569804757,35.638431233109543,1511.7428598789757,1026.3633601058614 +38.25,38.037975313386411,16.189037360374158,44828.340088049728,54417.805028840943,35.640244857323481,1511.7457357741628,1026.3663972911318 +38.55,38.336290041106466,16.189856256373421,44832.221920540062,54421.435269761409,35.642848629131535,1511.7562210307494,1026.3695334500135 +38.85,38.634604507732092,16.189727081737118,44828.86625789613,54417.53251840864,35.639854470222119,1511.7573461733273,1026.3685845241271 +39.15,38.932919030841283,16.188218882786938,44826.426695206414,54416.563657162566,35.638914232570883,1511.7566270409598,1026.3695353758899 +39.45,39.231233289873956,16.189640858639716,44828.3779303752,54417.053652183335,35.639256565243628,1511.7663452222751,1026.3707922846479 +39.75,39.529547532259784,16.188631105372973,44824.124671151578,54413.22455761872,35.63625292582477,1511.7647677006964,1026.3700405243958 +40.05,39.827861480057109,16.186310613904361,44823.829503036744,54415.9319382013,35.637952346884,1511.7646124843166,1026.3732100126949 +40.35,40.126174887878584,16.182983599593161,44818.921748267116,54414.369517304563,35.636444876361963,1511.7576775588673,1026.3741468163712 +40.65,40.424488045204939,16.185504801089618,44822.236346598555,54415.062487485549,35.637015744270094,1511.7710206496481,1026.3753243308042 +40.95,40.722800905739476,16.185147689006243,44821.790678732425,54414.993260661453,35.6368190303257,1511.7746782280356,1026.3765797176761 +41.25,41.021113481539736,16.183751394288926,44819.711686652896,54414.314103581368,35.636099481359338,1511.7745552579759,1026.3776742645878 +41.55,41.319425856524163,16.183169166711064,44818.120451955307,54413.151487358606,35.635083954500608,1511.7765792484702,1026.3783521876999 +41.85,41.617737262690838,16.18126225053339,44823.065555659254,54421.675181992141,35.641082173930577,1511.7826503169765,1026.3847316292556 +42.133501106668788,41.8996421229912,16.180421275171469,44816.995840319119,54415.416905096376,35.636314358944084,1511.7792774224181,1026.3825110580399 From b037e4693b1a0c9f4f2a012e4fad5b321f4c8117 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 22 Aug 2021 07:20:00 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ctd/read.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ctd/read.py b/ctd/read.py index 095cf3e..e303577 100644 --- a/ctd/read.py +++ b/ctd/read.py @@ -489,6 +489,7 @@ def rosette_summary(fname): ros.set_index("nbf", drop=True, inplace=True, verify_integrity=False) return ros + def from_castaway_csv(fname): """ DataFrame constructor to open CastAway CSV format. @@ -505,30 +506,32 @@ def from_castaway_csv(fname): """ with open(fname) as file: f = file.readlines() - + # Strip newline characters f = [s.strip() for s in f] # separte meta data and CTD profile - meta = [s for s in f if s[0] == '%'][0:-1] - data = [s.split(',') for s in f if s[0] != '%'] + meta = [s for s in f if s[0] == "%"][0:-1] + data = [s.split(",") for s in f if s[0] != "%"] df = pd.DataFrame(data[1:-1], columns=data[0]) # convert to numeric for col in df.columns: df[col] = pd.to_numeric(df[col]) - + # normlise column names and extract units - units = [s[s.find("(")+1:s.find(")")] for s in df.columns] - df.columns = [_normalize_names(s.split('(')[0]).lower().replace(' ','_') for s in df.columns] + units = [s[s.find("(") + 1 : s.find(")")] for s in df.columns] + df.columns = [ + _normalize_names(s.split("(")[0]).lower().replace(" ", "_") for s in df.columns + ] df.set_index("pressure", drop=True, inplace=True, verify_integrity=False) # Add metadata - meta = [s.replace('%','').strip().split(',') for s in meta] + meta = [s.replace("%", "").strip().split(",") for s in meta] metadata = {} for l in meta: metadata[l[0]] = l[1] - metadata['units'] = units + metadata["units"] = units setattr(df, "_metadata", metadata) return df From f73dd0347ae1fd2664680faf0224ed876b617a9a Mon Sep 17 00:00:00 2001 From: Lachlan Date: Sun, 22 Aug 2021 17:31:59 +1000 Subject: [PATCH 3/4] Grammar fixes --- ctd/read.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctd/read.py b/ctd/read.py index e303577..ff1169d 100644 --- a/ctd/read.py +++ b/ctd/read.py @@ -498,7 +498,7 @@ def from_castaway_csv(fname): -------- >>> import ctd >>> cast = ctd.from_castaway_csv('tests/data/castaway_data.csv') - >>> downcast, upcast = cast.split() # upcast often prefiltered + >>> downcast, upcast = cast.split() # Upcast often prefiltered >>> fig, ax = plt.subplots() >>> ax = downcast['temperature'].plot_cast() >>> fig.show() @@ -510,16 +510,16 @@ def from_castaway_csv(fname): # Strip newline characters f = [s.strip() for s in f] - # separte meta data and CTD profile + # Separate meta data and CTD profile meta = [s for s in f if s[0] == "%"][0:-1] data = [s.split(",") for s in f if s[0] != "%"] df = pd.DataFrame(data[1:-1], columns=data[0]) - # convert to numeric + # Convert to numeric for col in df.columns: df[col] = pd.to_numeric(df[col]) - # normlise column names and extract units + # Normalise column names and extract units units = [s[s.find("(") + 1 : s.find(")")] for s in df.columns] df.columns = [ _normalize_names(s.split("(")[0]).lower().replace(" ", "_") for s in df.columns From 143cf11908895f1d8146c44cae906b13b65a91cc Mon Sep 17 00:00:00 2001 From: Lachlan Date: Sun, 22 Aug 2021 21:47:41 +1000 Subject: [PATCH 4/4] Make code more verbose to pass checks --- ctd/read.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctd/read.py b/ctd/read.py index ff1169d..5eae33c 100644 --- a/ctd/read.py +++ b/ctd/read.py @@ -529,8 +529,8 @@ def from_castaway_csv(fname): # Add metadata meta = [s.replace("%", "").strip().split(",") for s in meta] metadata = {} - for l in meta: - metadata[l[0]] = l[1] + for line in meta: + metadata[line[0]] = line[1] metadata["units"] = units setattr(df, "_metadata", metadata)