## 3 Implementation of The Proposed System
### Plant Electrical Data Online Analysis Method  
#### 3.2.1 Web-Based Electrical Signals Extracting Method for Fluorescence Images  
Plant electrical signals can be obtained by optical mapping methods in a non-contact method. Optical mapping technology can obtain plant fluorescence image sequence in a certain period. The plant electrical signals can be extracted through the image processing. The previous work of our research group was based on the local desktop system conditions. The detail of the extraction algorithm [18] of plant electrical signals in a single area of the image is shown in the Supplementary Materials Method 1. To carry out the online computing of a large amount of data, the extraction process of the plant electrical signals includes following two steps: (1) obtaining the time series from fluorescence images using voltage-sensitive dye; (2) fitting calculation is carried out to correct bleaching. In other words, the main calculation includes gray value extraction and curve fitting processing. In addition, besides the calculation of a single area, the entire image can be divided equally and calculated the gray value of each small area, which can obtain a number of the fluorescence time curve from series of continuous fluorescence images, and then get the corresponding plant electrical signals by fitting each fluorescence time curve. Single and multi-ROI of plant electrical signals extraction methods can be done through the distributed computing. Since the image time series is stored in HBase, distributed computing can be implemented using MapReduce. For enhancing the speed of calculation, we used Spark. The detail of plant electrical signals extraction for images datasets based on Spark is showed in Algorithm 1:  
Figure 3: Data storage process of MySQL, HDFS and HBase. MySQL stores the user information and metadata, HDFS stores MEA files, HBase stores small files. ```
Spark Master:
1. Set parameters (cores number, memory and others) of Spark context. Create the SparkContext object SC. 2. Calling the newAPIHadoopRDD method of SC, and read images from the HBase
``` Spark Slaves (Parallel)
3. For each slave node, read image from HBase, and convert it to PairRDD\(<\)key = rowKey, value = the byte array of image\(>\)
4. If single-region analysis:
5. compute the average gray value in the user specified region
6. if multi-ROI analysis:
7. For each region, compute its average gray value. 8. Transform to PairRDD\(<\)key=rowKey, value= the average gray value (single value or array)\(>\) Spark Master:
9. Collect all results to local machine by calling collect() method of RDD. 10. if single-region analysis:
11. transform average signals to double array. 12. if multi-ROI analysis:
13. make a transposition for the signals matrix. 14. Call the parallel method to transform signals transposition to RDD ```
Spark Slaves(Parallel):
15. For each slave node. read each signal. 16. if single-region analysis:
17. Based on the parameters, fitting the signals RF(t) by the exponent functions to get fitting signals F(t). Then minus the F(t) by RF(t), we can get the electrical signals S(t) = RF(t) \(-\) F(t). 18. if multi-ROI analysis:
19. For each region, fitting the signals RF(t) by the exponent functions to get fitting signals F(t). Then minus the F(t) by RF(t), we can get the electrical signals S(t) = RF(t) \(-\) F(t). 20. Use collect () method to collect electrical signals from each slave node. Save electrical signals in HBase. ```

**Algorithm 1**Parallel plant electrical signals extraction for fluorescence images datasets based on Spark

Figure 4 indicates the extraction process of the electrical signals from plant fluorescence image based on MapReduce. In Mapper1, it reads each image, and obtains time series by calculating the gray scale of the corresponding area of each image, and then stores them directly to the disk after sorting.