Fix error in google earth engine script: FeatureCollection (Error)
Join.apply: Join condition must be a binary filter or a combination of binary filters.
var ET = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/ET");
var PR = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/PR");
var RH = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/RH");
var RS = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/RS");
var TMAX = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/TMAX");
var TMIN = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/TMIN");
var U2 = ee.ImageCollection("projects/sat-io/open-datasets/BR-DWGD/U2");
var RAIN_GAUGES = ee.FeatureCollection("projects/sat-io/open-datasets/BR-DWGD/RAIN_GAUGES");
var WEATHER_STATIONS = ee.FeatureCollection("projects/sat-io/open-datasets/BR-DWGD/WEATHER_STATIONS");

var mask = ee.Image(1).clip(geometry3); // Placeholder for masking if necessary

// Define scaling factors for ET and PR
var ET_offset = 0; // Evapotranspiration
var ET_scale = 0.051181102;

var PR_offset = 225; // Precipitation
var PR_scale = 0.006866665;

// Function to scale ET images
var scaleETBand = function(img) {
 return img.select("b1").multiply(ET_scale).add(ET_offset)
 .rename(['ET1'])
 .set('system:time_start', img.get('system:time_start'))
 .set('anomes', ee.Number.parse(img.date().format("YYYYMM")).toInt());
};

// Function to scale PR images
var scalePRBand = function(img) {
 return img.select("b1").multiply(PR_scale).add(PR_offset)
 .rename(['PR1'])
 .set('system:time_start', img.get('system:time_start'))
 .set('anomes', ee.Number.parse(img.date().format("YYYYMM")).toInt());
};

// Scale ET and PR collections
var ET_scaled = ET.filterDate('2014-01-01', '2024-12-31').map(scaleETBand);
var PR_scaled = PR.filterDate('2014-01-01', '2024-12-31').map(scalePRBand);

// Define join and perform the join operation based on system:time_start
var join = ee.Join.inner();
var joinedCollection = join.apply(ET_scaled, PR_scaled, ee.Filter.equals('system:time_start', 'system:time_start'));

print(joinedCollection, 'joinedCollection')
// Function to calculate the monthly average and perform subtraction
var monthlyAvgAndSubtract = function(feature) {
 var etImage = ee.Image(feature.get('first')).select('ET1');
 var prImage = ee.Image(feature.get('second')).select('PR1');

 // Get 'anomes' for both images
 var anomes = feature.get('anomes');

 // Create a new image with the difference
 var diffImage = prImage.subtract(etImage).rename('Difference');

 // Set properties for the new image
 return diffImage.set('anomes', anomes);
};

// Apply the function to the joined collection
var resultCollection = ee.ImageCollection.fromImages(joinedCollection.map(monthlyAvgAndSubtract));

// Generate monthly averages by 'anomes'
var monthlyResult = ee.ImageCollection.fromImages(
 resultCollection.distinct('anomes').aggregate_array('anomes').map(function(y) {
 var monthlyImages = resultCollection.filter(ee.Filter.eq('anomes', y)).mean()
 .set('anomes', y);
 return monthlyImages;
 })
);

// Set visualization parameters
var vis = {
 min: -100, // Adjust based on expected range
 max: 100, // Adjust based on expected range
 palette: ['blue', 'white', 'red']
};

// Define the chart and print it to the console.
var chart = ui.Chart.image.series({
 imageCollection: monthlyResult.select('Difference'),
 region: geometry3,
 reducer: ee.Reducer.mean(),
 scale: 1000, // Increase scale if necessary
 xProperty: 'system:time_start'
})
.setSeriesNames(['PR1 - ET1'])
.setOptions({
 title: 'Monthly Precipitation minus Evapotranspiration',
 hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
 vAxis: {title: 'Difference (Precipitation - Evapotranspiration)', titleTextStyle: {italic: false, bold: true}},
 lineWidth: 2,
 colors: ['1d6b99']
});

print(chart);