-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create direct bindings to DGGRID #121
Comments
This is how to convert coordinates from geographic to Q2DI space using PROJ:
# proj (x,y) to q2di (n,i,j):
# TODO: allow quads other than 1
# TODO: Generalize to DGGRID res_spec resolution other than 3
proj_to_q2di <- function(x,y) {
# rotate: diamond to parallelogram
theta <- 45
i <- x * cos(theta) - y * sin(theta)
j <- y * cos(theta) - x * sin(theta)
# shift: parallelogram to square
i <- i - (2 * x)
# move and reflect: align origin and basis
# values after rotation and shift
min_i <- 15563031
min_j <- 12159298
max_i <- 25465716
max_j <- 18269308
i <- (max_i - (i - min_i) - min_i)
j <- (max_j - (j - min_j) - min_j)
# scale to row and col number
# already starts with 0, devide by step (x_1 - x_o), multiply by number of rows/cols
# add one to step size so that last step still its into grid after floor
i <- i / (9902685+1) * 8
j <- j / (6110010+1) * 8
# floor: discretization
# round would result in sheared grid
# TODO: Is this equivalent to hexagonal nearest neighbor i.e. works on non-center points within a cell?
i <- as.integer(i)
j <- as.integer(j)
# transpose
i_old <- i
i <- j
j <- i_old
return(c(i,j))
} |
I tried to dig a bit on the library to understand what happens when we use it like you need:
I tried to dig further but I did not get how the core information of this DgLocationData is stored, but you can instantiate it with a constructor that takes a null pointer and then fill it with a DgDataList, and I did not find where the real numbers are stored. For now what I tired to do to have a bit of control is to fork the repo and mody the SubOpTransofrm.cpp in order to write the output as I would always get the input coordinates “15.1,23” 4 times (and levels still depends on the meta file). At least I succeeded! I mights sound silly, but this means that if I do something similar for the result writing, and we set up CxxWrap.jl, we could:
This would save at least the I/O of writing and reading the two files, leaving only the string/number conversion. But of course I will push to directly use the numbers, maybe adding some ad-hoc constructors to DgLocationData. Note also that I could easily make this threaded per point with OpenMP, it will be super fast! |
Thanks a lot @d-consoli ! Seems that we can't bypass parsing string to float in DGGRID. Usually, parsing is much slower than reading files (e.g. high user parsing time vs low system file reading time in CSV files). I expect that the speed up would not be much. |
Update:
I easily implemented a method |
Good news, I manged add some methods to bypass all the strings conversion, both in input and in output! At least for the classes involved in our case. You can check this out. Now it's only missing to interface it with CxxWrap.jl. |
Great news :) This is a big leap towards reducing the overhead. Is https://github.com/d-consoli/DGGRID backwards compatible with the original https://github.com/sahrk/DGGRID by just extending the API with a function accepting integers? I'd be great to open a PR such that all other bindings e.g. https://github.com/am2222/pydggrid will profit from your work? |
Currently, communication between DGGS.jl and DGGRID is done via files and the shell interface of DGGRID7_jll binary. This is ineffective and the bottleneck of this package. DGGS.jl would profit drastically from direct memory access of C++ DGGRID functions. This is known so far:
The text was updated successfully, but these errors were encountered: