Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Franssen, Wietse
WFRTools
Commits
d0888d44
Commit
d0888d44
authored
Mar 17, 2015
by
Franssen, Wietse
Browse files
made some ajustments and shitched arrays
parent
5f43ebd9
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/WFRTools.R
View file @
d0888d44
...
...
@@ -17,10 +17,10 @@ plotje <-function(data, title = NULL) {
}
if
(
length
(
dim
(
data
$
Data
))
>
2
)
{
dataTmp
<-
data
$
Data
[,,
1
]
dataTmp
<-
aperm
(
data
$
Data
[
1
,,]
,
c
(
2
,
1
))
cat
(
"Plotting first timestep\n"
)
}
else
{
dataTmp
<-
data
$
Data
dataTmp
<-
aperm
(
data
$
Data
,
c
(
2
,
1
))
}
image.plot
(
data
$
xyCoords
$
x
,
data
$
xyCoords
$
y
,
dataTmp
,
asp
=
1
,
main
=
title
,
xlab
=
''
,
ylab
=
''
)
world
(
add
=
TRUE
)
...
...
@@ -53,14 +53,16 @@ rDataStructure <-function() {
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
#' @export
r2ggplotDataStructure
<-
function
(
data
)
{
r2ggplotDataStructure
<-
function
(
data
,
timestep
=
1
)
{
lonList
=
array
(
1
,
dim
=
c
(
length
(
data
$
xyCoords
$
x
)
*
length
(
data
$
xyCoords
$
y
)))
latList
=
array
(
1
,
dim
=
c
(
length
(
data
$
xyCoords
$
x
)
*
length
(
data
$
xyCoords
$
y
)))
i
=
1
for
(
y
in
1
:
dim
(
data
$
xyCoords
$
y
))
#for(y in 1:dim(data$xyCoords$y))
for
(
x
in
1
:
length
(
data
$
xyCoords
$
x
))
{
for
(
x
in
1
:
dim
(
data
$
xyCoords
$
x
))
{
#for(x in 1:dim(data$xyCoords$x))
for
(
y
in
1
:
length
(
data
$
xyCoords
$
y
))
{
lonList
[
i
]
=
data
$
xyCoords
$
x
[
x
];
latList
[
i
]
=
data
$
xyCoords
$
y
[
y
];
i
=
i
+1
...
...
@@ -70,8 +72,14 @@ r2ggplotDataStructure <-function(data) {
ggplotData
<-
NULL
ggplotData
$
lon
=
lonList
ggplotData
$
lat
=
latList
ggplotData
$
data
=
c
(
data
$
Data
)
if
(
length
(
dim
(
data
$
Data
))
==
2
)
{
ggplotData
$
data
=
c
(
data
$
Data
)
}
else
if
(
length
(
dim
(
data
$
Data
))
==
3
)
{
ggplotData
$
data
=
c
(
data
$
Data
[
timestep
,,])
}
else
if
(
length
(
dim
(
data
$
Data
))
==
4
)
{
ggplotData
$
data
=
c
(
data
$
Data
[
1
,
timestep
,,])
}
#ggplotFinal<-data.frame(ggplotData)
ggplotFinal
<-
na.omit
(
data.frame
(
ggplotData
))
...
...
@@ -282,6 +290,11 @@ ncLoad <-function(file, varName = NULL, lonlatbox = NULL, timesteps = NULL, z =
}
else
{
data
$
Data
<-
ncvar_get
(
ncFile
,
varName
,
start
=
c
(
LonIdx
[
1
],
LatIdx
[
1
],
z
,
timeIdx
[
1
]),
count
=
c
(
length
(
LonIdx
),
length
(
LatIdx
),
1
,
length
(
timeIdx
)))
}
if
(
length
(
dim
(
data
$
Data
==
2
)))
{
data
$
Data
<-
aperm
(
data
$
Data
,
c
(
2
,
1
))
}
else
if
(
length
(
dim
(
data
$
Data
==
2
)))
{
data
$
Data
<-
aperm
(
data
$
Data
,
c
(
3
,
2
,
1
))
}
attr
(
data
$
Data
,
"dimensions"
)
<-
ncCheckResult
$
dims
data
$
Variable
$
varName
<-
varName
...
...
@@ -368,7 +381,11 @@ ncWrite <-function(outFile = "~/out.nc", rData = data) {
FillValue
<-
NA
FillValue
<-
1e20
datavar
<-
ncvar_def
(
rData
$
Variable
$
varName
,
rData
$
Variable
$
units
,
list
(
dimX
,
dimY
,
dimT
),
FillValue
,
prec
=
"float"
)
if
(
!
is.null
(
rData
$
Variable
$
units
))
{
datavar
<-
ncvar_def
(
rData
$
Variable
$
varName
,
rData
$
Variable
$
units
,
list
(
dimT
,
dimY
,
dimX
),
FillValue
,
prec
=
"float"
)
}
else
{
datavar
<-
ncvar_def
(
rData
$
Variable
$
varName
,
" "
,
list
(
dimT
,
dimY
,
dimX
),
FillValue
,
prec
=
"float"
)
}
ncid_out
<-
nc_create
(
outFile
,
datavar
)
## ADD ATTRIBUTES
...
...
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