On Wed, Mar 22, 2017 at 4:27 PM, Jared Coughlin <Jared.W.Coughlin.29@nd.edu> wrote:
Hello! I've modified the Cosmology class is cosmology.py to take a couple of parameters for working with the Linder 2002 parameterization of w(a) = w_0 + w_a (1 - a) in dynamical dark energy, but leaving the cosmological constant as the default choice. However, because the cosmology class is used internally in yt in several places (where it takes its parameters from the dataset object itself), I was thinking it would make the most sense to add these parameters to the dataset object itself so that they could be set when loading data (as they're not actually stored in the simulation output itself).  These parameters are a value for w_0, a value for w_a, and a flag saying whether or not to use dynamical dark energy or the cosmological constant. I tried looking at the yt source code to find where the best place to do this would be, but I just thought I would ask, just to be safe and sure about it.  

So, my question is: what do I need to modify in order to add those three parameters to a generic dataset object (I'm using gadget, but it would be nice if they were independent of simulation code) so that they can then be passed to the cosmology class in yt? Thanks!
-Jared

Currently the Cosmology object gets instantiated here:

https://bitbucket.org/yt_analysis/yt/src/67f6393d8e53528357604621a5b5ad0ffbcc52bb/yt/data_objects/static_output.py?at=yt&fileviewer=file-view-default#static_output.py-966

By that point the `hubble_constant`, `omega_matter`, and `omega_lambda` dataset attributes need to be set. In addition, it looks like `current_redshift` also needs to be known at this point.

It looks like there isn't a single frontend-independent place where this happens. Instead, each frontend sets these attributes if it detects that a dataset is a cosmology simulation and gets the values for the parameters using some frontend-specific implementation. For example, here's where that happens for Enzo:

https://bitbucket.org/yt_analysis/yt/src/67f6393d8e53528357604621a5b5ad0ffbcc52bb/yt/frontends/enzo/data_structures.py?at=yt&fileviewer=file-view-default#data_structures.py-790

and for Gadget:

https://bitbucket.org/yt_analysis/yt/src/67f6393d8e53528357604621a5b5ad0ffbcc52bb/yt/frontends/gadget/data_structures.py?at=yt&fileviewer=file-view-default#data_structures.py-183

In general this seems to happen in `_parse_parameter_file`. So, I guess you'll need to setup default values for the new dataset attributes you'd like to add before `_parse_paremeter_file` gets called. One way to do it would be to make the following modification:

diff --git a/yt/data_objects/static_output.py b/yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -302,6 +302,7 @@ class Dataset(object):

         self._create_unit_registry()
         self._assign_unit_system(unit_system)
+        self._set_default_cosmological_parameters()

         self._parse_parameter_file()
         self.set_units()

And then add an implementation of _set_default_cosmological_parameters to the base Dataset class in static_output.py.

I think eventually we're going to only want to add these cosmology-specific attributes to all datasets (if I'm a geologist looking at some 3d model of the earth's mantle I don't care about the hubble constant), but that's not how it works now so setting default values will make it easier to refactor later. It would also be a nice cleanup to remove places where we set default values for these attributes in all the frontends.
 

_______________________________________________
yt-dev mailing list
yt-dev@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org