logan-berner / LandsatTS

LandsatTS is an R package to facilitate retrieval, cleaning, cross-calibration, and phenological modeling of Landsat time-series data.
Other
26 stars 4 forks source link

lsat_calibrate_rf() example fails to execute #34

Closed jakobjassmann closed 2 years ago

jakobjassmann commented 2 years ago

Code example in documentation for lsat_calibrate_rf()

data(lsat.example.dt)
lsat.dt <- lsat_general_prep(lsat.example.dt)
lsat.dt <- lsat_clean_data(lsat.dt)
lsat.dt <- lsat_calc_spec_index(lsat.dt, 'ndvi')
lsat.dt <- lsat_calibrate_rf(lsat.dt, band.or.si = 'ndvi', write.output = FALSE)

fails with error message:

Error: sample_fraction too small, no observations sampled. Ranger will EXIT now.
 Error in predict.ranger.forest(forest, data, predict.all, num.trees, type,  : 
  User interrupt or internal error. 

@logan-berner I am not sure how to interpret this error, is it because the last.example.dt dataset is too small?

jakobjassmann commented 2 years ago

For now, I have commented out the line in the example. This allowed me to run all remaining checks.

The function is also used in other code examples. In some it was already commented out, but not in other. I commented out the call in those too. The following examples now contain a commented out line with the call:

jtkerb commented 2 years ago

Unsure if this is related, but I run into an error when using lsat_calibrate_rf() on a dataset from west Greenland with >1000 pixels.

Code example: lsat.dt <- lsat_calibrate_rf(lsat.dt, band.or.si = 'ndvi', doy.rng = 150:242, min.obs = 5, frac.train = 0.75, overwrite.col = T, write.output = T, train.with.highlat.data = F, outdir = outputs_dir))

fails with error message:

Error in data.table::dcast.data.table(sample.doy.dt, sample.id + doy ~ : Can not cast an empty data.table

Everything runs fine if I switch the 'train.with.highlat.data' to TRUE.

Not an urgent issue, just wanted to have it flagged in case it was a more general problem.

logan-berner commented 2 years ago

@jakobjassmann and @jtkerb -- Yes, you both hit related issues with having few to no samples sites with temporally overlapping measurements between Landsat 7 and Landsat5/8. I updated the function so it now checks whether there are atleast 100 sample sites with temporally overlapping data from both sensors. If there is not adequate data, then the function now produces an error message, returns the original data.table, and stops. The error message looks like this, but is better formatted in R:

Error in lsat_calibrate_rf(lsat.dt, band.or.si = "ndvi", : 
 Your dataset has 0 sample sites with temporally overlapping measurements from LANDSAT_7 and LANDSAT_5. This is not enough data to cross-calibrate the sensors. Either set min.obs lower, set train.with.highlat.data = T if working in the Arctic or Boreal biome, or extract Landsat data from more sample sites...  The function will now stop!

Could you please update to the latest version of lsatTS on the repo and try again. I'll close this Issue, but please reopen if you still encounter issues.