Skip to content

[get_sim2_daily] NetCDF format does not return same results as CSV format

For a same query run in csv and another in netcdf translated into a csv, the number of rows differs and the values are not the same after the first row!!!

Just look at this:

> today <- Sys.Date()
> cutoff_date <- today - 90
> fields = c("PRENEI_Q", "PRELIQ_Q", "T_Q")
> climate_csv <- get_sim2_daily(
+   LAMBX__greater = 275000,
+   LAMBX__less = 304000,
+   LAMBY__greater = 1810000,
+   LAMBY__less = 1840000,
+   DATE__greater = cutoff_date,
+   fields = fields,
+   api_format = "csv"
+ )
Rows: 2136 Columns: 6                                                                                                     
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
dbl  (5): LAMBX, LAMBY, PRENEI_Q, PRELIQ_Q, T_Q
date (1): DATE

 Use `spec()` to retrieve the full column specification for this data.
 Specify the column types or set `show_col_types = FALSE` to quiet this message.
> climate_ncdf <- get_sim2_daily(
+   LAMBX__greater = 275000,
+   LAMBX__less = 304000,
+   LAMBY__greater = 1810000,
+   LAMBY__less = 1840000,
+   DATE__greater = cutoff_date,
+   fields = fields,
+   api_format = "ncdf",
+   overlay_mode = "extent"
+ )
>   df_csv <- climate_csv %>%
+     dplyr::arrange(LAMBX, LAMBY, DATE)
>   df_ncdf <- climate_ncdf %>%
+     as.data.frame() %>%
+     dplyr::rename(
+       LAMBX = x,
+       LAMBY = y,
+       DATE = time
+     ) %>%
+     dplyr::mutate(DATE = as.Date(DATE)) %>%
+     dplyr::select(LAMBX, LAMBY, DATE, dplyr::all_of(fields)) %>%
+     dplyr::arrange(LAMBX, LAMBY, DATE)
>   expect_equal(df_ncdf, df_csv)
Error: `df_ncdf` (`actual`) not equal to `df_csv` (`expected`).

`class(actual)`:   "data.frame"                   
`class(expected)`: "tbl_df"     "tbl" "data.frame"

  `attr(actual, 'row.names')[2134:2225]`: 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 and 82 more...
`attr(expected, 'row.names')[2134:2136]`: 2134 2135 2136                                               ...

`attr(actual, 'query')` is absent
`attr(expected, 'query')` is a character vector ('https://api.g-eau.fr/sim2_daily.csv?LAMBX__greater=275000&LAMBY__greater=1810000&LAMBX__less=304000&LAMBY__less=1840000&DATE__greater=2025-06-27&fields=PRENEI_Q&fields=PRELIQ_Q&fields=T_Q')

  `actual$LAMBX[354:448]`: 276000 276000 276000

> head(df_csv)
# A tibble: 6 × 6
   LAMBX   LAMBY DATE       PRENEI_Q PRELIQ_Q   T_Q
   <dbl>   <dbl> <date>        <dbl>    <dbl> <dbl>
1 276000 1809000 2025-06-27        0      0    22  
2 276000 1809000 2025-06-28        0      0.1  23.1
3 276000 1809000 2025-06-29        0      0    25.1
4 276000 1809000 2025-06-30        0      0    25.7
5 276000 1809000 2025-07-01        0      0.2  24.7
6 276000 1809000 2025-07-02        0      2.3  20  
> head(df_ncdf)
   LAMBX   LAMBY       DATE PRENEI_Q   PRELIQ_Q       T_Q
1 276000 1809000 2025-06-27 0 [mm/d] 0.0 [mm/d] 22.0 [°C]
2 276000 1809000 2025-06-28 0 [mm/d] 0.1 [mm/d] 22.6 [°C]
3 276000 1809000 2025-06-29 0 [mm/d] 0.0 [mm/d] 24.3 [°C]
4 276000 1809000 2025-06-30 0 [mm/d] 0.0 [mm/d] 26.7 [°C]
5 276000 1809000 2025-07-01 0 [mm/d] 0.7 [mm/d] 25.6 [°C]
6 276000 1809000 2025-07-02 0 [mm/d] 2.2 [mm/d] 20.2 [°C]