1

I have successfully exported wind speed to a csv file, and am trying to add wind direction. I know my wind direction calculation works and I can see it when printing ERA5total. If I understand correctly, I need to use an inner join, but I only end up with an empty csv file.

//  1. Setup
var countries = ee.FeatureCollection("FAO/GAUL/2015/level0");
var NL = countries.filterMetadata('ADM0_NAME', 'equals', 'Netherlands');
var start_period = ee.Date('2018-07-01');
var end_period = ee.Date(new Date().getTime());

var ERA5 = ee.ImageCollection("ECMWF/ERA5_LAND/HOURLY")
     .filter(ee.Filter.date(start_period, end_period))
     .filterMetadata('hour', 'equals', 14);

var ERA5NL=ERA5.map(function(image){ 
   return image.clip(NL)});


//  2. Calculate wind speed as windspeed band
var ERA5windspeed = ERA5NL.map(function(image){
  var wind_10m = image.expression(
    'sqrt(u**2 + v**2)', {
      'u': image.select('u_component_of_wind_10m'),
      'v': image.select('v_component_of_wind_10m')
  }).rename('windspeed');
  var time = image.get('system:time_start');
  return wind_10m.set('system:time_start', time) } );
  

//  3. Calculate mean wind speed for entire NL per day
var ERA5meanspeed = ERA5windspeed.map(function(image){
  var meandict = image.select('windspeed').reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: NL
  })
  return image.set(meandict); 
});


  //  4. Calculate wind direction as winddir band
var ERA5winddir = ERA5NL.map(function(image){
  var winddir = image.expression(
    'mod(180 + (180/3.14) * atan2(v,u),360)', {
      'u': image.select('u_component_of_wind_10m'),
      'v': image.select('v_component_of_wind_10m')
  }).rename('winddir');
  var time = image.get('system:time_start');
  return winddir.set('system:time_start', time) } );
  
  
//  5. Calculate mean wind direction for entire NL per day
var ERA5meandir = ERA5winddir.map(function(image){
  var meandict = image.select('winddir').reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: NL
  })
  return image.set(meandict); 
});


//6. Join wind speed and wind direction datasets

// Use an equals filter to define how the collections match.
var filter = ee.Filter.equals({
  leftField: 'system:index',
  rightField: 'system:index', 
});

 // Define the join.
var innerJoin = ee.Join.inner('primary', 'secondary');

// Apply the join.
var ERA5total = innerJoin.apply(ERA5meanspeed, ERA5meandir, filter);

// Display the result.
print('Join', ERA5total);


//7. Filter out wind speeds > 3 m/s and keep only yyyymmdd in output table
var ERA5x = ERA5total.filter(ee.Filter.lt('windspeed',3.0))  //select only wind speeds < 3 m/s
  .map(function(image){
      var yyyymmdd = ee.String(image.get('system:index')).slice(0,8) //slice date: only yyyymmdd left
    return image.set('date', yyyymmdd)
});

Export.table.toDrive({
  collection: ERA5x.sort('windspeed'),
  description: 'NL_mean_wind',
  selectors: ['date', 'windspeed', 'winddir']
});
2

Your join is working fine, however the result isn't quite what you're expecting.

The matching images are set as properties on a new, otherwise empty, feature. You can turn this into what you're expecting (a feature with simple properties) by mapping over the result and pulling the properties up from the images:

var ERA5total = innerJoin.apply(ERA5meanspeed, ERA5meandir, filter)
  .map(function(f) {
    var img1 = f.get('primary')
    var img2 = f.get('secondary')
    return ee.Feature(null).copyProperties(img1).copyProperties(img2)
  })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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