[yt-users] override code units

Yingchao Lu yingchao.lu at rice.edu
Fri Feb 17 12:03:52 PST 2017


Hi Nathan,

 

Thanks. ds.field_info shows

 

------------------begin------------------------------------------------------------------------

{('flash', 'abar'): <yt.fields.derived_field.DerivedField at 0xb4f5828>,

('flash', u'cham'): <yt.fields.derived_field.DerivedField at 0xb35c4a8>,

('flash', u'dens'): <yt.fields.derived_field.DerivedField at 0xb35c1d0>,

('flash', u'depo'): <yt.fields.derived_field.DerivedField at 0xb35c400>,

('flash', 'edens'): <yt.fields.derived_field.DerivedField at 0xb4f57b8>,

('flash', u'eint'): <yt.fields.derived_field.DerivedField at 0xb4f5748>,

('flash', u'magp'): <yt.fields.derived_field.DerivedField at 0xb35ca58>,

('flash', u'magz'): <yt.fields.derived_field.DerivedField at 0xb35ca90>,

('flash', 'nele'): <yt.fields.derived_field.DerivedField at 0xb4f5780>,

('flash', 'nion'): <yt.fields.derived_field.DerivedField at 0xb4f57f0>,

('flash', u'pres'): <yt.fields.derived_field.DerivedField at 0xb35cac8>,

('flash', u'sumy'): <yt.fields.derived_field.DerivedField at 0xb35cb70>,

('flash', u'targ'): <yt.fields.derived_field.DerivedField at 0xb35ccf8>,

('flash', u'tele'): <yt.fields.derived_field.DerivedField at 0xb35cba8>,

('flash', u'tion'): <yt.fields.derived_field.DerivedField at 0xb35cb38>,

('flash', u'velx'): <yt.fields.derived_field.DerivedField at 0xb35cd30>,

('flash', u'vely'): <yt.fields.derived_field.DerivedField at 0xb35cd68>,

('flash', u'ye'): <yt.fields.derived_field.DerivedField at 0xb35cdd8>,

('gas',

  'H_nuclei_density'): <yt.fields.derived_field.DerivedField at 0xb556ba8>,

('gas',

  'He_nuclei_density'): <yt.fields.derived_field.DerivedField at 0xb556be0>,

('gas',

  'averaged_density'): <yt.fields.derived_field.DerivedField at 0xb54b7f0>,

('gas', 'cell_mass'): <yt.fields.derived_field.DerivedField at 0xb549e48>,

('gas', 'density'): <yt.fields.derived_field.DerivedField at 0xb35c9b0>,

('gas',

  'density_gradient_z'): <yt.fields.derived_field.DerivedField at 0xb54b668>,

('gas',

  'dynamical_time'): <yt.fields.derived_field.DerivedField at 0xb52a390>,

('gas', 'mach_number'): <yt.fields.derived_field.DerivedField at 0xb549f28>,

('gas',

  'magnetic_field_z'): <yt.fields.derived_field.DerivedField at 0xb35cb00>,

('gas',

  'mean_molecular_weight'): <yt.fields.derived_field.DerivedField at 0xb54b0b8>,

('gas',

  'number_density'): <yt.fields.derived_field.DerivedField at 0xb4f5860>,

('gas', 'pressure'): <yt.fields.derived_field.DerivedField at 0x440a630>,

('gas',

  'pressure_gradient_z'): <yt.fields.derived_field.DerivedField at 0xb54b320>,

('gas', 'shear_mach'): <yt.fields.derived_field.DerivedField at 0xb556048>,

('gas', 'sound_speed'): <yt.fields.derived_field.DerivedField at 0xb549e80>,

('gas', 'sz_kinetic'): <yt.fields.derived_field.DerivedField at 0xb526128>,

('gas',

  'thermal_energy'): <yt.fields.derived_field.DerivedField at 0xb35c9e8>,

('gas', 'total_energy'): <yt.fields.derived_field.DerivedField at 0xb0e4198>,

('gas',

  'velocity_magnitude'): <yt.fields.derived_field.DerivedField at 0xb526b70>,

('gas', 'velocity_x'): <yt.fields.derived_field.DerivedField at 0xb35cda0>,

('gas', 'velocity_y'): <yt.fields.derived_field.DerivedField at 0xb35ce10>,

('index', 'cell_volume'): <yt.fields.derived_field.DerivedField at 0xb0e40b8>,

('index', 'dr'): <yt.fields.derived_field.DerivedField at 0xb35cf28>,

('index', 'dtheta'): <yt.fields.derived_field.DerivedField at 0xb0e4048>,

('index', 'dz'): <yt.fields.derived_field.DerivedField at 0xb35cf98>,

('index',

  'grid_indices'): <yt.fields.derived_field.DerivedField at 0xb556278>,

('index', 'grid_level'): <yt.fields.derived_field.DerivedField at 0xb556198>,

('index', 'ones'): <yt.fields.derived_field.DerivedField at 0xb556320>,

('index',

  'path_element_r'): <yt.fields.derived_field.DerivedField at 0xb0e40f0>,

('index',

  'path_element_theta'): <yt.fields.derived_field.DerivedField at 0xb0e4128>,

('index',

  'path_element_z'): <yt.fields.derived_field.DerivedField at 0xb0e4160>,

('index', 'r'): <yt.fields.derived_field.DerivedField at 0xb35cf60>,

('index', 'theta'): <yt.fields.derived_field.DerivedField at 0xb0e4080>,

('index', 'z'): <yt.fields.derived_field.DerivedField at 0xb35cfd0>,

('index', 'zeros'): <yt.fields.derived_field.DerivedField at 0xb5562e8>}

--------------------end----------------------------------------------------------------------------

 

 

I found the universal field for ‘magz’ is 'magnetic_field_z', but  none for ‘nele’. It seems the following work well

 

--------------------begin----------------------------------------------------------------------------

import yt

from yt import derived_field

from yt import units

 

@derived_field(name="nele", units="cm**-3", force_override=True)

def _nele(field, data):

    Na = yt.physical_constants.Na

    Na_code = data.ds.quan(Na, 'code_length**3/cm**3/code_mass')

    return data["flash","dens"]*data["flash","ye"]*Na_code

 

ds = yt.load('LLEMagnetizedJet2D_hdf5_plt_cnt_0000')

print ds.point([0,0,0])['magnetic_field_z']

print ds.point([0,0,0])['nele']

------------------end------------------------------------------------------------------------------

 

The output:

--------------begin---------------------------------------------------------------------------

[ 0.] sqrt(g)/(sqrt(cm)*s)

[  3.00911334e+16] cm**(-3)

---------------end---------------------------------------------------------------------------

 

I do not know if this is a good way.

 

Thank you,

Yingchao

 

 

From: Nathan Goldbaum [mailto:nathan12343 at gmail.com] 
Sent: Friday, February 17, 2017 12:07 PM
To: Discussion of the yt analysis package <yt-users at lists.spacepope.org>; yingchao.lu at rice.edu
Subject: Re: [yt-users] override code units

 

Hi,

 

On-disk fields are always presented in code units. As you saw, for your data you've specified that code units *are* cgs, however that doesn't change the rule that I -disk fields are presented using code units.

 

To get fields that are presented in CGS, you should use "universal" field names. Unfortunately I'm on my phone right now so I can't look up the universal field names for those two fields.

 

Finally, you can always convert to CGS:

 

ds.point([0,0,0])['magz'].to('G')

 

On Fri, Feb 17, 2017 at 11:55 AM Yingchao Lu <yingchao.lu at rice.edu <mailto:yingchao.lu at rice.edu> > wrote:

Hi All,

 

My simulation seems to have no detail information on units, so I want to assign cgs to the output. However, when I do the following 

 

---------------------------------------------------------------------

import yt

units_override = {"length_unit":(1.0,"cm"),

                  "time_unit":(1.0,"s"),

                  "mass_unit":(1.0,"g"),

                  'nele_unit': (1.0, "cm**-3"),

                 "magnetic_unit":(1.0,"gauss")}

ds = yt.load('flash_hdf5_plt_cnt_0000', units_override=units_override)

print ds.point([0,0,0])['magz']

print ds.point([0,0,0])['nele']

---------------------------------------------------------------------

 

 

The output is:

---------------------------------------------------------------------

[ 0.] code_magnetic

[  2.87595814e+15] code_length**(-3)

---------------------------------------------------------------------

 

How can I get:

---------------------------------------------------------------------

[ 0.] gauss

[  2.87595814e+15] cm**(-3)

---------------------------------------------------------------------

 

 

Thanks,

Yingchao

_______________________________________________
yt-users mailing list
yt-users at lists.spacepope.org <mailto: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/20170217/b73b68dc/attachment-0001.htm>


More information about the yt-users mailing list