<div>We should have a nicer API for this. Something like astropy's def_unit:</div><div><br></div><div><a href="http://docs.astropy.org/en/stable/api/astropy.units.def_unit.html#astropy.units.def_unit">http://docs.astropy.org/en/stable/api/astropy.units.def_unit.html#astropy.units.def_unit</a><br></div><div><br><div class="gmail_quote"><div>On Thu, Jan 5, 2017 at 7:48 AM John ZuHone <<a href="mailto:jzuhone@gmail.com">jzuhone@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">Hi Axel,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">You can assign new symbols as well. It sounds like you want to do this for a number of datasets, so you could define new symbols and add them to yt’s unit registry (though you could also add them to a specific dataset’s unit registry). To do the former, you could do something like this in your plugins [1] file (which would ensure they got loaded every time you used yt):</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">```python</div><div class="gmail_msg">from yt.units.unit_object import default_unit_registry</div><div class="gmail_msg">from yt.units import dimensions</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">default_unit_registry.add("lambda_0", 8.0e-5, dimensions.length, 0.0, r"$\lambda_0$")</div><div class="gmail_msg">default_unit_registry.add("omega_pe", 1.0e15, dimensions.rate, 0.0, r"$\omega_\text{pe}$") </div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The arguments in .add are the name of the symbol, the conversion to CGS+Ampere, the dimensions of the unit, the unit offset (only used for temperature and angle units), and the last is the LaTeX representation. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Note that I defined omega_pe as a rate, so you’d have to use its inverse when creating your unit system to define the base time units.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">And yes, as I mentioned above the internal base by which all yt units reference is cgs units + Amperes for current (for historical reasons, mostly). </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Best,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">John</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">[1] <a href="http://yt-project.org/doc/reference/configuration.html#the-plugin-file" class="gmail_msg" target="_blank">http://yt-project.org/doc/reference/configuration.html#the-plugin-file</a></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 5, 2017, at 8:24 AM, Axel Huebl <<a href="mailto:a.huebl@hzdr.de" class="gmail_msg" target="_blank">a.huebl@hzdr.de</a>> wrote:</div><br class="m_6248936637519617806Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Ha, I oversaw a link in [1] linking to [2].<br class="gmail_msg"><br class="gmail_msg">Ok, so I can just specify my own unit system in user-code with that.<br class="gmail_msg">But anyhow, I can't assign it new symbols. Also, do all conversion<br class="gmail_msg">factors need to go through CGS?<br class="gmail_msg"><br class="gmail_msg">Also, microns turns out to be<br class="gmail_msg">   .in_units("um")<br class="gmail_msg">:)<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">Axel<br class="gmail_msg"><br class="gmail_msg">[2] <a href="http://yt-project.org/docs/dev/analyzing/units/unit_systems.html" class="gmail_msg" target="_blank">http://yt-project.org/docs/dev/analyzing/units/unit_systems.html</a><br class="gmail_msg"><br class="gmail_msg">On 05.01.2017 13:59, Axel Huebl wrote:<br class="gmail_msg"><blockquote type="cite" class="gmail_msg">Hi yt-devs!<br class="gmail_msg"><br class="gmail_msg">I have a quick user-question (sorry) and a devel question:<br class="gmail_msg"><br class="gmail_msg">First, how to convert to a unit like microns (10^-6 meters) or<br class="gmail_msg">pico-seconds? I can't find an example here [1]. I tried<br class="gmail_msg"><br class="gmail_msg">  .in_units("mum")<br class="gmail_msg">  .in_units("mu m)<br class="gmail_msg">  .in_units("1.e-6 m")<br class="gmail_msg">  .in_units("microns")<br class="gmail_msg">  .in_units("micro meter")<br class="gmail_msg">  .in_units("micro meters")<br class="gmail_msg">  .in_units("micro m")<br class="gmail_msg">  .in_units("μm")<br class="gmail_msg"><br class="gmail_msg">and only<br class="gmail_msg">  .in_units("1.e-6 * m")<br class="gmail_msg"><br class="gmail_msg">does not fail but looks ugly.<br class="gmail_msg"><br class="gmail_msg">An orthogonal question: in our domain (laser-plasma physics) unit<br class="gmail_msg">systems are scaled by something like the applied laser wavelength or the<br class="gmail_msg">plasma density (and more to make a full set).<br class="gmail_msg"><br class="gmail_msg">Following again [1] I would implement something like .in_base('plasma')<br class="gmail_msg">or .in_base('laserplasma') but those are not scaled to "fixed" reference<br class="gmail_msg">quantities as the other base systems but are depending on either user input<br class="gmail_msg">  [ length = ("$\lambda_0$", "800 nm"),<br class="gmail_msg">    time   = ("$\omega_\text{pe}^{-1}$", "1.e-15 s"),<br class="gmail_msg">     ...]<br class="gmail_msg">or alternatively scalings the data file already provided. (Ok, the<br class="gmail_msg">symbol is always fixed per "in_base" but the value to scale with needs<br class="gmail_msg">to be provided.)<br class="gmail_msg"><br class="gmail_msg">Is that already possible or any ideas how we could implement that?<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">Thanks,<br class="gmail_msg">Axel<br class="gmail_msg"><br class="gmail_msg">[1]<br class="gmail_msg"><a href="http://yt-project.org/docs/dev/analyzing/units/fields_and_unit_conversion.html#data-selection-and-fields" class="gmail_msg" target="_blank">http://yt-project.org/docs/dev/analyzing/units/fields_and_unit_conversion.html#data-selection-and-fields</a><br class="gmail_msg"><br class="gmail_msg"></blockquote><br class="gmail_msg">-- <br class="gmail_msg"><br class="gmail_msg">Axel Huebl<br class="gmail_msg">Phone +49 351 260 3582<br class="gmail_msg"><a href="https://www.hzdr.de/crp" class="gmail_msg" target="_blank">https://www.hzdr.de/crp</a><br class="gmail_msg">Computational Radiation Physics<br class="gmail_msg">Laser Particle Acceleration Division<br class="gmail_msg">Helmholtz-Zentrum Dresden - Rossendorf e.V.<br class="gmail_msg"><br class="gmail_msg">Bautzner Landstrasse 400, 01328 Dresden<br class="gmail_msg">POB 510119, D-01314 Dresden<br class="gmail_msg">Vorstand: Prof. Dr.Dr.h.c. R. Sauerbrey<br class="gmail_msg">          Prof. Dr.Dr.h.c. P. Joehnk<br class="gmail_msg">VR 1693 beim Amtsgericht Dresden<br class="gmail_msg">_______________________________________________<br class="gmail_msg">yt-dev mailing list<br class="gmail_msg"><a href="mailto:yt-dev@lists.spacepope.org" class="gmail_msg" target="_blank">yt-dev@lists.spacepope.org</a><br class="gmail_msg"><a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" class="gmail_msg" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br class="gmail_msg"></div></div></blockquote></div><br class="gmail_msg"></div></div>_______________________________________________<br class="gmail_msg"><br>yt-dev mailing list<br class="gmail_msg"><br><a href="mailto:yt-dev@lists.spacepope.org" class="gmail_msg" target="_blank">yt-dev@lists.spacepope.org</a><br class="gmail_msg"><br><a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br class="gmail_msg"><br></blockquote></div></div>