How to use if, elif, else statements in creating a derived field
Dear all, I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error. @derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01 Please suggest me how to implement if, elif, else statements in creating a derived field. Thank You Reju Sam John
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace? One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this: @derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp Cheers, Kacper
Dear Kacper,
This is my backtrace....
Traceback (most recent call last):
File "cosmic_ray_fra.py", line 50, in <module>
p = pc.add_slice("MyField", 2)
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py",
line 430, in add_slice
center=center, **field_parameters)
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 1058, in __init__
self._refresh_data()
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 320, in _refresh_data
self.get_data()
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 859, in get_data
if self._generate_field(field):
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 362, in _generate_field
self[field] = self.pf.field_info[field](self)
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py",
line 395, in __call__
dd = self._function(self, data)
File "cosmic_ray_fra.py", line 32, in my_new_field
if data.pf["MachNumber"] < 2:
File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/static_output.py",
line 147, in __getitem__
raise KeyError(key)
KeyError: 'MachNumber'
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
On 10/21/2013 12:31 PM, Reju Sam John wrote:
Dear Kacper, This is my backtrace....
Traceback (most recent call last): File "cosmic_ray_fra.py", line 50, in <module> p = pc.add_slice("MyField", 2) File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py", line 430, in add_slice center=center, **field_parameters) File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 1058, in __init__ self._refresh_data() File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 320, in _refresh_data self.get_data() File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 859, in get_data if self._generate_field(field): File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 362, in _generate_field self[field] = self.pf.field_info[field](self) File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py", line 395, in __call__ dd = self._function(self, data) File "cosmic_ray_fra.py", line 32, in my_new_field if data.pf["MachNumber"] < 2: File "/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/static_output.py", line 147, in __getitem__ raise KeyError(key) KeyError: 'MachNumber'
Yeah, that pretty much says that there's no such thing as data.pf["MachNumber"]. Please try the derived field that I've suggested in my previous mail. Cheers, Kacper
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
wrote: On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ 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
Dear Kacper,
Thanks thanks a lot... by combining your and my code I sussed in creating
my derived field. The new code is follows....
@derived_field(name = "MyField")
def my_new_field(field, data):
if np.where(data["MachNumber"] <= 2):
return (.5* data["MachNumber"]) * data["Temperature"]
elif np.where(data["MachNumber"] <= 100):
return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)
else:
return 5.446361E-01
On Mon, Oct 21, 2013 at 4:07 PM, Kacper Kowalik
On 10/21/2013 12:31 PM, Reju Sam John wrote:
Dear Kacper, This is my backtrace....
Traceback (most recent call last): File "cosmic_ray_fra.py", line 50, in <module> p = pc.add_slice("MyField", 2) File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/visualization/plot_collection.py",
line 430, in add_slice center=center, **field_parameters) File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 1058, in __init__ self._refresh_data() File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 320, in _refresh_data self.get_data() File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 859, in get_data if self._generate_field(field): File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
line 362, in _generate_field self[field] = self.pf.field_info[field](self) File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/field_info_container.py",
line 395, in __call__ dd = self._function(self, data) File "cosmic_ray_fra.py", line 32, in my_new_field if data.pf["MachNumber"] < 2: File
"/data1/pdf/csurajit/yt-x86_64/src/yt-hg/yt/data_objects/static_output.py",
line 147, in __getitem__ raise KeyError(key) KeyError: 'MachNumber'
Yeah, that pretty much says that there's no such thing as data.pf["MachNumber"]. Please try the derived field that I've suggested in my previous mail. Cheers, Kacper
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in
creating
a
derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ 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
-- Reju Sam John
Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField")
def my_new_field(field, data):
temp = data["MachNumber"].copy().fill(5.446361E-01)
#print temp
ind = np.where(data["MachNumber"] < 2)
temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1)
ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) < 100)
temp[ind] =
(5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4)
- (3.337557E-1*
((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) +
(4.173271E+0*
((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) -
(9.775620E+0*
((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+
5.455605E+0/(data["MachNumber"][ind])**4
return temp
I am getting this Traceback
line 41, in my_new_field
temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1)
TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
Hi Reju,
On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) < 100) temp[ind] = (5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4) - (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance: temp = data["MachNumber"].copy() temp.fill(5.446361E-01) -Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
wrote: On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
Dear Matt,
Thanks for the help. Now my problem with the code solved. But the slice
plot of the new field has some problem -- white patch are coming as shown
below. What may be the reason?
[image: Inline image 1]
On Sat, Oct 26, 2013 at 7:59 PM, Matthew Turk
Hi Reju,
Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) <
On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
wrote: 100) temp[ind] =
(5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4)
- (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance:
temp = data["MachNumber"].copy() temp.fill(5.446361E-01)
-Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
wrote:
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in
creating
a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
_______________________________________________ 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
-- Reju Sam John
Hi Reju,
The first thing occurs to me is that the area of white patch contains no positive field value, so it can not be plotted in log scale.
Also, about the way of defining a derived field, I might prefer the following way, for example:
@derived_field(name = "MyField")
def my_new_field(field, data):
tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1)
tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3))
tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01
return tmp_data
Best wishes,
Suoqing
On Oct 26, 2013, at 10:27 PM, Reju Sam John
Dear Matt, Thanks for the help. Now my problem with the code solved. But the slice plot of the new field has some problem -- white patch are coming as shown below. What may be the reason?
On Sat, Oct 26, 2013 at 7:59 PM, Matthew Turk
wrote: Hi Reju, On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
wrote: Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) < 100) temp[ind] = (5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4) - (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance:
temp = data["MachNumber"].copy() temp.fill(5.446361E-01)
-Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik
wrote: On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is shown below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
_______________________________________________ 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
-- Reju Sam John _______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
And using suoqing's example, I can control whether or not we should take
the logarithm of a variable in plots:
@derived_field(name = "MyField", take_log=False)
def my_new_field(field, data):
tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1)
tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <=
100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3))
tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01
return tmp_data
If you've already created a plot, you can also disable field logging like
so:
slc = SlicePlot(pf, 0, 'Density')
slc.set_log('Density', False)
-Nathan
On Sat, Oct 26, 2013 at 11:02 PM, Suoqing JI
Hi Reju,
The first thing occurs to me is that the area of white patch contains no positive field value, so it can not be plotted in log scale.
Also, about the way of defining a derived field, I might prefer the following way, for example:
@derived_field(name = "MyField") def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
Best wishes, Suoqing
On Oct 26, 2013, at 10:27 PM, Reju Sam John
wrote: Dear Matt, Thanks for the help. Now my problem with the code solved. But the slice plot of the new field has some problem -- white patch are coming as shown below. What may be the reason?
On Sat, Oct 26, 2013 at 7:59 PM, Matthew Turk
wrote: Hi Reju,
Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) <
On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
wrote: 100) temp[ind] =
(5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4)
- (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance:
temp = data["MachNumber"].copy() temp.fill(5.446361E-01)
-Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik <
xarthisius.kk@gmail.com>
wrote:
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is
shown
below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
_______________________________________________ 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
-- Reju Sam John _______________________________________________ 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
Thanks nathan and suoqing..... Let me try with your suggestions....
On Sun, Oct 27, 2013 at 11:37 AM, Nathan Goldbaum
And using suoqing's example, I can control whether or not we should take the logarithm of a variable in plots:
@derived_field(name = "MyField", take_log=False) def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
If you've already created a plot, you can also disable field logging like so:
slc = SlicePlot(pf, 0, 'Density') slc.set_log('Density', False)
-Nathan
On Sat, Oct 26, 2013 at 11:02 PM, Suoqing JI
wrote: Hi Reju,
The first thing occurs to me is that the area of white patch contains no positive field value, so it can not be plotted in log scale.
Also, about the way of defining a derived field, I might prefer the following way, for example:
@derived_field(name = "MyField") def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
Best wishes, Suoqing
On Oct 26, 2013, at 10:27 PM, Reju Sam John
wrote: Dear Matt, Thanks for the help. Now my problem with the code solved. But the slice plot of the new field has some problem -- white patch are coming as shown below. What may be the reason?
On Sat, Oct 26, 2013 at 7:59 PM, Matthew Turk
wrote: Hi Reju,
On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
wrote: Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) < 100) temp[ind] =
(5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4)
- (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance:
temp = data["MachNumber"].copy() temp.fill(5.446361E-01)
-Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik <
xarthisius.kk@gmail.com>
wrote:
On 10/21/2013 11:10 AM, Reju Sam John wrote:
Dear all,
I would like to create a derived field which should return a value according to specified conditions. My definition of new field is
shown
below.. But it is giving error.
@derived_field(name = "MyField") def my_new_field(field, data): if data.pf["MachNumber"] < 2 : return (.5* (data["MachNumber"])**2) - 1 elif data.pf["MachNumber"] < 100 : return (.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3) else: return 5.446361E-01
Please suggest me how to implement if, elif, else statements in creating a derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
_______________________________________________ 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
-- Reju Sam John _______________________________________________ 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
-- Reju Sam John
Still white patches are coming. I don't know what's the problem.
On Sun, Oct 27, 2013 at 11:46 AM, Reju Sam John
Thanks nathan and suoqing..... Let me try with your suggestions....
On Sun, Oct 27, 2013 at 11:37 AM, Nathan Goldbaum
wrote: And using suoqing's example, I can control whether or not we should take the logarithm of a variable in plots:
@derived_field(name = "MyField", take_log=False) def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
If you've already created a plot, you can also disable field logging like so:
slc = SlicePlot(pf, 0, 'Density') slc.set_log('Density', False)
-Nathan
On Sat, Oct 26, 2013 at 11:02 PM, Suoqing JI
wrote: Hi Reju,
The first thing occurs to me is that the area of white patch contains no positive field value, so it can not be plotted in log scale.
Also, about the way of defining a derived field, I might prefer the following way, for example:
@derived_field(name = "MyField") def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
Best wishes, Suoqing
On Oct 26, 2013, at 10:27 PM, Reju Sam John
wrote: Dear Matt, Thanks for the help. Now my problem with the code solved. But the slice plot of the new field has some problem -- white patch are coming as shown below. What may be the reason?
On Sat, Oct 26, 2013 at 7:59 PM, Matthew Turk
wrote: Hi Reju,
On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
wrote: Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) < 100) temp[ind] =
(5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4)
- (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance:
temp = data["MachNumber"].copy() temp.fill(5.446361E-01)
-Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik <
xarthisius.kk@gmail.com>
wrote:
On 10/21/2013 11:10 AM, Reju Sam John wrote: > Dear all, > > I would like to create a derived field which should return a value > according to specified conditions. My definition of new field is
shown
> below.. But it is giving error. > > > @derived_field(name = "MyField") > def my_new_field(field, data): > if data.pf["MachNumber"] < 2 : > return (.5* (data["MachNumber"])**2) - 1 > elif data.pf["MachNumber"] < 100 : > return (.5* (data["MachNumber"])**4) + (.5* > (data["MachNumber"])**3) > else: > return 5.446361E-01 > > > > Please suggest me how to implement if, elif, else statements in creating > a > derived field.
Hi, your derived fields looks fine (except for missing space in the indentation of the last statement). Could you attach the backtrace?
One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a global parameter with such name defined or you'd rather create a MyField based on local value of "MachNumber" field? If the latter you could try something like this:
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) ind = np.where(data["MachNumber"] < 2) temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 ind = np.where((data["MachNumber"] >= 2) & (data["MachNumber"]) < 100)) temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ 0.5 * data["MachNumber"][ind] ** 3 return temp
Cheers, Kacper
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
-- Reju Sam John
_______________________________________________ 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
-- Reju Sam John _______________________________________________ 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
-- Reju Sam John
-- Reju Sam John
Is the image actually being made in a linear scale now? If not, this is
most likely the problem as your field does have the potential to be
negative.
If the image is being made in a linear scale and you are still seeing white
patches, then I think you need to inspect the values of this field
throughout your data by hand.
Do something like:
ad = pf.h.all_data()
print ad["My_Field"]
You can use this to search for NaNs, zeros, or any sort of numbers that you
don't think you should be getting.
Also, in the future, please use yt_lodgeit.py to upload images to imgur,
then just post the link in your email rather than including the image as an
attachment. The syntax is:
yt_lodgeit.py some_image.png
On Sun, Oct 27, 2013 at 9:02 AM, Reju Sam John
Still white patches are coming. I don't know what's the problem.
On Sun, Oct 27, 2013 at 11:46 AM, Reju Sam John
wrote: Thanks nathan and suoqing..... Let me try with your suggestions....
On Sun, Oct 27, 2013 at 11:37 AM, Nathan Goldbaum
wrote: And using suoqing's example, I can control whether or not we should take the logarithm of a variable in plots:
@derived_field(name = "MyField", take_log=False) def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
If you've already created a plot, you can also disable field logging like so:
slc = SlicePlot(pf, 0, 'Density') slc.set_log('Density', False)
-Nathan
On Sat, Oct 26, 2013 at 11:02 PM, Suoqing JI
wrote: Hi Reju,
The first thing occurs to me is that the area of white patch contains no positive field value, so it can not be plotted in log scale.
Also, about the way of defining a derived field, I might prefer the following way, for example:
@derived_field(name = "MyField") def my_new_field(field, data): tmp_data = (data["MachNumber"] <= 2) * (.5 * data["MachNumber"]**2. - 1) tmp_data = tmp_data + (data["MachNumber"] > 2) * (data["MachNumber"] <= 100) * ((.5* (data["MachNumber"])**4) + (.5* (data["MachNumber"])**3)) tmp_data = tmp_data + (data["MachNumber"] > 100) * 5.446361E-01 return tmp_data
Best wishes, Suoqing
On Oct 26, 2013, at 10:27 PM, Reju Sam John
wrote: Dear Matt, Thanks for the help. Now my problem with the code solved. But the slice plot of the new field has some problem -- white patch are coming as shown below. What may be the reason?
On Sat, Oct 26, 2013 at 7:59 PM, Matthew Turk
wrote: Hi Reju,
On Sat, Oct 26, 2013 at 2:50 AM, Reju Sam John
wrote: Dear Kacper,
My logic was wrong, and yours is right. But with the following code
@derived_field(name = "MyField") def my_new_field(field, data): temp = data["MachNumber"].copy().fill(5.446361E-01) #print temp
ind = np.where(data["MachNumber"] < 2) temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) ind = np.where((data["MachNumber"] >= 2) and (data["MachNumber"]) < 100) temp[ind] =
(5.699327E-1*((data["MachNumber"][ind]-1)**4))/(data["MachNumber"][ind]**4)
- (3.337557E-1* ((data["MachNumber"][ind]-1)**3))/((data["MachNumber"][ind])**4) + (4.173271E+0* ((data["MachNumber"][ind]-1)**2))/((data["MachNumber"][ind])**4) - (9.775620E+0* ((data["MachNumber"][ind]-1)))/((data["MachNumber"][ind])**4)+ 5.455605E+0/(data["MachNumber"][ind])**4 return temp
I am getting this Traceback
line 41, in my_new_field temp[ind] = 1.9564E-3*((data["MachNumber"][ind]**2) - 1) TypeError: 'NoneType' object does not support item assignment
Would you suggest any solution?
I believe the problem is in your .fill() statement. That doesn't return an array, so you need to do it after the assignment. For instance:
temp = data["MachNumber"].copy() temp.fill(5.446361E-01)
-Matt
On Mon, Oct 21, 2013 at 2:58 PM, Kacper Kowalik <
xarthisius.kk@gmail.com>
wrote: > > On 10/21/2013 11:10 AM, Reju Sam John wrote: > > Dear all, > > > > I would like to create a derived field which should return a value > > according to specified conditions. My definition of new field is shown > > below.. But it is giving error. > > > > > > @derived_field(name = "MyField") > > def my_new_field(field, data): > > if data.pf["MachNumber"] < 2 : > > return (.5* (data["MachNumber"])**2) - 1 > > elif data.pf["MachNumber"] < 100 : > > return (.5* (data["MachNumber"])**4) + (.5* > > (data["MachNumber"])**3) > > else: > > return 5.446361E-01 > > > > > > > > Please suggest me how to implement if, elif, else statements in creating > > a > > derived field. > > Hi, > your derived fields looks fine (except for missing space in the > indentation of the last statement). Could you attach the backtrace? > > One thing that's confusing me is 'data.pf["MachNumber"]'. Do you have a > global parameter with such name defined or you'd rather create a MyField > based on local value of "MachNumber" field? > If the latter you could try something like this: > > @derived_field(name = "MyField") > def my_new_field(field, data): > temp = data["MachNumber"].copy().fill(5.446361E-01) > ind = np.where(data["MachNumber"] < 2) > temp[ind] = 0.5 * data["MachNumber"][ind] ** 2 - 1.0 > ind = np.where((data["MachNumber"] >= 2) & > (data["MachNumber"]) < 100)) > temp[ind] = 0.5 * data["MachNumber"][ind] ** 4 + \ > 0.5 * data["MachNumber"][ind] ** 3 > return temp > > > Cheers, > Kacper > > > > _______________________________________________ > yt-users mailing list > yt-users@lists.spacepope.org > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org >
-- Reju Sam John
_______________________________________________ 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
-- Reju Sam John _______________________________________________ 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
-- Reju Sam John
-- Reju Sam John
_______________________________________________ yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
участники (6)
-
Britton Smith
-
Kacper Kowalik
-
Matthew Turk
-
Nathan Goldbaum
-
Reju Sam John
-
Suoqing JI