1

Using this Google Earth Engine code I am trying to create a line graph of the data for the specified date range. The result I got is not a continuous line graph and the exported value shows undefined:0. How can I get continuous line graph with the proper value? also a request to the forum that how can I incorporate several city points in one graph. Here I have taken only one city point The code is written as

var city1 = /* color: #d63000 */ee.Geometry.Point([-93.881640625, 37.391718430950796]),
   city2 = /* color: #d63000 */ee.Geometry.Point([-106.27421875, 33.71035637052483]),
   city3 = /* color: #98ff00 */ee.Geometry.Point([-117.436328125, 39.7618477958936]),
   city4 = /* color: #0b4a8b */ee.Geometry.Point([-95.5515625, 29.74978297462196]),
   city5 = /* color: #ffc82d */ee.Geometry.Point([-115.151171875, 36.15978520358036]);



// get the data
var y2019 = ee.ImageCollection("COPERNICUS/S5P/NRTI/L3_NO2")
             .filterDate("2019-01-01","2019-12-30");
// Select the NO2 column number density.
var times2019 = y2019
   .select("NO2_column_number_density")
// Create a time series chart.
var TimeSeries = ui.Chart.image.seriesByRegion(
   times2019, city1, ee.Reducer.mean(), "NO2_column_number_density", 100, 'system:time_start', 'label')
       .setChartType('ScatterChart')
       .setOptions({
         title: 'NO2 Timeseries',
         vAxis: {title: 'NO2'},
         lineWidth: 1,
         pointSize: 4,
         series: {
           1: {color: '0000FF'}  
}});

// Display.
print(TimeSeries);

Time series graph

2
  • This code isn't reproducible because we don't have access to city1. Also, please limit questions to one specific question, and save other questions fo either googling or a separate, specific question. – JepsonNomad Oct 14 '20 at 19:00
  • @JepsonNomad I have added the city points. – goldy_mit Oct 15 '20 at 6:28
1

Set the argument interpolateNulls of the options of the chart to true. By default, that is false. Make sure you put this argument before the series argument:

// Create a time series chart.
var TimeSeries = ui.Chart.image.seriesByRegion(
    times2019, city1, ee.Reducer.mean(), "NO2_column_number_density", 200, 
    'system:time_start', 'label')
        .setChartType('ScatterChart')
        .setOptions({
          interpolateNulls: true,
          title: 'NO2 Timeseries',
          vAxis: {title: 'NO2'},
          lineWidth: 1,
                    pointSize: 4,
                    series: {
            1: {color: '0000FF'}  ,
          }});

To get the data as a CSV, use Export.table.toDrive and make a featurecollection of the data (using reduceRegion() or reduceRegions() for multiple goemetries):

// filter to region
var filtCol = times2019.filterBounds(city1);

// export to CSV
var data = ee.FeatureCollection(filtCol.map(function(image){
  return ee.Feature(null, image.reduceRegion(ee.Reducer.mean(), city1, 200))
             .set('system:time_start', image.get('system:time_start'));
}));
print(data)

// export directly as CSV
Export.table.toDrive({collection: data, 
                      description: 'YOURDESCRIPTION', 
                      fileFormat: 'CSV', 
                      selectors: ['NO2_column_number_density', 'system:time_start']})

Link to code

2
  • The graph looks fine but the exported csv file shows '0' and blank. what is the probable solution to get that values. – goldy_mit Oct 15 '20 at 6:23
  • See my edit. You see 0 values probably by some rounding of values occurring on the backend when downloading a CSV from the graph directly. – Kuik Oct 17 '20 at 10:16

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.