Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segCount for 'all' 'loss' and 'gain' disturbance #24

Open
Mcflyuu opened this issue Aug 19, 2021 · 6 comments
Open

segCount for 'all' 'loss' and 'gain' disturbance #24

Mcflyuu opened this issue Aug 19, 2021 · 6 comments
Assignees

Comments

@Mcflyuu
Copy link

Mcflyuu commented Aug 19, 2021

I have used the LT-GEE for a while and found it's a very useful and powerful tool. Recently, I have been troubled by a problem, I ran LT-GEE API in order to get change map and segment count, including 'all', 'loss' and 'gain'. Finally three segCount maps have been obtained. From my perspective, the value for a pixel in three segCount maps should be '' 'all' = 'loss' + 'gain' ''. However, the pixels values which equal to 1 in 'all' map are also 1 in both 'loss' and 'gain' maps. I carefully checked my code but didn't find any mistakes. So I decided to write to ask for help. Any suggestions will be appreciated.

@jdbcode jdbcode self-assigned this Sep 3, 2021
@jdbcode
Copy link
Member

jdbcode commented Sep 3, 2021

@Mcflyuu's code from email thread

var roi = table.geometry()

// ImageCollection parameters definition
var startYear = 1984;
var endYear = 2020;
var startDay = '06-01';
var endDay = '09-30';
var index = 'NDVI';
var maskThese = ['cloud','shadow','snow','water'];

// landTrendr parameters definition
var runParams = {
  maxSegments:            6,
  spikeThreshold:         0.9,
  vertexCountOvershoot:   3,
  preventOneYearRecovery: true,
  recoveryThreshold:      0.25,
  pvalThreshold:          0.05,
  bestModelProportion:    0.75,
  minObservationsNeeded:  6
};

// LandTrendr running
// API load
var ltgee = require('users/emaprlab/public:Modules/LandTrendr.js');
// run landTrendr
var lt = ltgee.runLT(startYear, endYear, startDay, endDay, roi, index, [], runParams, maskThese);
// get segmentation map
var segData = ltgee.getSegmentData(lt, index, 'all', true); // 'loss' 'gain' were also obtained
var segCount = ltgee.getSegmentCount(segData);

// visual dictionary
var palette = ['#05FBDD', '#4B0082', '#0000FF', '#00FF00', '#FFFF00', '#FF7F00', '#FF0000'];
//visual parameters
var segCountVizParms = {
  min: 0,
  max: 6,
  palette: palette
};

//disturbance visulization
Map.addLayer(segCount_mask, segCountVizParms, 'Map of Segment count');

// results export
Export.image.toDrive({
  image: exportImg,
  description: 'lt-gee_test project_1',
  folder: 'lt-gee_disturbance_map',
  region: roi,
  scale: 30,
  crs: 'EPSG:4326',
  maxPixels: 1e13
})

Attached images:

image

@jdbcode
Copy link
Member

jdbcode commented Sep 3, 2021

Can reproduce: https://code.earthengine.google.com/7c7396190dc4b3fa4f8aa0af6e62650a

  • WAI for pixels with greater than 1 segment that include both 'loss' and 'gain' segments
  • Bug for pixels with 1 segment, the single segment appears in both the 'loss' and 'gain' segment subsets
  • Unsure about pixels with greater than 1 segment that are all either 'gain' or 'loss' segments

@jdbcode
Copy link
Member

jdbcode commented Sep 3, 2021

I suspect the problem is that the array returned from getSegmentData have no masked values, they are filled with value -9999, so will appear to have a segment when the array length is counted; see lines:

.unmask(ee.Image(ee.Array([[-9999]])))

.unmask(ee.Image(ee.Array([[-9999]])))

The solution may be to mask value -9999 from the input array in getSegmentCount

@jdbcode
Copy link
Member

jdbcode commented Sep 16, 2021

@Mcflyuu I wonder if you would help test a fix?

In my test, the count seems to be correct now:
https://code.earthengine.google.com/bcc79285efd8230e7b1133c3d2a71772

If you replace:

var ltgee = require('users/emaprlab/public:Modules/LandTrendr.js');

with

var ltgee = require('users/emaprlab/public:Modules/LandTrendr-braaten-test.js');

in your script, you'll be using code that includes a proposed fix. Are the results as you expect?

@Mcflyuu
Copy link
Author

Mcflyuu commented Sep 18, 2021

@jdbcode Of course, I'm pleased to help test the fix and I'll tell you the results soon.

@Mcflyuu
Copy link
Author

Mcflyuu commented Sep 22, 2021

@jdbcode After my test, I found the count relationship seems to be correct now, but the running speed is relatively slower compared with the previous API, I'm not sure it is because the script or network status. In addition, I still have several questions about the segment and the segment count.

Firstly, as you can see in the first picture below, when there is no loss segment and gain segment, there is still a segment of "all" from 1988 to 2020, how to understand this situation? Specially, the parameters of LandTrendr analysis precess are 1984 for startYear and 2020 for endYear, respectively, how about the remaining period of 1984 to 1988?

Secondly, as shown in the second picture below, when there is only a gain segment from 1990 to 2020, there is a "all" segment from 1990 to 2020, correspondingly. How about the period of 1984 to 1990?

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants