meder411 / Tangent-Images

Official repository for "Tangent Images for Mitigating Spherical Distortion," CVPR 2020
https://arxiv.org/abs/1912.09390
Other
74 stars 16 forks source link

How do I generate tangent images for the actual earth science data in lat-lon grid? #8

Open manmeet3591 opened 4 years ago

manmeet3591 commented 4 years ago

Hi @meder411 really nice work. I had the chance to read your paper some months ago and was looking out for the best possible way to transform my earth science data to tangent images and back. I can see that the example you gave in your medium post is from data on the sphere with Earth as an example and also the animation on the readme of this github repository, but how can I actually generate tangent images from the lat-lon gridded dataset ?

manmeet3591 commented 4 years ago

I checked that you are using the equirectangular image in your examples. But what if I want to use the actual data on a spherical latitude-longitude grid as an input.

meder411 commented 4 years ago

Hi @manmeet3591, glad you like the paper!

Can you be a little more specific about the format of your data? Is it truly like (lat, lon, value)? If so, what is the resolution of the sampling?

manmeet3591 commented 4 years ago

Sorry for this late reply. @meder411 Yes the format of the data is truly (lat,lon). By resolution of sampling I hope you mean the spatial resolution, in that case we have in many different resolutions like 0.25 degrees x 0.25 degrees for example. Can you please also have a look at https://towardsdatascience.com/handling-netcdf-files-using-xarray-for-absolute-beginners-111a8ab4463f for more info on such data.

manmeet3591 commented 4 years ago

You can look at http://schubert.atmos.colostate.edu/~cslocum/netcdf_example.html also as an example

manmeet3591 commented 4 years ago

Do you think if I can project my data on the lat-lon grid to the projection you have used (for example the equiangular input projection file https://github.com/meder411/Tangent-Images/blob/master/examples/inputs/earthmap4k.jpg), I should be able to transform my lat-lon data to tangent images? Also I see that your input is an image, what if we want to directly input a 2d numpy array which is in equiangular projection? Can you help me with directly inputting such data to your code?

manmeet3591 commented 4 years ago

I am presently working with a cubed-sphere projection (using https://github.com/jweyn/DLWP-CS), but I very firmly believe that tangent images is better than that as you have also explained in your paper.

manmeet3591 commented 4 years ago

@meder411

meder411 commented 3 years ago

Tangent images are really nothing more than a resampling of the data to a new, lower distortion, format. If your data is already indexed by spherical coordinates (like an equirectangular image or a cubed sphere), you just need to resample from that representation to the tangent images themselves. The way this resampling is typically done is by generating a mapping *from* the source format according to the layout of the destination format.

For example, this function generated the mapping from spherical coordinates to tangent images. If you run it, you will see that the output is the shape of the tangent images, and each tangent image pixel contains the spherical coordinates it should sample from. Similarly, this function expressly creates a sampling map from an equirectangular representation. If you look closely, it really just wraps that first function and adds a call to a function that converts spherical coordinates to a floating point pixel location on the equirectangular image.

Not having worked with the cubed sphere, I am not exactly sure how you represent that data, but I would recommend copying the create_equirectangular_to_tangent_images_sample_map function linked before, but change this line to some function you need to write that converts spherical coordinates to an index in your representation. Then, you can use the unresample function to resample from your current source representation to the target. Note that unresample on its own expects a 2D image grid and applies bilinear or nearest-neighbor interpolation per a passed argument. However, you can provide pre-computed interpolation weights if you have them and your source representation needs them.

manmeet3591 commented 3 years ago

@meder411 Thank you very much for the elaborate answer. I got your point. Ideally how many tangent images would you recommend when we are mapping from spherical data to tangent images, is there a quantitative formula for the same to ensure that the spherical distortion is minimized.