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
euporias
biascorrection
Commits
7d623289
Commit
7d623289
authored
Sep 21, 2017
by
Franssen, Wietse
Browse files
added some files
parent
ef49cdae
Changes
3
Hide whitespace changes
Inline
Side-by-side
SCRIPTS/globalDownloadTest.R
0 → 100644
View file @
7d623289
rm
(
list
=
ls
())
library
(
fields
)
# e.g: using the fields library
library
(
abind
)
library
(
ncdf4
)
library
(
loadeR.ECOMS
)
source
(
file
=
"./functions/infoGeneral.R"
)
source
(
file
=
"./functions/functionsGeneral.R"
)
source
(
file
=
"./functions/functionR2Netcdf.R"
)
loginUDG
(
username
=
"wietsefranssen"
,
password
=
"ECOMS"
)
RData
<-
loadECOMS
(
dataset
=
"System4_seasonal_15"
,
var
=
"tas"
,
members
=
1
,
lonLim
=
c
(
-180
,
180
),
latLim
=
c
(
-90
,
90
),
season
=
1
,
years
=
1990
,
leadMonth
=
1
,
time
=
"DD"
,
aggr.d
=
"mean"
)
RData2
<-
loadECOMS
(
dataset
=
"System4_seasonal_15"
,
var
=
"tas"
,
members
=
1
,
lonLim
=
c
(
-179
,
180
),
latLim
=
c
(
-90
,
90
),
season
=
1
,
years
=
1990
,
leadMonth
=
1
,
time
=
"DD"
,
aggr.d
=
"mean"
)
RData3
<-
loadECOMS
(
dataset
=
"System4_seasonal_15"
,
var
=
"tas"
,
members
=
1
,
lonLim
=
c
(
-179
,
179
),
latLim
=
c
(
-90
,
90
),
season
=
1
,
years
=
1990
,
leadMonth
=
1
,
time
=
"DD"
,
aggr.d
=
"mean"
)
RData4
<-
loadECOMS
(
dataset
=
"System4_seasonal_15"
,
var
=
"tas"
,
members
=
1
,
lonLim
=
c
(
-180
,
180
),
latLim
=
c
(
-70
,
70
),
season
=
1
,
years
=
1990
,
leadMonth
=
1
,
time
=
"DD"
,
aggr.d
=
"mean"
)
RData5
<-
loadECOMS
(
dataset
=
"System4_seasonal_15"
,
var
=
"tas"
,
members
=
1
,
lonLim
=
c
(
-179
,
180
),
latLim
=
c
(
-70
,
70
),
season
=
1
,
years
=
1990
,
leadMonth
=
1
,
time
=
"DD"
,
aggr.d
=
"mean"
)
RData6
<-
loadECOMS
(
dataset
=
"System4_seasonal_15"
,
var
=
"tas"
,
members
=
1
,
lonLim
=
c
(
-179
,
179
),
latLim
=
c
(
-70
,
70
),
season
=
1
,
years
=
1990
,
leadMonth
=
1
,
time
=
"DD"
,
aggr.d
=
"mean"
)
RData
$
xyCoords
$
x
[]
<-
round
(
RData
$
xyCoords
$
x
[],
2
)
RData2
$
xyCoords
$
x
[]
<-
round
(
RData2
$
xyCoords
$
x
[],
2
)
RData3
$
xyCoords
$
x
[]
<-
round
(
RData3
$
xyCoords
$
x
[],
2
)
RData4
$
xyCoords
$
x
[]
<-
round
(
RData4
$
xyCoords
$
x
[],
2
)
RData5
$
xyCoords
$
x
[]
<-
round
(
RData5
$
xyCoords
$
x
[],
2
)
RData6
$
xyCoords
$
x
[]
<-
round
(
RData6
$
xyCoords
$
x
[],
2
)
print
(
RData
$
xyCoords
$
x
)
print
(
RData2
$
xyCoords
$
x
)
print
(
RData3
$
xyCoords
$
x
)
RData
$
xyCoords
$
x
[
1
:
3
]
RData2
$
xyCoords
$
x
[
1
:
3
]
RData3
$
xyCoords
$
x
[
1
:
3
]
RData4
$
xyCoords
$
x
[
1
:
3
]
RData5
$
xyCoords
$
x
[
1
:
3
]
RData6
$
xyCoords
$
x
[
1
:
3
]
length
(
RData
$
xyCoords
$
x
)
length
(
RData2
$
xyCoords
$
x
)
length
(
RData3
$
xyCoords
$
x
)
RData
$
xyCoords
$
x
[
479
:
481
]
RData2
$
xyCoords
$
x
[
478
:
480
]
RData3
$
xyCoords
$
x
[
477
:
479
]
RData4
$
xyCoords
$
x
[
479
:
481
]
RData5
$
xyCoords
$
x
[
478
:
480
]
RData6
$
xyCoords
$
x
[
477
:
479
]
RData
$
Data
[
1
,
1
:
2
,
1
:
3
]
RData2
$
Data
[
1
,
1
:
2
,
1
:
3
]
RData3
$
Data
[
1
,
1
:
2
,
1
:
3
]
RData4
$
Data
[
1
,
1
:
2
,
1
:
3
]
RData5
$
Data
[
1
,
1
:
2
,
1
:
3
]
RData6
$
Data
[
1
,
1
:
2
,
1
:
3
]
RData
$
Data
[
1
,
1
:
2
,
479
:
481
]
RData2
$
Data
[
1
,
1
:
2
,
478
:
480
]
RData3
$
Data
[
1
,
1
:
2
,
477
:
479
]
RData
$
Data
[
1
,
1
,]
RData2
$
Data
[
1
,
1
,]
RData3
$
Data
[
1
,
1
,]
RData4
$
Data
[
1
,
1
,]
SCRIPTS/makeSystem4UsableForLPJ.sh
0 → 100755
View file @
7d623289
inPath
=
"/home/WUR/frans004/L_BACKUP/PROJECTS/EUPORIAS/biascorrection/DATA/System4_seasonal_15_rev5.0/0.50deg/SA_BC_final/"
outPath
=
"/home/WUR/frans004/L_DATA/PROJECT_DATA/EUPORIAS/FORCING_DATA/System4_seasonal_15_rev5.0/0.50deg/SA_BC/"
tmpPath
=
"./tmp/"
mkdir
-p
$tmpPath
currPath
=
$(
pwd
)
"/"
cd
$inPath
for
i
in
$(
ls
*
.nc4
)
;
do
cdo sellonlatbox,-83.25,-32.25,-55.75,14.25
$i
"
$currPath$tmpPath
/
$i
"
done
cd
$currPath$tmpPath
for
i
in
$(
ls
*
.nc4
)
;
do
nccopy
-k
'netCDF-4 classic model'
$i
"
$outPath
/
$i
"
done
SCRIPTS/ttt2.R
0 → 100644
View file @
7d623289
## CREATE NETCDF
FillValue
<-
1e20
## Check dimensions
dimensions
<-
attributes
(
RData
$
Data
)
$
dimensions
## Check if 'member', or 4th dimension exist
nDims
<-
length
(
dim
(
RData
$
Data
))
## Define dimensions
dimX
<-
ncdim_def
(
"lon"
,
"degrees_east"
,
RData
$
xyCoords
$
x
)
dimY
<-
ncdim_def
(
"lat"
,
"degrees_north"
,
RData
$
xyCoords
$
y
)
if
(
nDims
>
3
)
{
dimZ
<-
ncdim_def
(
"member"
,
"layer"
,
1
:
dim
(
RData
$
Data
)[
which
(
dimensions
==
"member"
)])
}
timeString
<-
format
(
strptime
(
RData
$
Dates
$
start
[
1
],
format
=
"%Y-%m-%d"
,
tz
=
"GMT"
),
format
=
"%Y-%m-%d %T"
)
timeArray
<-
as.double
(
difftime
(
RData
$
Dates
$
start
,
RData
$
Dates
$
start
[
1
],
units
=
c
(
"days"
),
tz
=
"GMT"
))
dimT
<-
ncdim_def
(
"time"
,
paste0
(
"days since "
,
timeString
),
timeArray
,
unlim
=
FALSE
)
# if ('units' %in% names(RData$Variable)) {
# units<-RData$Variable$units
# } else {
# units<-""
# }
if
(
nDims
>
3
)
{
data
<-
ncvar_def
(
name
=
RData
$
Variable
$
varName
,
units
=
''
,
dim
=
list
(
dimX
,
dimY
,
dimZ
,
dimT
),
missval
=
FillValue
,
prec
=
"float"
,
chunksizes
=
c
(
length
(
RData
$
xyCoords
$
x
),
length
(
RData
$
xyCoords
$
y
),
1
,
1
),
compression
=
4
)
}
else
{
data
<-
ncvar_def
(
name
=
RData
$
Variable
$
varName
,
units
=
''
,
dim
=
list
(
dimX
,
dimY
,
dimT
),
missval
=
FillValue
,
prec
=
"float"
,
chunksizes
=
c
(
length
(
RData
$
xyCoords
$
x
),
length
(
RData
$
xyCoords
$
y
),
1
),
compression
=
4
)
}
## SAVE AS NC-DATA
print
(
paste0
(
"Writing: "
,
outFile
))
ncid
<-
nc_create
(
outFile
,
list
(
data
))
if
(
nDims
>
3
)
{
ncvar_put
(
ncid
,
data
,
aperm
(
RData
$
Data
,
c
(
which
(
dimensions
==
"lon"
),
which
(
dimensions
==
"lat"
),
which
(
dimensions
==
"member"
),
which
(
dimensions
==
"time"
))))
}
else
{
ncvar_put
(
ncid
,
data
,
aperm
(
RData
$
Data
,
c
(
which
(
dimensions
==
"lon"
),
which
(
dimensions
==
"lat"
),
which
(
dimensions
==
"time"
))))
}
ncatt_put
(
ncid
,
"lon"
,
"standard_name"
,
"longitude"
)
ncatt_put
(
ncid
,
"lon"
,
"long_name"
,
"Longitude"
)
ncatt_put
(
ncid
,
"lon"
,
"axis"
,
"X"
)
ncatt_put
(
ncid
,
"lat"
,
"standard_name"
,
"latitude"
)
ncatt_put
(
ncid
,
"lat"
,
"long_name"
,
"Latitude"
)
ncatt_put
(
ncid
,
"lat"
,
"axis"
,
"Y"
)
ncatt_put
(
ncid
,
"time"
,
"standard_name"
,
"time"
)
ncatt_put
(
ncid
,
"time"
,
"calendar"
,
"standard"
)
ncatt_put
(
ncid
,
RData
$
Variable
$
varName
,
"standard_name"
,
RData
$
Variable
$
varName
)
if
(
'longName'
%in%
names
(
RData
$
Variable
))
{
ncatt_put
(
ncid
,
RData
$
Variable
$
varName
,
"long_name"
,
RData
$
Variable
$
longName
)
}
## Global Attributes
if
(
'InitializationDates'
%in%
names
(
RData
))
{
initDateNames
<-
paste
(
RData
$
InitializationDates
,
sep
=
','
,
collapse
=
','
)
ncatt_put
(
ncid
,
0
,
"InitializationDates"
,
initDateNames
)
}
if
(
'Members'
%in%
names
(
RData
))
{
membernames
<-
paste
(
RData
$
Members
,
sep
=
','
,
collapse
=
','
)
ncatt_put
(
ncid
,
0
,
"Members"
,
membernames
)
}
## Get all global attributes from RData and put them in the NetCDF file
attributeList
<-
attributes
(
RData
)
attributeList
[
"names"
]
<-
NULL
for
(
iAttribute
in
1
:
length
(
attributeList
))
{
ncatt_put
(
ncid
,
0
,
names
(
attributeList
)[
iAttribute
],
as.character
(
attributeList
[
iAttribute
[]]))
}
ncatt_put
(
ncid
,
0
,
"NetcdfCreatationDate"
,
as.character
(
Sys.Date
()))
## Get all attributes of variable from RData and put them in the NetCDF file
attributeList
<-
attributes
(
RData
$
Variable
)
attributeList
[
"names"
]
<-
NULL
if
(
length
(
attributeList
)
>
0
)
{
for
(
iAttribute
in
1
:
length
(
attributeList
))
{
ncatt_put
(
ncid
,
RData
$
Variable
$
varName
,
names
(
attributeList
)[
iAttribute
],
as.character
(
attributeList
[
iAttribute
[]]))
}
}
## Get all xyCoords attributes and put them in the NetCDF file
attributeList
<-
attributes
(
RData
$
xyCoords
)
attributeList
[
"names"
]
<-
NULL
if
(
length
(
attributeList
)
>
0
)
{
for
(
iAttribute
in
1
:
length
(
attributeList
))
{
ncatt_put
(
ncid
,
0
,
paste0
(
"xyCoords_"
,
names
(
attributeList
)[
iAttribute
]),
as.character
(
attributeList
[
iAttribute
[]]))
}
}
# length(attributeList)
## Close Netcdf file
nc_close
(
ncid
)
}
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