How to set masked pixel value in Earth Engine image export Planned maintenance scheduled April...

Monty Hall Problem-Probability Paradox

Printing attributes of selection in ArcPy?

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

Is CEO the "profession" with the most psychopaths?

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?

Is openssl rand command cryptographically secure?

Resize vertical bars (absolute-value symbols)

Random body shuffle every night—can we still function?

What initially awakened the Balrog?

Would color changing eyes affect vision?

Did any compiler fully use 80-bit floating point?

How does the math work when buying airline miles?

How many time has Arya actually used Needle?

Tannaka duality for semisimple groups

Why datecode is SO IMPORTANT to chip manufacturers?

Why is std::move not [[nodiscard]] in C++20?

Select every other edge (they share a common vertex)

New Order #6: Easter Egg

Mounting TV on a weird wall that has some material between the drywall and stud

How were pictures turned from film to a big picture in a picture frame before digital scanning?

Is multiple magic items in one inherently imbalanced?

What is the difference between CTSS and ITS?

Does any scripture mention that forms of God or Goddess are symbolic?

Project Euler #1 in C++



How to set masked pixel value in Earth Engine image export



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How to stack bands in Google Earth Engine?Image Export fails in Google Earth Engine because "export region contains no valid (un-masked) pixelsBlack vertical lines on exported image from Google Earth EngineEarth Engine: Mosaic 2 collectionsMosaicking a Image Collection by Date (day) in Google Earth EngineUnique List of Image Dates from Image Collection in Google Earth EngineGoogle Earth Engine, how to distinguish between rivers/streams and ponds/lakes in a water maskGoogle Earth Engine API: How to select an image from an image collection based on NDVI value?Google Earth Engine - error when exporting tableGoogle Earth Engine - how to set masked pixels to 'noData'Earth Engine export scale interpretation





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I'm using Earth Engine to preprocess and download some NDVI data. I used a region of interest to clip the imagery to a geometry, and values from the Summary QA layer to mask out pixels that were of poor quality. However, when I export imagery to my drive account, download, and open in R, the areas that were masked have pixel values set to 0. I want those pixels to be set to NA's instead. A repeatable example:



// Generate Region of Interest
var ROI = ee.FeatureCollection('TIGER/2016/Counties')
.filter(ee.Filter.eq('NAME', 'Waldo'));

// Create clipping function
var clipper = function(image){
return image.clip(ROI);
};

// Create a QA mask function
var masker = function(image){
var mask1 = image.select('SummaryQA').lte(1);
var mask2 = image.select('SummaryQA').gte(0);
return image.updateMask(mask1).updateMask(mask2);
};

// Compile the data
var dataset = ee.ImageCollection('MODIS/006/MOD13Q1')
.filter(ee.Filter.date('2018-01-01', '2018-12-31'))
.map(clipper);
print("MOD13Q1 Image Collection", dataset);

// Select just NDVI for repeatable code
var ndvi = dataset.map(masker).select('NDVI');
print("MOD13Q1 NDVI Collection",ndvi);


// PREPARE DATA FOR EXPORT
// Tyler Erickson provided the stacking function
// https://gis.stackexchange.com/a/254778/67264
var stackCollection = function(collection) {
var first = ee.Image(collection.first()).select([]);

// Write a function that appends a band to an image.
var appendBands = function(image, previous) {
var dateString = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');
return ee.Image(previous).addBands(image.rename(dateString));
};
return ee.Image(collection.iterate(appendBands, first));
};
var ndvi_img = stackCollection(ndvi);

// Export the data
Export.image.toDrive({
image: ndvi_img,
description: 'MOD13Q1_comp_NDVI',
scale: 250,
region: ROI,
fileFormat: 'GeoTIFF',
formatOptions: {
cloudOptimized: true
}
});


If you take the product from Export.image.toDrive() and read it into R using...



library(raster)
NDVI = stack("/PATH/TO/MOD13Q1_comp_NDVI.tif")
plot(NDVI[[10]])


...you will find that areas outside the AOI, and areas that were masked, have values of 0, rather than NA. Is there a way to export imagery from Earth Engine with masked areas set to NA, or some other obvious non-standard value? I'd be fine with masked areas set to -99999 because they can get set to NA after the fact.



I looked into using the defaultValue argument described here but when I include that in the formatOptions an error is returned indicating that it isn't a valid argument ("defaultValue" is not a valid option, the image format "GEO_TIFF""may have the following options: cloudOptimized, fileDimensions").










share|improve this question































    0















    I'm using Earth Engine to preprocess and download some NDVI data. I used a region of interest to clip the imagery to a geometry, and values from the Summary QA layer to mask out pixels that were of poor quality. However, when I export imagery to my drive account, download, and open in R, the areas that were masked have pixel values set to 0. I want those pixels to be set to NA's instead. A repeatable example:



    // Generate Region of Interest
    var ROI = ee.FeatureCollection('TIGER/2016/Counties')
    .filter(ee.Filter.eq('NAME', 'Waldo'));

    // Create clipping function
    var clipper = function(image){
    return image.clip(ROI);
    };

    // Create a QA mask function
    var masker = function(image){
    var mask1 = image.select('SummaryQA').lte(1);
    var mask2 = image.select('SummaryQA').gte(0);
    return image.updateMask(mask1).updateMask(mask2);
    };

    // Compile the data
    var dataset = ee.ImageCollection('MODIS/006/MOD13Q1')
    .filter(ee.Filter.date('2018-01-01', '2018-12-31'))
    .map(clipper);
    print("MOD13Q1 Image Collection", dataset);

    // Select just NDVI for repeatable code
    var ndvi = dataset.map(masker).select('NDVI');
    print("MOD13Q1 NDVI Collection",ndvi);


    // PREPARE DATA FOR EXPORT
    // Tyler Erickson provided the stacking function
    // https://gis.stackexchange.com/a/254778/67264
    var stackCollection = function(collection) {
    var first = ee.Image(collection.first()).select([]);

    // Write a function that appends a band to an image.
    var appendBands = function(image, previous) {
    var dateString = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');
    return ee.Image(previous).addBands(image.rename(dateString));
    };
    return ee.Image(collection.iterate(appendBands, first));
    };
    var ndvi_img = stackCollection(ndvi);

    // Export the data
    Export.image.toDrive({
    image: ndvi_img,
    description: 'MOD13Q1_comp_NDVI',
    scale: 250,
    region: ROI,
    fileFormat: 'GeoTIFF',
    formatOptions: {
    cloudOptimized: true
    }
    });


    If you take the product from Export.image.toDrive() and read it into R using...



    library(raster)
    NDVI = stack("/PATH/TO/MOD13Q1_comp_NDVI.tif")
    plot(NDVI[[10]])


    ...you will find that areas outside the AOI, and areas that were masked, have values of 0, rather than NA. Is there a way to export imagery from Earth Engine with masked areas set to NA, or some other obvious non-standard value? I'd be fine with masked areas set to -99999 because they can get set to NA after the fact.



    I looked into using the defaultValue argument described here but when I include that in the formatOptions an error is returned indicating that it isn't a valid argument ("defaultValue" is not a valid option, the image format "GEO_TIFF""may have the following options: cloudOptimized, fileDimensions").










    share|improve this question



























      0












      0








      0








      I'm using Earth Engine to preprocess and download some NDVI data. I used a region of interest to clip the imagery to a geometry, and values from the Summary QA layer to mask out pixels that were of poor quality. However, when I export imagery to my drive account, download, and open in R, the areas that were masked have pixel values set to 0. I want those pixels to be set to NA's instead. A repeatable example:



      // Generate Region of Interest
      var ROI = ee.FeatureCollection('TIGER/2016/Counties')
      .filter(ee.Filter.eq('NAME', 'Waldo'));

      // Create clipping function
      var clipper = function(image){
      return image.clip(ROI);
      };

      // Create a QA mask function
      var masker = function(image){
      var mask1 = image.select('SummaryQA').lte(1);
      var mask2 = image.select('SummaryQA').gte(0);
      return image.updateMask(mask1).updateMask(mask2);
      };

      // Compile the data
      var dataset = ee.ImageCollection('MODIS/006/MOD13Q1')
      .filter(ee.Filter.date('2018-01-01', '2018-12-31'))
      .map(clipper);
      print("MOD13Q1 Image Collection", dataset);

      // Select just NDVI for repeatable code
      var ndvi = dataset.map(masker).select('NDVI');
      print("MOD13Q1 NDVI Collection",ndvi);


      // PREPARE DATA FOR EXPORT
      // Tyler Erickson provided the stacking function
      // https://gis.stackexchange.com/a/254778/67264
      var stackCollection = function(collection) {
      var first = ee.Image(collection.first()).select([]);

      // Write a function that appends a band to an image.
      var appendBands = function(image, previous) {
      var dateString = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');
      return ee.Image(previous).addBands(image.rename(dateString));
      };
      return ee.Image(collection.iterate(appendBands, first));
      };
      var ndvi_img = stackCollection(ndvi);

      // Export the data
      Export.image.toDrive({
      image: ndvi_img,
      description: 'MOD13Q1_comp_NDVI',
      scale: 250,
      region: ROI,
      fileFormat: 'GeoTIFF',
      formatOptions: {
      cloudOptimized: true
      }
      });


      If you take the product from Export.image.toDrive() and read it into R using...



      library(raster)
      NDVI = stack("/PATH/TO/MOD13Q1_comp_NDVI.tif")
      plot(NDVI[[10]])


      ...you will find that areas outside the AOI, and areas that were masked, have values of 0, rather than NA. Is there a way to export imagery from Earth Engine with masked areas set to NA, or some other obvious non-standard value? I'd be fine with masked areas set to -99999 because they can get set to NA after the fact.



      I looked into using the defaultValue argument described here but when I include that in the formatOptions an error is returned indicating that it isn't a valid argument ("defaultValue" is not a valid option, the image format "GEO_TIFF""may have the following options: cloudOptimized, fileDimensions").










      share|improve this question
















      I'm using Earth Engine to preprocess and download some NDVI data. I used a region of interest to clip the imagery to a geometry, and values from the Summary QA layer to mask out pixels that were of poor quality. However, when I export imagery to my drive account, download, and open in R, the areas that were masked have pixel values set to 0. I want those pixels to be set to NA's instead. A repeatable example:



      // Generate Region of Interest
      var ROI = ee.FeatureCollection('TIGER/2016/Counties')
      .filter(ee.Filter.eq('NAME', 'Waldo'));

      // Create clipping function
      var clipper = function(image){
      return image.clip(ROI);
      };

      // Create a QA mask function
      var masker = function(image){
      var mask1 = image.select('SummaryQA').lte(1);
      var mask2 = image.select('SummaryQA').gte(0);
      return image.updateMask(mask1).updateMask(mask2);
      };

      // Compile the data
      var dataset = ee.ImageCollection('MODIS/006/MOD13Q1')
      .filter(ee.Filter.date('2018-01-01', '2018-12-31'))
      .map(clipper);
      print("MOD13Q1 Image Collection", dataset);

      // Select just NDVI for repeatable code
      var ndvi = dataset.map(masker).select('NDVI');
      print("MOD13Q1 NDVI Collection",ndvi);


      // PREPARE DATA FOR EXPORT
      // Tyler Erickson provided the stacking function
      // https://gis.stackexchange.com/a/254778/67264
      var stackCollection = function(collection) {
      var first = ee.Image(collection.first()).select([]);

      // Write a function that appends a band to an image.
      var appendBands = function(image, previous) {
      var dateString = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');
      return ee.Image(previous).addBands(image.rename(dateString));
      };
      return ee.Image(collection.iterate(appendBands, first));
      };
      var ndvi_img = stackCollection(ndvi);

      // Export the data
      Export.image.toDrive({
      image: ndvi_img,
      description: 'MOD13Q1_comp_NDVI',
      scale: 250,
      region: ROI,
      fileFormat: 'GeoTIFF',
      formatOptions: {
      cloudOptimized: true
      }
      });


      If you take the product from Export.image.toDrive() and read it into R using...



      library(raster)
      NDVI = stack("/PATH/TO/MOD13Q1_comp_NDVI.tif")
      plot(NDVI[[10]])


      ...you will find that areas outside the AOI, and areas that were masked, have values of 0, rather than NA. Is there a way to export imagery from Earth Engine with masked areas set to NA, or some other obvious non-standard value? I'd be fine with masked areas set to -99999 because they can get set to NA after the fact.



      I looked into using the defaultValue argument described here but when I include that in the formatOptions an error is returned indicating that it isn't a valid argument ("defaultValue" is not a valid option, the image format "GEO_TIFF""may have the following options: cloudOptimized, fileDimensions").







      google-earth-engine export masking






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 18 mins ago







      JepsonNomad

















      asked 15 hours ago









      JepsonNomadJepsonNomad

      578515




      578515






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f319404%2fhow-to-set-masked-pixel-value-in-earth-engine-image-export%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f319404%2fhow-to-set-masked-pixel-value-in-earth-engine-image-export%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          Энтрерриос (город) Содержание История | Географическое...