Commit 8cb1a255 authored by Benjam's avatar Benjam
Browse files

ajout elements analyse

parent 4bf1147a
......@@ -22,10 +22,10 @@ hvn10[I3_ElemtNaturel_2010 == 0]
hvn10[is.na(I1_DivAssol2010) | is.na(I2_Scor_Pratiques_2010) | is.na(I3_ElemtNaturel_2010) | Scor_HNV_2010 == 0]
#jointure
communes[hvn17, on = .(CODGEO = COD_COM2018), ':='(hvn1_17 = i.HVN_Ind1_17,
hvn2_17 = i.HVN_Ind2_17,
hvn3_17 = i.HVN_Ind3_17,
hvn_17 = HVN_score
communes[hvn17, on = .(CODGEO = COD_COM2018), ':='(hvn1_17 = round(i.HVN_Ind1_17,1),
hvn2_17 = round(i.HVN_Ind2_17,1),
hvn3_17 = round(i.HVN_Ind3_17,1),
hvn_17 = round(HVN_score,1)
)]
#vérifs
......
source("crater-data/exploration-data/cartographie.R")
epcis[,list(minutes=sum(minutes),
mean=mean(pp48),
min=min(pp48),
lower=quantile(pp48, .25, na.rm=TRUE),
middle=quantile(pp48, .50, na.rm=TRUE),
upper=quantile(pp48, .75, na.rm=TRUE),
max=max(pp48)),
by='player']
var = "note_pop_agricole"
group = "NATURE_EPCI"
df = copy(epci)
#dispersion des notes
ggplot(df,
aes(x=get(var))) +
geom_density(alpha=0.2,size=1)
ggplot(df,
aes(x=get(var), color=get(group), fill=get(group))) +
geom_density(alpha=0.2,size=1)
ggplot(df,
aes(x=dens_hab, y=get(var), color=get(group))) +
geom_point(alpha=0.5,size=2) +
scale_x_continuous(trans = "log10")
#carto interactive
mapview(dep_shp,
zcol = var,
col.regions = sf.colors(5),
na.color = "grey")
ggplot(epci,
aes(x=var, color=NATURE_EPCI, fill=NATURE_EPCI)) +
geom_density(alpha=0.2,size=1)
quantile(epci$prop_agr, c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
ggplot(epci,
aes(x=dens_hab, y=var, color=NATURE_EPCI)) +
geom_point(alpha=0.5,size=2) +
scale_x_continuous(trans = "log10")
\ No newline at end of file
......@@ -60,10 +60,12 @@ variables = c("id","nom","sau_ha","surfcom18_km2","pop16","pop10","pop_agr10","p
"hvn1_17","hvn2_17","hvn3_17","hvn_17")
territoires = rbind(
pays[, ..variables],
list("TEST1","TEST1",100,10,120,100,10,20,10000,10,0,3,4,5,12),
list("TEST1","",100,10,120,100,10,20,10000,10,0,3,4,5,12),
list("TEST2","",100,10,240,200,10,10,10000,10,0,3,4,5,12),
types_epci[, ..variables],
regions[, ..variables],
epcis[EPCI %in% c("243100518","200090561","200073393","242900769","243300316"), ..variables]
epcis[EPCI %in% c("243100518","200090561","200073393","242900769","243300316","200030658"), ..variables],
communes[CODGEO %in% c("29153","38185","38242","38226","38113"), ..variables]
)
......@@ -77,14 +79,24 @@ ajouter_variables = function(df){
df[, prop_agr := round(pop_agr10/pop10*100,1)]
#evolution pop agricole
df[, evol_pop_agr := round((pop_agr10 / pop_agr88 -1) * 100,1)]
#flux artificialisé total (ha)
df[, naf11art16_ha := round(naf11art16_m2/10000,1)]
#flux artificialisé total par nouveau ménage/emploi (m2/mep)
df[, artmep1116 := round(naf11art16_m2/(men1116 + emp1116),-1)]
df[, artmep1116 := round(naf11art16_m2/(men1116 + emp1116),0)]
#nouveau ménage/emploi par flux artificialisé total (mep/ha)
df[,mepart1116 := round((men1116 + emp1116)/(naf11art16_m2/10000),-1)]
#sau par hab (ha/hab)
df[, sau_par_hab := round(sau_ha/pop10,1)]
df[, mepart1116 := round((men1116 + emp1116)/(naf11art16_m2/10000),0)]
#solde artificialisation (ha)
df[,solde_artif1116 := round((men1116 + emp1116)/20 - naf11art16_m2/10000,1)]
#crédit artificialisation (ha)
df[,credit_artif1116 := round((men1116 + emp1116)/20,1)]
#part credit restant artificialisation utilisé (%)
df[,part_credit_artif1116 := round(solde_artif1116/abs(credit_artif1116)*100,1)]
#sau par hab (m2/hab)
df[, sau_par_hab_m2 := round(sau_ha*10000/pop10,0)]
#part du territoire artificialisé (%)
df[, artmep_sur_surperficie := round(naf11art16_m2/1000000/surfcom18_km2*100,1)]
#part de SAU artificialisé (%)
df[, artmep_sur_sau := round(naf11art16_m2/10000/sau_ha*100,1)]
#eau : m3 utilisé par hectare
#df[, eau_sau := round(eau_m3/sau_ja,1)]
}
......
......@@ -58,8 +58,9 @@ fwrite(pays,"crater-data/exploration-data/exports/pays.csv", sep=";")
fwrite(territoires,"crater-data/exploration-data/exports/territoires.csv", sep=";")
resume = epcis[, .SD, .SDcols = names(epcis) %like% "note"]
resume = melt(resume[, lapply(.SD, round,0)])[,.N,by=c("variable","value")][order(variable,value)]
fwrite(resume,"crater-data/exploration-data/exports/resume_epcis.csv", sep=";")
fwrite(resume[, lapply(.SD, quantile)],"crater-data/exploration-data/exports/quantiles_epcis.csv", sep=";")
resume2 = dcast(melt(resume[, lapply(.SD, round,0)])[,list(r=round(.N/nrow(resume)*100,2)),by=c("variable","value")][order(variable,value)], value~variable, value.var = "r", fun.aggregate = sum)
fwrite(resume2,"crater-data/exploration-data/exports/repartition_epcis.csv", sep=";")
#write_json(communes[1:3], "crater-data/exploration-data/exports/communes.json",pretty=T)
#write_json(epci[1:3], "crater-data/exploration-data/exports/epci.json",pretty=T)
......
......@@ -3,31 +3,45 @@ message("\n => Notes axes")
interpol = function(x,xa,ya,xb,yb){
round(ya + (x-xa)*(yb-ya)/(xb-xa),1)
}
note1 = function(x,s){
note1a = function(x,s){
if(is.na(x)) NA
else if(x<0) NA
else if(x<s) interpol(x,0,0,s,10)
else if(x<=s) interpol(x,0,0,s,10)
else 10
}
note2 = function(x,s1,s2,s3){
note1b = function(x,s){
if(is.na(x)) NA
else if(x<0) 10
else if(x<=s) interpol(x,0,10, s,0)
else 0
}
note2a = function(x,s1,s2,s3){
if(is.na(x)) NA
else if(x<s1) 0
else if(x<s2) interpol(x,s1,0,s2,5)
else if(x<s3) interpol(x,s2,5,s3,10)
else if(x<=s3) interpol(x,s2,5,s3,10)
else 10
}
note2b = function(x,s1,s2,s3){
if(is.na(x)) NA
else if(x<s1) 10
else if(x<s2) interpol(x,s1,10,s2,5)
else if(x<=s3) interpol(x,s2,5,s3,0)
else 0
}
ajouter_notes = function(df){
#population agricole
df[,note_prop_agr := mapply(note1,prop_agr,5)]
df[,note_evol_pop_agr := mapply(note2,evol_pop_agr,-100,0,50)]
df[,note_prop_agr := mapply(note1a,prop_agr,5)]
df[,note_evol_pop_agr := mapply(note2a,evol_pop_agr,-100,0,50)]
df[,note_pop_agricole := (note_prop_agr + note_evol_pop_agr)/2]
#politique foncière
df[,note_mepart1116 := mapply(note2,mepart1116,0,10,20)]
df[,note_sauhab := mapply(note1,sau_par_hab,0.35)]
df[,note_pol_fonciere := (note_mepart1116 + note_sauhab)/2]
df[,note_mepart1116 := mapply(note2a,mepart1116,0,10,20)]
df[,note_sau_par_hab := mapply(note1a,sau_par_hab_m2,4500)]
df[,note_pol_fonciere := (note_mepart1116 + note_sau_par_hab)/2]
df[,note_artmep_sur_sau := mapply(note1b,artmep_sur_sau,1)]
}
ajouter_notes(communes)
......
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