Bilinear interpolation while projecting

120 views
Skip to first unread message

sajid pareeth

unread,
Oct 27, 2014, 6:37:25 AM10/27/14
to pyt...@googlegroups.com
Hi

I am trying to read and save calibrated thermal bands from a MODIS swath product (MYD021KM).
I am successful in getting the band 31 of MODIS as geo tiff.

from mpop.satellites import PolarFactory
from datetime import datetime
time_slot
= datetime(2003,8,10,12,30)
global_data
= PolarFactory.create_scene("aqua", "", "modis", time_slot)
global_data
.load([11.0300])
global_data
.image.channel_image(11.0300).show()
local_data
= global_data.project("euro_laea", mode="nearest")
img
= local_data.image(11.0300, mode="L")
img
.save("output.tif", floating_point=True)


My question is, Is it possible to set interpolation mode to bilinear while projecting?
local_data = global_data.project("euro_laea", mode="nearest")

I see that only options available is "nearest" and "quick".
Nearest is not very suitable when dealing with image which has course resolution both the sides.

Regards

Sajid


Martin Raspaud

unread,
Oct 27, 2014, 7:18:33 AM10/27/14
to pyt...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Sajid,

When it comes to bilinear interpolation, as fas as I know, it's not
implemented in pyresample at the moment.

However, I'm working on a new way of resampling using gradient search,
and there we have bilinear interpolation: have a look at the
feature-gradient branch in pyresample!

Best regards,
Martin

On 27/10/14 11:37, sajid pareeth wrote:
> Hi
>
> I am trying to read and save calibrated thermal bands from a MODIS
> swath product (MYD021KM). I am successful in getting the band 31 of
> MODIS as geo tiff.
>
> | frommpop.satellites importPolarFactory fromdatetime
> importdatetime time_slot =datetime(2003,8,10,12,30) global_data
> =PolarFactory.create_scene("aqua","","modis",time_slot)
> global_data.load([11.0300])
> global_data.image.channel_image(11.0300).show() local_data
> =global_data.project("euro_laea",mode="nearest") img
> =local_data.image(11.0300,mode="L")
> img.save("output.tif",floating_point=True)
>
> |
>
> My question is, Is it possible to set interpolation mode to
> bilinear while projecting? |local_data
> =global_data.project("euro_laea",mode="nearest")
>
> I see that only options available is "nearest" and "quick". Nearest
> is not very suitable when dealing with image which has course
> resolution both the sides.
>
> Regards
>
> Sajid
>
> |
>
> -- You received this message because you are subscribed to the
> Google Groups "pytroll" group. To unsubscribe from this group and
> stop receiving emails from it, send an email to
> pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iQEcBAEBAgAGBQJUTioHAAoJEBdvyODiyJI4HMMIAMIpaj5fo5ykp5qTCGWbb2XE
1kTp2yN5uUbqgvFjYNaYjc6oHiHtYyR57oeyt8hGKa4OaOyVpWyLilLiY1QGilGu
PdU2duVcPwCFLCoBvRfA5wHAqutwWdv5LQu9pig5vtqrRgB0MX4ccjgWLL8vQ3fq
7FlWlUgSMxOjb/h3iV/5GQbatli1nAhJsCsOD9oinxvZ9VSsUn9X98GiRj9OyZIb
h916XAwojYYTn5CpPUOF2NaXF7akxPuM14iHJhvs5zlrI5fr8Nob5tFkPTE3/0XS
eYYp6MJYqK8ePoykIneUu5R5Py+l8T9Dsf8aoZ2mWdxwccLMJbcCxQYX+pvsDiQ=
=XCAr
-----END PGP SIGNATURE-----
martin_raspaud.vcf

sajid pareeth

unread,
Oct 27, 2014, 11:54:31 AM10/27/14
to pyt...@googlegroups.com, martin....@smhi.se
Hi Martin

Thanks for the hint.

I would like to try the gradient search method of resampling. I changed the pyresample branch to "feature-gradient".
Did you mean, gradient_search method as the bilinear? Or is there specific bilinear algorithm implemented other than gradient_search.

I am getting an error while trying the fast_gradient_search method on MODIS MYD021KM dataset.

The code is:
res = fast_gradient_search(g[0.8585].data.astype(np.float64), g[0.8585].area.lons, g[0.8585].area.lats, area, 10)

I am getting the following error

Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
 
File "pyresample/_gradient_search.pyx", line 32, in pyresample._gradient_search.fast_gradient_search (/home/sajid/.pyxbld/temp.linux-x86_64-2.7/pyrex/pyresample/_gradient_search.c:1597)
   
def fast_gradient_search(np.ndarray[DTYPE_t, ndim=2] data, np.ndarray[DTYPE_t, ndim=2] source_x, np.ndarray[DTYPE_t, ndim=2] source_y, area_extent, size):
ValueError: Buffer dtype mismatch, expected 'DTYPE_t' but got 'float'

Please advice..

Regards

Sajid

David Hoese

unread,
Oct 27, 2014, 12:10:09 PM10/27/14
to pyt...@googlegroups.com
Hey Martin,

I was going to email you about this later, but this looks like a good
time given the topic. Is this gradient search similar to what polar2grid
uses with ll2cr/fornav (elliptical weighted averaging)? I'm rewriting a
lot of polar2grid and part of that will include rewriting fornav (like
we discussed a long time ago). I was hoping to rewrite this in to
pyresample somewhere, but haven't looked in to it too much yet. Liam
Gumley also showed me some more remapping algorithms that are scan size
independent that I was hoping to implement. What do you think?

-Dave

Martin Raspaud

unread,
Oct 28, 2014, 2:54:56 AM10/28/14
to pyt...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 27/10/14 17:10, David Hoese wrote:
> Hey Martin,
>
> I was going to email you about this later, but this looks like a
> good time given the topic. Is this gradient search similar to what
> polar2grid uses with ll2cr/fornav (elliptical weighted averaging)?
> I'm rewriting a lot of polar2grid and part of that will include
> rewriting fornav (like we discussed a long time ago). I was hoping
> to rewrite this in to pyresample somewhere, but haven't looked in
> to it too much yet. Liam Gumley also showed me some more remapping
> algorithms that are scan size independent that I was hoping to
> implement. What do you think?

Hi Dave,

The gradient search resampling doesn't use the same algorithm as
fornav, but is based on Trishchenko's method for resampling MODIS
data. From what I see it is similar in terms of performance to what
you described about fornav.

Regarding integrating the fornav rewrite into pyresample, that would
be brilliant ! Don't hesitate to ask for help :)

Other algorithms would be nice to have too of course.

Best regards,
Martin


> -Dave
>
> On 10/27/14 6:18 AM, Martin Raspaud wrote: Hi Sajid,
iQEcBAEBAgAGBQJUTz2+AAoJEBdvyODiyJI4SPwH/jURvHOwBRBWrHuQ2TQncuqb
m4ZZFSJYkB7PZHNTqDGFUnTN+oDtvzu+GNyLU1jxxBCEaxiNpsB5OWxtYdpdpAhN
1JBhnOPCeBhix6Z8/y3SIAfp1wIp9S7N/XZNKYO9+a3E2X5Zd6qd2pGMSOAYQeke
ullngLv2mDLbVg3aNrV7ZFPQZqG9JM9RZm519N9dInHcPqLh+FJUkLMSJtCnjcEs
0TJVyYeOEBGKHHpnC+jsOCQUInDc1cBIE6cIS74BFAwgcL7Ngi9UvV4LSz8/pnRk
quQwXM26LEe1DQEV1/wS0Rpsh0QkgykyGDl99psr3J8OV7JC5ZviRfzzbTnDyck=
=8/CR
-----END PGP SIGNATURE-----
martin_raspaud.vcf

Martin Raspaud

unread,
Oct 28, 2014, 2:59:36 AM10/28/14
to pyt...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 27/10/14 16:54, sajid pareeth wrote:
> Hi Martin
>
> Thanks for the hint.
>
> I would like to try the gradient search method of resampling. I
> changed the pyresample branch to "feature-gradient". Did you mean,
> gradient_search method as the bilinear? Or is there specific
> bilinear algorithm implemented other than gradient_search.

Hi Sajid,

With the "nearest" method, you can get n nearest neighbours, but it's
a bit difficult to perform bilinear interpolation since you don't know
which of the n neighbours to interpolate from.

The gradient search however can give you the location of the output
grid point in terms of lines and columns in the unprojected data. So
it's trivial to get the 4 surrounding neighbours to interpolate from.

> I am getting an error while trying the fast_gradient_search method
> on MODIS MYD021KM dataset.
>
> The co|de is: | | res
> =fast_gradient_search(g[0.8585].data.astype(np.float64),g[0.8585].area.lons,g[0.8585].area.lats,area,10)
>
>
|
>
> I am getting the following error
>
> | Traceback(most recent call last): File"<stdin>",line
> 1,in<module> File"pyresample/_gradient_search.pyx",line
> 32,inpyresample._gradient_search.fast_gradient_search
> (/home/sajid/.pyxbld/temp.linux-x86_64-2.7/pyrex/pyresample/_gradient_search.c:1597)
>
>
> deffast_gradient_search(np.ndarray[DTYPE_t,ndim=2]data,np.ndarray[DTYPE_t,ndim=2]source_x,np.ndarray[DTYPE_t,ndim=2]source_y,area_extent,size):
>
>
ValueError:Bufferdtype mismatch,expected 'DTYPE_t'but got 'float'
> |


I'm not really sure what's happening here, but do you run from the
gradient_search.py script ? At the moment, it just a draft, so just
insert your changes into the ifmain part of the .py file.

Best regards,
Martin


> Please advice..
>
> Regards
>
> Sajid
>
>
> On Monday, October 27, 2014 12:18:33 PM UTC+1, Martin Raspaud
> wrote:
>
> Hi Sajid,
>
> When it comes to bilinear interpolation, as fas as I know, it's
> not implemented in pyresample at the moment.
>
> However, I'm working on a new way of resampling using gradient
> search, and there we have bilinear interpolation: have a look at t
> <https://groups.google.com/d/optout>.
>
>
> -- You received this message because you are subscribed to the
> Google Groups "pytroll" group. To unsubscribe from this group and
> stop receiving emails from it, send an email to
> pytroll+u...@googlegroups.com
> <mailto:pytroll+u...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iQEcBAEBAgAGBQJUTz7WAAoJEBdvyODiyJI4jmQH/iDe4w0VDaL90ZqxCLe3NVFy
Uu7uMRZYUSIv15zndt+R7eP1C3C5BASE+9d1bJrCK5t+WCnxPIoELX/dGGuZG5tY
CHEkMyJYk0jypAmIMT1pMmSiR+ZwZzgwoVMRHNdN8KtcjFZJVE3mDh+xZmziclVM
l2o6GBXDWDNSUwDZToxv+/nE3khmjWb7AOIXq52x2rJ9ckTVEgJol+owx3jW8+OI
b/NVoCYiIQWLyqSYqAu5GPV2Rbp9vSBW3tqK5KBM3FFsXAo0xjyd9IIq7gxneQ+Y
+GFSxvMdB6FhXti2Gqt14bVGKjOZNnq5HfZdFPUqvejlr12LpABkKfBtMcAOOy8=
=JfWW
-----END PGP SIGNATURE-----
martin_raspaud.vcf
Reply all
Reply to author
Forward
0 new messages