Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from .calculateSC import *
- from cv2 import imread
- import pandas as pd
- from wolong.base import BasePlugin
- from wolong.cli import entrypoint
- class CalcSCPlugin(BasePlugin): # REQUIRED
- consumes_cols = ['filenames'] # REQUIRED
- provides_cols = ['SpatialCorrelation'] # REQUIRED
- def __init__(self, df):
- super(CalcSCPlugin, self).__init__(df) # REQUIRED
- def process(self, window_size): # TYPICAL
- def _helper(filenames):
- SC = calculateSC(filenames,spatial_correlation=True,window_size=window_size)
- return {'SpatialCorrelation': SC}
- new_df = self._df.apply(_helper) # Do some computation
- self.result = new_df # REQUIRED
- class CalcTCPlugin(BasePlugin): # REQUIRED
- consumes_cols = ['filenames'] # REQUIRED
- provides_cols = ['TemporalCorrelation'] # REQUIRED
- def __init__(self, df):
- super(CalcCPlugin, self).__init__(df) # REQUIRED
- def process(self, window_size): # TYPICAL
- def _helper(filenames):
- SC = calculateSC(filenames,temporal_correlation=True,window_size=window_size)
- return {'TemporalCorrelation': SC}
- new_df = self._df.apply(_helper) # Do some computation
- self.result = new_df # REQUIRED
- class CalcRenderPlugin(BasePlugin): # REQUIRED
- consumes_cols = ['filename'] # REQUIRED
- provides_cols = ['new_filenames'] # REQUIRED
- def __init__(self, df):
- super(CalcRenderPlugin, self).__init__(df) # REQUIRED
- def process(self): # TYPICAL
- # def _helper(filename_s):
- # input_arr = imread(filename_s)
- # output_arr = calculateSC(input_image)
- # with tempfile.mktemp(suffix=".bmp") as tfile:
- # imwrite(output_arr, tfile)
- # return {'new_filename': output_img}
- # new_df = self._df.apply(_helper) # Do some computation
- # self.result = new_df # REQUIRED
- pass
- def setargs(parser): # TYPICAL
- parser.add_argument('-w', '--window-size', default=5, type=int)
- @entrypoint(['algo', 'calc', 'SC'], args=setargs) #REQUIRED
- def cli_run_my_plgin(api, ns, parser): # REQUIRED
- plugin = CalcSCPlugin(api.cursor) # TYPICAL
- plugin.process() # TYPICAL
- api.cursor = plugin.result # TYPICAL
- @entrypoint(['algo', 'calc', 'TC'], args=setargs) #REQUIRED
- def cli_run_my_plgin(api, ns, parser): # REQUIRED
- plugin = CalcTCPlugin(api.cursor) # TYPICAL
- plugin.process(...) # TYPICAL
- api.cursor = plugin.result # TYPICAL
- @entrypoint(['algo', 'calc', 'Render'], args=setargs) #REQUIRED
- def cli_run_my_plgin(api, ns, parser): # REQUIRED
- plugin = CalcRenderPlugin(api.cursor) # TYPICAL
- plugin.process(...) # TYPICAL
- api.cursor = plugin.result # TYPICAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement