eMapR / LT-GEE

Google Earth Engine implementation of the LandTrendr spectral-temporal segmentation algorithm. For documentation see:
https://emapr.github.io/LT-GEE
Apache License 2.0
198 stars 65 forks source link

getFittedData() -- returned data can not be saved as an asset #25

Closed clarype closed 3 years ago

clarype commented 3 years ago

The output from getFittedData() can not be save as an asset in GEE do to its band naming syntax, that leads the band name with a numerical character. The error meassage can be seen below.

Error: Band ID "1999" is invalid. Band IDs must start with a..z or A..Z and must contain only the following characters: a..z, A..Z, 0..9, "_", or "-". Band IDs must be at most 100 characters long.

I am pretty sure the these bands are named like "1999_ftv" or something like that. So the easiest solution I see would be to just flip the name to something like "ftv_1999".

I'll go ahead and look into it.

jdbcode commented 3 years ago

Peter, what file did you change?

clarype commented 3 years ago

Oops that should not be closed. I am looking around to make sure that a change wont break anything. So I have not change anything yet.

jdbcode commented 3 years ago

I think that makeRGBcomposite would need to change too. The inputs for redYear, greenYear, blueYear are used to select the bands by year. In the return line https://github.com/eMapR/LT-GEE/blob/de1f5f4c3bcf4c90872bafda584318e98f34ee75/LandTrendr.js#L915 I think you could add 'ftv_' + to e.g. redYear.toString() to fix it: 'ftv_' + redYear.toString().

Not sure about other places.

clarype commented 3 years ago

Ok. So the easiest edit is adding a hard coded prefix string in getYearBandName() at i.toString() on the line below

https://github.com/eMapR/LT-GEE/blob/de1f5f4c3bcf4c90872bafda584318e98f34ee75/LandTrendr.js#L1188

The hard coded string could be anything like yrs_, ftv_, etc. But the change should be structured to what getYeatBandName() is currently being used for. This function is currently being used in functions: TScollectionToStack() (directly), makeRGBcomposite() (indirectly via getFittedData()), and getFittedRGBcol()(indirectly via getFittedData(), getFittedData(). Since the TScollectionToStack() does not typically use fitted data the prefix should not use reference fitting. So something like yr_ should be used since it is giving the band a year value anyway.

changes to each function getYearBandName(), getFittedRGBcol(), TScollectionToStack(), makeRGBcomposite(), getFittedData().

Changes to come

getYearBandName()

// FROM
for (var i = startYear; i <= endYear; ++i) years.push(i.toString());  

// TO
for (var i = startYear; i <= endYear; ++i) years.push("yr_"+i.toString());    

getFittedRGBcol()

// FROM
var years = ee.List.sequence(startYear, endYear);
  var yearsStr = years.map(function(year){  
    return ee.Algorithms.String(year).slice(0,4);
  });

// TO
var yearsStr = ee.List(getYearBandNames(startYear, endYear))

TScollectionToStack()

no change needed

makeRGBcomposite()

// FROM
return ftvStack.select([redYear.toString(),greenYear.toString(),blueYear.toString()]); 

//TO
return ftvStack.select(["yr_"+redYear.toString(),"yr_"+greenYear.toString(),"yr_"+blueYear.toString()]); 

No changes have been made yet.

clarype commented 3 years ago

Tested changed functions and the functions that call the changed functions. Everything looks good.