snapio

package
v0.0.0-...-7eedc68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

package snapio contains functions for reading snapshot files. It centers around three main types. The first is a Buffer type which files read data into, the second is a File interface that abstracts over the details of different files, and the last is a Header interface that abstracts around header information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(hd Header) (*Buffer, error)

NewBuffer creates a buffer object which can read files with the given Header.

func (*Buffer) Get

func (buf *Buffer) Get(name string) (interface{}, error)

Get returns an interface pointing to the slice associated with a given variable name.

func (*Buffer) Reset

func (buf *Buffer) Reset()

Reset resets a buffer so that a new file can be read into it. This allows informative internal errors to be thrown.

type FakeFile

type FakeFile struct {
	// contains filtered or unexported fields
}

FakeFile is a object that implements the File interface for testing purposes, but can be initialized directly from arrays. See the File interface for method documentation.

func NewFakeFile

func NewFakeFile(
	names []string, values []interface{},
	nTot int, order binary.ByteOrder,
) (*FakeFile, error)

NewFakeFile creates a new FakeFile with the given IDs and position vectors. The snapshot has nTot files across all files and the byte order is given by order. The box will be 100 cMpc/h on a side and has z=1.0, Om = 0.27, and h100 = 0.7.

func (*FakeFile) Read

func (f *FakeFile) Read(name string, buf *Buffer) error

func (*FakeFile) ReadHeader

func (f *FakeFile) ReadHeader() (Header, error)

type FakeFileHeader

type FakeFileHeader struct {
	// contains filtered or unexported fields
}

FakeFileHEader implements the Header interface for the purposes of giving FakeFile a valid ReaderHeader() return value. See the Header interface for method documentation.

func (*FakeFileHeader) ByteOrder

func (f *FakeFileHeader) ByteOrder() binary.ByteOrder

func (*FakeFileHeader) H100

func (f *FakeFileHeader) H100() float64

func (*FakeFileHeader) L

func (f *FakeFileHeader) L() float64

func (*FakeFileHeader) Mass

func (f *FakeFileHeader) Mass() float64

func (*FakeFileHeader) NTot

func (f *FakeFileHeader) NTot() int64

func (*FakeFileHeader) Names

func (f *FakeFileHeader) Names() []string

func (*FakeFileHeader) OmegaL

func (f *FakeFileHeader) OmegaL() float64

func (*FakeFileHeader) OmegaM

func (f *FakeFileHeader) OmegaM() float64

func (*FakeFileHeader) ToBytes

func (f *FakeFileHeader) ToBytes() []byte

func (*FakeFileHeader) Types

func (f *FakeFileHeader) Types() []string

func (*FakeFileHeader) Z

func (f *FakeFileHeader) Z() float64

type File

type File interface {
	// ReadHeader reads the file's header and abstracts it behind the Header
	// interface.
	ReadHeader() (Header, error)
	// Read reads a given variable into a Buffer.
	Read(name string, buf *Buffer) error
}

File is a generic interface around different file types.

type Gadget2Cosmological

type Gadget2Cosmological struct {
	// contains filtered or unexported fields
}

Gadget2Cosmological is an implementation of the File interface for standard Gadget-2 files. Gadget-2 files do not have a standard set of variables or order to those variables, so they must be specified at runtime. This file assumes that particle masses are uniform. See the File interface for a description of the methods.

func NewGadget2Cosmological

func NewGadget2Cosmological(
	fileName string, names, types []string, order binary.ByteOrder,
) (*Gadget2Cosmological, error)

NewLGadget2Cosmological creates a new cosmological Gadget2 file with the given file name, byte order, field names, and types. The field names are only used internally to keep track fo variables and the the varaible names follow the common Guppy convention: "u32" and "u64" are ints, "f32" and "f64" are floats, and "v32" and "v64" are 3-vectors.

To aid with error-catching, Guppy recognizes serveral common varaibles names and will crash if incorrect types are assigned to them: x - v32 v - v32 id - u32 or u64 phi - f32 acc - v32 dt - f32

func (*Gadget2Cosmological) Read

func (f *Gadget2Cosmological) Read(name string, buf *Buffer) error

func (*Gadget2Cosmological) ReadHeader

func (f *Gadget2Cosmological) ReadHeader() (Header, error)

type Gadget2Header

type Gadget2Header struct {
	// contains filtered or unexported fields
}

Gadget2Header implements the Header interface for either an LGadget-2 or Gadget-2 simulation. See the Header interface for a description of the methods.

func (*Gadget2Header) ByteOrder

func (hd *Gadget2Header) ByteOrder() binary.ByteOrder

func (*Gadget2Header) H100

func (hd *Gadget2Header) H100() float64

func (*Gadget2Header) L

func (hd *Gadget2Header) L() float64

func (*Gadget2Header) Mass

func (hd *Gadget2Header) Mass() float64

func (*Gadget2Header) NTot

func (hd *Gadget2Header) NTot() int64

func (*Gadget2Header) Names

func (hd *Gadget2Header) Names() []string

func (*Gadget2Header) OmegaL

func (hd *Gadget2Header) OmegaL() float64

func (*Gadget2Header) OmegaM

func (hd *Gadget2Header) OmegaM() float64

func (*Gadget2Header) ToBytes

func (hd *Gadget2Header) ToBytes() []byte

func (*Gadget2Header) Types

func (hd *Gadget2Header) Types() []string

func (*Gadget2Header) Z

func (hd *Gadget2Header) Z() float64
type Header interface {
	// ToBytes converts the content of the original header to bytes. This should
	// be preserved exactly, so that there is no header information lost.
	ToBytes() []byte
	// ByteOrder returns the order of bytes in the file.
	ByteOrder() binary.ByteOrder

	// Names returns the names of the fields stored in the file, in the order
	// they will be stored in the .gup file.
	Names() []string
	// Types returns strings describing the types of the file's fields.
	Types() []string

	// NTot returns the total number of particles in the simulation.
	NTot() int64
	// Z returns the redshift of the snapshot.
	Z() float64
	// OmegaM returns Omega_m(z=0).
	OmegaM() float64
	// OmegaL returns Omega_Lambda(z=0)
	OmegaL() float64
	// H100 returns H0 / (100 km/s/Mpc).
	H100() float64
	// L returns the width of the simulation box in comoving Mpc/h.
	L() float64
	// Mass returns the particle mass in the simulation.
	Mass() float64
}

Header is a generic interface around the headers of different file tpyes.

type LGadget2

type LGadget2 struct {
	// contains filtered or unexported fields
}

LGadget2 is an implementation of the File interface for LGadget-2 files. These files have different header fields than a standard Gadget-2 file and always have uniform particle masses, but store data identically. See the File interface for a description of the methods.

func NewLGadget2

func NewLGadget2(
	fileName string, names, types []string, order binary.ByteOrder,
) (*LGadget2, error)

NewLGadget2 creates a new LGadget2 file with the given file name, byte order, field names, and types. The field names are only used internally to keep track fo variables and the the varaible names follow the common Guppy convention: "u32" and "u64" are ints, "f32" and "f64" are floats, and "v32" and "v64" are 3-vectors.

To aid with error-catching, Guppy recognizes serveral common varaibles names and will crash if incorrect types are assigned to them: x - v32 v - v32 id - u32 or u64 phi - f32 acc - v32 dt - f32

func (*LGadget2) Read

func (f *LGadget2) Read(name string, buf *Buffer) error

func (*LGadget2) ReadHeader

func (f *LGadget2) ReadHeader() (Header, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL