
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> ###################################################################
> # SELECT TIME PERIOD
> # seconds for  2 days
> daystep <- 60*60*24
> step <- daystep*2
> args <- commandArgs(trailingOnly = TRUE)
> message("ARGUMENTS = ",length(args))
ARGUMENTS = 0
> if (length(args)==0) {
+   t2 <- Sys.time()
+   t1 <- t2 - step
+   #"args:" length(args)
+ } else {
+   t1 <- as.POSIXct(args[1])
+   t2 <- as.POSIXct(args[2])
+ }
> 
> # SET TIME PERIOD HERE:
> #t1 <- as.POSIXct("2021-11-10 00:00:00 CET")
> #t2 <- as.POSIXct("2021-11-13 00:00:00 CET")
> t1 <- as.POSIXct(format(t1,"%Y-%m-%d %H:%M:00"))
> t2 <- as.POSIXct(format(t2,"%Y-%m-%d %H:%M:00"))
> message("PERIOD = ",t1," ",t2)
PERIOD = 2022-04-03 16:45:00 2022-04-05 16:45:00
> runningdate <- seq.Date( from=as.Date(t1), to=as.Date(t2), by="day")
> 
> aggregation <- "60 sec"
> aggregation <- "1 min"
> 
> 
> 
> ###################################################################
> # GET MATCHING FILE NAMES FOR SELECTED DAYS
> flist <- NULL
> for (i in seq_along(runningdate)) {
+   name1 <- runningdate[i]
+   #name1 <- "2021-11-03"
+   #name1 <- format(t1,"%Y-%m-%d")
+   name2 <- "OPC"
+   #name3 <- runningdate[3]
+   name3 <- ""
+   url <- paste("https://saqn.geo.uni-augsburg.de/asopc.cgi?name1=",name1,"&name2=",name2,"&name3=",name3,sep="")
+   message("URL = ",url)
+   flist_tmp <- try(read.table(url,stringsAsFactors=F))
+   if(inherits(flist_tmp, "try-error")){
+     message("no files")
+   }else{
+     #message("FILE LIST = ",flist_tmp)
+     flist <- rbind(flist,flist_tmp)
+   }
+ }
URL = https://saqn.geo.uni-augsburg.de/asopc.cgi?name1=2022-04-03&name2=OPC&name3=
URL = https://saqn.geo.uni-augsburg.de/asopc.cgi?name1=2022-04-04&name2=OPC&name3=
URL = https://saqn.geo.uni-augsburg.de/asopc.cgi?name1=2022-04-05&name2=OPC&name3=
> 
> ###################################################################
> # READ MATCHING FILES DATA IN OBJECT asopc
> opcid <- ""
> for (i in seq_along(flist$V1)) {
+   #message("flist =",flist$V1[i]," ",i)
+   opctype <- strsplit(flist$V1[i],"_",fixed=T)[[1]][3]
+   opcid <- strsplit(flist$V1[i],"_",fixed=T)[[1]][4]
+   shttype <- strsplit(flist$V1[i],"_",fixed=T)[[1]][5]
+   shtid <- strsplit(flist$V1[i],"_",fixed=T)[[1]][6]
+   shtid <- gsub(".txt", "", shtid)
+   #fname <- paste("https://saqn.geo.uni-augsburg.de/asopc/",substr(flist$V1[i],2,9),"/",flist$V1[i],sep="")
+   fname <- paste("https://saqn.geo.uni-augsburg.de/asopc/",flist$V1[i],sep="")
+   message(opcid," FILE ADRESS = ",fname)
+   if (i == 1) {
+     asopc <- read.table(fname,header=T,stringsAsFactors=F)
+     asopc$opctype <- opctype
+     asopc$opcid <- opcid
+     asopc$shttype <- shttype
+     asopc$shtid <- shtid
+     if(grepl( "OPC-N2", fname, fixed = TRUE)){
+       asopc$Bin_16 <- NA
+       asopc$Bin_17 <- NA
+       asopc$Bin_18 <- NA
+       asopc$Bin_19 <- NA
+       asopc$Bin_20 <- NA
+       asopc$Bin_21 <- NA
+       asopc$Bin_22 <- NA
+       asopc$Bin_23 <- NA
+       asopc$Fan_rev_count <- NA
+       asopc$Laser_status <- NA
+       asopc$PM_1 <- asopc$PM1
+       asopc <- subset( asopc, select = -PM1 )
+       asopc$PM_10 <- asopc$PM10
+       asopc <- subset( asopc, select = -PM10 )
+       asopc$PM_2.5 <- asopc$PM2.5
+       asopc <- subset( asopc, select = -PM2.5 )
+       asopc <- subset( asopc, select = -Pressure )
+       asopc$Reject_count_Glitch  <- NA
+       asopc$Reject_count_LongTOF <- NA
+       asopc$Reject_Count_OutOfRange <- NA
+       asopc$Reject_count_Ratio <- NA
+       asopc$Relative_humidity <- NA
+       asopc$Sample_Flow_Rate <- NA
+       asopc$Sampling_Period <- NA
+       asopc <- subset( asopc, select = -SFR )
+     }
+    }
+   else {
+     asopc_temp <- read.table(fname,header=T,stringsAsFactors=F)
+     asopc_temp$opctype <- opctype
+     asopc_temp$opcid <- opcid
+     asopc_temp$shttype <- shttype
+     asopc_temp$shtid <- shtid
+     if(grepl( "OPC-N2", fname, fixed = TRUE)){
+       asopc_temp$Bin_16 <- NA
+       asopc_temp$Bin_17 <- NA
+       asopc_temp$Bin_18 <- NA
+       asopc_temp$Bin_19 <- NA
+       asopc_temp$Bin_20 <- NA
+       asopc_temp$Bin_21 <- NA
+       asopc_temp$Bin_22 <- NA
+       asopc_temp$Bin_23 <- NA
+       asopc_temp$Fan_rev_count <- NA
+       asopc_temp$Laser_status <- NA
+       asopc_temp$PM_1 <- asopc_temp$PM1
+       asopc_temp <- subset( asopc_temp, select = -PM1 )
+       asopc_temp$PM_10 <- asopc_temp$PM10
+       asopc_temp <- subset( asopc_temp, select = -PM10 )
+       asopc_temp$PM_2.5 <- asopc_temp$PM2.5
+       asopc_temp <- subset( asopc_temp, select = -PM2.5 )
+       asopc_temp <- subset( asopc_temp, select = -Pressure )
+       asopc_temp$Reject_count_Glitch  <- NA
+       asopc_temp$Reject_count_LongTOF <- NA
+       asopc_temp$Reject_Count_OutOfRange <- NA
+       asopc_temp$Reject_count_Ratio <- NA
+       asopc_temp$Relative_humidity <- NA
+       asopc_temp$Sample_Flow_Rate <- NA
+       asopc_temp$Sampling_Period <- NA
+       asopc_temp <- subset( asopc_temp, select = -SFR )
+     }
+     #message(str(asopc_temp))
+     asopc <- rbind(asopc,asopc_temp)
+   }
+ }
177470212 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-03_00-00_OPC-N3_177470212_SHT85_327854.txt
177470208 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-03_00-00_OPC-N3_177470208_SHT85_327733.txt
177470205 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-03_00-00_OPC-N3_177470205_SHT85_720924.txt
177470215 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-03_00-00_OPC-N3_177470215_SHT85_327780.txt
177470207 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./alphasense/2022-04/2022-04-04_13-52_OPC-N3_177470207_SHT85_721132.txt
177470212 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-04_00-00_OPC-N3_177470212_SHT85_327854.txt
177470208 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-04_00-00_OPC-N3_177470208_SHT85_327733.txt
177470205 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-04_00-00_OPC-N3_177470205_SHT85_720924.txt
177470215 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-04_00-00_OPC-N3_177470215_SHT85_327780.txt
177470207 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-04_13-52_OPC-N3_177470207_SHT85_721132.txt
177470212 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-05_00-00_OPC-N3_177470212_SHT85_327854.txt
176430103 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-05_14-21_OPC-N2_176430103_SHT85_327710.txt
177410815 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-05_10-36_OPC-N3_177410815_SHT85_721132.txt
> asopc$time <- as.POSIXct(asopc$time_UTC,format="%Y-%m-%dT%H:%M:%S")
> asopc[as.character(asopc)=="nan"] <- NA
> message("reading done!")
reading done!
> 
> 
> ###################################################################
> # CREATE DATA FRAME OF aggregation INTERVALL TIME STEPS
> #secs <- seq.POSIXt(from=as.POSIXct(t1),to=as.POSIXct(t2),by="sec")
> #secs <- data.frame( time=seq.POSIXt(from=as.POSIXct(t1),to=as.POSIXct(t2),by=aggregation))
> secs <- data.frame( time=seq(from=as.POSIXct(t1),to=as.POSIXct(t2),by=aggregation))
> sec5pm10 <- secs
> ids <- unique(asopc$opcid)
> for (i in seq_along(ids)) {
+    message(" ")
+    message("id =",ids[i])
+    idser <- c(0.0,asopc$PM_10[asopc$opcid==ids[i]])
+    #idser[1] <- NA
+    #idtime <- c(as.POSIXct(t1),asopc$time[asopc$opcid==ids[i]])
+    idtime <- c(as.POSIXct(runningdate[1]),asopc$time[asopc$opcid==ids[i]])
+    tmp <- data.frame(time=idtime,pm10=idser)
+ 
+    #tmp$cuts <- cut( idtime,breaks=aggregation)
+    tmp$cuts <- cut( idtime,breaks=secs$time)
+ 
+    #tmp$cuts <- cut( idtime,breaks=seq.POSIXt(from=as.POSIXct(t1),to=as.POSIXct(t2),by="5 sec" ) )
+    #agg <- aggregate( idser, by=list(cuts) , FUN=mean)
+    agg <- aggregate(. ~ cuts, tmp, mean)
+    agg$time <- as.POSIXct(agg$cuts)
+    reg <- merge(secs,agg,by="time",all.x=T)
+    #assign(paste0("id",ids[i]), reg$pm10)
+    message("len =",length(reg$pm10))
+    message("len =",length(sec5pm10$time))
+    sec5pm10$pm10 <- reg$pm10
+    names(sec5pm10)[length(names(sec5pm10))] <- paste0("id",ids[i])
+ }
 
id =177470212
len =2881
len =2881
 
id =177470208
len =2881
len =2881
 
id =177470205
len =2881
len =2881
 
id =177470215
len =2881
len =2881
 
id =177470207
len =2881
len =2881
 
id =176430103
len =2881
len =2881
 
id =177410815
len =2881
len =2881
> message("sec5-aggregation done!")
sec5-aggregation done!
> 
> 
> ###################################################################
> # GET LUEB REFERENCE DATA
> 
> path <- format(t2,"/zugspitze/lappwald/saqn/lueb/%Y_%m/%Y_%m_%d_Bourges-Platz_PM10.csv")
> bou <- read.csv(path,sep=";",header=F)
> colnames(bou) <- c("tdate","ttime","pm10")
> bou$time <- as.POSIXct(paste(bou$tdate," ",bou$ttime,sep=""),format="%d.%m.%Y %H:%M")
> bou$pm10[bou$pm10==":"] <- NA
> bou$pm10 <- as.numeric(bou$pm10)
> 
> 
> path <- format(t2,"/zugspitze/lappwald/saqn/lueb/%Y_%m/%Y_%m_%d_Karlstrasse_PM10.csv")
> kar <- read.csv(path,sep=";",header=F)
> colnames(kar) <- c("tdate","ttime","pm10")
> kar$time <- as.POSIXct(paste(kar$tdate," ",kar$ttime,sep=""),format="%d.%m.%Y %H:%M")
> kar$pm10[kar$pm10==":"] <- NA
> kar$pm10 <- as.numeric(kar$pm10)
> 
> 
> path <- format(t2,"/zugspitze/lappwald/saqn/lueb/%Y_%m/%Y_%m_%d_Koenigsplatz_PM10.csv")
> koe <- read.csv(path,sep=";",header=F)
> colnames(koe) <- c("tdate","ttime","pm10")
> koe$time <- as.POSIXct(paste(koe$tdate," ",koe$ttime,sep=""),format="%d.%m.%Y %H:%M")
> koe$pm10[koe$pm10==":"] <- NA
> koe$pm10 <- as.numeric(koe$pm10)
> 
> path <- format(t2,"/zugspitze/lappwald/saqn/lueb/%Y_%m/%Y_%m_%d_LfU_PM10.csv")
> lfu <- read.csv(path,sep=";",header=F)
> colnames(lfu) <- c("tdate","ttime","pm10")
> lfu$time <- as.POSIXct(paste(lfu$tdate," ",lfu$ttime,sep=""),format="%d.%m.%Y %H:%M")
> lfu$pm10[lfu$pm10==":"] <- NA
> lfu$pm10 <- as.numeric(lfu$pm10)
> 
> 
> ###################################################################
> # PLOT TIME SERIES
> png("/zugspitze/lappwald/saqn/asopc/asopc.png",width=1900, height=400, units="px", res=300, pointsize=3)
> #tmin <- t1
> #tmax <- t2
> tmin <- min(sec5pm10$time)
> tmax <- max(sec5pm10$time)
> message("tmin =",tmin)
tmin =2022-04-03 16:45:00
> message("tmax =",tmax)
tmax =2022-04-05 16:45:00
> 
> plot(sec5pm10$time,sec5pm10[,2],xlab=paste("time UTC"),ylab="pm10 (µg/m³)",
+ xlim=c(as.POSIXct(tmin),as.POSIXct(tmax)),ylim=c(0,30),type="n",xaxs="i",yaxs="i",xaxt="n",
+ main=paste("asopc 1 min mean (",tmin," - ",tmax," UTC)" ))
> 
> axis.POSIXct(1, at = seq(tmin, tmax, by = "hour"), format = "%a %m-%d %Hh")
> 
> for (i in seq_along(ids)) {
+   lines(sec5pm10$time,sec5pm10[,i+1],col=i,t="l",lwd=0.3)
+ }
> lines(bou$time,bou$pm10,col=i+1,t="l",lwd=0.3)
> lines(kar$time,kar$pm10,col=i+2,t="l",lwd=0.3)
> lines(koe$time,koe$pm10,col=i+3,t="l",lwd=0.3)
> lines(lfu$time,lfu$pm10,col=i+4,t="l",lwd=0.3)
> 
> legend("topleft",unique(asopc$opcid),col=1:length(asopc$opcid),lty=1,lwd=0.5)
> legend("topright",c("bou","kar","koe","lfu"),col=seq(i+1,i+4),lty=1,lwd=0.5)
> dev.off()
null device 
          1 
> 
> proc.time()
   user  system elapsed 
 18.071   0.573  19.420 
