[Matplotlib-users] Question about copy_from_bbox

2014-03-31 Thread Michka Popoff
Hi

I am using blitting and am not able to get it to work as I want.

I am using copy_from_bbox during the setup of my PyQt GUI to save a meshgrid as 
a starting empty background.
Then, once the GUI is loaded, the user can click on the meshgrid and a square 
is displayed on the selected pixel with blitting, so that no re-plotting needs 
to be done.

The problem is that between the copy_from_bbox call and the final GUI setup, 
there is some movement of the widgets (don’t really know why, surely PyQt 
layout adjustments).
This leads to a shift of the restored region, because the saved one (after the 
draw() call) is not the one which is finally displayed in the GUI. This can 
lead to strange display errors …

I tried to trim down my code to the essential, I hope it’s short enough.
I am using Matplotlib 1.3.1 on OS X, but I am having this problem one or two 
years and had never time to tackle it (I have it also on Windows and Fedora)

Here is my code, just run it and click on the meshgrid, you will see it move 
down, so that the top of the red square is not drawn correctly.
https://gist.github.com/iMichka/9901318

In the case of my example the shift is quite small (I could live with a shift 
of one pixel …), but in my real app there is more stuff and the shift is bigger 
… the plot even overlaps with PyQt buttons …

Is there any way to call copy_from_bbox when the PyQt GUI has stabilized ? This 
means after the PyQt event loop has finished refreshing, and not before the 
refreshing ?

Any help would be much appreciated :)


Michka




--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [Pyaos] CAPE and CIN calculation in Python

2014-03-31 Thread Gökhan Sever
Hello Marry,

I am highly interested in getting "wrf_cape_3d" wrapped to be accessible in
Python. So far, that's how I calculate CAPE and CIN for my WRF outputs.
wrf_cape_3d is more robust comparing to the function in the SkewT script.
For some reason, I have no luck getting wrf_cape_2d working properly as it
throws a NaN error.


On Mon, Mar 31, 2014 at 2:25 PM, Mary Haley  wrote:

> Hi all,
>
> I’ve been following this thread somewhat peripherally.
>
> I’ve slowly started creating Python wrappers of some of the WRF Fortran
> calculation functions (not the graphical ones) that are used in NCL.
>
> You can see the list of the NCL ones at:
>
> http://www.ncl.ucar.edu/Document/Functions/wrf.shtml
>
> So far I’ve only wrapped these six: wrf_avo, wrf_tk, wrf_td, wrf_slp,
> wrf_rh, wrf_dbz.
>
> Would the wrf_cape_2d and wrf_cape_3d routines be of interest? These are
> specific to WRF data.  I believe these are the same ones that Wanli is
> referring to.
>
> We also have the ones that we use for the basic Skew-T code in NCL, that
> Gökhan has been corresponding with Dennis on.
> I could wrap these as well. These routines are not advertised in NCL, but
> they are used by the Skew-T examples you see at:
>
> http://www.ncl.ucar.edu/Applications/skewt.shtml
>
> --Mary
>
> On Mar 31, 2014, at 11:41 AM, Wanli Wu  wrote:
>
> All,
>
> Another good example of Skew-T with all Parcel stability info including
> CIN, CAPE is produced through RIP4 (see this example:
> http://www.mmm.ucar.edu/mm5/WRF_post/RIP4/pages/rip_sample_cgm030_gif.htm).
> If this one can be duplicated with python, it'd great for the community.
>
> Wanli Wu
>
>
>
> On Mon, Mar 31, 2014 at 7:49 AM, Gökhan Sever wrote:
>
>> Hi James,
>>
>> I have managed to run CLIMT's thermodyn.py . Most of the functions I
>> tested from within the Driver.f90 works fine except the CAPE and CIN
>> routines. I sent an e-mail to the author regarding this but nothing back
>> from him so far. Would you give a test if I send you a simple sounding
>> data? My system is Window 7 (x64) and using Python(XY). f2py uses the
>> gfortran provided in MinGW32 folder.
>>
>> Could you provide an example (with some test data) for Kerry Emanuel's
>> code? That code has definitely more functions than I need but it might be a
>> valuable source.
>>
>> As for the NCL, it is easy to interface to a WRF output, it also includes
>>  a SkewT/LogP [https://www.ncl.ucar.edu/Applications/skewt.shtml], but
>> the CAPE estimation in this script is very sensitive to the number of
>> data-points, which I have bitten a couple of times. Dennis Shea has
>> provided some CAPE calculation routines coded in fortran. [Check under
>> http://www.cgd.ucar.edu/~shea/ for the files starting with cape*]. Yet I
>> have no luck wrapping them via f2py.
>>
>>
>> On Sat, Mar 29, 2014 at 7:11 PM, James Boyle wrote:
>>
>>> I have used the CAPE and CIN from ClMT - a bit of overkill but many
>>> useful functions:
>>> http://people.su.se/~rcaba/climt/
>>>
>>> I have also wrapped using f2py the the Fortran CAPE and CIN of Kerry
>>> Emanuel ( a prestigious source) in his convect code:
>>> http://eaps4.mit.edu/faculty/Emanuel/products
>>>
>>> If you prowl about in the NCL source distribution, you will find the
>>> fortran that the NCL skew - T uses.
>>> If you ask, Dennis Shea of NCAR might break the code out for you. It is
>>> trivial to wrap using f2py ( f77).
>>>
>>>
>>> On Mar 29, 2014, at 3:32 PM, Gökhan Sever  wrote:
>>>
>>> Hello,
>>>
>>> Lately, I am working on plotting sounding profiles on a SkewT/LogP
>>> diagram. The SkewT package which is located at
>>> https://github.com/tchubb/SkewT has a nice feature to lift a parcel on
>>> dry/moist adiabats. This is very useful to demonstrate the regions of CIN
>>> and CAPE overlaid with the full sounding.
>>>
>>> However, the package misses these diagnostic calculations. This is the
>>> only step holding me back to use Python only (migrating from NCL) for my
>>> plotting tasks.  I am aware that these calculations are usually performed
>>> in fortran. Are there any routines wrapped in Python to calculate CAPE and
>>> CIN parameters?  Any suggestions or comments would be really appreciated.
>>>
>>> --
>>> Gökhan
>>>
>>> --
>>> ___
>>> Matplotlib-users mailing list
>>> Matplotlib-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>>
>>
>>
>> --
>> Gökhan
>>
>> ___
>> Pyaos mailing list
>> py...@lists.johnny-lin.com
>> http://lists.johnny-lin.com/listinfo.cgi/pyaos-johnny-lin.com
>>
>>
> ___
> Pyaos mailing list
> py...@lists.johnny-lin.com
> http://lists.johnny-lin.com/listinfo.cgi/pyaos-johnny-lin.com
>
>
>


-- 
Gökhan
--
__

[Matplotlib-users] why does floor(x) return a float while docs state it returns integer?

2014-03-31 Thread Mark Bakker
I expected that floor(x) would return an integer especially since the docs
state:

Return the floor of the input, element-wise.


The floor of the scalar `x` is the largest integer `i`, such that

`i <= x`. It is often denoted as :math:`\lfloor x \rfloor`.


Any reason why it returns a float? Bug/feature?


Thanks, Mark
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] CAPE and CIN calculation in Python

2014-03-31 Thread Gökhan Sever
As for the rest of the two suggestions: [
https://github.com/pmarshwx/SHARPpy/tree/gui
https://github.com/PyAOS/aoslib]
there doesn't seem be routines included for CAPE and CIN calculations.

I am working on idealized orographic precipitation simulations in WRF that
will hopefully be presented in the Mountain Meteorology conference in
August. Perhaps I am extra cautious, but I need a good control especially
on CAPE calculation (independent of data-points, being able to specify
where to lift the parcel and specify mixed layer depth etc.).

This could be a good subject to discuss on the coming SciPy conference. The
abstract deadline is tomorrow. I might join if I can get some funding to
attend the conference. Is there any symposium planned for atmospheric
science people? Thanks again.


On Sat, Mar 29, 2014 at 6:32 PM, Gökhan Sever  wrote:

> Hello,
>
> Lately, I am working on plotting sounding profiles on a SkewT/LogP
> diagram. The SkewT package which is located at
> https://github.com/tchubb/SkewT has a nice feature to lift a parcel on
> dry/moist adiabats. This is very useful to demonstrate the regions of CIN
> and CAPE overlaid with the full sounding.
>
> However, the package misses these diagnostic calculations. This is the
> only step holding me back to use Python only (migrating from NCL) for my
> plotting tasks.  I am aware that these calculations are usually performed
> in fortran. Are there any routines wrapped in Python to calculate CAPE and
> CIN parameters?  Any suggestions or comments would be really appreciated.
>
> --
> Gökhan
>



-- 
Gökhan
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [Pyaos] CAPE and CIN calculation in Python

2014-03-31 Thread Gökhan Sever
Thanks Daniel. Your CAPE calculation approach looks robust. I will give it
a try with my sounding data. In the mean time, do you plan on putting a
function for CIN calculation?


On Sun, Mar 30, 2014 at 10:37 AM, Daniel Rothenberg wrote:

> Hello Gokhan,
>
> I've written my own SkewT/LogP code with some lifted parcel calculations -
> it's included in a GitHub repo I use to maintain a collection of utilities
> I've written for analyzing output from a cloud resolving model I use. You
> can find my code for this purpose at
> https://github.com/darothen/crm-tools/blob/master/vis/soundings.py, along
> with other useful scripts.
>
> - Daniel Rothenberg
>
>
> On Sat, Mar 29, 2014 at 6:32 PM, Gökhan Sever wrote:
>
>> Hello,
>>
>> Lately, I am working on plotting sounding profiles on a SkewT/LogP
>> diagram. The SkewT package which is located at
>> https://github.com/tchubb/SkewT has a nice feature to lift a parcel on
>> dry/moist adiabats. This is very useful to demonstrate the regions of CIN
>> and CAPE overlaid with the full sounding.
>>
>> However, the package misses these diagnostic calculations. This is the
>> only step holding me back to use Python only (migrating from NCL) for my
>> plotting tasks.  I am aware that these calculations are usually performed
>> in fortran. Are there any routines wrapped in Python to calculate CAPE and
>> CIN parameters?  Any suggestions or comments would be really appreciated.
>>
>> --
>> Gökhan
>>
>> ___
>> Pyaos mailing list
>> py...@lists.johnny-lin.com
>> http://lists.johnny-lin.com/listinfo.cgi/pyaos-johnny-lin.com
>>
>>
>


-- 
Gökhan
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] CAPE and CIN calculation in Python

2014-03-31 Thread Gökhan Sever
Thanks Alex. This seems to be the easiest way to approach the problem.
However, for the sake of reproducibility, I am looking for a way to
interface to one of the common fortran routines for the task. Your
suggested approach will require some sort of interpolation at the very
least to make the estimation number of data point insensitive. Putting this
in my TODO list.


On Sat, Mar 29, 2014 at 7:56 PM, Alex Goodman wrote:

> You can easily visualize the CAPE and CIN with matplotlib using
> fill_between() on the environmental and parcel temperature curves. As for
> actually calculating it though, I don't know of a way to do it directly
> from matplotlib. There are probably several other python packages out there
> that can, but I am not familiar with them. In any case, why not just write
> your own function for calculating the CAPE and CIN? It is a bit surprising
> that this functionality isn't be included in the SkewT package, but since
> you can use it to get the parcel temperature curve, you should be able to
> calculate the CAPE and CIN rather easily by simply discretizing their
> respective formulas. Here's a rough example:
>
> import numpy as np
> cape = 9.8 * np.sum(dz * (Tp - T) / T)
>
> Where Tp and T are the parcel and environmental temperature arrays
> respectively, and dz are the height differences between layers. You would
> of course need to perform the sum from the LFC to EL for CAPE, so the
> arrays would have to to be subsetted. With numpy the easiest way to do this
> is with fancy indexing, eg:
>
> levs = (z >= LFC) & (z <= EL)
> Tp = Tp[levs]
> T = T[levs]
> where z is your array of heights (or pressure levels).
>
> Does this help?
>
> Alex
>
>
> On Sat, Mar 29, 2014 at 4:32 PM, Gökhan Sever wrote:
>
>> Hello,
>>
>> Lately, I am working on plotting sounding profiles on a SkewT/LogP
>> diagram. The SkewT package which is located at
>> https://github.com/tchubb/SkewT has a nice feature to lift a parcel on
>> dry/moist adiabats. This is very useful to demonstrate the regions of CIN
>> and CAPE overlaid with the full sounding.
>>
>> However, the package misses these diagnostic calculations. This is the
>> only step holding me back to use Python only (migrating from NCL) for my
>> plotting tasks.  I am aware that these calculations are usually performed
>> in fortran. Are there any routines wrapped in Python to calculate CAPE and
>> CIN parameters?  Any suggestions or comments would be really appreciated.
>>
>> --
>> Gökhan
>>
>>
>> --
>>
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
>
> --
> Alex Goodman
> Graduate Research Assistant
> Department of Atmospheric Science
> Colorado State University
>



-- 
Gökhan
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] CAPE and CIN calculation in Python

2014-03-31 Thread Gökhan Sever
Hi James,

I have managed to run CLIMT's thermodyn.py . Most of the functions I tested
from within the Driver.f90 works fine except the CAPE and CIN routines. I
sent an e-mail to the author regarding this but nothing back from him so
far. Would you give a test if I send you a simple sounding data? My system
is Window 7 (x64) and using Python(XY). f2py uses the gfortran provided in
MinGW32 folder.

Could you provide an example (with some test data) for Kerry Emanuel's
code? That code has definitely more functions than I need but it might be a
valuable source.

As for the NCL, it is easy to interface to a WRF output, it also includes
 a SkewT/LogP [https://www.ncl.ucar.edu/Applications/skewt.shtml], but the
CAPE estimation in this script is very sensitive to the number of
data-points, which I have bitten a couple of times. Dennis Shea has
provided some CAPE calculation routines coded in fortran. [Check under
http://www.cgd.ucar.edu/~shea/ for the files starting with cape*]. Yet I
have no luck wrapping them via f2py.


On Sat, Mar 29, 2014 at 7:11 PM, James Boyle  wrote:

> I have used the CAPE and CIN from ClMT - a bit of overkill but many useful
> functions:
> http://people.su.se/~rcaba/climt/
>
> I have also wrapped using f2py the the Fortran CAPE and CIN of Kerry
> Emanuel ( a prestigious source) in his convect code:
> http://eaps4.mit.edu/faculty/Emanuel/products
>
> If you prowl about in the NCL source distribution, you will find the
> fortran that the NCL skew - T uses.
> If you ask, Dennis Shea of NCAR might break the code out for you. It is
> trivial to wrap using f2py ( f77).
>
>
> On Mar 29, 2014, at 3:32 PM, Gökhan Sever  wrote:
>
> Hello,
>
> Lately, I am working on plotting sounding profiles on a SkewT/LogP
> diagram. The SkewT package which is located at
> https://github.com/tchubb/SkewT has a nice feature to lift a parcel on
> dry/moist adiabats. This is very useful to demonstrate the regions of CIN
> and CAPE overlaid with the full sounding.
>
> However, the package misses these diagnostic calculations. This is the
> only step holding me back to use Python only (migrating from NCL) for my
> plotting tasks.  I am aware that these calculations are usually performed
> in fortran. Are there any routines wrapped in Python to calculate CAPE and
> CIN parameters?  Any suggestions or comments would be really appreciated.
>
> --
> Gökhan
>
> --
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>


-- 
Gökhan
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users