def read_header(self): if not self.exists: self.field_offsets = {} self.field_types = {} self.local_particle_count = 0 return fd = FortranFile(self.fname) fd.seek(0, os.SEEK_END) flen = fd.tell() fd.seek(0) hvals = {} # Read the header of the file attrs = self.attrs hvals.update(fd.read_attrs(attrs)) self._header = hvals # This is somehow a trick here: we only want one domain to # be read, as ramses writes all the sinks in all the # domains. Here, we set the local_particle_count to 0 except # for the first domain to be red. if getattr(self.ds, "_sink_file_flag", False): self.local_particle_count = 0 else: self.ds._sink_file_flag = True self.local_particle_count = hvals["nsink"] # Read the fields + add the sink properties if self.has_descriptor: fields = _read_part_file_descriptor(self.file_descriptor) else: fields = list(self.known_fields) # Note: this follows RAMSES convention. for i in range(self.ds.dimensionality * 2 + 1): for ilvl in range(self.ds.max_level + 1): fields.append((f"particle_prop_{ilvl}_{i}", "d")) field_offsets = {} _pfields = {} # Fill the fields, offsets and types self.fields = [] for field, vtype in fields: self.fields.append(field) if fd.tell() >= flen: break field_offsets[self.ptype, field] = fd.tell() _pfields[self.ptype, field] = vtype fd.skip(1) self.field_offsets = field_offsets self.field_types = _pfields fd.close()
def read_header(self): if not self.exists: self.field_offsets = {} self.field_types = {} self.local_particle_count = 0 return fd = FortranFile(self.fname) fd.seek(0, os.SEEK_END) flen = fd.tell() fd.seek(0) hvals = {} attrs = self.attrs hvals.update(fd.read_attrs(attrs)) self.header = hvals self.local_particle_count = hvals['npart'] extra_particle_fields = self.ds._extra_particle_fields if self.has_part_descriptor: particle_fields = (_read_part_file_descriptor( self.file_descriptor)) else: particle_fields = list(self.known_fields) if extra_particle_fields is not None: particle_fields += extra_particle_fields if hvals["nstar_tot"] > 0 and extra_particle_fields is not None: particle_fields += [("particle_birth_time", "d"), ("particle_metallicity", "d")] field_offsets = {} _pfields = {} ptype = self.ptype # Read offsets for field, vtype in particle_fields: if fd.tell() >= flen: break field_offsets[ptype, field] = fd.tell() _pfields[ptype, field] = vtype fd.skip(1) iextra = 0 while fd.tell() < flen: iextra += 1 field, vtype = ('particle_extra_field_%i' % iextra, 'd') particle_fields.append((field, vtype)) field_offsets[ptype, field] = fd.tell() _pfields[ptype, field] = vtype fd.skip(1) fd.close() if iextra > 0 and not self.ds._warned_extra_fields['io']: w = ("Detected %s extra particle fields assuming kind " "`double`. Consider using the `extra_particle_fields` " "keyword argument if you have unexpected behavior.") mylog.warning(w % iextra) self.ds._warned_extra_fields['io'] = True self.field_offsets = field_offsets self.field_types = _pfields