I'm trying to calculate and plot correlation coefficients between two Image Collections, which are monthly NDVI and MODIS hotspot counts (where hotspot counts represents the number of times a pixel has been detected as a hotspot, per month.) Each is a stack of aggregated monthly images with the same projection and scale. I want to get correlation values for each image pair in the stack (monthly correlation values), and plot them in a series. However, my MODIS hotspots data has masked pixels (where there are no hotspots), and NDVI does not. This means some of the MODIS pixels have a band value of 'Masked', which cannot pair with an NDVI value to get correlation.
I think this is why I get the error: "Error generating chart: Data column(s) for axis #0 cannot be of type string" when I try to generate this chart. How can I get Pearson's Correlation for only unmasked MODIS values and their matching NDVI pixels? In other words, I want to run a correlation between MODIS counts and NDVI for each month, but ONLY where MODIS is unmasked. Alternately, I could find the correlation between the sum of all unmasked hotspot counts and the mean NDVI for the study area, for all months (rather than pixel-wise), but I'm not sure how I would do this.
Here is the link to the full code: https://code.earthengine.google.com/38726b77beeb9924655e87949a57034f
Here is the relevant code snippet:
// Add bands: zip the image collections together into one collection. var size = hotspots_monthly.size(); var merged = hotspots_monthly.toList(size).zip(ndvi.toList(size)) .map(function(row) { return ee.Image(ee.List(row).get(0)) .addBands(ee.List(row).get(1)) }); var mergedIC = ee.ImageCollection(merged); print('zipped collection', mergedIC); // Make a band correlation chart. print(ui.Chart.image.series({ imageCollection: mergedIC.select(['MaxFRP','NDVI']), region: geometry, reducer: ee.Reducer.pearsonsCorrelation(), scale: 1000, //xProperty: 'system:time_start' }));