[yt-users] accessing single elements of data when defining a new field

sacielo sacielo at gmail.com
Fri Jul 14 07:35:50 PDT 2017


Thanks Matthew for your reply,

the general problem of doing that is that the 'data' structure can point to
arrays of 1, 2 or 3 dimensions, so it's difficult to loop over it. I ended
up solving the problem in a better way:
I switched to a scipy RectBivariateSpline interpolator, rather than a
simpler interp2d object.
Now I no more need to loop on the single elements, and can pass the full
arrays.
To get the numerical array, now I could simply use
data['mydata'].value

(I had to reshape it to a 1D array, but that was easy).

Thank you anyway!

Best,


On Wed, Jul 12, 2017 at 6:14 PM, <yt-users-request at lists.spacepope.org>
wrote:

> Send yt-users mailing list submissions to
>         yt-users at lists.spacepope.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> or, via email, send a message with subject or body 'help' to
>         yt-users-request at lists.spacepope.org
>
> You can reach the person managing the list at
>         yt-users-owner at lists.spacepope.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of yt-users digest..."
>
>
> Today's Topics:
>
>    1. Re: accessing single elements of data when defining a     new
>       field (Matthew Turk)
>    2. Re: IO error (Britton Smith)
>    3. Re: Field extraction from arbitrary grids (Carla Bernhardt)
>    4. 3-D Mass power spectra (???)
>    5. Re: 3-D Mass power spectra (Nathan Goldbaum)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 11 Jul 2017 07:16:20 -0500
> From: Matthew Turk <matthewturk at gmail.com>
> To: Discussion of the yt analysis package
>         <yt-users at lists.spacepope.org>
> Subject: Re: [yt-users] accessing single elements of data when
>         defining a      new field
> Message-ID:
>         <CALO3=5GQeESENDeFQR70aeE9EtcNOcwUUrhxJYN_9+PhyPz=
> oA at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi Salvatore,
>
> This is odd -- I believe that it should work as you have written it.
> Can you describe how it fails?  And, what happens if instead of doing
>
> for ii in range(0, len(t)):
>
> you did something like:
>
> for val in t:
>
> and then operated on val?
>
> On Tue, Jul 11, 2017 at 4:59 AM, sacielo <sacielo at gmail.com> wrote:
> > Hello
> >
> > I am trying to define a new field for a grid simulation (using ramses,
> if it
> > matters), basically an estimate of radiative cooling in a simulation that
> > does not include that.
> >
> > I find myself to perform a 2D interpolation in a table (cooling rate
> given
> > temperature and metal content), then I wish to save this as a new field.
> I
> > am using a scipy 2D interpolator in order to do so. The problem is that
> for
> > the interpolation I need to access the single elements in the temperature
> > and metal fields, within the function I use to define a new dataset
> > (unfortunately, I am forced to loop on the fields).
> >
> > Now, I can't understand how to do that from the "data" and "field"
> arguments
> > of the functions.
> >
> > Something like
> > t = data['temperature']
> > for ii in range(0, len(t)):
> >     print t[ii]
> >
> > fails (t[ii] is a complex array itself)
> >
> > t.base() and t.item() or t[ii].item()
> >
> > fail as well....
> >
> >
> > Any idea?
> >
> > Thank you!
> >
> >
> > --
> > Salvatore
> >
> > _______________________________________________
> > yt-users mailing list
> > yt-users at lists.spacepope.org
> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> >
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 11 Jul 2017 11:09:12 -0700
> From: Britton Smith <brittonsmith at gmail.com>
> To: Discussion of the yt analysis package
>         <yt-users at lists.spacepope.org>
> Subject: Re: [yt-users] IO error
> Message-ID:
>         <CABfs61k3p07Yfcze8Jrf3-wjwfe38nWN5Yb1vv1cnWANi-m47Q@
> mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi everyone,
>
> I just wanted to provide some resolution to this issue.  The issue had to
> do with some problems that have cropped up when trying to read hdf5 string
> attributes in Python 3.  You wouldn't see this if you were still using
> Python 2.  This has been resolved with the following pull request, which
> has already been accepted:
> https://github.com/yt-project/yt/pull/1487
>
> Britton
>
> On Mon, Jul 10, 2017 at 1:13 PM, Britton Smith <brittonsmith at gmail.com>
> wrote:
>
> > Hi Nick,
> >
> > This is a bit puzzling since I think there have been relatively few
> > changes to the halo catalog frontend responsible for loading that data.
> > That said, I would be more than happy to take a look as I am responsible
> > for much of this code.  Would you be able to share either 1) this dataset
> > that is failing to load or 2) a script that uses example data that I can
> > run to reproduce this?
> >
> > Britton
> >
> > On Mon, Jul 10, 2017 at 8:53 AM, Nick Gnedin <ngnedin at gmail.com> wrote:
> >
> >>
> >> Folks,
> >>
> >> I have encountered a bizarre IO error. I am reading a file previously
> >> created by yt HOP halo finder on two separate machines. The file reads
> >> correctly on the machine it was created on, but on another machine with
> the
> >> most recent anaconda install (yt 3.3.5) the format is not recognized.
> Both
> >> machines are little endian. Is there any way to get more info on what yt
> >> does not like about that file?
> >>
> >> yt : [ERROR    ] 2017-07-10 10:46:00,454 Couldn't figure out output type
> >> for hop.0.h5
> >> Traceback (most recent call last):
> >>   File "hmf.py", line 14, in <module>
> >>     Plot("hop.0.h5",color="b")
> >>   File "hmf.py", line 8, in Plot
> >>     my_halos = load(file)
> >>   File "/ext/anaconda3/lib/python3.6/site-packages/yt/convenience.py",
> >> line 98, in load
> >>     raise YTOutputNotIdentified(args, kwargs)
> >> yt.utilities.exceptions.YTOutputNotIdentified: Supplied ('hop.0.h5',)
> >> {}, but could not load!
> >>
> >> Here is the script (taken form your examples):
> >>
> >>
> >> import yt
> >> from yt.mods import *
> >> from yt.analysis_modules.halo_mass_function.api import *
> >> import matplotlib.pyplot as plt
> >>
> >> def Plot(file,color="r"):
> >>     my_halos = load(file)
> >>     hmf = HaloMassFcn(halos_ds=my_halos)
> >>     plt.loglog(hmf.masses_analytic, hmf.n_cumulative_analytic,colo
> >> r="orange",linewidth=3)
> >>     plt.loglog(hmf.masses_sim, hmf.n_cumulative_sim,color=col
> >> or,linewidth=3)
> >>
> >> Plot("hop.0.h5",color="b")
> >>
> >>
> >> Thank you for your advice,
> >>
> >> Nick Gnedin
> >> _______________________________________________
> >> yt-users mailing list
> >> yt-users at lists.spacepope.org
> >> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> >>
> >
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.
> org/attachments/20170711/19feaa01/attachment-0001.htm>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 12 Jul 2017 12:35:14 +0200
> From: Carla Bernhardt <carla.j.bernhardt at gmail.com>
> To: Discussion of the yt analysis package
>         <yt-users at lists.spacepope.org>
> Subject: Re: [yt-users] Field extraction from arbitrary grids
> Message-ID:
>         <CAKQMXAWJWUANaiSVaMBoBMEcPKST+UUN--4QLj_nLwEDKV7q2Q at mail.
> gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Matthew,
>
> Thank you for your reply. I was using yt Version 3.2.3 and am working out
> some installation issues on our server with version 3.3.5. As for the type
> of data, I have an enzo simulation with static nested grids as well as up
> to 6 levels AMR grids. I will have to get back to you once I get past the
> issues with the newest installation of yt.... Thanks for the initial
> pointers.
>
> Cheers,
> Carla
>
> 2017-07-11 14:15 GMT+02:00 Matthew Turk <matthewturk at gmail.com>:
>
> > Hi Carla,
> >
> > Interesting.  It's possible, for the call to "temperature" (which
> > raises NotImplementedError) that the version of yt you're on doesn't
> > yet support mesh fields in arbitrary grids; that was added reasonably
> > recently.  For the others, I'm not totally sure why it's breaking --
> > which version of yt are you using, and what type of data?  It may just
> > be that they aren't deposit fields.  In that case, try explicitly
> > stating obj["gas","temperature"] or obj["gas","HI_Density"].  It may
> > also be that the aliasing is getting in the way, in which case instead
> > of "HI_Density" you might need to try "Hp0_density".
> >
> > On Tue, Jul 11, 2017 at 5:42 AM, Carla Bernhardt
> > <carla.j.bernhardt at gmail.com> wrote:
> > > Dear yt-users,
> > >
> > > I am trying to extract a unigrid data cube within a specific region and
> > > specified dimensions, thus I am using arbitrary_grid(), however, beyond
> > the
> > > example given in the docs, my field extractions all fail. I would like
> to
> > > extract temperature, HI_Density and HII_Density. Here is a snippet from
> > my
> > > code:
> > >
> > > obj = ds.arbitrary_grid(left_edge, right_edge, dims=[256, 256, 256])
> > > print(obj["deposit", "all_density"])
> > > print(obj["temperature"])
> > > print(obj["HI_Density"])
> > >
> > > The line print(obj["deposit", "all_density"]) works, but the two lines
> > after
> > > both fail. Here is the traceback from the temperature, and I even tried
> > out
> > > deposited temperature and deposited HI_Density. Am I formatting this
> > > incorrectly, or is there a different way to extract the fields?
> > >
> > > Kind regards,
> > > Carla Bernhardt
> > > PhD Student
> > > ZAH Institut f?r Theoretische Astrophysik
> > > Universit?t Heidelberg
> > >
> > > _______________________________________________
> > > yt-users mailing list
> > > yt-users at lists.spacepope.org
> > > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> > >
> > _______________________________________________
> > yt-users mailing list
> > yt-users at lists.spacepope.org
> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.
> org/attachments/20170712/a46e0643/attachment-0001.htm>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 13 Jul 2017 00:10:02 +0800
> From: ??? <setsuna at phys.tw>
> To: Discussion of the yt analysis package
>         <yt-users at lists.spacepope.org>
> Subject: [yt-users] 3-D Mass power spectra
> Message-ID:
>         <CAEtGJOz5LssuwrWmuXSYO+u77DPaW2v5yPM2TGFg+CYP2AV+7A@
> mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Dear yt
>
> Can current yt calculate 3-D Mass power spectra? I checked the website but
> I didn't find any information. I think calculating 3-D Mass power
> spectra is a very useful for cosmological simulations. So I guess maybe yt
> supports this function now....?
>
> Thanks in advance
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.
> org/attachments/20170713/a3c9b005/attachment-0001.htm>
>
> ------------------------------
>
> Message: 5
> Date: Wed, 12 Jul 2017 11:13:50 -0500
> From: Nathan Goldbaum <nathan12343 at gmail.com>
> To: Discussion of the yt analysis package
>         <yt-users at lists.spacepope.org>
> Subject: Re: [yt-users] 3-D Mass power spectra
> Message-ID:
>         <CAJXewO=CQ3+PKt_jL9QBPvYd4g7hc7VrKLBD01W33u9jX
> vg7gw at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> We have an example in our docs that shows how to create a kinetic energy
> power spectrum with the numpy FFT:
>
> http://yt-project.org/doc/cookbook/calculating_information.html#making-a-
> turbulent-kinetic-energy-power-spectrum
>
> I think this could be adapted for your needs.
>
> Right now there isn't an analysis routine explicitly for computing power
> spectra in yt. If someone wanted to add it (or just wanted to add more
> examples to the docs of how to compute power spectra using e.g. pyfftw) I
> think that would be a very welcome contribution.
>
> -Nathan
>
> On Wed, Jul 12, 2017 at 11:10 AM, ??? <setsuna at phys.tw> wrote:
>
> > Dear yt
> >
> > Can current yt calculate 3-D Mass power spectra? I checked the website
> but
> > I didn't find any information. I think calculating 3-D Mass power
> > spectra is a very useful for cosmological simulations. So I guess maybe
> yt
> > supports this function now....?
> >
> > Thanks in advance
> >
> > _______________________________________________
> > yt-users mailing list
> > yt-users at lists.spacepope.org
> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> >
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.
> org/attachments/20170712/c8e1fe3f/attachment.htm>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
> ------------------------------
>
> End of yt-users Digest, Vol 113, Issue 17
> *****************************************
>



-- 
Salvatore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170714/375d6410/attachment.html>


More information about the yt-users mailing list