# Fine-Scale (10 m) Dynamics of Smallholder Farming through COVID-19 in Eastern Thailand
## 2 Materials and Methods
### Methodology
#### 2.3.2 Crop Type Mapping  
We capitalized on the open-access, high-performance computing platform Google Earth Engine(c) (GEE) to map crop types and their spatial-temporal distribution. Using the Sentinel-2 dense image time series, we fitted a harmonic regression model to each of the four spectral bands (NIR, R, G, and B), and the popular vegetation index NDVI (Normalized Difference Vegetation Index) to capture crop seasonal variation at the image pixel scale. The coefficients of the harmonic regression models were treated as features and were fed into the random forest (RF) algorithm for detailed crop type classification. We repeated the process for each year (e.g., June 2017 to June 2018) in the six years during  
Figure 4: **(f1)** A sugarcane plantation; **(f2)** sugarcane; **(g1)** a cassava plantation; **(g2)** young cassava; **(h1)** a rubber plantation; **(h2)** a rubber tree that has been harvested for latex; **(i1)** a mangosteen tree; **(i2)** mangosteen; **(j1)** a coconut tree; and **(j2)** coconut seedlings.  
the study timeframe. More details about the methods are shown in Figure 5 and the succeeding paragraphs.  
Harmonic regression, also known as Fourier transform, is well suited for data patterns that reappear at regular intervals [31]. The harmonic regression model was initially intended for use in meteorology [31]; however, it has also proved effective for the classification of vegetation [32]. In this study, we fit a second-order harmonic regression to balance model complexity and computation, as large harmonics (i.e., high-order Fourier series) were determined not to be essential to explain data variance [32; 33]. The following function was used for calculating the harmonic regression:  
\[f(t)=a_{1}cos(2\pi t/n)+b_{1}sin(2\pi t/n)+a_{2}cos(4\pi t/n)+b_{2}sin(4\pi t/n )+c_{0} \tag{1}\]  
where \(f(t)\) is the predicted value at the ordinal of the date \(t\). \(c_{0}\) is the constant term. \(a_{1}\) and \(b_{1}\) represent the first order seasonal harmonic coefficients, while \(a_{2}\) and \(b_{2}\) represent the second order seasonal harmonic coefficients. \(n\) controls the periodicity of the harmonic basis, and a period of 365.2421891 days per tropical year was used as the length of the annual cycle. Five coefficients were estimated for each regression model. The model was applied to fit five bands--NDVI, NIR, R, G, and B, resulting in a total of 25 coefficients, i.e., a 25-band image stored for the succeeding classification. Figure 6 shows examples of time series observations and the corresponding fitted curves using harmonic regression for urban, forest, rice, durian, and rubber pixels.  
RF is an ensemble of decision trees, in which each tree is independently determined using a bootstrap sample of the data set, and a simple majority vote is taken for final prediction [34]. RF has been widely applied to map vegetation with proven success (e.g., [35; 36]). In this study, RF was applied as the classifier to estimate crop types and map their extents. According to our previous experience in crop type mapping [16] and the exploratory trials with the current data, two major parameters were specified in RF: 100 for the number of trees and 3 for the number of predictor variables for each tree. Here, we combined harmonic regression and RF for the purpose of capitalizing on harmonic regression's strong ability to capture crop phenological stages and RF's proven success in vegetation classification.  
Figure 5: Research workflow of crop type mapping using high-resolution image time series over tropical smallholder farmlands.