Repository: yt-project/yt

Issue:
create_profile with extrema at zero of a log-scaled field produces NaNs and seg faults
### Bug report

**Bug summary**

This was originally reported by @stonnes to the website repo as https://github.com/yt-project/website/issues/22. I've reposted it here and trimmed down her example a bit to make it easier to see what's going wrong.

Using create_profile with an explicit extrema set to zero of a field that yt thinks should be log-scaled produces nonsense results.

<!--A short 1-2 sentences that succinctly describes the bug-->

**Code for reproduction**

<!--A minimum code snippet required to reproduce the bug, also minimizing the
number of dependencies required.-->

<!-- If you need to use a data file to trigger the issue you're having, consider
using one of the datasets from the yt data hub (http://yt-project.org/data). If
your issue cannot be triggered using a public dataset, you can use the yt
curldrop (https://docs.hub.yt/services.html#curldrop) to share data
files. Please include a link to the dataset in the issue if you use the
curldrop.-->

```python
import yt

ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
disk = ds.disk([0.5,0.5,0.5],[0,0,-1.0],(40,"kpc"),(2,"kpc"))

prof = yt.create_profile(disk,'radius',('gas','density'), units={'radius':'kpc'}, extrema={'radius':((0.0,'kpc'),(40.0,'kpc'))},weight_field='ones\
')

radius = prof.x
mean = prof['gas','density']
std = prof.standard_deviation['gas','density']
print(radius)
print(mean)
print(std)
```

**Actual outcome**

<!--The output produced by the above code, which may be a screenshot, console
output, etc.-->

On my machine, I sometimes get outputs like this:

```
[ nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan
  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan
  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan
  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan
  nan  nan  nan  nan] kpc
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.] g/cm**3
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.] g/cm**3
```

And sometimes get segfaults with the following python traceback:

```
Fatal Python error: Segmentation fault

Current thread 0x00007fff95d80340 (most recent call first):
  File "/Users/goldbaum/Documents/yt-git-fixes/yt/utilities/parallel_tools/parallel_analysis_interface.py", line 508 in parallel_objects
  File "/Users/goldbaum/Documents/yt-git-fixes/yt/data_objects/profiles.py", line 126 in add_fields
  File "/Users/goldbaum/Documents/yt-git-fixes/yt/data_objects/profiles.py", line 1095 in create_profile
  File "yt_diskprofile.py", line 6 in <module>
[1]    2128 segmentation fault  python -X faulthandler yt_diskprofile.py
```

**Expected outcome**

<!--A description of the expected outcome from the code snippet-->
<!--If this used to work in an earlier version of yt, please note the
version it used to work on-->

yt should either be issuing an error or should automatically switch to using a linear scaling when a user explicitly supplies an `extrema` value with one end set to zero.

**Version Information**
<!--Please specify your platform and versions of the relevant libraries you are
using:-->
  * Operating System: MacOS
  * Python Version: 3.6
  * yt version: 3.5-dev
  * Other Libraries (if applicable): 

<!--Please tell us how you installed yt and python e.g., from source,
pip, conda. If you installed from conda, please specify which channel you used
if not the default-->




Discussion:

Resolving patch:
diff --git a/yt/data_objects/profiles.py b/yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -30,7 +30,7 @@
 from yt.units.unit_object import Unit
 from yt.data_objects.field_data import YTFieldData
 from yt.utilities.exceptions import \
-    YTIllDefinedProfile
+    YTIllDefinedProfile, YTIllDefinedBounds
 from yt.utilities.lib.misc_utilities import \
     new_bin_profile1d, \
     new_bin_profile2d, \
@@ -1157,6 +1157,8 @@ def create_profile(data_source, bin_fields, fields, n_bins=64,
 
     args = [data_source]
     for f, n, (mi, ma), l in zip(bin_fields, n_bins, ex, logs):
+        if mi <= 0 and l:
+            raise YTIllDefinedBounds(mi, ma)
         args += [f, n, mi, ma, l]
     kwargs = dict(weight_field=weight_field)
     if cls is ParticleProfile:


Test patch: