[yt-users] MultiVariate volume rendering difficulties

Cameron Hummels chummels at gmail.com
Thu Aug 1 19:39:02 PDT 2013


I agree with Stella's solution, as that's what I've done in the past.
 Obviously you can get some blending between the two CTFs, but that's the
point right?

Cameron


On Thu, Aug 1, 2013 at 2:31 PM, Nathan Goldbaum <nathan12343 at gmail.com>wrote:

> Wow Noel, keep up the awesome work!
>
> I'm sure this will be helpful for Sam when he looks at this stuff next
> week.
>
>
> On Thu, Aug 1, 2013 at 1:53 PM, Noel Scudder <noel.scudder at stonybrook.edu>wrote:
>
>> Hi all,
>>
>> Over the past few days I've been investigating the
>> MultiVariateTransferFunction and receiving feedback from Matt. Since it
>> needs some updating and the documentation is so vague, I thought I'd try to
>> outline the basic flow and idea of an MVTF (thanks to Matt for his
>> outline), address a couple problems that have been noticed, and give an
>> example script with images. Please feel free to correct my mistakes, ask
>> questions, and add your own knowledge!
>>
>> The code for the MVTF is
>> in yt/visualization/volume_rendering/transfer_functions.py . It's also
>> useful to check out the Planck and Color Transfer Functions in the same
>> file.
>>
>> With a CTF, you are limited to one field, which is linked identically to
>> each of the RGB color channels and an alpha channel. However, an MVTF
>> allows you to set up different fields that control each channel and each
>> channel's opacity through the use of standard Transfer Functions. For
>> instance, I could link the red color channel and the red alpha channel to
>> Density, the blue and blue alpha channels to Temperature, and the green and
>> green alpha channels to Kinetic Energy.
>> It is important to note that only *one* field (and associated transfer
>> function) may be linked to any channel. This limits the number of variables
>> one can conceivably include to three.
>>
>> When an MVTF is created, it sets up a few variables:
>>
>> n_field_tables
>> tables
>> field_ids
>> weight_field_ids
>> field_table_ids
>> weight_table_ids
>> grad_field
>> light_source_v
>>
>> The important ones here are tables, field_ids, weight_field_ids,
>> field_table_ids, and weight_table_ids.
>> After creating your MVTF, the first thing you must do is create a
>> TransferFunction, which has some range and number of bins. This can then be
>> added as a "table" to your MVTF using add_field_table, which accepts the
>> table, the field_id used for interpolating on the x-axis of this table, a
>> weight_field_id, and/or a weight_table id.
>> The field_id is *not* the field index you get from pf.h.field_indexes .
>> Here, the field_id actually specifies the index of a certain field in the
>> field list you supply to the camera object. For instance, if I gave the
>> camera
>>
>> fields=['density', 'Temp']
>>
>> I would have previously called add_field_table using a field_id of 0 for
>> the TransferFunctions I wanted for density, and using a field_id of 1 for
>> the TransferFunctions I wanted for temperature.
>> The same specification with the field_id goes for weight_field_id, which
>> is used if the field itself should be a weighting factor for the
>> emission/absorption (although this does not do scaling, so you will likely
>> need to supply a pre-scaled field).
>> By supplying a weight_table_id, you are taking the results of
>> interpolation along the x-axis to get a y value from *another* field table
>> and using that as a weight.
>>
>> *Apparently density is typically logged by default. If you want to use it
>> as a weight, you probably want it un-logged.
>>
>> At this point you have added all of your field tables. The second step is
>> to link the field tables to the channels you want. Right now, all you have
>> is a set of "tables," TransferFunctions that describe how to get a value
>> out as a combination of:
>>
>> 1) The y-value interpolated along the x-axis defined by the table
>> 2) The weighting from a given field
>> 3) The weighting from a given field_table (i.e., if you had some scaling
>> that was a function of temperature)
>>
>> On its own, a table will do nothing--you must link it to a channel. These
>> are, in order, RGB and aR, aG, aB. You use the link_channels function for
>> this purpose, for instance linking table 0 to channel 0 (R). When linking
>> channels, there are a couple things to keep in mind. The two arguments you
>> supply are the  table_id and the channel, both *integers *(seems like a
>> common theme for MVTF stuff :-) ). The channel can be integers 0-5,
>> assigned in the order above. The table_id is a bit more nebulous: a
>> table_id is assigned to a table when it is created, meaning that the first
>> table you create using add_field_table will have a table_id of 0, the next
>> will have a table_id of 1, and so on. Although you cannot link more than
>> one table to a channel, you can have more than one channel linked to a
>> single table--simply supply a list in place of an integer for the channel
>> argument.
>>
>> Finally, don't leave your TransferFunctions empty! Add some gaussians,
>> keeping in mind the channel and field each TF uses. After that your MVTF
>> will be ready, and you can supply it to the camera object like any other
>> transfer function and take a snapshot.
>>
>> Here's a example script: http://pastebin.com/NC4pHPR7
>>
>> Which creates this image: http://i.imgur.com/EKv943G.png
>>
>> The main problem I've been noticing is with the grey_opacity, which was
>> already discussed--apparently the MVTF was never updated after opaque
>> volume rendering was implemented. Although by default an MVTF doesn't have
>> a grey_opacity attribute and yt will complain about this, you can placate
>> the beast by supplying
>>
>> mv.grey_opacity=False
>>
>> anyway. If you set grey_opacity to True, however, odd things will happen,
>> which I suspect is simply due to the MVTF not having been updated for
>> opaque rendering yet: http://i.imgur.com/rrOnbgy.png
>> I think that about sums up my two cents on the MVTF.
>>
>>
>> Finally, my original desire was to have two different
>> ColorTransferFunctions with two different fields rendered by one camera at
>> once. In other words, simultaneously render two different colormaps applied
>> to two different fields. Right now this isn't possible in yt (although Matt
>> thinks it may be somewhat straightforward to implement), so I came up with
>> a makeshift way, where I render one TF for the first field without a
>> background and the second TF for the second field *with* a background,
>> and then overlay them using ImageMagick:
>>
>> im.write_png('transparent_temp.png', background=None)
>> ...
>> im2.write_png('dens_and_background.png')
>> os.system('composite transparent_temp.png dens_and_background.png
>> multi.png')
>>
>> However, it's expensive, and it goes outside yt. Does anyone know if
>> there's a way to combine these images without leaving yt?
>>
>> Thanks for reading!
>>
>> -Noel
>>
>>
>> On Tue, Jul 30, 2013 at 1:03 PM, Sam Skillman <samskillman at gmail.com>wrote:
>>
>>> Hi all,
>>> The multivariate tf could use both some updating and documentation. I'm
>>> offline for the next few days but if it hasn't been fixed by next week I
>>> can take a look.
>>>
>>> Sam
>>> On Jul 30, 2013 8:40 AM, "Nathan Goldbaum" <nathan12343 at gmail.com>
>>> wrote:
>>>
>>>> Hi Noel,
>>>>
>>>> I believe this is a bug that needs to be fixed.  It seems
>>>> MultiVariateTransferFunction was never updated after opaque volume
>>>> rendering was added.
>>>>
>>>> Can you please open a new issue about this?
>>>>
>>>> Nathan
>>>>
>>>> On Tuesday, July 30, 2013, Noel Scudder wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I'm attempting to visualize multiple variables in the same volume
>>>>> rendering. For instance, I'd like to show some density surfaces of a star
>>>>> and then get temperature overlayed to show hotspots. I found the
>>>>> MultiVariateTransferFunction, but it is unfortunately not particularly well
>>>>> documented yet, and I'm being repeatedly thwarted. I'm not sure if I've set
>>>>> it up correctly, or how to go from the transfer function to an image.
>>>>> Here's my current script, using just one variable for now:
>>>>>
>>>>> #----------------------------------
>>>>> from yt.mods import *
>>>>> pf = load('plt00100')
>>>>>
>>>>> #<some constants>
>>>>>
>>>>> pf.h
>>>>> pf.field_info['density'].take_log=True
>>>>>
>>>>> mv = MultiVariateTransferFunction()
>>>>>
>>>>> tf = TransferFunction((mi-1, ma+1), nbins=1.0e6)
>>>>> tf.add_gaussian(np.log10(9.0e5), 0.01, 1.0)
>>>>>
>>>>> mv.add_field_table(tf, 0)
>>>>> mv.link_channels(0, [0,1,2,3])
>>>>>
>>>>> c = [5.0e9, 5.0e9, 5.0e9]
>>>>> L = [0.15, 1.0, 0.40]
>>>>> W = wi*0.7
>>>>> Nvec = 1024
>>>>>
>>>>> cam = pf.h.camera(c, L, W, (Nvec,Nvec), transfer_function = mv,
>>>>>                              fields=['density'], pf=pf, no_ghost=True)
>>>>>
>>>>> im = cam.snapshot(num_threads=4)
>>>>>
>>>>> im.write_png('plt00100.png' )
>>>>> #----------------------------------
>>>>>
>>>>> I checked to make sure density is indeed my 0-index field. I get the
>>>>> following error after ray casting:
>>>>>
>>>>> Traceback (most recent call last):
>>>>>   File "<stdin>", line 1, in <module>
>>>>>   File "multivol.py", line 153, in <module>
>>>>>     im = cam.snapshot(num_threads=4)
>>>>>   File
>>>>> "/home/noel/shocks/yt-x86_64/src/yt-hg/yt/visualization/volume_rendering/camera.py",
>>>>> line 742, in snapshot
>>>>>     image, sampler),
>>>>>   File
>>>>> "/home/noel/shocks/yt-x86_64/src/yt-hg/yt/visualization/volume_rendering/camera.py",
>>>>> line 632, in _render
>>>>>     image = self.finalize_image(image)
>>>>>   File
>>>>> "/home/noel/shocks/yt-x86_64/src/yt-hg/yt/visualization/volume_rendering/camera.py",
>>>>> line 611, in finalize_image
>>>>>     if self.transfer_function.grey_opacity is False:
>>>>> AttributeError: 'MultiVariateTransferFunction' object has no attribute
>>>>> 'grey_opacity'
>>>>>
>>>>>
>>>>> Can I not use snapshot in this case, or is something else the matter
>>>>> entirely?
>>>>>
>>>>> Thanks,
>>>>> Noel Scudder
>>>>>
>>>>
>>>> _______________________________________________
>>>> yt-users mailing list
>>>> yt-users at lists.spacepope.org
>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>>
>>>>
>>> _______________________________________________
>>> yt-users mailing list
>>> yt-users at lists.spacepope.org
>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>
>>>
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>


-- 
Cameron Hummels
Postdoctoral Researcher
Steward Observatory
University of Arizona
http://chummels.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20130801/3eb8ad04/attachment.htm>


More information about the yt-users mailing list