Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Earth Sciences
startR
Commits
7e36da1c
Commit
7e36da1c
authored
May 10, 2022
by
aho
Browse files
Bugfix if return_vars = NULL and split param is used.
parent
42ca5c19
Changes
2
Hide whitespace changes
Inline
Side-by-side
R/Start.R
View file @
7e36da1c
...
...
@@ -3716,11 +3716,13 @@ Start <- function(..., # dim = indices/selectors,
tmp_fun
<-
function
(
x
,
y
)
{
any
(
names
(
dim
(
x
))
%in%
y
)
}
inner_dim_has_split_dim
<-
names
(
which
(
unlist
(
lapply
(
picked_common_vars
,
tmp_fun
,
names
(
all_split_dims
)))))
if
(
!
identical
(
inner_dim_has_split_dim
,
character
(
0
)))
{
# If merge_across_dims also, it will be replaced later
saved_reshaped_attr
<-
attr
(
picked_common_vars
[[
inner_dim_has_split_dim
]],
'variables'
)
if
(
!
is.null
(
picked_common_vars
))
{
inner_dim_has_split_dim
<-
names
(
which
(
unlist
(
lapply
(
picked_common_vars
,
tmp_fun
,
names
(
all_split_dims
)))))
if
(
!
identical
(
inner_dim_has_split_dim
,
character
(
0
)))
{
# If merge_across_dims also, it will be replaced later
saved_reshaped_attr
<-
attr
(
picked_common_vars
[[
inner_dim_has_split_dim
]],
'variables'
)
}
}
}
}
...
...
@@ -3785,7 +3787,7 @@ Start <- function(..., # dim = indices/selectors,
if
(
!
merge_across_dims
&
split_multiselected_dims
&
identical
(
inner_dim_has_split_dim
,
character
(
0
)))
{
final_dims_fake_metadata
<-
NULL
}
else
{
if
(
!
merge_across_dims
&
split_multiselected_dims
)
{
if
(
!
merge_across_dims
&
split_multiselected_dims
&
!
is.null
(
picked_common_vars
)
)
{
if
(
any
(
names
(
all_split_dims
[[
1
]])
%in%
names
(
dim
(
picked_common_vars
[[
inner_dim_has_split_dim
]])))
&
names
(
all_split_dims
)[
1
]
!=
inner_dim_has_split_dim
)
{
if
(
inner_dim_has_split_dim
%in%
names
(
final_dims
))
{
...
...
@@ -4000,7 +4002,7 @@ Start <- function(..., # dim = indices/selectors,
picked_common_vars
[[
across_inner_dim
]]
<-
metadata_tmp
attr
(
picked_common_vars
[[
across_inner_dim
]],
'variables'
)
<-
saved_reshaped_attr
}
if
(
split_multiselected_dims
)
{
if
(
split_multiselected_dims
&
!
is.null
(
picked_common_vars
)
)
{
if
(
!
identical
(
inner_dim_has_split_dim
,
character
(
0
)))
{
metadata_tmp
<-
array
(
picked_common_vars
[[
inner_dim_has_split_dim
]],
dim
=
final_dims_fake_metadata
)
# Convert numeric back to dates
...
...
@@ -4129,7 +4131,7 @@ Start <- function(..., # dim = indices/selectors,
picked_common_vars
[[
across_inner_dim
]]
<-
metadata_tmp
attr
(
picked_common_vars
[[
across_inner_dim
]],
'variables'
)
<-
saved_reshaped_attr
}
if
(
split_multiselected_dims
)
{
if
(
split_multiselected_dims
&
!
is.null
(
picked_common_vars
)
)
{
if
(
!
identical
(
inner_dim_has_split_dim
,
character
(
0
)))
{
metadata_tmp
<-
array
(
picked_common_vars
[[
inner_dim_has_split_dim
]],
dim
=
final_dims_fake_metadata
)
# Convert numeric back to dates
...
...
tests/testthat/test-Start-metadata_reshaping.R
View file @
7e36da1c
...
...
@@ -615,6 +615,45 @@ datesF,
dates
)
# no return_vars
suppressWarnings
(
data
<-
Start
(
dat
=
paste0
(
'/esarchive/recon/ecmwf/erainterim/6hourly/'
,
'$var$/$var$_$file_date$.nc'
),
var
=
'tas'
,
file_date
=
file_date
,
#[syear = 3, smonth = 2]
time
=
indices
(
1
:
2
),
latitude
=
indices
(
1
),
longitude
=
indices
(
1
),
split_multiselected_dims
=
TRUE
,
# return_vars = list(latitude = NULL,
# longitude = NULL,
# time = 'file_date'),
retrieve
=
TRUE
)
)
expect_equal
(
names
(
attributes
(
data
)
$
Variables
$
common
),
'tas'
)
suppressWarnings
(
data
<-
Start
(
dat
=
paste0
(
'/esarchive/recon/ecmwf/erainterim/6hourly/'
,
'$var$/$var$_$file_date$.nc'
),
var
=
'tas'
,
file_date
=
file_date
,
#[syear = 3, smonth = 2]
time
=
indices
(
1
:
2
),
latitude
=
indices
(
1
),
longitude
=
indices
(
1
),
split_multiselected_dims
=
TRUE
,
# return_vars = list(latitude = NULL,
# longitude = NULL,
# time = 'file_date'),
retrieve
=
FALSE
)
)
expect_equal
(
names
(
attributes
(
data
)
$
Variables
$
common
),
NULL
)
})
test_that
(
"9. split file dim that contains 'time', and 'time' inner dim is implicit"
,
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment