0

I am working with two collections of satellite data. I want to select specific bands from "collection 1", join them to "collection 2", and then run a function. Unfortunately, the function does not work with the joined data, although it works for "collection 1".

Here is an example just using B10 of Sentinel-2

//identifying area and date
var geometry = ee.Geometry.Point([4,45]);

Map.centerObject(geometry,10);
var start = '2019-03-10';
var end   = '2019-05-10';


//my function
function testing(img){
  img = img.updateMask(img.select(['B10']).gt(200).focal_min(2).focal_max(2).not());
  return img;
}

//my two collections
var collection1 = ee.ImageCollection('COPERNICUS/S2').filterDate(start,end)
                  .filterBounds(geometry);
  
var B10s=collection1.select('B10');
//print('B10s',B10s);


var collection2 = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterDate(start,end)
                  .filterBounds(geometry);
                  
// joining the collections
var filtering = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

var simpleJoin = ee.Join.inner();
var innerJoin = simpleJoin.apply(collection2, B10s, filtering);
var joined = innerJoin.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});

print('Joined', joined);

//just to visualize one image
//var coll1 = ee.Image(collection1.first());
//Map.addLayer(coll1, {bands:['B2'], min:0, max:5000},'B2Coll1 test');

//running the function for collection 1 works
var test = collection1.map(testing);
var tess = ee.Image(test.first());
Map.addLayer(tess, {bands:['B2'], min:0, max:5000},'B2 test');

//here when running with the joined collection, there is a problem
var TestingJoined = joined.map(testing);

The error is: img.select(...).gt is not a function

How do I make this work?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
ie-con
  • 53
  • 4
  • Please in code questions give a [mre]--cut & paste & runnable code, including smallest representative example input as code; desired & actual output (including verbatim error messages); tags & versions; clear specification & explanation. Give the least code you can that is code that you show is OK extended by code that you show is not OK. (Debugging fundamental.) For SQL that includes DBMS & DDL (including constraints & indexes) & input as code in table format. [ask] Pause work on the overall goal, chop code to the 1st expression not giving what you expect & say what you expect & why. – philipxy Oct 13 '20 at 03:28
  • Why do you expect a gt to be accessible there? (With justification referencing authoritate documentation.) – philipxy Oct 13 '20 at 03:31

2 Answers2

0

When you debug, does the join work as intended? Is there any issue with the datetimes being too-precise to allow a full join?

The second route I would go down is ensuring that the joined object is identical to collections. I doubt this would be the case without you casting it or something (though I'm not familiar with this library). Your "testing" function that you're mapping to these collections may work with just the unjoined ones. If you provide the actual 'Problem' or error output that would be immensely helpful.

Ryanman
  • 880
  • 1
  • 8
  • 20
0

Ok. I solved it. Thank you for your input. I needed to use a cast in the function. Now it works.

function testing(img){
  img = ee.Image(img).updateMask(ee.Image(img).select(['B10']).gt(200).focal_min(2).focal_max(2).not());
  return img;
}
ie-con
  • 53
  • 4