adokter / bioRad

R package for analysis and visualisation of biological signals in weather radar data
http://adokter.github.io/bioRad
Other
28 stars 16 forks source link

binding scans into a pvol and binding params into a scan #422

Open adokter opened 3 years ago

adokter commented 3 years ago

Prototype function to bind list of scan objects into a pvol:

scans2pvol=function(scans,radar,datetime,wavelength=10){
  if (FALSE %in% sapply(scans,is.scan)){
    stop("only scans expected as input")
  }
  vol=list()
  vol$radar=radar
  vol$datetime=datetime
  vol$scans=scans
  vol$attributes=list()
  vol$attributes$how$wavelength=wavelength
  vol$attributes$what$date=format(datetime, "%Y%m%d")
  vol$attributes$what$object="PVOL"
  vol$attributes$what$source=paste("RAD:",radar,sep="")
  vol$attributes$what$time=format(datetime, "%H%M%S")
  vol$attributes$where$height=scans[[1]]$geo$height
  vol$attributes$where$lat=scans[[1]]$geo$lat
  vol$attributes$where$lon=scans[[1]]$geo$lon
  vol$geo$height=scans[[1]]$geo$height
  vol$geo$lat=scans[[1]]$geo$lat
  vol$geo$lon=scans[[1]]$geo$lon
  class(vol)="pvol"
  vol
}

Prototype function to bind list of param objects into a scan:

params2scan=function(...,startdate=Sys.time(),enddate=Sys.time()){
  if (FALSE %in% sapply(list(...),is.param)){
    stop("only scan parameters expected as input")
  }
  params=list(...)
  scan=list()
  scan$params=params
  param_names=sapply(params,function(x) attributes(x)$param)
  names(scan$params)=param_names
  scan$attributes=list()
  elangles=sapply(params,function(x) attributes(x)$geo$elangle)
  if(length(unique(elangles))!=1) stop("scan parameters with unequal elevations")
  rscales=sapply(params,function(x) attributes(x)$geo$rscale)
  if(length(unique(rscales))!=1) stop("scan parameters with unequal range dimension")
  ascales=sapply(params,function(x) attributes(x)$geo$ascale)
  if(length(unique(ascales))!=1) stop("scan parameters with unequal azimuth dimension")
  lats=sapply(params,function(x) attributes(x)$geo$lat)
  lons=sapply(params,function(x) attributes(x)$geo$lon)
  if(length(unique(lats))!=1 || length(unique(lons))!=1) stop("scan parameters have different radar latitude and/or longitude")
  heights=sapply(params,function(x) attributes(x)$geo$height)
  if(length(unique(ascales))!=1) stop("scan parameters with unequal antenna height")
  nbins=sapply(params,function(x) dim(x)[1])
  nazims=sapply(params,function(x) dim(x)[2])
  if(length(unique(nbins))!=1 || length(unique(nazims))!=1) stop("scan parameters have different dimensions")
  NIs=sapply(params,function(x) attributes(x)$how$NI)
  if(length(unique(NIs))!=1) stop("scan parameters with different nyquist intervals")

  scan$attributes=list()
  scan$attributes$how$NI=NIs[1]

  scan$attributes$where$elangle=elangles[1]
  scan$attributes$where$nbins=nbins[1]
  scan$attributes$where$nrays=nazims[1]
  scan$attributes$where$rscale=rscales[1]

  scan$attributes$what$enddate=format(enddate, "%Y%m%d")
  scan$attributes$what$endtime=format(enddate, "%H%M%S")
  scan$attributes$what$product="SCAN"
  scan$attributes$what$startdate=format(startdate, "%Y%m%d")
  scan$attributes$what$starttime=format(startdate, "%H%M%S")

  scan$geo=attributes(params[[1]])$geo
  class(scan)="scan"
  scan
}
bart1 commented 3 years ago

Quick question should scans be ordered by time or elev angle when making a pvol? Is there a convention there?

adokter commented 3 years ago

I don't think there is a strict convention in ODIM, but ordered by elevation angle is most common

bart1 commented 3 years ago

Ok but nothing to enforce in the function then

adokter commented 3 years ago

No, but it would be nice if it just sorts by itself. Above prototypes have been written a long time ago, so need some updating ...