示例#1
0
文件: arbor.py 项目: stalei/ytree
 def _parse_parameter_file(self):
     fh = h5py.File(self.filename, "r")
     for attr in ["hubble_constant", "omega_matter", "omega_lambda"]:
         setattr(self, attr, fh.attrs[attr])
     if "unit_registry_json" in fh.attrs:
         self.unit_registry = \
           UnitRegistry.from_json(
               fh.attrs["unit_registry_json"].astype(str))
     self.unit_registry.modify("h", self.hubble_constant)
     self.box_size = _hdf5_yt_attr(fh,
                                   "box_size",
                                   unit_registry=self.unit_registry)
     field_list = []
     fi = {}
     for field in fh["data"]:
         d = fh["data"][field]
         units = _hdf5_yt_attr(d, "units")
         if isinstance(units, bytes):
             units = units.decode("utf")
         if len(d.shape) > 1:
             for ax in "xyz":
                 my_field = "%s_%s" % (field, ax)
                 field_list.append(my_field)
                 fi[my_field] = {"vector": True, "units": units}
         else:
             field_list.append(field)
             fi[field] = {"units": units}
     fh.close()
     self.field_list = field_list
     self.field_info.update(fi)
示例#2
0
    def _parse_parameter_file(self):
        fh = h5py.File(self.filename, "r")

        for attr in ["hubble_constant", "omega_matter", "omega_lambda"]:
            setattr(self, attr, fh.attrs[attr])

        my_ur = UnitRegistry.from_json(parse_h5_attr(fh, "unit_registry_json"))
        right = _hdf5_yt_attr(fh, "domain_right_edge", unit_registry=my_ur)
        left = _hdf5_yt_attr(fh, "domain_left_edge", unit_registry=my_ur)
        # Drop the "cm" suffix because all lengths will
        # be in comoving units.
        self.box_size = self.quan((right - left)[0].to("Mpccm/h"), "Mpc/h")
        fh.close()
示例#3
0
    def _parse_parameter_file(self):
        self._prefix = \
          self.filename[:self.filename.rfind(self._suffix)]

        fh = h5py.File(self.filename, mode="r")
        for attr in ["hubble_constant", "omega_matter", "omega_lambda"]:
            setattr(self, attr, fh.attrs.get(attr, None))
        if "unit_registry_json" in fh.attrs:
            self.unit_registry = \
              UnitRegistry.from_json(
                  parse_h5_attr(fh, "unit_registry_json"))
        if "box_size" in fh.attrs:
            self.box_size = _hdf5_yt_attr(fh,
                                          "box_size",
                                          unit_registry=self.unit_registry)
        self.field_info.update(json.loads(parse_h5_attr(fh, "field_info")))
        self._size = fh.attrs["total_trees"]
        fh.close()

        # analysis fields in sidecar files
        analysis_filename = f"{self._prefix}-analysis{self._suffix}"
        if os.path.exists(analysis_filename):
            self.analysis_filename = analysis_filename
            fh = h5py.File(analysis_filename, mode="r")
            analysis_fi = json.loads(parse_h5_attr(fh, "field_info"))
            fh.close()
            for field in analysis_fi:
                analysis_fi[field]["type"] = "analysis_saved"
            self.field_info.update(analysis_fi)
        else:
            self.analysis_filename = None

        self.field_list = list(self.field_info.keys())
示例#4
0
 def _parse_parameter_file(self):
     self._prefix = \
       self.filename[:self.filename.rfind(self._suffix)]
     fh = h5py.File(self.filename, "r")
     for attr in ["hubble_constant", "omega_matter", "omega_lambda"]:
         setattr(self, attr, fh.attrs[attr])
     if "unit_registry_json" in fh.attrs:
         self.unit_registry = \
           UnitRegistry.from_json(
               parse_h5_attr(fh, "unit_registry_json"))
     self.box_size = _hdf5_yt_attr(fh,
                                   "box_size",
                                   unit_registry=self.unit_registry)
     self.field_info.update(json.loads(parse_h5_attr(fh, "field_info")))
     self.field_list = list(self.field_info.keys())
     fh.close()