I am trying to filter imported AIS data (https://marinecadastre.gov/AIS/) by time, as ground truth for ship detection using SAR images. The imported CSV stores the date in a column ["BaseDateTime"], which can be shown in the bottom image and GEE code link. The format seems to be yyyy-MM-dd'T'HH:mm:ssZ
.
My problems are the following:
- GEE doesn't let me simply filter something in a "column" that isn't a "property" of a
FeatureCollection
- The "BaseDateTime" values are not in
ee.Date
format, so reducing by column is difficult.
How do I select the AIS points that would correspond to the time a SAR image was taken?
Link Code: https://code.earthengine.google.com/ec4c3c9f7f983cc99ed3daee44f47bf5
//////////////////////////////////////////////////////////////
//SAR Data
//////////////////////////////////////////////////////////////////////
var dataset = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterDate('2020-06-30', '2020-07-01')
.filterBounds(roi)
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
// Filter to get images collected in interferometric wide swath mode.
.filter(ee.Filter.eq('instrumentMode', 'IW'));
var listOfImages = dataset.toList(dataset.size()); // 29 images
//////////////////////////////////////////////////////////////////////
///AIS
//////////////////////////////////////////////////////////////////////
//Importing Feature Collection
var ais = ee.FeatureCollection('users/sheilababer/AIS_2020_06_30').filterBounds(roi);
Map.addLayer(ais);
//Treating "BaseDateTime" as a Property yields errors:
var dayRange = ee.Number(0.08) //wanting the AIS data to be within 2 hours of SAR
var feats = ais.map(function(feat){
feat = ee.Feature(feat);
var date = ee.Date(feat.get('BaseDateTime'));
var dateRange = ee.DateRange(date.advance(-(dayRange/2), 'day'), date.advance(dayRange/2, 'day'));
var image = dataset.filterDate(dateRange).mean();
var data = image.reduceRegion(ee.Reducer.first(), feat.geometry(), 500);
return ee.Feature(feat.setMulti(data))
});
var date_col = ['BaseDateTime']
//Trying to reduce the feature collection by column also yields errors,
//probably because date is parsed as a string:
print(ais.reduceColumns({
reducer: ee.Reducer.mean(),
selectors: ['BaseDateTime'],
}));
print(ais['BaseDateTime'])