Newly defined unit not registered

I am trying to change flux units to Jansky, but I run into an error. Mor specifically I am starting from a FLASH hdf5 output, computing some flux and trying to have it plotted in Jansky instead of SI units. Here are the relevant code lines:
import yt
... LFLY = YTArray(1.0/cosmo.hubble_constant.value,"Mpc").in_cgs() TFLY = (2./3./cosmo.hubble_constant).in_cgs() MFLY = YTArray(5.23e12/cosmo.hubble_constant.value,"Msun").in_cgs() uo = {"length_unit":LFLY, "time_unit":TFLY, "mass_unit":MFLY} .... yt.add_field(("gas", "i_nu"), function=_i_nu, units="W/(m**2)/Hz", sampling_type='cell', display_name="Synchr. emission", force_override=True, validators=[ValidateParameter(['lmin', 'l.o.s.', 'lmin origin', 'Background I_nu', 'Electron p-law index', 'b(p)', 'E_min', 'E_max', 'Magnetic field','nu (Ghz)'])]) .... ds=yt.load(<hdf5 output>,units_override=uo) ds.define_unit("Jansky", (1.e-26, "W/(m**2)/Hz")) .... rg=ds.region([0.,0.,0.],[-0.05,-0.05,-0.1],[0.05,0.05,0.1]) .... plt_synchr = yt.OffAxisSlicePlot(ds,n_dir,'i_nu', width=((40,'kpc'),(100,'kpc')),north_vector=north, data_source=rg) ... plt_synchr.set_unit('i_nu','Jansky')
Here I get the error:
yt.units.unit_registry.UnitParseError: Could not find unit symbol 'Jansky' in the provided symbols.
I had understood that define_unit also registers the newly defined unit: what is going wrong here? Many thanks in advance.

Hi Vincenzo, I am actually having trouble reproducing your issue with the following minimal example: import yt uo = {"length_unit": (1.0,"Mpc"), "mass_unit":(1.0e10,"Msun"), "time_unit":(1.0,"Gyr")} ds = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150", units_override=uo) ds.define_unit(“myJansky", (1.e-26, "W/(m**2)/Hz”)) then I try to use the unit and it works. The reason I did not define the unit as “Jansky” is that unit is already in yt: import yt print(yt.YTQuantity(1.0,"Jansky").to("W/m**2/Hz”)) gives: unyt_quantity(1.e-26, 'W/(Hz*m**2)') Which version of yt are you using?
On Jul 10, 2021, at 11:09 AM, vincenzo.antonuccio@inaf.it wrote:
I am trying to change flux units to Jansky, but I run into an error. Mor specifically I am starting from a FLASH hdf5 output, computing some flux and trying to have it plotted in Jansky instead of SI units. Here are the relevant code lines:
import yt
... LFLY = YTArray(1.0/cosmo.hubble_constant.value,"Mpc").in_cgs() TFLY = (2./3./cosmo.hubble_constant).in_cgs() MFLY = YTArray(5.23e12/cosmo.hubble_constant.value,"Msun").in_cgs() uo = {"length_unit":LFLY, "time_unit":TFLY, "mass_unit":MFLY} .... yt.add_field(("gas", "i_nu"), function=_i_nu, units="W/(m**2)/Hz", sampling_type='cell', display_name="Synchr. emission", force_override=True, validators=[ValidateParameter(['lmin', 'l.o.s.', 'lmin origin', 'Background I_nu', 'Electron p-law index', 'b(p)', 'E_min', 'E_max', 'Magnetic field','nu (Ghz)'])]) .... ds=yt.load(<hdf5 output>,units_override=uo) ds.define_unit("Jansky", (1.e-26, "W/(m**2)/Hz")) .... rg=ds.region([0.,0.,0.],[-0.05,-0.05,-0.1],[0.05,0.05,0.1]) .... plt_synchr = yt.OffAxisSlicePlot(ds,n_dir,'i_nu', width=((40,'kpc'),(100,'kpc')),north_vector=north, data_source=rg) ... plt_synchr.set_unit('i_nu','Jansky')
Here I get the error:
yt.units.unit_registry.UnitParseError: Could not find unit symbol 'Jansky' in the provided symbols.
I had understood that define_unit also registers the newly defined unit: what is going wrong here? Many thanks in advance. _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: jzuhone@gmail.com

Hi Vincenzo, I am guessing it will--I haven’t had the chance yet to check to see if this was an issue that was fixed between 3.6.1 and 4.0 or not. For FLASH datasets I do not expect any major issues with backwards-compatibility. John
On Jul 13, 2021, at 9:35 AM, vincenzo.antonuccio@inaf.it wrote:
John Zuhone wrote:
Which version of yt are you using?
I am using v. 3.6.1. I saw the very recent announcement concerning v. 4.0.0: you are confident that an update (besides possible issues with backward compatibility) could solve the problem? _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: jzuhone@gmail.com
participants (3)
-
John Zuhone
-
John ZuHone
-
vincenzo.antonuccio@inaf.it