[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #AFB-689678]: Help



Hi Sudhansu,

I believe that longitude was the x-axis dimension due to the *mostly* 
longitudinal orientation of the example cross-section. That being said, you can 
choose whatever you would like. The np.arange(100) option worked cleanly for 
me. To use the latitudes, I had to sort the array in order 
(np.sort(cross['lat'])) to get the desired output. You could also just keep 
longitude as the x-axis coordinate and replace the x-tick labels with the 
ax.set_xticklabels function from Matplotlib if you wanted to display another 
variable along the x-axis. 

Hope that helps!
Zach 

> Thank you for this information! Your help is much appreciated. and because
> of this, I am able to plot cross section using metpy. I have one more small
> doubt. Why the default output in x-axis is longitude while plotting??
> 
> (*rh_contour = ax.contourf(cross['lon'], cross['pressure'], cross['rh']*)
> 
> Can I use *cross['lat'], or a numpy array of same length (*np.arange(100)*)
> in place of **cross['lon'].*
> 
> *I tried using these and it works fine. I just want to clarify why the
> default output for x-axis label is kept as "lon" (As I was told by  Zach
> Bruick my earlier mail replies.).*
> 
> 
> address@hidden> wrote:
> 
> > Hi Sudhansu,
> >
> > Happy to help! Since your file has more than one time, the squeeze
> > function doesn't eliminate the time dimension here. The cross section will
> > compute all times, but it's when you plot, you'll need to specify the time
> > to be output. Within the final block of the example (the plotting block),
> > you'll need to add [0] after every variable (or if it is already index,
> > such as the u and v components, put "0," before the other indices) to plot
> > the first time, for instance. For your dataset, you'll want to loop through
> > all times. For a loop, you can just start it with "for i in
> > range(len(data['time'])):" and then put cross["your_variable"][i] to
> > specify the time as you loop through.
> >
> > Hope that helps!
> > Zach
> >
> >
> >  Thank you for your support. I am not very familiar with python. Trying to
> > > figure out the cross-section analysis in metpy. I understand the example
> > > given in the cross-section analysis. But my data having an extra
> > dimension
> > > (time). and I am not able to figure out how to make it work with the
> > cross
> > > function.
> > >
> > > Below is the output of my data after i did " data =
> > > data.metpy.parse_cf().squeeze()"
> > >
> > >
> > > print(data)
> > > <xarray.Dataset>
> > > Dimensions:    (lat: 324, lev_2: 11, lev_3: 4, lev_4: 3, lev_5: 7, lon:
> > > 282, time: 25)
> > > Coordinates:
> > > * time       (time) datetime64[ns] 2014-03-24 ... 2014-03-25
> > > * lon        (lon) float32 87.82086 87.82476 87.82865 ... 88.91126
> > > 88.91516
> > > * lat        (lat) float32 22.026062 22.029663 22.03328 ... 23.183662
> > > 23.18724
> > > lev        float64 1e+03
> > > crs        object Projection: latitude_longitude
> > > * lev_2      (lev_2) float64 1e+03 950.0 900.0 850.0 ... 600.0 550.0
> > 500.0
> > > * lev_3      (lev_3) float64 1e+03 950.0 900.0 850.0
> > > * lev_4      (lev_4) float64 1e+03 950.0 900.0
> > > * lev_5      (lev_5) float64 1e+03 950.0 900.0 850.0 800.0 750.0 700.0
> > > Data variables:
> > > xlat       (time, lat, lon) float32 ...
> > > xlong      (time, lat, lon) float32 ...
> > > lu_index   (time, lat, lon) float32 ...
> > > var_sso    (time, lat, lon) float32 ...
> > > u          (time, lev_2, lat, lon) float32 ...
> > > v          (time, lev_2, lat, lon) float32 ...
> > > w          (time, lev_2, lat, lon) float32 ...
> > > ph         (time, lev_2, lat, lon) float32 ...
> > > phb        (time, lev_2, lat, lon) float32 ...
> > > t          (time, lev_2, lat, lon) float32 ...
> > > mu         (time, lat, lon) float32 ...
> > > mub        (time, lat, lon) float32 ...
> > > nest_pos   (time, lat, lon) float32 ...
> > > p          (time, lev_2, lat, lon) float32 ...
> > > pb         (time, lev_2, lat, lon) float32 ...
> > > p_hyd      (time, lev_2, lat, lon) float32 ...
> > > q2         (time, lat, lon) float32 ...
> > > t2         (time, lat, lon) float32 ...
> > > th2        (time, lat, lon) float32 ...
> > > psfc       (time, lat, lon) float32 ...
> > > u10        (time, lat, lon) float32 ...
> > > v10        (time, lat, lon) float32 ...
> > > lpi        (time, lat, lon) float32 ...
> > > *qvapor     (time, lev_2, lat, lon) float32 ...*
> > >
> > > *I want to plot qvapor cross section along "*start = (22.30, 88.15) end =
> > > (23.05, 88.45)" for all the time steps (25)
> > >
> > > Please guide me to create a script for this.....
> > >
> > > address@hidden> wrote:
> > >
> > > > Hi Sudhansu,
> > > >
> > > > We're glad to hear you're using MetPy! If I understand your question
> > > > correctly, you want to confirm that MetPy performs cross-sections
> > between
> > > > any two pairs of coordinates, regardless of if they are at the same
> > > > latitude or not. The answer is yes, the MetPy cross-section tool will
> > take
> > > > a cross section between any two lat/lon pairs. You can see in the
> > title of
> > > > the example that you linked that the full coordinates of the start and
> > end
> > > > points are shown. The default output for the x-axis label is just
> > > > longitude, which is why it shows up a little differently than the NCL
> > plot.
> > > >
> > > > Best regards,
> > > > Zach Bruick
> > > >
> > > > >I am currently starting to use metpy with python. I want to confirm
> > one
> > > > > thing that is there any difference between the cross-section
> > function in
> > > > > metpy(
> > > > >
> > > >
> > https://unidata.github.io/MetPy/latest/examples/cross_section.html#sphx-glr-examples-cross-section-py
> > > > > ) and wrf_user_vert_cross in NCL(
> > > > > https://www.ncl.ucar.edu/Applications/wrfinterp.shtml  ).
> > > > >
> > > > > Because in metpy we have to provide input for start and end lat and
> > lon
> > > > > pairs but in metpy plot x-axis only li=ongitudes are displaying
> > instead
> > > > of
> > > > > latlon pairs as shown in NCL plots.
> > > > >
> > > > > Figures attached
> > > > >
> > > >
> > > > Ticket Details
> > > > ===================
> > > > Ticket ID: AFB-689678
> > > > Department: Support Python
> > > > Priority: Low
> > > > Status: Open
> > > > ===================
> > > > NOTE: All email exchanges with Unidata User Support are recorded in the
> > > > Unidata inquiry tracking system and then made publicly available
> > through
> > > > the web.  If you do not want to have your interactions made available
> > in
> > > > this way, you must let us know in each email you send to us.
> > > >
> > > >
> > > >
> > >
> > > --
> > >
> > > *Sudhansu S. Rath*
> > >
> >
> > Ticket Details
> > ===================
> > Ticket ID: AFB-689678
> > Department: Support Python
> > Priority: Low
> > Status: Open
> > ===================
> > NOTE: All email exchanges with Unidata User Support are recorded in the
> > Unidata inquiry tracking system and then made publicly available through
> > the web.  If you do not want to have your interactions made available in
> > this way, you must let us know in each email you send to us.
> >
> >
> >
> 
> --
> 
> *Sudhansu S. Rath*
> 
> 

Ticket Details
===================
Ticket ID: AFB-689678
Department: Support Python
Priority: Low
Status: Open
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.