0

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);
1
  • Just tried calling the function, then I receive an error that image.expression is not a function: 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); }; var cf_1 = dataset_selectbands.map(T,G); print(cf_1); Commented Jan 1, 2023 at 22:40

1 Answer 1

0

You shouldn't write comments to your own post. If you have additional information to include in your post, such as an error message, it should be in the post. I submitted an edit for your post. If the edit is approved, the post should be updated with what is in the comment you wrote.

I'm kind of confused by what you wrote in your post, but I think I understand what you're trying to do. You want take the temperature and shortwave irradiation to calculate solar capacitance. I have no idea what the required inputs are nor the formula for the calculation, so I just used what you supplied in the code and tried to correct what was causing the error. You actually set up three variables, which you used to create "datasets": temperature, shortwave irradiation, and wind speed, but only use 2 of them in your expression, so I don't know what is going there.

What you call datasets are part of one image collection. GEE is super confusing, I understand. I still have lots of questions after months of use. However, what you're doing is pretty standard. Divide the image collection into relevant subsets, perform calculations, and create a new set of bands. Two different image collections would be ee.ImageCollection('NASA/GLDAS/V20/NOAH/G025/T3H') and ee.ImageCollection("NASA/ORNL/DAYMET_V4") and trying to combine bands from those would be a pain because of different resolutions or coverage or time steps, etc.

Basically, the problem was on lines 20 and 21. You wrote:

   { 'T': dataset_selectbands.select('Tair_f_inst'),
     'G': dataset_selectbands.select('SWdown_f_tavg')

and it should be

   { 'T': image.select('Tair_f_inst'),
     'G': image.select('SWdown_f_tavg')

Also, on lines 4 and 6, you wrote filterBounds(coords), but you named a variable home_coords on your first line, so you should be using that.

I don't have access to the object called coords that you used to create home_coords, so I just stuck a random point in there. Otherwise, that would return an error for me and I wouldn't be able to get anywhere. So I don't know how that geometry might affect the code. In the future, if you're going to use a custom geometry that, you need to provide in the code or share the asset in a GEE code editor environment.

As it stands, this code returns no errors, but I don't have any idea if the values calculated are correct, especially if wind speed is necessary. Also, you don't need lines 9-15, where you create var T, etc.

var home_coords = geometry; 

// load image stack for one year
var dataset = ee.ImageCollection('NASA/GLDAS/V20/NOAH/G025/T3H').filterDate('2010-01-01','2010-01-31')
.filterBounds(home_coords)
print(dataset,'dataset');
var dataset_selectbands = ee.ImageCollection('NASA/GLDAS/V20/NOAH/G025/T3H').filterDate('2010-01-01','2010-01-31')
.filterBounds(home_coords)
.select('Tair_f_inst','SWdown_f_tavg','Wind_f_inst')
print(dataset_selectbands,'dataset_selectbands');

// calculating solar capacitance 
function CF(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': image.select('Tair_f_inst'),
     'G': image.select('SWdown_f_tavg')
   }).set('system:time_start', image.get('system:time_start')).rename('Solar CF');
return image.addBands(cf_per_image)
}

var dataset_selected = dataset_selectbands.map(CF);
print(dataset_selected);
Map.addLayer(dataset_selected, null, 'cf_1');

https://code.earthengine.google.com/cb73f35779e8028c82cd84484d9f36e5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.