I am trying to calculate solar capacitance (CF). The dataset contains two bands: Temp and Irradiation Shortwave. I tried using .map()
function but it is asking for a single image and I have an image collection. How do I send a single image and iterate the process over the entire set. The problem is the data is available as feature collection and not bands. Converting to bands didn't work. Neither did .map()
function. Logically, converting to list and passing one variable for each dataset of Temperature and Irradiation Sortwave in a nested loop should do the trick but I'm familiar with the for loops which comes under client-side in GEE (this is very confusing for me), and I don't understand clearly how to proceed. I've looked up in the Google sources but got more confused.
The logic of the code, as I expect, is: Pass a variable from both the datasets (Temperature and Irradiation Shortwave) in the function to get CF and then return it to the dataset itself. But since the function needs two inputs from 2 different image collections, I don't know how to proceed. If there is a way to just use the original dataset without splitting it into two separate datasets of temperature and irradiation shortwave, that would also be welcome. But I also want to learn how to do it this way.
// import geometry (point to zoom in to)
var home_coords = coords;
// load image stack for one year
var dataset = ee.ImageCollection('NASA/GLDAS/V20/NOAH/G025/T3H').filterDate('2010-01-01','2010-12-31').filterBounds(coords)
print(dataset,'dataset');
var dataset_selectbands = ee.ImageCollection('NASA/GLDAS/V20/NOAH/G025/T3H').filterDate('2010-01-01','2010-12-31').filterBounds(coords).select('Tair_f_inst','SWdown_f_tavg','Wind_f_inst')
print(dataset_selectbands,'dataset_selectbands');
// selecting individual datasets
var T = dataset.select('Tair_f_inst'); //Air Temperature
var G = dataset.select('SWdown_f_tavg'); //Irradiation Shortwave
var W = dataset.select('Wind_f_inst'); //Windspeed
print(T,'T');
print(G,'G');
print(W,'W');
// calculating solar capacitance
var CF = function(image)
{
var cf_per_image = image.expression('((1-0.0045*(-3.75+1.14*T+0.0175*G-25)+ (0.1*log10(G+1)))*G/1000)',
{ 'T': dataset_selectbands.select('Tair_f_inst'),
'G': dataset_selectbands.select('SWdown_f_tavg')
}).set('system:time_start', image.get('system:time_start')).rename('Solar CF');
return image.addBands(cf_per_image)
};
// Calling the function
var cf_1 = dataset_selectbands.map(CF);
print(cf_1);
Just tried calling the function, then I receive an error:
image.expression is not a function:
{ 'T': dataset_selectbands.select('Tair_f_inst'),
'G': dataset_selectbands.select('SWdown_f_tavg') }).set('system:time_start', image.get('system:time_start')).rename('Solar CF'); return image.addBands(cf_per_image); };
var cf_1 = dataset_selectbands.map(T,G);
print(cf_1);