<div dir="ltr"><div>Hi Ashley,</div><div><br></div><div>That depends on the star formation rate prescription you are using. The formula in the cookbook recipe calculates the star formation rate based on the masses of particles that formed over a small time period in the past. The star formation rate calculated by the recipe in a given time bin is the initial masses of star particles that formed in that bin divided by the width of the time bin. In the limit where the width of the time bin goes to zero, the instantaneous star formation rate and the star formation rate you measure through this method should agree.<br></div><div><br></div><div>If your star particles participate in a feedback algorithm and lose mass or change mass for any other reason, that would impact the star formation rates one would measure with this algorithm. In this case, one should use the original mass of the star particles, which would need to be recorded somehow if the masses of newly formed star particles aren't known a priori.</div><div><br></div><div>A good check to make sure you're getting the right answer is to compute the instantaneous star formation rate in a snapshot early in the simulation and compare it with the star formation rate you measured at the time of that snapshot based on the star particles present in the *final* snapshot. Assuming that you are forming lots of star particles in a given time bin and that your star formation algorithm is stochastic, these numbers should match closely although you will likely not get perfect agreement.<br></div><div><br></div><div>For example, see Figure 1 of my 2015 paper (<a href="http://adsabs.harvard.edu/abs/2015ApJ...814..131G">http://adsabs.harvard.edu/abs/2015ApJ...814..131G</a>). The code used to generate the figure is available in these two notebooks:</div><div><br></div><div><a href="http://nbviewer.jupyter.org/urls/bitbucket.org/ngoldbaum/galaxy_analysis/raw/db50e8f3ae7ea78ba215d5ce1295085c5305f86e/helper_scripts/sfr.ipynb">http://nbviewer.jupyter.org/urls/bitbucket.org/ngoldbaum/galaxy_analysis/raw/db50e8f3ae7ea78ba215d5ce1295085c5305f86e/helper_scripts/sfr.ipynb</a></div><div><a href="http://nbviewer.jupyter.org/urls/bitbucket.org/ngoldbaum/galaxy_analysis/raw/db50e8f3ae7ea78ba215d5ce1295085c5305f86e/helper_scripts/sfr_figure.ipynb">http://nbviewer.jupyter.org/urls/bitbucket.org/ngoldbaum/galaxy_analysis/raw/db50e8f3ae7ea78ba215d5ce1295085c5305f86e/helper_scripts/sfr_figure.ipynb</a></div><div><br></div><div>Note that this paper did not include the effects of feedback, so there isn't any attempt to correct for the fact that the masses of star particles. However, for my 2016 paper I did account for that effect and just used the fixed 300 solar masses each new star particle in my simulation is created with. See Figure 3 of my 2016 paper (<a href="http://adsabs.harvard.edu/abs/2016ApJ...827...28G">http://adsabs.harvard.edu/abs/2016ApJ...827...28G</a>) and this notebook:</div><div><br></div><div><a href="http://nbviewer.jupyter.org/urls/bitbucket.org/ngoldbaum/galaxy_analysis/raw/db50e8f3ae7ea78ba215d5ce1295085c5305f86e/helper_scripts/star_formation_plot.ipynb">http://nbviewer.jupyter.org/urls/bitbucket.org/ngoldbaum/galaxy_analysis/raw/db50e8f3ae7ea78ba215d5ce1295085c5305f86e/helper_scripts/star_formation_plot.ipynb</a><br></div><div><br></div><div>Hope that's helpful,</div><div><br></div><div>Nathan<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 5, 2017 at 9:13 AM,  <span dir="ltr"><<a href="mailto:ajarvis@star.sr.bham.ac.uk" target="_blank">ajarvis@star.sr.bham.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nathan,<br>
<br>
I managed to implement the filter definition that you provided, but I have<br>
come across another problem. When I try to generate the SFR plots for the<br>
simulation at different time steps, there is always a sharp decline in the<br>
rate around 25Myr before the output time of the data dump (see attached<br>
plots).<br>
<br>
Is this happening because of something in the simulation itself, e.g.<br>
there is a delay between the region reaching a given density limit and the<br>
star particle actually being created (to represent the formation time of<br>
the stars), or is it being caused by something in the yt plotting process?<br>
<br>
Many thanks,<br>
Ashley<br>
<br>
<br>
<a href="https://i.imgur.com/mjCQvZy.png" rel="noreferrer" target="_blank">https://i.imgur.com/mjCQvZy.<wbr>png</a><br>
<a href="https://i.imgur.com/Cv5D1HK.png" rel="noreferrer" target="_blank">https://i.imgur.com/Cv5D1HK.<wbr>png</a><br>
<a href="https://i.imgur.com/6ZA2xgq.png" rel="noreferrer" target="_blank">https://i.imgur.com/6ZA2xgq.<wbr>png</a><br>
<span class=""><br>
<br>
<br>
> On Wed, Sep 13, 2017 at 7:58 AM, Ashley Jarvis<br>
> <<a href="mailto:ajarvis@star.sr.bham.ac.uk">ajarvis@star.sr.bham.ac.uk</a>><br>
> wrote:<br>
><br>
>> Thanks for your help. I have submitted a new issue about the<br>
>> documentation<br>
>> problem as you suggested.<br>
>><br>
</span>>> I have used the other example to produce a plot, but I’m not sure if<br>
<div><div class="h5">>> the<br>
>> particles are being filtered correctly. I am using Enzo simulation data.<br>
>> I<br>
>> think I want to select all particles that are stars, and then only keep<br>
>> those that have a creation time greater than 0; I am unsure how to do<br>
>> this.<br>
>> Is it possible to combine two conditions within the filter definition?<br>
>><br>
><br>
> Yup, you can combine boolean arrays using boolean operators in Numpy. For<br>
> your problem it would look like this:<br>
><br>
>     def formed_star(pfilter, data):<br>
>         # identify stars (particle_type 2) that have creation times after<br>
> the beginning<br>
>         # of the simulation<br>
>         filter = (data["all", "creation_time"] > 0) & (data['all',<br>
> 'particle_type'] == 2)<br>
>         return filter<br>
><br>
> -Nathan<br>
><br>
><br>
>> Many thanks,<br>
>> Ashley<br>
>><br>
>><br>
>><br>
>> On 12 Sep 2017, at 21:57, <a href="mailto:nathan12343@gmail.com">nathan12343@gmail.com</a> wrote:<br>
>><br>
>> Hi Ashley,<br>
>><br>
>> Unfortunately Stephanie's suggestion won't work, since units like Mpccm,<br>
>> which depend on details of the dataset, aren't available in yt.units. In<br>
>> particular the conversion from comoving megaparsecs to physical units<br>
>> depends on redshift and assumed cosmology.<br>
>><br>
>> I think what's happening here is that you are dealing with a<br>
>> non-cosmological simulation which does not have Mpccm defined.<br>
>><br>
>> It looks like yt's StarFormationRate class that you're trying to use<br>
>> assumes that it's being passed an output from a cosmological simulation<br>
>> and<br>
>> is failing in a less than graceful fashion when you try pass a<br>
>> non-cosmological output. We should probably emphasize more in the<br>
>> documentation that StarFormationRate only accepts a cosmological output<br>
>> (or<br>
>> improve it so that it *can* work with non-cosmological outputs) and<br>
>> improve<br>
>> the error message you saw. If you'd like to file an issue about this<br>
>> documentation problem (at <a href="https://github.com/yt-project/yt/issues/new" rel="noreferrer" target="_blank">https://github.com/yt-project/<wbr>yt/issues/new</a>)<br>
>> that<br>
>> will help us to avoid losing track of this deficiency.<br>
>><br>
>> Rather than using the StarFormationRate class, I'd suggest looking at<br>
>> this<br>
>> example in the cookbook section of the docs:<br>
>><br>
>> <a href="http://yt-project.org/doc/cookbook/calculating_information" rel="noreferrer" target="_blank">http://yt-project.org/doc/<wbr>cookbook/calculating_<wbr>information</a>.<br>
>> html#using-particle-filters-<wbr>to-calculate-star-formation-<wbr>rates<br>
>><br>
>> To adapt that example for your data, you're going to need to figure out<br>
>> how to select the star particles in your simulation and then either<br>
>> adapt<br>
>> the particle filter definition in the example for your data, or if you<br>
>> are<br>
>> using a frontend like Gadget where the output format defines a star<br>
>> particle type, just use that instead of the particle filter. The rest of<br>
>> the cookbook recipe just uses numpy to bin the star particle ages<br>
>> according<br>
>> to the formation time of the particle, and then backs out the star<br>
>> formation rate history.<br>
>><br>
>> Hope that helps,<br>
>><br>
>> Nathan<br>
>><br>
>> On Tue, Sep 12, 2017 at 3:23 PM Stephanie Tonnesen <<a href="mailto:stonnes@gmail.com">stonnes@gmail.com</a>><br>
>> wrote:<br>
>><br>
>>> I am not sure, but the first thing I would do would be to add<br>
>>><br>
>>> from yt.units import Mpccm<br>
>>><br>
>>> At the top and see what happens next.<br>
>>><br>
>>> Best,<br>
>>> Stephanie<br>
>>><br>
>>> On Tue, Sep 12, 2017 at 11:36 AM Ashley Jarvis <<br>
>>> <a href="mailto:ajarvis@star.sr.bham.ac.uk">ajarvis@star.sr.bham.ac.uk</a>> wrote:<br>
>>><br>
>>>> Hi all,<br>
>>>><br>
</div></div>>>>> I’m attempting to adapt the example script for plotting star<br>
<span class="">>>>> formation<br>
>>>> rates (found at <a href="http://yt-project.org/doc/a" rel="noreferrer" target="_blank">http://yt-project.org/doc/a</a><br>
>>>> nalyzing/analysis_modules/<wbr>star_analysis.html#star-<wbr>formation-rate) to<br>
>>>> work with output data from a simulation run using Enzo. However, when<br>
>>>> I<br>
>>>> attempt to run the script, I get the following error:<br>
>>>><br>
</span>>>>> â€”—————————<wbr>—————————<br>
<div><div class="h5">>>>><br>
>>>> File "PlotSFR.py", line 26, in <module><br>
>>>>     sfr = StarFormationRate(data, star_mass=mass_old,<br>
>>>> star_creation_time=ct_old, volume=sp.volume())<br>
>>>>   File "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>analysis<br>
>>>> _modules/star_analysis/sfr_<wbr>spectrum.py", line 115, in __init__<br>
>>>>     self._ds.quan(1.0, 'Mpccm**3').units<br>
>>>>   File<br>
>>>> "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>units/yt_array.py",<br>
>>>> line 1355, in __new__<br>
>>>>     dtype=dtype, bypass_validation=bypass_<wbr>validation)<br>
>>>>   File<br>
>>>> "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>units/yt_array.py",<br>
>>>> line 430, in __new__<br>
>>>>     units = Unit(input_units, registry=registry)<br>
>>>>   File<br>
>>>> "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>units/unit_object.py",<br>
>>>> line 257, in __new__<br>
>>>>     unit_data = _get_unit_data_from_expr(unit_<wbr>expr, registry.lut)<br>
>>>>   File<br>
>>>> "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>units/unit_object.py",<br>
>>>> line 572, in _get_unit_data_from_expr<br>
>>>>     unit_data = _get_unit_data_from_expr(unit_<wbr>expr.args[0],<br>
>>>> unit_symbol_lut)<br>
>>>>   File<br>
>>>> "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>units/unit_object.py",<br>
>>>> line 566, in _get_unit_data_from_expr<br>
>>>>     return _lookup_unit_symbol(str(unit_<wbr>expr), unit_symbol_lut)<br>
>>>>   File<br>
>>>> "/usr/local/anaconda/lib/<wbr>python2.7/site-packages/yt/<wbr>units/unit_object.py",<br>
>>>> line 657, in _lookup_unit_symbol<br>
>>>>     "symbols." % symbol_str)<br>
>>>> yt.units.unit_registry.<wbr>UnitParseError: Could not find unit symbol<br>
>>>> 'Mpccm' in the provided symbols.<br>
>>>><br>
</div></div>>>>> â€”—————————<wbr>—————————<br>
<div class="HOEnZb"><div class="h5">>>>><br>
>>>> I am using version 3.3.5 of yt.<br>
>>>><br>
>>>> Does anyone know how I can resolve this? Any suggestions would be<br>
>>>> greatly appreciated.<br>
>>>><br>
>>>> Thanks,<br>
>>>> Ashley<br>
>>>><br>
>>>><br>
>>>><br>
>>>> ______________________________<wbr>_________________<br>
>>>> yt-users mailing list<br>
>>>> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
>>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
>>>><br>
>>> --<br>
>>> --<br>
>>> Dr. Stephanie Tonnesen<br>
>>> Alvin E. Nashman Postdoctoral Fellow<br>
>>> Carnegie Observatories, Pasadena, CA<br>
>>> <a href="mailto:stonnes@gmail.com">stonnes@gmail.com</a><br>
>>> ______________________________<wbr>_________________<br>
>>> yt-users mailing list<br>
>>> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
>>><br>
>> ______________________________<wbr>_________________<br>
>> yt-users mailing list<br>
>> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
>><br>
>><br>
>><br>
>> ______________________________<wbr>_________________<br>
>> yt-users mailing list<br>
>> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
>><br>
>><br>
> ______________________________<wbr>_________________<br>
> yt-users mailing list<br>
> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
><br>
<br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
</div></div></blockquote></div><br></div>