Read_stars() with file_path() hits error

,

@aspina , I was trying to use the codes in R handbook to import my weather data using the read_stars() and file_path() options .

## define path to weather folder 
file_paths <- list.files(
  here::here("data", "weather"), 
  full.names = TRUE)

## only keep those with the current name of interest 
 file_paths <- file_paths[str_detect(file_paths, "Lankien_weather")]

# read the weather data 
data <- stars::read_stars(file_paths)

this hits an error of:

**Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: The dataset has several variables that could be identified as vector fields, but not all share the same primary dimension. Consequently they will be ignored.Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: The dataset has several variables that could be identified as vector fields, but not all share the same primary dimension. Consequently they will be ignored.Warning: GDAL Message 1: dimension #1 (expver) is not a Time dimension.Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: The dataset has several variables that could be identified as vector fields, but not all share the same primary dimension. Consequently they will be ignored.Warning: GDAL Message 1: dimension #1 (expver) is not a Time dimension.Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1
Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: The dataset has several variables that could be identified as vector fields, but not all share the same primary dimension. Consequently they will be ignored.t2m, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: The dataset has several variables that could be identified as vector fields, but not all share the same primary dimension. Consequently they will be ignored.Warning: GDAL Message 1: dimension #1 (expver) is not a Time dimension.Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1tp, Warning: GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".Warning: GDAL Message 1: The dataset has several variables that could be identified as vector fields, but not all share the same primary dimension. Consequently they will be ignored.Warning: GDAL Message 1: dimension #1 (expver) is not a Time dimension.Warning: GDAL Message 1: 1-pixel width/height files not supported, xdim: 1 ydim: 1**

and never imported my data

I managed to import the weather data files one by one (using the read_stars and read_ncdf) and bind the rows after changing to DF and all worked fine.

# OR
# Import files individual either using read_stars() or read_ncdf()

data0 <- read_ncdf(here("data", "weather","Lankien_weather2014.nc")) 
data1 <- read_ncdf(here("data", "weather","Lankien_weather2015.nc"))
data2 <- read_ncdf(here("data", "weather","Lankien_weather2016.nc"))
data3 <- read_ncdf(here("data", "weather","Lankien_weather2017.nc"))
data4 <- read_ncdf(here("data", "weather","Lankien_weather2018.nc"))
data5 <- read_ncdf(here("data", "weather","Lankien_weather2019.nc"))
data6 <- read_ncdf(here("data", "weather","Lankien_weather2020.nc"))
data7 <- read_ncdf(here("data", "weather","Lankien_weather2021.nc"))
data8 <- read_ncdf(here("data", "weather","Lankien_weather2022.nc"))
  
#  then bind rows 

data<-bind_rows(as_tibble(data0,data1,data2,data3,data4,data5,data6,data7,data8))

I wonder why the ```read_stars(file_paths) is not working and what the error means?

I have searched stack overflow as well but none of them explained what this error could be. J curious.

2 Likes

hey @berhe_tesfay - not really sure what that is about. Think there was a recent release of {gdal}, wonder if that has broken things upstream (?).
Seems like theres a couple things going on there, it doesnt like recoding format (utf-8 to cp_acp), it doesn’t recognise t2m (which is the temperature variable at 2 metres above ground) and then it doesnt like that vectors are different dimensions.
I think the last point is probably the main problem - and that read_stars is expecting dataframes (or another input) of the same size.
Is it possible one of the files in your folder has “lankien” in the name but isn’t one of those weather .nc files?
Eitherway seems odd - and honestly cant say know what to do with it … probably worth posting an issue on their github?

3 Likes