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-04 10:12:00 2022-04-06 10:12: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-04&name2=OPC&name3= URL = https://saqn.geo.uni-augsburg.de/asopc.cgi?name1=2022-04-05&name2=OPC&name3= URL = https://saqn.geo.uni-augsburg.de/asopc.cgi?name1=2022-04-06&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) + } + } 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 176430103 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-06_00-00_OPC-N2_176430103_SHT85_327710.txt 177470212 FILE ADRESS = https://saqn.geo.uni-augsburg.de/asopc/./2022-04/2022-04-06_00-00_OPC-N3_177470212_SHT85_327854.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 <- sort(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 =176430103 len =2881 len =2881 id =177410815 len =2881 len =2881 id =177470205 Error in aggregate.data.frame(lhs, mf[-1L], FUN = FUN, ...) : no rows to aggregate Calls: aggregate -> aggregate.formula -> aggregate.data.frame Execution halted