Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
reservebenefit
environmental_assign_data
Commits
f84bd622
Commit
f84bd622
authored
Aug 29, 2019
by
peguerin
Browse files
clean scripts folder
parent
de25808c
Changes
1
Hide whitespace changes
Inline
Side-by-side
00-scripts/sst.R
deleted
100644 → 0
View file @
de25808c
###############################################################################
## Librairies
library
(
"raster"
)
library
(
"rgdal"
)
library
(
"ncdf4"
)
## load data
coo
=
read.csv
(
"01-sample_coords/all_coords.csv"
,
sep
=
"\t"
)
coo
=
na.omit
(
coo
)
names
(
coo
)
=
c
(
"id"
,
"lat"
,
"lon"
)
latlon
=
data.frame
(
lon
=
coo
$
lon
,
lat
=
coo
$
lat
)
coordinates
(
latlon
)
=
c
(
"lon"
,
"lat"
)
### indiquer que les lat/lon est en projection google map
proj4string
(
latlon
)
=
CRS
(
"+init=epsg:4326"
)
fichier
=
"01-infos/temperature/MEDSEA_PHY_006_004_SST_jan1987-nov2016_monthly.nc"
br
<-
brick
(
fichier
)
##convertir les lat/lon dans la projection du raster "rp"
latlon
=
spTransform
(
latlon
,
proj4string
(
br
))
buffer_distance
=
13000
tt
=
extract
(
br
,
latlon
,
buffer
=
buffer_distance
,
fun
=
mean
,
normalizeWeights
=
FALSE
,
weigths
=
TRUE
,
factors
=
TRUE
)
january
=
tt
[,
seq
(
1
,(
359-10
),
12
)]
february
=
tt
[,
seq
(
2
,(
359-9
),
12
)]
march
=
tt
[,
seq
(
3
,(
359-8
),
12
)]
april
=
tt
[,
seq
(
4
,(
359-7
),
12
)]
may
=
tt
[,
seq
(
5
,(
359-6
),
12
)]
june
=
tt
[,
seq
(
6
,(
359-5
),
12
)]
july
=
tt
[,
seq
(
7
,(
359-4
),
12
)]
august
=
tt
[,
seq
(
8
,(
359-3
),
12
)]
september
=
tt
[,
seq
(
9
,(
359-2
),
12
)]
october
=
tt
[,
seq
(
10
,(
359-1
),
12
)]
november
=
tt
[,
seq
(
11
,
359
,
12
)]
december
=
tt
[,
seq
(
12
,
359-11
,
12
)]
year
=
list
(
january
,
february
,
march
,
april
,
may
,
june
,
july
,
august
,
september
,
october
,
november
,
december
)
monthlytemp.frame
<-
as.data.frame
(
matrix
(,
ncol
=
(
36
),
nrow
=
0
))
for
(
i
in
seq
(
1
,
dim
(
tt
)[
1
])){
yeartemp
=
c
()
for
(
mois
in
seq
(
1
,
12
))
{
month_min
=
min
(
as.numeric
(
as.data.frame
(
year
[
mois
])[
i
,]),
na.rm
=
TRUE
)
month_max
=
max
(
as.numeric
(
as.data.frame
(
year
[
mois
])[
i
,]),
na.rm
=
TRUE
)
month_mean
=
mean
(
as.numeric
(
as.data.frame
(
year
[
mois
])[
i
,]),
na.rm
=
TRUE
)
yeartemp
=
c
(
yeartemp
,
month_min
,
month_max
,
month_mean
)
}
monthlytemp.frame
=
rbind
(
monthlytemp.frame
,
yeartemp
)
}
mois_nom
=
c
(
"january"
,
"february"
,
"march"
,
"april"
,
"may"
,
"june"
,
"july"
,
"august"
,
"september"
,
"october"
,
"november"
,
"december"
)
value_nom
=
c
(
"min"
,
"max"
,
"mean"
)
col_nom
=
c
()
for
(
m
in
mois_nom
){
for
(
n
in
value_nom
)
{
mois_value
=
paste
(
m
,
n
,
sep
=
"_"
)
nom_value
=
paste
(
"SST"
,
as.character
(
mois_value
),
sep
=
"_"
)
col_nom
=
c
(
col_nom
,
as.character
(
nom_value
))
}
}
colnames
(
monthlytemp.frame
)
=
col_nom
monthlytemp.coo
=
cbind
(
coo
,
monthlytemp.frame
)
write.table
(
monthlytemp.coo
,
file
=
"03-results/all_monthly_temperature.tsv"
,
quote
=
F
,
sep
=
"\t"
,
col.names
=
T
,
row.names
=
F
)
\ No newline at end of file
Write
Preview
Markdown
is supported
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