Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. from .calculateSC import *
  2. from cv2 import imread
  3.  
  4. import pandas as pd
  5. from wolong.base import BasePlugin
  6. from wolong.cli import entrypoint
  7.  
  8. class CalcSCPlugin(BasePlugin): # REQUIRED
  9. consumes_cols = ['filenames'] # REQUIRED
  10. provides_cols = ['SpatialCorrelation'] # REQUIRED
  11.  
  12. def __init__(self, df):
  13. super(CalcSCPlugin, self).__init__(df) # REQUIRED
  14.  
  15. def process(self, window_size): # TYPICAL
  16. def _helper(filenames):
  17. SC = calculateSC(filenames,spatial_correlation=True,window_size=window_size)
  18. return {'SpatialCorrelation': SC}
  19. new_df = self._df.apply(_helper) # Do some computation
  20. self.result = new_df # REQUIRED
  21.  
  22. class CalcTCPlugin(BasePlugin): # REQUIRED
  23. consumes_cols = ['filenames'] # REQUIRED
  24. provides_cols = ['TemporalCorrelation'] # REQUIRED
  25.  
  26. def __init__(self, df):
  27. super(CalcCPlugin, self).__init__(df) # REQUIRED
  28.  
  29. def process(self, window_size): # TYPICAL
  30. def _helper(filenames):
  31. SC = calculateSC(filenames,temporal_correlation=True,window_size=window_size)
  32. return {'TemporalCorrelation': SC}
  33. new_df = self._df.apply(_helper) # Do some computation
  34. self.result = new_df # REQUIRED
  35.  
  36. class CalcRenderPlugin(BasePlugin): # REQUIRED
  37. consumes_cols = ['filename'] # REQUIRED
  38. provides_cols = ['new_filenames'] # REQUIRED
  39.  
  40. def __init__(self, df):
  41. super(CalcRenderPlugin, self).__init__(df) # REQUIRED
  42.  
  43. def process(self): # TYPICAL
  44. # def _helper(filename_s):
  45. # input_arr = imread(filename_s)
  46. # output_arr = calculateSC(input_image)
  47. # with tempfile.mktemp(suffix=".bmp") as tfile:
  48. # imwrite(output_arr, tfile)
  49. # return {'new_filename': output_img}
  50. # new_df = self._df.apply(_helper) # Do some computation
  51. # self.result = new_df # REQUIRED
  52. pass
  53.  
  54.  
  55. def setargs(parser): # TYPICAL
  56. parser.add_argument('-w', '--window-size', default=5, type=int)
  57.  
  58. @entrypoint(['algo', 'calc', 'SC'], args=setargs) #REQUIRED
  59. def cli_run_my_plgin(api, ns, parser): # REQUIRED
  60. plugin = CalcSCPlugin(api.cursor) # TYPICAL
  61. plugin.process() # TYPICAL
  62. api.cursor = plugin.result # TYPICAL
  63.  
  64. @entrypoint(['algo', 'calc', 'TC'], args=setargs) #REQUIRED
  65. def cli_run_my_plgin(api, ns, parser): # REQUIRED
  66. plugin = CalcTCPlugin(api.cursor) # TYPICAL
  67. plugin.process(...) # TYPICAL
  68. api.cursor = plugin.result # TYPICAL
  69.  
  70. @entrypoint(['algo', 'calc', 'Render'], args=setargs) #REQUIRED
  71. def cli_run_my_plgin(api, ns, parser): # REQUIRED
  72. plugin = CalcRenderPlugin(api.cursor) # TYPICAL
  73. plugin.process(...) # TYPICAL
  74. api.cursor = plugin.result # TYPICAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement