Good afternoon list, I am looking at feature tracking in a 2D numpy array, along the lines of Dixon and Wiener 1993 (for tracking precipitating storms) Identifying features based on threshold is quite trivial using ndimage.label b_fld=np.zeros(mygrid.fields['rain_rate_A']['data'].shape) rr=10 b_fld[mygrid.fields['rain_rate_A']['data'] > rr]=1.0 labels, numobjects = ndimage.label(b_fld[0,0,:,:]) (note mygrid.fields['rain_rate_A']['data'] is dimensions time,height, y, x) using the matplotlib contouring and fetching the vertices I can get a nice list of polygons of rain rate above a certain threshold… Now from here I can just go and implement the Dixon and Wiener methodology but I thought I would check here first to see if anyone know of a object/feature tracking algorithm in numpy/scipy or using numpy arrays (it just seems like something people would want to do!).. i.e. something that looks back and forward in time and identifies polygon movement and identifies objects with temporal persistence.. Cheers! Scott Dixon, M., and G. Wiener, 1993: TITAN: Thunderstorm Identification, Tracking, Analysis, and Nowcasting—A Radar-based Methodology. Journal of Atmospheric and Oceanic Technology, 10, 785–797, doi:10.1175/1520-0426(1993)010<0785:TTITAA>2.0.CO;2. http://journals.ametsoc.org/doi/abs/10.1175/1520-0426%281993%29010%3C0785%3A...
Hi all, For a 3d array in matlab, I can do the below to reshape it before an eof analysis. Is there a way to do the same using numpy? Please help. [nlat,nlon,ntim ]=size(ssh); tssh=reshape(ssh,nlat*nlon,ntim); and afterwards eofout=[] eofout=reshape(eof1,nlat,nlon,ntime) with best regards, Sudheer
On Sat, Mar 2, 2013 at 6:03 PM, Sudheer Joseph <sudheer.joseph@yahoo.com>wrote:
Hi all, For a 3d array in matlab, I can do the below to reshape it before an eof analysis. Is there a way to do the same using numpy? Please help.
[nlat,nlon,ntim ]=size(ssh); tssh=reshape(ssh,nlat*nlon,ntim); and afterwards eofout=[] eofout=reshape(eof1,nlat,nlon,ntime)
Yes, easy: nlat, nlon, ntim = ssh.shape tssh = ssh.reshape(nlat*nlon, ntim, order='F') and afterwards eofout = eofl.reshape(nlat, nlon, ntim, order='F') You probably want to go read through http://www.scipy.org/NumPy_for_Matlab_Users. Cheers, Brad
Thank you Brad, for the quick reply with solution, special thanks to the link for matlab users. with best regards, Sudheer *************************************************************** Sudheer Joseph Indian National Centre for Ocean Information Services Ministry of Earth Sciences, Govt. of India POST BOX NO: 21, IDA Jeedeemetla P.O. Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55 Tel:+91-40-23886047(O),Fax:+91-40-23895011(O), Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile) E-mail:sjo.India@gmail.com;sudheer.joseph@yahoo.com Web- http://oppamthadathil.tripod.com *************************************************************** ________________________________ From: Bradley M. Froehle <brad.froehle@gmail.com> To: Discussion of Numerical Python <numpy-discussion@scipy.org> Sent: Sunday, 3 March 2013 8:50 AM Subject: Re: [Numpy-discussion] reshaping arrays On Sat, Mar 2, 2013 at 6:03 PM, Sudheer Joseph <sudheer.joseph@yahoo.com> wrote: Hi all,
For a 3d array in matlab, I can do the below to reshape it before an eof analysis. Is there a way to do the same using numpy? Please help.
[nlat,nlon,ntim ]=size(ssh); tssh=reshape(ssh,nlat*nlon,ntim); and afterwards eofout=[] eofout=reshape(eof1,nlat,nlon,ntime)
Yes, easy: nlat, nlon, ntim = ssh.shape tssh = ssh.reshape(nlat*nlon, ntim, order='F') and afterwards eofout = eofl.reshape(nlat, nlon, ntim, order='F') You probably want to go read through http://www.scipy.org/NumPy_for_Matlab_Users. Cheers, Brad _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Hi Brad, I am not getting the attribute reshape for the array, are you having a different version of numpy than mine? I have In [55]: np.__version__ Out[55]: '1.7.0' and detail of the shape details of variable In [57]: ssh?? Type: NetCDFVariable String Form:<NetCDFVariable object at 0x492d3d8> Namespace: Interactive Length: 75 Docstring: NetCDF Variable In [58]: ssh.shape Out[58]: (75, 140, 180) ssh?? Type: NetCDFVariable String Form:<NetCDFVariable object at 0x492d3d8> Namespace: Interactive Length: 75 Docstring: NetCDF Variable In [66]: ssh.shape Out[66]: (75, 140, 180) In [67]: ssh.reshape(75,140*180) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/sjo/RAMA_20120807/adcp/<ipython-input-67-1a21dae1d18d> in <module>() ----> 1 ssh.reshape(75,140*180) AttributeError: reshape *************************************************************** Sudheer Joseph Indian National Centre for Ocean Information Services Ministry of Earth Sciences, Govt. of India POST BOX NO: 21, IDA Jeedeemetla P.O. Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55 Tel:+91-40-23886047(O),Fax:+91-40-23895011(O), Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile) E-mail:sjo.India@gmail.com;sudheer.joseph@yahoo.com Web- http://oppamthadathil.tripod.com *************************************************************** ________________________________ From: Sudheer Joseph <sudheer.joseph@yahoo.com> To: Discussion of Numerical Python <numpy-discussion@scipy.org> Sent: Sunday, 3 March 2013 9:19 AM Subject: Re: [Numpy-discussion] reshaping arrays Thank you Brad, for the quick reply with solution, special thanks to the link for matlab users. with best regards, Sudheer *************************************************************** Sudheer Joseph Indian National Centre for Ocean Information Services Ministry of Earth Sciences, Govt. of India POST BOX NO: 21, IDA Jeedeemetla P.O. Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55 Tel:+91-40-23886047(O),Fax:+91-40-23895011(O), Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile) E-mail:sjo.India@gmail.com;sudheer.joseph@yahoo.com Web- http://oppamthadathil.tripod.com *************************************************************** ________________________________ From: Bradley M. Froehle <brad.froehle@gmail.com> To: Discussion of Numerical Python <numpy-discussion@scipy.org> Sent: Sunday, 3 March 2013 8:50 AM Subject: Re: [Numpy-discussion] reshaping arrays On Sat, Mar 2, 2013 at 6:03 PM, Sudheer Joseph <sudheer.joseph@yahoo.com> wrote: Hi all,
For a 3d array in matlab, I can do the below to reshape it before an eof analysis. Is there a way to do the same using numpy? Please help.
[nlat,nlon,ntim ]=size(ssh); tssh=reshape(ssh,nlat*nlon,ntim); and afterwards eofout=[] eofout=reshape(eof1,nlat,nlon,ntime)
Yes, easy: nlat, nlon, ntim = ssh.shape tssh = ssh.reshape(nlat*nlon, ntim, order='F') and afterwards eofout = eofl.reshape(nlat, nlon, ntim, order='F') You probably want to go read through http://www.scipy.org/NumPy_for_Matlab_Users. Cheers, Brad _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Sat, Mar 2, 2013 at 11:35 PM, Sudheer Joseph <sudheer.joseph@yahoo.com>wrote:
Hi Brad, I am not getting the attribute reshape for the array, are you having a different version of numpy than mine?
I have In [55]: np.__version__ Out[55]: '1.7.0' and detail of the shape
details of variable
In [57]: ssh?? Type: NetCDFVariable String Form:<NetCDFVariable object at 0x492d3d8> Namespace: Interactive Length: 75 Docstring: NetCDF Variable
In [58]: ssh.shape Out[58]: (75, 140, 180)
ssh?? Type: NetCDFVariable String Form:<NetCDFVariable object at 0x492d3d8> Namespace: Interactive Length: 75 Docstring: NetCDF Variable
In [66]: ssh.shape Out[66]: (75, 140, 180)
In [67]: ssh.reshape(75,140*180) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/sjo/RAMA_20120807/adcp/<ipython-input-67-1a21dae1d18d> in <module>() ----> 1 ssh.reshape(75,140*180)
AttributeError: reshape
Ah, you have a NetCDF variable, which in many ways purposefully looks like a NumPy array, but isn't. Just keep in mind that a NetCDF variable is merely a way to have the data available without actually reading it in until you need it. If you do: ssh_data = ssh[:] Then the NetCDF variable will read all the data in the file and return it as a numpy array that can be manipulated as you wish. I hope that helps! Ben Root
Thanks a lot Benjamin, it did the trick. I have another question, I have ocean section along latitude 0 ( equator) which is sampled at depths. size of the array is 12x14 but this is just the index of the array I need to make a plot which shows depth value as one axis and longitude values as another axis. Is there a quick way to rescale the data to lat depth section by adding a new axis? depth=[0,10,20,30,40,50,60,70,80,90,100,120] lon=[ 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105] In [20]: data.shape Out[20]: (12, 14) can you please advice me on what is the best way to re-scale the data to depth lat dimensions from the indices 1-12 and 1-14 With best regards, Sudheer From: Benjamin Root <ben.root@ou.edu> To: Discussion of Numerical Python <numpy-discussion@scipy.org> Sent: Monday, 4 March 2013 7:40 PM Subject: Re: [Numpy-discussion] reshaping arrays On Sat, Mar 2, 2013 at 11:35 PM, Sudheer Joseph <sudheer.joseph@yahoo.com> wrote: Hi Brad,
I am not getting the attribute reshape for the array, are you having a different version of numpy than mine?
I have In [55]: np.__version__ Out[55]: '1.7.0' and detail of the shape
details of variable
In [57]: ssh?? Type: NetCDFVariable String Form:<NetCDFVariable object at 0x492d3d8> Namespace: Interactive Length: 75 Docstring: NetCDF Variable
In [58]: ssh.shape Out[58]: (75, 140, 180)
ssh?? Type: NetCDFVariable String Form:<NetCDFVariable object at 0x492d3d8> Namespace: Interactive Length: 75 Docstring: NetCDF Variable
In [66]: ssh.shape Out[66]: (75, 140, 180)
In [67]: ssh.reshape(75,140*180) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/sjo/RAMA_20120807/adcp/<ipython-input-67-1a21dae1d18d> in <module>() ----> 1 ssh.reshape(75,140*180)
AttributeError: reshape
Ah, you have a NetCDF variable, which in many ways purposefully looks like a NumPy array, but isn't. Just keep in mind that a NetCDF variable is merely a way to have the data available without actually reading it in until you need it. If you do: ssh_data = ssh[:] Then the NetCDF variable will read all the data in the file and return it as a numpy array that can be manipulated as you wish. I hope that helps! Ben Root _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Sat, Mar 2, 2013 at 5:32 PM, Scott Collis <scollis.acrf@gmail.com> wrote:
Good afternoon list, I am looking at feature tracking in a 2D numpy array, along the lines of Dixon and Wiener 1993 (for tracking precipitating storms)
Identifying features based on threshold is quite trivial using ndimage.label
b_fld=np.zeros(mygrid.fields['rain_rate_A']['data'].shape) rr=10 b_fld[mygrid.fields['rain_rate_A']['data'] > rr]=1.0 labels, numobjects = ndimage.label(b_fld[0,0,:,:]) (note mygrid.fields['rain_rate_A']['data'] is dimensions time,height, y, x)
using the matplotlib contouring and fetching the vertices I can get a nice list of polygons of rain rate above a certain threshold… Now from here I can just go and implement the Dixon and Wiener methodology but I thought I would check here first to see if anyone know of a object/feature tracking algorithm in numpy/scipy or using numpy arrays (it just seems like something people would want to do!).. i.e. something that looks back and forward in time and identifies polygon movement and identifies objects with temporal persistence..
Cheers! Scott
Dixon, M., and G. Wiener, 1993: TITAN: Thunderstorm Identification, Tracking, Analysis, and Nowcasting—A Radar-based Methodology. *Journal of Atmospheric and Oceanic Technology*, *10*, 785–797, doi:10.1175/1520-0426(1993)010<0785:TTITAA>2.0.CO;2.
http://journals.ametsoc.org/doi/abs/10.1175/1520-0426%281993%29010%3C0785%3A...
Say hello to my PhD project: https://github.com/WeatherGod/ZigZag In it, I have the centroid-tracking portion of the TITAN code, along with SCIT, and hooks into MHT. Several of the dependencies are also available in my repositories. Cheers! Ben P.S. - I have personally met Dr. Dixon on multiple occasions and he is a great guy to work with. Feel free to email him or myself with questions about TITAN.
participants (4)
-
Benjamin Root
-
Bradley M. Froehle
-
Scott Collis
-
Sudheer Joseph