GEE- When I mask two years landsat image with one year data, the error: If one image has no bands, the other...

The logistics of corpse disposal

Stars Make Stars

How can I fade player when goes inside or outside of the area?

What does the "x" in "x86" represent?

Single word antonym of "flightless"

When is phishing education going too far?

"Seemed to had" is it correct?

Is there a "higher Segal conjecture"?

Using et al. for a last / senior author rather than for a first author

How can I make names more distinctive without making them longer?

If 'B is more likely given A', then 'A is more likely given B'

Storing hydrofluoric acid before the invention of plastics

How can players work together to take actions that are otherwise impossible?

How to motivate offshore teams and trust them to deliver?

How to draw this diagram using TikZ package?

How to bypass password on Windows XP account?

3 doors, three guards, one stone

Is it true to say that an hosting provider's DNS server is what links the entire hosting environment to ICANN?

I am not a queen, who am I?

How does cp -a work

Why are there no cargo aircraft with "flying wing" design?

How do I keep my slimes from escaping their pens?

What are the motives behind Cersei's orders given to Bronn?

What makes black pepper strong or mild?



GEE- When I mask two years landsat image with one year data, the error: If one image has no bands, the other must also have no bands. Got 0 and 1



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Determining the best month for discriminating between different vegetation types?Histogram matching of two NDVI imagesClassify forest with NDVI from Landsat 8 and 7How to create an annual NDVI from Landsat 8 imageryPer-pixel linear regression over multiple rasters, issue with NoDataDifferent values for NDVI from different techniquesIs it possible to create an average image of the analyzed period after the removal of the clouds to fill the flaws in the images?GEE Landsat SR year composite // mask cloud / shadow out w/ other method than quality pixelWhy does the Extent of NIR Band 8 Landsat image not match other bands, even when cropping to a specified extent?





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







0















I would like to mask the one year Landsat 5 surface reflectance data with two years landsat 5 surface reflectace data with every 15 days. However, I cannot mask successfully if the one year Landsat 5 sr data not include any image.
I use this code as following:
// Load a collection of Landsat 5 surface reflectance images.
var L5coll = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')



// Load BOUND
var BOUND = ee.Geometry.Rectangle(108.68, 35.61, 108.93, 35.55);
Map.addLayer (BOUND)



// Add NDVI band to image.
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
return image.addBands(ndvi);
};



// Remove cloud for Landsat surface reflectance data
function maskL5sr(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
// Get the pixel QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0))
return image.updateMask(mask);
}



// Calculate the basic NDVI (one year)
var Oneyear = L5coll
// return L5coll
.filterBounds(BOUND)
.filterDate('1987-02-01','1987-02-15')
.map(maskL5sr)
.map(addNDVI)
.select('NDVI')
.max();
print (Oneyear,'Oneyear')
Map.addLayer (Oneyear,{},'Oneyear')



// Calculate the two years ndvi (have same days with 'basicndvi').
var Twoyears = L5coll
.filterDate('1986-02-01','1987-02-15')
.filterBounds(BOUND)
.map(addNDVI)
.map(maskL5sr)
.select('NDVI')
.max();
print (Twoyears ,'Twoyears ')
Map.addLayer (Twoyears ,{},'Twoyears')



// Seperating composite into two parts: exist value is origin value, null value is 0
var divide = Oneyear.mask(1).rename('Oneyear')



// Calculate finalndvi through replace the value is 0 of Oneyear into climatology
var finalndvi = (divide.where(divide.eq(0),Twoyears));



print (finalndvi,'finalndvi')
Map.addLayer (finalndvi,{},'finalndvi')



// Seperating finalndvi into two parts: exist value is 1, null value is 0
var mask = finalndvi.mask().rename('mask');



// Calculate the area through multiply pixelArea by mask
var area = ee.Image.pixelArea().multiply(mask).rename('area');



// Calculate the pixelarea as a proportion of the area of the study area.
var percent = area.divide(300).divide(10000).rename('percent');



// Sum the percent in the study area.
var calculate = percent.reduceRegion({
reducer:ee.Reducer.sum(),
geometry:BOUND,
scale:30,
maxPixels:1e9
});



// Change the calculate into Number.
var percentnumber = ee.Number(calculate.get('percent'))



var ndviwithpercent = finalndvi.set('percentnumber',percentnumber)



print (ndviwithpercent,'ndviwithpercent')
Map.addLayer (ndviwithpercent,{},'ndviwithpercent')









share







New contributor




Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    0















    I would like to mask the one year Landsat 5 surface reflectance data with two years landsat 5 surface reflectace data with every 15 days. However, I cannot mask successfully if the one year Landsat 5 sr data not include any image.
    I use this code as following:
    // Load a collection of Landsat 5 surface reflectance images.
    var L5coll = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')



    // Load BOUND
    var BOUND = ee.Geometry.Rectangle(108.68, 35.61, 108.93, 35.55);
    Map.addLayer (BOUND)



    // Add NDVI band to image.
    var addNDVI = function(image) {
    var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
    return image.addBands(ndvi);
    };



    // Remove cloud for Landsat surface reflectance data
    function maskL5sr(image) {
    // Bits 3 and 5 are cloud shadow and cloud, respectively.
    var cloudShadowBitMask = (1 << 3);
    var cloudsBitMask = (1 << 5);
    // Get the pixel QA band.
    var qa = image.select('pixel_qa');
    // Both flags should be set to zero, indicating clear conditions.
    var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
    .and(qa.bitwiseAnd(cloudsBitMask).eq(0))
    return image.updateMask(mask);
    }



    // Calculate the basic NDVI (one year)
    var Oneyear = L5coll
    // return L5coll
    .filterBounds(BOUND)
    .filterDate('1987-02-01','1987-02-15')
    .map(maskL5sr)
    .map(addNDVI)
    .select('NDVI')
    .max();
    print (Oneyear,'Oneyear')
    Map.addLayer (Oneyear,{},'Oneyear')



    // Calculate the two years ndvi (have same days with 'basicndvi').
    var Twoyears = L5coll
    .filterDate('1986-02-01','1987-02-15')
    .filterBounds(BOUND)
    .map(addNDVI)
    .map(maskL5sr)
    .select('NDVI')
    .max();
    print (Twoyears ,'Twoyears ')
    Map.addLayer (Twoyears ,{},'Twoyears')



    // Seperating composite into two parts: exist value is origin value, null value is 0
    var divide = Oneyear.mask(1).rename('Oneyear')



    // Calculate finalndvi through replace the value is 0 of Oneyear into climatology
    var finalndvi = (divide.where(divide.eq(0),Twoyears));



    print (finalndvi,'finalndvi')
    Map.addLayer (finalndvi,{},'finalndvi')



    // Seperating finalndvi into two parts: exist value is 1, null value is 0
    var mask = finalndvi.mask().rename('mask');



    // Calculate the area through multiply pixelArea by mask
    var area = ee.Image.pixelArea().multiply(mask).rename('area');



    // Calculate the pixelarea as a proportion of the area of the study area.
    var percent = area.divide(300).divide(10000).rename('percent');



    // Sum the percent in the study area.
    var calculate = percent.reduceRegion({
    reducer:ee.Reducer.sum(),
    geometry:BOUND,
    scale:30,
    maxPixels:1e9
    });



    // Change the calculate into Number.
    var percentnumber = ee.Number(calculate.get('percent'))



    var ndviwithpercent = finalndvi.set('percentnumber',percentnumber)



    print (ndviwithpercent,'ndviwithpercent')
    Map.addLayer (ndviwithpercent,{},'ndviwithpercent')









    share







    New contributor




    Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I would like to mask the one year Landsat 5 surface reflectance data with two years landsat 5 surface reflectace data with every 15 days. However, I cannot mask successfully if the one year Landsat 5 sr data not include any image.
      I use this code as following:
      // Load a collection of Landsat 5 surface reflectance images.
      var L5coll = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')



      // Load BOUND
      var BOUND = ee.Geometry.Rectangle(108.68, 35.61, 108.93, 35.55);
      Map.addLayer (BOUND)



      // Add NDVI band to image.
      var addNDVI = function(image) {
      var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
      return image.addBands(ndvi);
      };



      // Remove cloud for Landsat surface reflectance data
      function maskL5sr(image) {
      // Bits 3 and 5 are cloud shadow and cloud, respectively.
      var cloudShadowBitMask = (1 << 3);
      var cloudsBitMask = (1 << 5);
      // Get the pixel QA band.
      var qa = image.select('pixel_qa');
      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0))
      return image.updateMask(mask);
      }



      // Calculate the basic NDVI (one year)
      var Oneyear = L5coll
      // return L5coll
      .filterBounds(BOUND)
      .filterDate('1987-02-01','1987-02-15')
      .map(maskL5sr)
      .map(addNDVI)
      .select('NDVI')
      .max();
      print (Oneyear,'Oneyear')
      Map.addLayer (Oneyear,{},'Oneyear')



      // Calculate the two years ndvi (have same days with 'basicndvi').
      var Twoyears = L5coll
      .filterDate('1986-02-01','1987-02-15')
      .filterBounds(BOUND)
      .map(addNDVI)
      .map(maskL5sr)
      .select('NDVI')
      .max();
      print (Twoyears ,'Twoyears ')
      Map.addLayer (Twoyears ,{},'Twoyears')



      // Seperating composite into two parts: exist value is origin value, null value is 0
      var divide = Oneyear.mask(1).rename('Oneyear')



      // Calculate finalndvi through replace the value is 0 of Oneyear into climatology
      var finalndvi = (divide.where(divide.eq(0),Twoyears));



      print (finalndvi,'finalndvi')
      Map.addLayer (finalndvi,{},'finalndvi')



      // Seperating finalndvi into two parts: exist value is 1, null value is 0
      var mask = finalndvi.mask().rename('mask');



      // Calculate the area through multiply pixelArea by mask
      var area = ee.Image.pixelArea().multiply(mask).rename('area');



      // Calculate the pixelarea as a proportion of the area of the study area.
      var percent = area.divide(300).divide(10000).rename('percent');



      // Sum the percent in the study area.
      var calculate = percent.reduceRegion({
      reducer:ee.Reducer.sum(),
      geometry:BOUND,
      scale:30,
      maxPixels:1e9
      });



      // Change the calculate into Number.
      var percentnumber = ee.Number(calculate.get('percent'))



      var ndviwithpercent = finalndvi.set('percentnumber',percentnumber)



      print (ndviwithpercent,'ndviwithpercent')
      Map.addLayer (ndviwithpercent,{},'ndviwithpercent')









      share







      New contributor




      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I would like to mask the one year Landsat 5 surface reflectance data with two years landsat 5 surface reflectace data with every 15 days. However, I cannot mask successfully if the one year Landsat 5 sr data not include any image.
      I use this code as following:
      // Load a collection of Landsat 5 surface reflectance images.
      var L5coll = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')



      // Load BOUND
      var BOUND = ee.Geometry.Rectangle(108.68, 35.61, 108.93, 35.55);
      Map.addLayer (BOUND)



      // Add NDVI band to image.
      var addNDVI = function(image) {
      var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
      return image.addBands(ndvi);
      };



      // Remove cloud for Landsat surface reflectance data
      function maskL5sr(image) {
      // Bits 3 and 5 are cloud shadow and cloud, respectively.
      var cloudShadowBitMask = (1 << 3);
      var cloudsBitMask = (1 << 5);
      // Get the pixel QA band.
      var qa = image.select('pixel_qa');
      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0))
      return image.updateMask(mask);
      }



      // Calculate the basic NDVI (one year)
      var Oneyear = L5coll
      // return L5coll
      .filterBounds(BOUND)
      .filterDate('1987-02-01','1987-02-15')
      .map(maskL5sr)
      .map(addNDVI)
      .select('NDVI')
      .max();
      print (Oneyear,'Oneyear')
      Map.addLayer (Oneyear,{},'Oneyear')



      // Calculate the two years ndvi (have same days with 'basicndvi').
      var Twoyears = L5coll
      .filterDate('1986-02-01','1987-02-15')
      .filterBounds(BOUND)
      .map(addNDVI)
      .map(maskL5sr)
      .select('NDVI')
      .max();
      print (Twoyears ,'Twoyears ')
      Map.addLayer (Twoyears ,{},'Twoyears')



      // Seperating composite into two parts: exist value is origin value, null value is 0
      var divide = Oneyear.mask(1).rename('Oneyear')



      // Calculate finalndvi through replace the value is 0 of Oneyear into climatology
      var finalndvi = (divide.where(divide.eq(0),Twoyears));



      print (finalndvi,'finalndvi')
      Map.addLayer (finalndvi,{},'finalndvi')



      // Seperating finalndvi into two parts: exist value is 1, null value is 0
      var mask = finalndvi.mask().rename('mask');



      // Calculate the area through multiply pixelArea by mask
      var area = ee.Image.pixelArea().multiply(mask).rename('area');



      // Calculate the pixelarea as a proportion of the area of the study area.
      var percent = area.divide(300).divide(10000).rename('percent');



      // Sum the percent in the study area.
      var calculate = percent.reduceRegion({
      reducer:ee.Reducer.sum(),
      geometry:BOUND,
      scale:30,
      maxPixels:1e9
      });



      // Change the calculate into Number.
      var percentnumber = ee.Number(calculate.get('percent'))



      var ndviwithpercent = finalndvi.set('percentnumber',percentnumber)



      print (ndviwithpercent,'ndviwithpercent')
      Map.addLayer (ndviwithpercent,{},'ndviwithpercent')







      landsat ndvi masking band





      share







      New contributor




      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 min ago









      Chenlu HuangChenlu Huang

      1




      1




      New contributor




      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Chenlu Huang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          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
          });


          }
          });






          Chenlu Huang is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318927%2fgee-when-i-mask-two-years-landsat-image-with-one-year-data-the-error-if-one-i%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








          Chenlu Huang is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Chenlu Huang is a new contributor. Be nice, and check out our Code of Conduct.













          Chenlu Huang is a new contributor. Be nice, and check out our Code of Conduct.












          Chenlu Huang is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f318927%2fgee-when-i-mask-two-years-landsat-image-with-one-year-data-the-error-if-one-i%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

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

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          Meter-Bus Содержание Параметры шины | Стандартизация |...