Commit efc72c4e authored by peguerin's avatar peguerin
Browse files

salinity temperature from nc files

parent 49499138
## just a tiny script to combine all descriptors table into single one
habitat=read.csv("03-results/all_chlorophyll.tsv",sep="\t")
habitat=read.csv("03-results/all_habitat.tsv",sep="\t")
chlorophyll=read.csv("03-results/all_chlorophyll.tsv",sep="\t")
final=cbind(habitat,chlorophyll[,-c(1:3)])
write.table(final, file="03-results/all.tsv",quote=F,sep="\t",col.names=T,row.names=F)
###############################################################################
## Librairies
library("raster")
library("rgdal")
library("ncdf4")
###############################################################################
## Functions
extract_variable <- function(ma_variable, repro_period, depth_range ){
sa=ma_variable[,repro_period,depth_range]
sa_max=apply(sa,1, function(x) max(x,na.rm=T))
sa_mean=apply(sa,1, function(x) mean(x,na.rm=T))
sa_min=apply(sa,1, function(x) min(x,na.rm=T))
return(data.frame(max=sa_max,mean=sa_mean,min=sa_min))
}
###############################################################################
## Load data
fichier="01-infos/CMEMS-MedSea_Reanalysis_Phys_006_004_0to210m_1987-2015_1m_votemper_vosaline_SampleLoc.nc"
samplecsv=read.csv("01-sample_coords/samples_labels.csv",sep="\t",header=F)
labels=as.character(samplecsv[,1])
br <- nc_open(fichier)
## to know the value of each "level" depth
brdepth = ncvar_get(br, "depth")
temperatures=ncvar_get(br,"GenTemp")
salinities=ncvar_get(br,"GenSalt")
january=seq(1,(348-11),12)
february=seq(2,(348-10),12)
march=seq(3,(348-9),12)
april=seq(4,(348-8),12)
may=seq(5,(348-7),12)
june=seq(6,(348-6),12)
july=seq(7,(348-5),12)
august=seq(8,(348-4),12)
september=seq(9,(348-3),12)
october=seq(10,(348-2),12)
november=seq(11,348-1,12)
december=seq(12,348,12)
###############################################################################
## extraction
## surface whole year
repro_period=cbind(january,february,march,april,may,june,july,august,september,october,november,december)
depth_range=which(brdepth <2)
temp_surface_wyear=extract_variable(temperatures,repro_period,depth_range)
sal_surface_wyear=extract_variable(salinities,repro_period,depth_range)
## depth range 0-200 whole year
repro_period=cbind(january,february,march,april,may,june,july,august,september,october,november,december)
depth_range=which(brdepth <300)
temp_0_200_wyear=extract_variable(temperatures,repro_period,depth_range)
sal_0_200_wyear=extract_variable(salinities,repro_period,depth_range)
## depth range 5-50 whole year
repro_period=cbind(january,february,march,april,may,june,july,august,september,october,november,december)
depth_range=which(brdepth < 51 & brdepth > 4)
temp_5_50_wyear=extract_variable(temperatures,repro_period,depth_range)
sal_5_50_wyear=extract_variable(salinities,repro_period,depth_range)
## depth range 20-90 whole year
repro_period=cbind(january,february,march,april,may,june,july,august,september,october,november,december)
depth_range=which(brdepth < 91 & brdepth > 19)
temp_20_90_wyear=extract_variable(temperatures,repro_period,depth_range)
sal_20_90_wyear=extract_variable(salinities,repro_period,depth_range)
## surface march july
repro_period=cbind(march,april,may,june,july)
depth_range=which(brdepth <2)
temp_surface_march_july=extract_variable(temperatures,repro_period,depth_range)
sal_surface_march_july=extract_variable(salinities,repro_period,depth_range)
## surface march june
repro_period=cbind(march,april,may,june)
depth_range=which(brdepth <2)
temp_surface_march_june=extract_variable(temperatures,repro_period,depth_range)
sal_surface_march_june=extract_variable(salinities,repro_period,depth_range)
## surface june november
repro_period=cbind(june,july,august,september,october,november)
depth_range=which(brdepth <2)
temp_surface_june_nov=extract_variable(temperatures,repro_period,depth_range)
sal_surface_june_nov=extract_variable(salinities,repro_period,depth_range)
## 0-10 march july
repro_period=cbind(march,april,may,june,july)
depth_range=which(brdepth < 11)
temp_0_10_march_july=extract_variable(temperatures,repro_period,depth_range)
sal_0_10_march_july=extract_variable(salinities,repro_period,depth_range)
## 0-10 march june
repro_period=cbind(march,april,may,june)
depth_range=which(brdepth < 11)
temp_0_10_march_june=extract_variable(temperatures,repro_period,depth_range)
sal_0_10_march_june=extract_variable(salinities,repro_period,depth_range)
## 60-110 june november
repro_period=cbind(june,july,august,september,october,november)
depth_range=which(brdepth < 111 & brdepth > 59)
temp_60_110_june_nov=extract_variable(temperatures,repro_period,depth_range)
sal_60_110_june_nov=extract_variable(salinities,repro_period,depth_range)
salt_temp=data.frame(labels=labels,
salinity_surface_whole_year_max=sal_surface_wyear$max,
salinity_surface_whole_year_mean=sal_surface_wyear$mean,
salinity_surface_whole_year_min=sal_surface_wyear$min,
salinity_0_200_whole_year_max=sal_0_200_wyear$max,
salinity_0_200_whole_year_mean=sal_0_200_wyear$mean,
salinity_0_200_whole_year_min=sal_0_200_wyear$min,
salinity_5_50_whole_year_max=sal_5_50_wyear$max,
salinity_5_50_whole_year_mean=sal_5_50_wyear$mean,
salinity_5_50_whole_year_min=sal_5_50_wyear$min,
salinity_20_90_whole_year_max=sal_20_90_wyear$max,
salinity_20_90_whole_year_mean=sal_20_90_wyear$mean,
salinity_20_90_whole_year_min=sal_20_90_wyear$min,
salinity_surface_march_july_max=sal_surface_march_july$max,
salinity_surface_march_july_mean=sal_surface_march_july$mean,
salinity_surface_march_july_min=sal_surface_march_july$min,
salinity_surface_march_june_max=sal_surface_march_june$max,
salinity_surface_march_june_mean=sal_surface_march_june$mean,
salinity_surface_march_june_min=sal_surface_march_june$min,
salinity_surface_june_november_max=sal_surface_june_nov$max,
salinity_surface_june_november_mean=sal_surface_june_nov$mean,
salinity_surface_june_november_min=sal_surface_june_nov$min,
salinity_0_10_march_july_max=sal_0_10_march_july$max,
salinity_0_10_march_july_mean=sal_0_10_march_july$mean,
salinity_0_10_march_july_min=sal_0_10_march_july$min,
salinity_0_10_march_june_max=sal_0_10_march_june$max,
salinity_0_10_march_june_mean=sal_0_10_march_june$mean,
salinity_0_10_march_june_min=sal_0_10_march_june$min,
salinity_60_110_june_november_max=sal_60_110_june_nov$max,
salinity_60_110_june_november_mean=sal_60_110_june_nov$mean,
salinity_60_110_june_november_min=sal_60_110_june_nov$min,
temperature_surface_whole_year_max=temp_surface_wyear$max,
temperature_surface_whole_year_mean=temp_surface_wyear$mean,
temperature_surface_whole_year_min=temp_surface_wyear$min,
temperature_0_200_whole_year_max=temp_0_200_wyear$max,
temperature_0_200_whole_year_mean=temp_0_200_wyear$mean,
temperature_0_200_whole_year_min=temp_0_200_wyear$min,
temperature_5_50_whole_year_max=temp_5_50_wyear$max,
temperature_5_50_whole_year_mean=temp_5_50_wyear$mean,
temperature_5_50_whole_year_min=temp_5_50_wyear$min,
temperature_20_90_whole_year_max=temp_20_90_wyear$max,
temperature_20_90_whole_year_mean=temp_20_90_wyear$mean,
temperature_20_90_whole_year_min=temp_20_90_wyear$min,
temperature_surface_march_july_max=temp_surface_march_july$max,
temperature_surface_march_july_mean=temp_surface_march_july$mean,
temperature_surface_march_july_min=temp_surface_march_july$min,
temperature_surface_march_june_max=temp_surface_march_june$max,
temperature_surface_march_june_mean=temp_surface_march_june$mean,
temperature_surface_march_june_min=temp_surface_march_june$min,
temperature_surface_june_november_max=temp_surface_june_nov$max,
temperature_surface_june_november_mean=temp_surface_june_nov$mean,
temperature_surface_june_november_min=temp_surface_june_nov$min,
temperature_0_10_march_july_max=temp_0_10_march_july$max,
temperature_0_10_march_july_mean=temp_0_10_march_july$mean,
temperature_0_10_march_july_min=temp_0_10_march_july$min,
temperature_0_10_march_june_max=temp_0_10_march_june$max,
temperature_0_10_march_june_mean=temp_0_10_march_june$mean,
temperature_0_10_march_june_min=temp_0_10_march_june$min,
temperature_60_110_june_november_max=temp_60_110_june_nov$max,
temperature_60_110_june_november_mean=temp_60_110_june_nov$mean,
temperature_60_110_june_november_min=temp_60_110_june_nov$min
)
salt_temp[salt_temp==-Inf] <- NA
salt_temp[salt_temp==Inf] <- NA
write.table(salt_temp, file="03-results/all_depth_repro_temperature_salinity.tsv",quote=F,sep="\t",col.names=T,row.names=F)
This diff is collapsed.
This diff is collapsed.
,pguerin,berry,25.03.2019 11:45,file:///home/pguerin/.config/libreoffice/4;
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment