Pressure/temperature gradient field

Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition ( http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex) and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan

Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field: http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m... http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-more-complicated-examples
Best wishes, -- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li yuan@astro.columbia.edu wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition (http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex) and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

Hi Suoqing,
I added validators=[ValidateSpatial(1, ["Pressure"])]
Now the error message is ValueError: could not broadcast input array from shape (64,64,66) into shape (64,64,64)
Yuan
On Sun, Jul 19, 2015 at 6:25 PM, Suoqing Ji suoqing@physics.ucsb.edu wrote:
Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field: http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m...
Best wishes,
Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li yuan@astro.columbia.edu wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition (http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex) and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

Hi Yuan,
Unfortunately I can not reproduce this error with either yt 2.6 or yt 3… If you did not mind, could you provide your script and dataset (or send me offline) so I can take a quick look at it?
Best wishes, -- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
On Jul 20, 2015, at 2:29 PM, Yuan Li bear0980@gmail.com wrote:
Hi Suoqing,
I added validators=[ValidateSpatial(1, ["Pressure"])]
Now the error message is ValueError: could not broadcast input array from shape (64,64,66) into shape (64,64,64)
Yuan
On Sun, Jul 19, 2015 at 6:25 PM, Suoqing Ji <suoqing@physics.ucsb.edu mailto:suoqing@physics.ucsb.edu> wrote: Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field: http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m... http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-more-complicated-examples
Best wishes,
Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li <yuan@astro.columbia.edu mailto:yuan@astro.columbia.edu> wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition (http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex) and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

On 07/20/2015 05:03 PM, Suoqing Ji wrote:
Hi Yuan,
Unfortunately I can not reproduce this error with either yt 2.6 or yt 3… If you did not mind, could you provide your script and dataset (or send me offline) so I can take a quick look at it?
Best wishes, -- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
Hi, could you show us the method you're using for your fields?
Maybe, it's also a good opportunity to advertise yt-3.x a bit ;) In latest version you can do:
ds.add_gradient_fields(("gas", "temperature"))
where ds is your loaded dataset. It should create following fields:
[('gas', 'temperature_gradient_x'), ('gas', 'temperature_gradient_y'), ('gas', 'temperature_gradient_z'), ('gas', 'temperature_gradient_magnitude')]
Cheers, Kacper
On Jul 20, 2015, at 2:29 PM, Yuan Li bear0980@gmail.com wrote:
Hi Suoqing,
I added validators=[ValidateSpatial(1, ["Pressure"])]
Now the error message is ValueError: could not broadcast input array from shape (64,64,66) into shape (64,64,64)
Yuan
On Sun, Jul 19, 2015 at 6:25 PM, Suoqing Ji <suoqing@physics.ucsb.edu mailto:suoqing@physics.ucsb.edu> wrote: Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field: http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m... http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-more-complicated-examples
Best wishes,
-- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li <yuan@astro.columbia.edu mailto:yuan@astro.columbia.edu> wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition (http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex) and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

Hi Kacper,
Thank you for pointing that out! It works great! Maybe it is time for me to move to yt3 for real...
Yuan
On Mon, Jul 20, 2015 at 6:08 PM, Kacper Kowalik xarthisius.kk@gmail.com wrote:
On 07/20/2015 05:03 PM, Suoqing Ji wrote:
Hi Yuan,
Unfortunately I can not reproduce this error with either yt 2.6 or yt 3… If you did not mind, could you provide your script and dataset (or send me offline) so I can take a quick look at it?
Best wishes, -- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
Hi, could you show us the method you're using for your fields?
Maybe, it's also a good opportunity to advertise yt-3.x a bit ;) In latest version you can do:
ds.add_gradient_fields(("gas", "temperature"))
where ds is your loaded dataset. It should create following fields:
[('gas', 'temperature_gradient_x'), ('gas', 'temperature_gradient_y'), ('gas', 'temperature_gradient_z'), ('gas', 'temperature_gradient_magnitude')]
Cheers, Kacper
On Jul 20, 2015, at 2:29 PM, Yuan Li bear0980@gmail.com wrote:
Hi Suoqing,
I added validators=[ValidateSpatial(1, ["Pressure"])]
Now the error message is ValueError: could not broadcast input array from shape (64,64,66) into shape (64,64,64)
Yuan
On Sun, Jul 19, 2015 at 6:25 PM, Suoqing Ji <suoqing@physics.ucsb.edu mailto:suoqing@physics.ucsb.edu> wrote: Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field:
http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m...
<
http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m...
Best wishes,
-- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li <yuan@astro.columbia.edu mailto:yuan@astro.columbia.edu> wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition (
http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex
<
http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex%3E)
and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

Hi Kacper,
Can I add the gradient fields globally instead of to a specific dataset?
Yuan
On Mon, Jul 20, 2015 at 6:08 PM, Kacper Kowalik xarthisius.kk@gmail.com wrote:
On 07/20/2015 05:03 PM, Suoqing Ji wrote:
Hi Yuan,
Unfortunately I can not reproduce this error with either yt 2.6 or yt 3… If you did not mind, could you provide your script and dataset (or send me offline) so I can take a quick look at it?
Best wishes, -- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
Hi, could you show us the method you're using for your fields?
Maybe, it's also a good opportunity to advertise yt-3.x a bit ;) In latest version you can do:
ds.add_gradient_fields(("gas", "temperature"))
where ds is your loaded dataset. It should create following fields:
[('gas', 'temperature_gradient_x'), ('gas', 'temperature_gradient_y'), ('gas', 'temperature_gradient_z'), ('gas', 'temperature_gradient_magnitude')]
Cheers, Kacper
On Jul 20, 2015, at 2:29 PM, Yuan Li bear0980@gmail.com wrote:
Hi Suoqing,
I added validators=[ValidateSpatial(1, ["Pressure"])]
Now the error message is ValueError: could not broadcast input array from shape (64,64,66) into shape (64,64,64)
Yuan
On Sun, Jul 19, 2015 at 6:25 PM, Suoqing Ji <suoqing@physics.ucsb.edu mailto:suoqing@physics.ucsb.edu> wrote: Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field:
http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m...
<
http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m...
Best wishes,
-- Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li <yuan@astro.columbia.edu mailto:yuan@astro.columbia.edu> wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition (
http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex
<
http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex%3E)
and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org mailto:yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

Hi Suoqing,
I basically copy-pasted from universal_fields.py:
def _gradPX(field, data): # We need to set up stencils if data.pf["HydroMethod"] == 2: sl_left = slice(None,-2,None) sl_right = slice(1,-1,None) div_fac = 1.0 else: sl_left = slice(None,-2,None) sl_right = slice(2,None,None) div_fac = 2.0 new_field = np.zeros(data["Pressure"].shape, dtype='float64') ds = div_fac * data['dx'].flat[0] new_field[1:-1,1:-1,1:-1] = data["Pressure"][sl_right,1:-1,1:-1]/ds new_field[1:-1,1:-1,1:-1] -= data["Pressure"][sl_left ,1:-1,1:-1]/ds return new_field def _convertgradPressure(data): return 1.0/data.convert("cm") add_field("gradPX",function=_gradPX,convert_function=_convertgradPressure,validators=[ValidateSpatial(1, ["Pressure"])])
It gives me the array shape error when I use HydroMethod=2 in the simulation. Interestingly, if I use a different HydroMethod, the script will always try to make a slice plot even if I want a projection of gradPX.
Yuan
On Mon, Jul 20, 2015 at 6:03 PM, Suoqing Ji suoqing@physics.ucsb.edu wrote:
Hi Yuan,
Unfortunately I can not reproduce this error with either yt 2.6 or yt 3… If you did not mind, could you provide your script and dataset (or send me offline) so I can take a quick look at it?
Best wishes,
Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
On Jul 20, 2015, at 2:29 PM, Yuan Li bear0980@gmail.com wrote:
Hi Suoqing,
I added validators=[ValidateSpatial(1, ["Pressure"])]
Now the error message is ValueError: could not broadcast input array from shape (64,64,66) into shape (64,64,64)
Yuan
On Sun, Jul 19, 2015 at 6:25 PM, Suoqing Ji suoqing@physics.ucsb.edu wrote:
Hi Yuan,
Just to check, have you included the “ValidateSpatial" object when adding the field? See the definition of DivV field: http://yt-project.org/docs/2.6/analyzing/creating_derived_fields.html#some-m...
Best wishes,
Suoqing JI Ph.D Candidate Department of Physics University of California, Santa Barbara http://web.physics.ucsb.edu/~suoqing
On Jul 19, 2015, at 2:52 PM, Yuan Li yuan@astro.columbia.edu wrote:
Dear all,
I am using yt2.6. I was trying to define a field of the temperature gradient like gradPressureX, but I got an error message: ... new_field[1:-1,1:-1,1:-1] = data["Temperature"][sl_right,1:-1,1:-1]/ds ValueError: could not broadcast input array from shape (62,62,64) into shape (62,62,62)
I then tried to re-define gradPressureX by copying the original definition ( http://yt-project.org/docs/2.6/reference/field_list.html#gradpressurex) and giving it a different name, and I got the same error. The original gradPressureX works fine.
Is it because I did not load some specific module or something?
Thank you! Yuan _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
participants (4)
-
Kacper Kowalik
-
Suoqing Ji
-
Yuan Li
-
Yuan Li