SticsRPacks / SticsRFiles

Read and modify STICS input/output files:
https://sticsrpacks.github.io/SticsRFiles
GNU Lesser General Public License v3.0
3 stars 4 forks source link

A way to directly load a xml usm file into a dataframe? #7

Closed Chabrier closed 1 year ago

Chabrier commented 1 year ago

To put usms according to a xml usm file inside a dataframe, i did use get_usms_list and then get_parama_xml.

Is there a more straightforward way to do this?

plecharpent commented 1 year ago

An unexported function can do this, and may be also used for generating csv files for every kind of file usms, tec, ini, ... 2 data.frame output format can be produced a wide (as in excel files used for generating xml files) or a long format. It works on a list of xml files, so parameters can be extracted for a whole JavaStics workspace

SticsRFiles:::get_xml_files_param_df(file_path = xml_files, wide_shape = TRUE)


<pre>
# A tibble: 182 × 1,052
   name         type  julres coderes  qres Crespc CsurN…¹ Nminres eaures code_…²  resk  resz jultrav profres proft…³ iplt0 profsem densi…⁴
   <chr>        <chr>  <int>   <int> <dbl>  <int>   <int>   <int>  <int>   <int> <dbl> <int>   <int>   <int>   <int> <int>   <dbl>   <dbl>
 1 aiadan4_tec… fich…     70       1  2.33     42      80       0      0       1  0.14     5      70       0      20    77     4    200   
 2 AuzevilleJ_… fich…     NA      NA NA        NA      NA      NA     NA      NA NA       NA      NA      NA      NA    NA    NA     NA   
 3 banane_ini.… init…     NA      NA NA        NA      NA      NA     NA      NA NA       NA      NA      NA      NA    NA    NA     NA   
 4 banane_tec.… fich…     30       1  4        42      40       0      0       1  0.14     5      30       0      20    32    20      0.18
 5 bettera_ini… init…     NA      NA NA        NA      NA      NA     NA      NA NA       NA      NA      NA      NA    NA    NA     NA   
</pre>

Guess it will help.
Patrice.
Chabrier commented 1 year ago

Excellent, il will help, yes!

Very interesting when you have to develop an experimental plan.

Just wondering, why this is not exported?

Anyway, thanks for the feedback.

Chabrier commented 1 year ago

I went farther, but when working either with tec or init files i get some issues that i share here, with this code.

library(SticsRFiles)
library(dplyr)

javasticsPath <- "/home/pchabrier/DEVS/playingWithSticsR/distrib/JavaSTICS-1.5.1-STICS-10.0.0"

exampleXmlPath <- file.path(javasticsPath,"example")

exampleTecFile <- file.path(exampleXmlPath, "ble1_tec.xml")

# getting all the parameters
ble1_Tec <- SticsRFiles:::get_xml_files_param_df(file_path = exampleTecFile, wide_shape = TRUE)

# removing the type column and renaming the name column
ble1_Tec_T <- rename(ble1_Tec, Tec_name = name) %>% select(-type)

# now expecting to recreate the xml file

# this does not work, the error message is curious 
# Unknown parameters found in table: julapN_or_sum_upvt_or_sum_upvt
# But one of the reason could be that the default template file is not compatible with
# ble1_tec.xml
gen_tec_xml(out_dir = getwd(), param_df = ble1_Tec_T)

# this does not work either, and in this case, we could expect get the same file,
# since we take as template the file from where the parameters comes
gen_tec_xml(out_dir = getwd(), param_df = ble1_Tec_T, file = exampleTecFile)

# on a subset of parameters it does work
ble1_Tec_Dummy <- ble1_Tec_T %>% select(Tec_name, julres, jultrav)
gen_tec_xml(out_dir = getwd(), param_df = ble1_Tec_Dummy, file = exampleTecFile)

# But what if i want them all?

When working with usm, soil, or stations, things seems to be clearer.

Chabrier commented 1 year ago

fixed on https://github.com/SticsRPacks/SticsRFiles/tree/master thanks!