Repository: yt-project/yt

Issue:
Default field parameters are not set for AMRGridPatch
### Bug report

**Bug summary**

When accessing the grids directly, default field parameters are not set for the grid object, resulting in errors when calling fields requiring field parameters.

**Code for reproduction**


```python
import yt
ds = yt.load('./IsolatedGalaxy/galaxy0030/galaxy0030')
grid = ds.index.grids[0]
print(grid.field_parameters)
ad = ds.all_data()
print(ad.field_parameters)
```

**Actual outcome**

```
yt : [INFO     ] 2017-09-26 13:49:47,178 Parameters: current_time              = 0.0060000200028298
yt : [INFO     ] 2017-09-26 13:49:47,179 Parameters: domain_dimensions         = [32 32 32]
yt : [INFO     ] 2017-09-26 13:49:47,180 Parameters: domain_left_edge          = [ 0.  0.  0.]
yt : [INFO     ] 2017-09-26 13:49:47,182 Parameters: domain_right_edge         = [ 1.  1.  1.]
yt : [INFO     ] 2017-09-26 13:49:47,185 Parameters: cosmological_simulation   = 0.0
Parsing Hierarchy : 100%|██████████| 173/173 [00:00<00:00, 27188.80it/s]
yt : [INFO     ] 2017-09-26 13:49:47,210 Gathering a field list (this may take a moment.)
{}
{'center': YTArray([ 0.5,  0.5,  0.5]) code_length, 'bulk_velocity': YTArray([ 0.,  0.,  0.]) cm/s, 'normal': YTArray([ 0.,  0.,  1.]) (dimensionless)}
```

If one wants to access fields that require default field parameters, it will result in errors. In this example, ```bulk_velocity``` is needed for ```particle_velocity_magnitude```.

```python
grid['particle_velocity_magnitude']
```
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-ea26250246dd> in <module>()
----> 1 grid['particle_velocity_magnitude']

/home/ychen/src/yt-git/yt/data_objects/grid_patch.py in __getitem__(self, key)
     93 
     94     def __getitem__(self, key):
---> 95         tr = super(AMRGridPatch, self).__getitem__(key)
     96         try:
     97             fields = self._determine_fields(key)

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in __getitem__(self, key)
    279                 return self.field_data[f]
    280             else:
--> 281                 self.get_data(f)
    282         # fi.units is the unit expression string. We depend on the registry
    283         # hanging off the dataset to define this unit object.

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in get_data(self, fields)
   1334 
   1335         fields_to_generate += gen_fluids + gen_particles
-> 1336         self._generate_fields(fields_to_generate)
   1337         for field in list(self.field_data.keys()):
   1338             if field not in ofields:

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in _generate_fields(self, fields_to_generate)
   1354                 fi = self.ds._get_field_info(*field)
   1355                 try:
-> 1356                     fd = self._generate_field(field)
   1357                     if fd is None:
   1358                         raise RuntimeError

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in _generate_field(self, field)
    314                 tr = self._generate_container_field(field)
    315             if finfo.particle_type: # This is a property now
--> 316                 tr = self._generate_particle_field(field)
    317             else:
    318                 tr = self._generate_fluid_field(field)

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in _generate_particle_field(self, field)
    399         else:
    400             with self._field_type_state(ftype, finfo, gen_obj):
--> 401                 rv = self.ds._get_field_info(*field)(gen_obj)
    402         return rv
    403 

/home/ychen/src/yt-git/yt/fields/derived_field.py in __call__(self, data)
    235                 "for %s" % (self.name,))
    236         with self.unit_registry(data):
--> 237             dd = self._function(self, data)
    238         for field_name in data.keys():
    239             if field_name not in original_fields:

/home/ychen/src/yt-git/yt/fields/particle_fields.py in _particle_velocity_magnitude(field, data)
    282         return np.sqrt((data[ptype, svel % 'x'] - bulk_velocity[0])**2
    283                      + (data[ptype, svel % 'y'] - bulk_velocity[1])**2
--> 284                      + (data[ptype, svel % 'z'] - bulk_velocity[2])**2 )
    285 
    286     registry.add_field((ptype, "particle_velocity_magnitude"),

TypeError: 'NoneType' object is not subscriptable
```


**Expected outcome**
I would expect all data container will have the same default field parameters, including the ```AMRGridPatch```. It seems that during the initialization of AMRGridPatch, it does not call the ```__init__``` function of the parent class ```YTSelectionContainer```, instead it sets the ```field_parameters``` to an empty dictionary.
https://github.com/yt-project/yt/blob/9e5b259395801959c0202b82bf9a126b839caf6a/yt/data_objects/grid_patch.py#L60-L62

I am not sure whether this is intentionally designed or a bug that should be fixed.


**Version Information**
  * Operating System: Linux
  * Python Version: 3.6.1
  * yt version: 3.5.dev0




Discussion:
To answer your question: this is a bug.
I see. I will prepare a pull request for this. What I plan is to use the ```super``` to call the ```__init__``` function and remove the ```self.field_parameters = {}```. Is there anything that I should pay attention to?

The same bug will probably happen in ```OctreeSubset``` and ```UnstructuredMesh```. But I have never use them before.
I'm not sure offhand if calling `__init__` on the superclass will break things - only one way to check :)

Resolving patch:
diff --git a/yt/data_objects/grid_patch.py b/yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -21,8 +21,6 @@
 from yt.config import ytcfg
 from yt.data_objects.data_containers import \
     YTSelectionContainer
-from yt.data_objects.field_data import \
-    YTFieldData
 from yt.funcs import iterable
 from yt.geometry.selection_routines import convert_mask_to_indices
 import yt.geometry.particle_deposit as particle_deposit
@@ -58,8 +56,7 @@ class AMRGridPatch(YTSelectionContainer):
     OverlappingSiblings = None
 
     def __init__(self, id, filename=None, index=None):
-        self.field_data = YTFieldData()
-        self.field_parameters = {}
+        super(AMRGridPatch, self).__init__(index.dataset, None)
         self.id = id
         self._child_mask = self._child_indices = self._child_index_mask = None
         self.ds = index.dataset
@@ -69,8 +66,6 @@ def __init__(self, id, filename=None, index=None):
         self._last_mask = None
         self._last_count = -1
         self._last_selector_id = None
-        self._current_particle_type = 'all'
-        self._current_fluid_type = self.ds.default_fluid_type
 
     def get_global_startindex(self):
         """
diff --git a/yt/data_objects/octree_subset.py b/yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -55,10 +55,9 @@ class OctreeSubset(YTSelectionContainer):
     _block_reorder = None
 
     def __init__(self, base_region, domain, ds, over_refine_factor = 1):
+        super(OctreeSubset, self).__init__(ds, None)
         self._num_zones = 1 << (over_refine_factor)
         self._oref = over_refine_factor
-        self.field_data = YTFieldData()
-        self.field_parameters = {}
         self.domain = domain
         self.domain_id = domain.domain_id
         self.ds = domain.ds
@@ -66,8 +65,6 @@ def __init__(self, base_region, domain, ds, over_refine_factor = 1):
         self.oct_handler = domain.oct_handler
         self._last_mask = None
         self._last_selector_id = None
-        self._current_particle_type = 'all'
-        self._current_fluid_type = self.ds.default_fluid_type
         self.base_region = base_region
         self.base_selector = base_region.selector
 
diff --git a/yt/data_objects/unstructured_mesh.py b/yt/data_objects/unstructured_mesh.py
--- a/yt/data_objects/unstructured_mesh.py
+++ b/yt/data_objects/unstructured_mesh.py
@@ -23,8 +23,6 @@
 
 from yt.data_objects.data_containers import \
     YTSelectionContainer
-from yt.data_objects.field_data import \
-    YTFieldData
 import yt.geometry.particle_deposit as particle_deposit
 
 class UnstructuredMesh(YTSelectionContainer):
@@ -39,9 +37,8 @@ class UnstructuredMesh(YTSelectionContainer):
 
     def __init__(self, mesh_id, filename, connectivity_indices,
                  connectivity_coords, index):
-        self.field_data = YTFieldData()
+        super(UnstructuredMesh, self).__init__(index.dataset, None)
         self.filename = filename
-        self.field_parameters = {}
         self.mesh_id = mesh_id
         # This is where we set up the connectivity information
         self.connectivity_indices = connectivity_indices
@@ -56,8 +53,6 @@ def __init__(self, mesh_id, filename, connectivity_indices,
         self._last_mask = None
         self._last_count = -1
         self._last_selector_id = None
-        self._current_particle_type = 'all'
-        self._current_fluid_type = self.ds.default_fluid_type
 
     def _check_consistency(self):
         if self.connectivity_indices.shape[1] != self._connectivity_length:


Test patch: