Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adokter opened this issue Mar 17, 2021 · 4 comments
Open

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

adokter opened this issue Mar 17, 2021 · 4 comments
Labels
Milestone

Comments

@adokter
Copy link
Owner

adokter commented Mar 17, 2021

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
Copy link
Collaborator

bart1 commented Mar 18, 2021

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

@adokter
Copy link
Owner Author

adokter commented Mar 18, 2021

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

@bart1
Copy link
Collaborator

bart1 commented Mar 18, 2021

Ok but nothing to enforce in the function then

@adokter
Copy link
Owner Author

adokter commented Mar 18, 2021

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 ...

@adokter adokter added sprint and removed sprint labels May 27, 2021
@peterdesmet peterdesmet added this to the 0.6.0 milestone May 28, 2021
@adokter adokter modified the milestones: 0.6.0, 0.7.0 Jun 11, 2021
@adokter adokter modified the milestones: 1.0.0, 1.1.0 Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants