MagicForrest / DGVMTools

R package for processing, analysing and visualising ouput from Dynamic Global Vegetation Models (DGVMs)
GNU General Public License v3.0
26 stars 22 forks source link

conflict with function 'setnames' #17

Closed sedrickel closed 5 years ago

sedrickel commented 5 years ago

Hello,

I have been using a dev version of DGVMTools (v 0.5) for aDGVM2 post-processing. Prior to updating to the latest dev version, I don't get any errors related to 'setnames' being masked. After updating however, I started to get errors in plotTemporal, specifically:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘setnames’ for signature ‘"data.table", "character", "character"’

I tried to go back to the 0.5 version but this error persists now. Is there anything I can do to restore the 0.5 version completely, as I also need to source my own biome classifications (I also couldn't source them after the update.).

Thanks!

MagicForrest commented 5 years ago

Hi, thanks for reporting! And sorry that your code broke :-(

I am not sure why you can't go back to v0.5, you should be able to! Did you try something like:

devtools::install_github("MagicForrest/DGVMTools", ref = "release/v0.5.0")

??

And is the package version now stated to be v0.5.0? Then you should have exactly version 0.5.0.

If that isn't working, maybe it is because of updates to other packages. Did you also update other packages recently?

I will work towards solving the bugs you mentioned in the latest version. I might ask you for a bit more debug info if that is okay?

sedrickel commented 5 years ago

Okay, so I just updated to the latest version again (v. 0.6.2) to make things easier (together with all the package dependencies it requires), and I'm okay with updating my code too. The biome schemes I was also using are on the latest version so I can work with this now...

That said, I tried to run the following:

test.run <- defineSource(id = "1_1_yunnan",  
                         name = "Indochina",
                         format = aDGVM,
                         year.offset = 1950,
                         dir = "location")

test.biome5 <- getBiomes(test.run, Hickler2012BiomeScheme, first.year=2018, last.year=2099, adgvm.scheme=2)

I get the following error message from the getBiomes run after converting all my trait files.

Error in as(this.Field, "STAInfo") : no method or default for coercing “list” to “STAInfo” In addition: Warning message: In [.data.table(out.all, , :=(Day, NULL)) : Adding new column 'Day' then assigning NULL (deleting it).

Is this caused by something that I am not doing properly?

Thanks for the quick response!

MagicForrest commented 5 years ago

Hey again Sedricke. No, you are not doing anything wrong, this is a known issue (or rather a consequence of incompletely implemented changes) that I will fix today. Stand by...

MagicForrest commented 5 years ago

Sooo... reading aDGVM output should be working in the dev branch but I have not been able to test it because I don't have aDGVM output to hand. Give it a go and let me know how it works for you!

sedrickel commented 5 years ago

Hey Matthew. So I updated the DGVMTools package and ran the same code. I got this now:

> test.run <- defineSource(id = "1_1_yunnan",   
+                          name = "Indochina",
+                          format = aDGVM,
+                          year.offset = 1950,
+                          dir = "location")

PFTs for adgvm.scheme==1: Tr, C4G, C3G PFTs for adgvm.scheme==2: TrBE, TrBR, TrBES, TrBRS, C4G, C3G determinePFTs returns list with all available aDGVM2 PFTs.

test.biome5 <- getBiomes(test.run, Hickler2012BiomeScheme, first.year=2018, last.year=2099, adgvm.scheme=2)

Error in getQuantity_aDGVM_Scheme2(source, target.STAInfo, quant) : no slot of name "first.year" for this object of class "Quantity"

Should I put an argument for sta.info? Thanks!

MagicForrest commented 5 years ago

Hi Sedricke. No, you don't need to do that, the problem was internal and should be solved now with the latest dev version.

sedrickel commented 5 years ago

Alright so I tried the latest version with different aDGVM2 output files and consistently I got this. See code and error below:

test.run <- defineSource(id = "70_0",
                         name = "Test Thai site",
                         format = aDGVM,
                         year.offset = 1950,
                         dir = "loc")

PFTs for adgvm.scheme==1: Tr, C4G, C3G PFTs for adgvm.scheme==2: TrBE, TrBR, TrBES, TrBRS, C4G, C3G determinePFTs returns list with all available aDGVM2 PFTs.

test.field <- getField(source = test.run,
                       first.year = 1950,
                       last.year = 2099,
                       adgvm.scheme = 2,
                       var = "agb",   
                       write = TRUE,
                       read.full = TRUE)

Convert K:/aDGVM data/aDGVM2-thai-mys-1/trait_70_0.nc

     Lon      Lat        TrBES       TrBRS        TrBE         TrBR        C3G        C4G

1: 101.5833 14.58333 0.0072363403 0.004163873 0.001545783 0.0010653537 0.15622923 0.09305742 2: 101.5833 14.58333 0.0322217325 0.011857354 0.021120114 0.0068023546 0.22302421 0.14965523 ... Year Month 1: 1950 1 2: 1960 1 3: 1970 1 ... Year Month $Lon [1] 101.5833 101.7500

$Lat [1] 14.58333 14.91667

$Year [1] 1950 2090

$Month [1] 1 1

Error in min(years.present) : invalid 'type' (list) of argument In addition: There were 50 or more warnings (use warnings() to see the first 50)

warnings()

Warning messages: 1: In [.data.table(out.all, , :=(Day, NULL)) : Adding new column 'Day' then assigning NULL (deleting it). 2: In selectYears(this.Field, first = first.year, last = last.year) : Year 1951 requested, but it is not in the data! 3: In selectYears(this.Field, first = first.year, last = last.year) : Year 1952 requested, but it is not in the data! ... 49: In selectYears(this.Field, first = first.year, last = last.year) : Year 2003 requested, but it is not in the data! 50: In selectYears(this.Field, first = first.year, last = last.year) : Year 2004 requested, but it is not in the data!

Running the code below yields the same error as above:

test.biome5 <- getBiomes(test.run, SimpleAdgvm2BiomeScheme, first.year=2018, last.year=2099, adgvm.scheme=2)

Error in min(years.present) : invalid 'type' (list) of argument In addition: There were 50 or more warnings (use warnings() to see the first 50)

MagicForrest commented 5 years ago

Okay, progress! I found another little bug and hopefully fixed it. Try again ;-)

sedrickel commented 5 years ago

That worked! Now it is able to read in my aDGVM2 outputs and proceed with plotSpatial. Later my questions would be about sourcing my own biome schemes, but for now, thanks for the help, I appreciate it a lot!

MagicForrest commented 5 years ago

Excellent, happy days!

I will be totally happy to help about sourcing new biome schemes, I have no idea why that stopped working. I will mark close this current issue, but just open another one for biomes schemes or anything else you like ;-)