Package: pipeline-csv
PipelineCsv libraryIn RussianThe free, open source PipelineCsv library is designed to work with the results of analysis of in-line flaw detection data in the form of a CSV file.The library provides a set of high-level operations with CSV file.Data can bemirroredglued together from several CSV filesstretched/compressed along the distance according to a given set of intermediate pointsinterpreted as an iterable sequence of pipes with geodataInstallationpipinstallpipeline-csvUsageIt is necessary to define the sets of defects and markers used in your project.
To do this, you need to define your class for CSV row by deriving it from thepipeline_csv.csvfile.row.Rowclass and
override two methods of this class:defekts_dictandlineobj_dict.frompipeline_csv.csvfile.rowimportRowclassTypeMarker:VALVE=0CASE_START=1CASE_END=2classTypeDefekt:CORROZ=0DENT=1classMyRow(Row):@staticmethoddefdefekts_dict():return{TypeDefekt.CORROZ:"Corrosion",TypeDefekt.DENT:"Dent",}@staticmethoddeflineobj_dict():return{TypeMarker.VALVE:"Valve",TypeMarker.CASE_START:"Casing start",TypeMarker.CASE_END:"Casing end",}For the data mirroring operation, you need to override themarkers_reversemethod, which returns a dictionary that specifies the rules for replacing when mirroring.classMyRow(Row):@staticmethoddefmarkers_reverse():return{TypeMarker.CASE_START:TypeMarker.CASE_END,TypeMarker.CASE_END:TypeMarker.CASE_START,}Further, the MyRow class can be used in operations with data of CSV files.Creating a CSV fileConstruct new csv file from scratch for pipeline 1000 mm diameter.frompipeline_csv.csvfileimportFilecsv_file=File(1000)Define tube at distance 1.0 m length = 11.0 m, thick = 10.5 mm with one seam with orientation 3 hour 00 minutes.frompipeline_csvimportTypeHorWeldfrompipeline_csv.orientationimportOrientationcsv_file.data=[MyRow.as_weld(1000),MyRow.as_thick(1010,105),MyRow.as_seam(1020,TypeHorWeld.HORIZONTAL,Orientation(3,0),None),MyRow.as_weld(12000),]Add outside defect to tube at distance 5.0 m from left tube weld,
length = 20 mm, width = 10 mm, depth = 30% tube wall thickness,
orientation from 4 hours 00 minutes to 5 hours 00 minutes,
maximum depth point at distance 5.01 m from left tube weld, orientation 4 hours 30 minutes
with comment 'metal loss'.frompipeline_csvimportDefektSidecsv_file.data.append(MyRow.as_defekt(6000,TypeDefekt.CORROZ,DefektSide.OUTSIDE'20','10','30',Orientation(4,0),Orientation(5,0),6010,Orientation(4,30),'metal loss'))Save csv to file.importoscsv_file.to_file('example.csv')assertos.path.getsize('example.csv')>0Data mirroringCreate copy from saved file.csv_copy=File.from_file('example.csv',1000)Check distance of the last object in copy and defect orientation.assertcsv_copy.total_length==12000assertlen(csv_copy.data)==5defect_row=csv_copy.data[3]assertdefect_row.is_defectassertdefect_row.orient_td=='4,00'assertdefect_row.orient_bd=='5,00'Reverse copy.csv_copy.reverse()Relative position of defekt must change and defect orientation must be mirrored.defect_row=csv_copy.data[2]assertdefect_row.is_defectassertdefect_row.orient_td=='7,00'assertdefect_row.orient_bd=='8,00'Save reversed copy to file.csv_file.to_file('reversed.csv')assertos.path.getsize('reversed.csv')>0Docking new data and compression/stretchingAppend to initial CSV empty pipe with length 10.0 m and reversed copy from the file.csv_file.join([10000,'reversed.csv'])assertcsv_file.total_length==28000assertlen(csv_file.data)==11Compress distances and length of all objects in half.csv_file.dist_modify(# table of corrections# each node define as pair 'existing distance', 'new distance'[[0,0],[28000,14000],])assertcsv_file.total_length==14000Save file with compress distances.csv_file.to_file('transformed.csv')assertos.path.getsize('transformed.csv')>0Pipe sequenceIterate by pipes.csv_trans=File.from_file('transformed.csv',1000)warnings=[]current_dist=0foriincsv_trans.get_tubes(warnings):asserti.dist>=current_distcurrent_dist=i.disttube=iassertnotwarningsSet geodata for tubeasserttube.latitude==''asserttube.longtitude==''asserttube.altitude==''tube.set_geo(10,11,12)asserttube.latitude==10asserttube.longtitude==11asserttube.altitude==12csv_trans.to_file('geo.csv')assertos.path.getsize('geo.csv')>0Load from saved file and check geodata from last pipe.csv_geo=File.from_file('geo.csv',1000)last_tube=list(csv_geo.get_tubes(warnings))[-1]assertlast_tube.latitude=='10'assertlast_tube.longtitude=='11'assertlast_tube.altitude=='12'Defect location at the pipePipeline diameter 1000 mm.csv=File(1000)Define one pipe at distance 1.0 m, length = 11.0 m with one seam with orientation 3 hour 00 minutes and one defect at distance 5.0 m from left tube weld.Defect length = 20 mm, width = 10 mm, depth = 30% tube wall thickness, orientation from 4 hours 00 minutes to 5 hours 00 minutes.Maximum depth point at 10 mm from left border of defect, orientation 4 hours 30 minutes.csv.data=[Row.as_weld(1000),Row.as_seam(1020,TypeHorWeld.HORIZONTAL,Orientation(3,0),None),Row.as_defekt(6000,TypeDefekt.CORROZ,DefektSide.INSIDE,'20','10','30',Orientation(4,0),Orientation(5,0),Orientation(4,30),6010,'corrozion'),Row.as_weld(12000),]pipes=list(csv.get_tubes())assertlen(pipes)==1pipe=pipes[0]assertpipe.diam==1000One defect at the pipe.assertlen(pipe.defects)==1defect=pipe.defects[0]Defect is metal loss, not dent.
Defect is not located at the weld/seam.assertdefect.is_metal_lossassertnotdefect.is_dentassertnotdefect.is_at_weldassertnotdefect.is_at_seamDefect as point orientation is maximum depth point orientation at 4:30.assertdefect.orientation_point.as_minutes==270Distance (mm) from maximum depth point to upstream weld.assertdefect.mp_left_weld==5010Distance (mm) from maximum depth point to downstream weld.assertdefect.mp_right_weld==5990Distance (mm) from maximum depth point to seam.assertdefect.mp_seam==392Distance (mm) from maximum depth point to nearest seam/weld.assertdefect.mp_seam_weld==392Distance (mm) from left defect border to upstream weld.assertdefect.to_left_weld==5000Distance (mm) from right defect border to downstream weld.assertdefect.to_right_weld==5980Distance (mm) from defect borders to seam.assertdefect.to_seam==60Distance (mm) from defect borders to nearest seam/weld.assertdefect.to_seam_weld==60Development$ git clone git@github.com:vb64/pipeline.csv.git
$ cd pipeline.csv
$ make setup PYTHON_BIN=/path/to/python3
$ make tests