def read(self, inputs, geometry, atmos): f = open(self.filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() self.Nspect = up.unpack_int() self.waves = read_farray(self.Nspect, up, "double") if geometry.type == "ONE_D_PLANE" or\ geometry.type == 'SPHERICAL_SYMMETRIC': dim = [geometry.Nrays, self.Nspect] elif geometry.type == 'TWO_D_PLANE': dim = [geometry.Nx, geometry.Nrays, self.Nspect] elif geometry.type == 'THREE_D_PLANE': dim = [geometry.Nx, geometry.Ny, geometry.Nrays, self.Nspect] self.I = read_farray(dim, up, "double") self.vacuum_to_air = up.unpack_int() self.air_limit = float(up.unpack_double()) if atmos.stokes or inputs.backgr_pol: self.Q = read_farray(dim, up, "double") self.U = read_farray(dim, up, "double") self.V = read_farray(dim, up, "double") up.done()
def read(self, inputs, geometry, spectrum): f = open(self.filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() if geometry.type == "ONE_D_PLANE": self.muz = up.unpack_double() dim1 = [spectrum.Nspect] dim2 = [geometry.Ndep] elif geometry.type == 'SPHERICAL_SYMMETRIC': self.muz = up.unpack_double() dim1 = [spectrum.Nspect] dim2 = [geometry.Nradius] elif geometry.type == 'TWO_D_PLANE': self.mux = up.unpack_double() self.muz = up.unpack_double() dim1 = [geometry.Nx, spectrum.Nspect] dim2 = [geometry.Nx, geometry.Nz] elif geometry.type == 'THREE_D_PLANE': self.mux = up.unpack_double() self.muy = up.unpack_double() dim1 = [geometry.Nx, geometry.Ny, spectrum.Nspect] dim2 = [geometry.Nx, geometry.Ny, geometry.Nz] self.I = read_farray(dim1, up, "double") self.Nopac = up.unpack_int() if self.Nopac > 0: self.opac = {} for n in range(self.Nopac): self.opac[n] = opac(dim2, up) try: spectrum.Q except AttributeError: up.done() return else: self.Q = read_farray(dim1, up, "double") self.U = read_farray(dim1, up, "double") self.V = read_farray(dim1, up, "double") up.done()
def read(self, geometry): f = open(self.filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() self.active = up.unpack_int() self.Nlevel = up.unpack_int() self.Nline = up.unpack_int() self.Ncont = up.unpack_int() self.Nfixed = up.unpack_int() self.abund = up.unpack_double() self.weight = up.unpack_double() self.labels = {} for i in range(self.Nlevel): self.labels[i] = read_string(up) self.atomID = self.labels[0][0:2].strip() self.g = read_farray([self.Nlevel], up, "double") self.E = read_farray([self.Nlevel], up, "double") self.stage = read_farray([self.Nlevel], up, "int") Nrad = self.Nline + self.Ncont self.transition = {} for kr in range(Nrad): self.transition[kr] = atoms.transition(up) for kr in range(self.Nline, Nrad): if self.transition[kr].shape == "HYDROGENIC": self.transition[kr].waves = up.unpack_double() else: self.transition[kr].waves =\ read_farray([self.transition[kr].Nwave], up, "double") self.transition[kr].alpha =\ read_farray([self.transition[kr].Nwave], up, "double") self.fixed = {} for kr in range(self.Nfixed): self.transition[kr] = atoms.fixed(up) up.done()
def readdamping(self, geometry, filename): f = open(filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() if geometry.type == "ONE_D_PLANE": dim = [geometry.Ndep] elif geometry.type == 'SPHERICAL_SYMMETRIC': dim = [geometry.Nradius] elif geometry.type == 'TWO_D_PLANE': dim = [geometry.Nx, geometry.Nz] elif geometry.type == 'THREE_D_PLANE': dim = [geometry.Nx, geometry.Ny, geometry.Nz] self.vbroad = read_farray(dim, up, "double") for kr in range(self.Nline): self.transition[kr].adamp =\ read_farray(dim, up, "double") up.done()
def readrates(self, geometry, filename): f = open(filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() Nrad = self.Nline + self.Ncont if geometry.type == "ONE_D_PLANE": dim = [geometry.Ndep] elif geometry.type == 'SPHERICAL_SYMMETRIC': dim = [geometry.Nradius] elif geometry.type == 'TWO_D_PLANE': dim = [geometry.Nx, geometry.Nz] elif geometry.type == 'THREE_D_PLANE': dim = [geometry.Nx, geometry.Ny, geometry.Nz] for kr in range(Nrad): self.transition[kr].Rij = read_farray(dim, up, "double") self.transition[kr].Rji = read_farray(dim, up, "double") up.done()
def read_BRS(self): brsfile = '{0}/brs.out'.format(self.rhdir) f = open(brsfile, 'rb') up = xdrlib.Unpacker(f.read()) f.close() atmosID = read_string(up) Nspace = up.unpack_int() Nspect = up.unpack_int() hasline = read_farray(Nspect, up, "int") ispolarized = read_farray(Nspect, up, "int") self.backgrflags = backgrflags(hasline, ispolarized) if self.atmos.moving or self.atmos.stokes: dim = 2 * Nspect * self.geometry.Nrays else: dim = Nspect self.bg_recno = read_farray(dim, up, "int") up.done()
def readpops(self, geometry, popsfile): f = open(popsfile, 'rb') up = xdrlib.Unpacker(f.read()) f.close() atmosID = read_string(up) Nlevel = up.unpack_int() Nspace = up.unpack_int() if geometry.type == "ONE_D_PLANE": dim = [geometry.Ndep, self.Nlevel] elif geometry.type == 'SPHERICAL_SYMMETRIC': dim = [geometry.Nradius, self.Nlevel] elif geometry.type == 'TWO_D_PLANE': dim = [geometry.Nx, geometry.Nz, self.Nlevel] elif geometry.type == 'THREE_D_PLANE': dim = [geometry.Nx, geometry.Ny, geometry.Nz, self.Nlevel] self.n = read_farray(dim, up, "double") self.nstar = read_farray(dim, up, "double") up.done()
def read(self, geometry): f = open(self.filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() self.NHydr = up.unpack_int() self.Nelem = up.unpack_int() self.moving = up.unpack_int() if geometry.type == "ONE_D_PLANE": dim1 = [geometry.Ndep] dim2 = [geometry.Ndep, self.NHydr] elif geometry.type == 'SPHERICAL_SYMMETRIC': dim1 = [geometry.Nradius] dim2 = [geometry.Nradius, self.NHydr] elif geometry.type == 'TWO_D_PLANE': dim1 = [geometry.Nx, geometry.Nz] dim2 = [geometry.Nx, geometry.Nz, self.NHydr] elif geometry.type == 'THREE_D_PLANE': dim1 = [geometry.Nx, geometry.Ny, geometry.Nz] dim2 = [geometry.Nx, geometry.Ny, geometry.Nz, self.NHydr] self.T = read_farray(dim1, up, "double") self.n_elec = read_farray(dim1, up, "double") self.vturb = read_farray(dim1, up, "double") self.nH = read_farray(dim2, up, "double") self.ID = read_string(up) self.elements = {} for n in range(self.Nelem): self.elements[n] = element(up) if geometry.type != 'SPHERICAL_SYMMETRIC': try: stokes = up.unpack_int() except EOFError or IOError: self.stokes = False return else: self.stokes = True self.B = read_farray(dim1, up, "double") self.gamma_B = read_farray(dim1, up, "double") self.chi_B = read_farray(dim1, up, "double") up.done()
def read_ASRS(self): asrsfile = '{0}/asrs.out'.format(self.rhdir) if not os.path.isfile(asrsfile): self.as_recno = None return f = open(asrsfile, 'rb') up = xdrlib.Unpacker(f.read()) f.close() if self.atmos.moving or self.atmos.stokes or\ self.inputs.PRD_angle_dep: dim = self.spectrum.Nspect * self.geometry.Nrays else: dim = self.spectrum.Nspect self.as_recno = read_farray(dim, up, "int") up.done()
def readcollisions(self, geometry, filename): f = open(filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() if geometry.type == "ONE_D_PLANE": dim = [geometry.Ndep, self.Nlevel, self.Nlevel] elif geometry.type == 'SPHERICAL_SYMMETRIC': dim = [geometry.Nradius, self.Nlevel, self.Nlevel] elif geometry.type == 'TWO_D_PLANE': dim = [geometry.Nx, geometry.Nz, self.Nlevel, self.Nlevel] elif geometry.type == 'THREE_D_PLANE': dim = [geometry.Nx, geometry.Ny, geometry.Nz,\ self.Nlevel, self.Nlevel] self.Cij = read_farray(dim, up, "double") up.done()
def read(self): geometry_types = [ 'ONE_D_PLANE', 'TWO_D_PLANE', 'SPHERICAL_SYMMETRIC', 'THREE_D_PLANE' ] f = open(self.filename, 'rb') up = xdrlib.Unpacker(f.read()) f.close() self.type = geometry_types[up.unpack_int()] self.Nrays = up.unpack_int() if self.type == 'ONE_D_PLANE': self.Ndep = up.unpack_int() self.xmu = read_farray(self.Nrays, up, "double") self.wmu = read_farray(self.Nrays, up, "double") self.height = read_farray(self.Ndep, up, "double") self.cmass = read_farray(self.Ndep, up, "double") self.tau500 = read_farray(self.Ndep, up, "double") self.vz = read_farray(self.Ndep, up, "double") elif self.type == 'SPHERICAL_SYMMETRIC': self.Nradius = up.unpack_int() self.Ncore = up.unpack_int() self.radius = up.unpack_double() self.xmu = read_farray(self.Nrays, up, "double") self.wmu = read_farray(self.Nrays, up, "double") self.r = read_farray(self.Nradius, up, "double") self.cmass = read_farray(self.Nradius, up, "double") self.tau500 = read_farray(self.Nradius, up, "double") self.vr = read_farray(self.Nradius, up, "double") elif self.type == 'TWO_D_PLANE': self.Nx = up.unpack_int() self.Nz = up.unpack_int() self.AngleSet = up.unpack_int() self.xmu = read_farray(self.Nrays, up, "double") self.ymu = read_farray(self.Nrays, up, "double") self.wmu = read_farray(self.Nrays, up, "double") self.x = read_farray(self.Nx, up, "double") self.z = read_farray(self.Nz, up, "double") dim = [self.Nx, self.Nz] self.vx = read_farray(dim, up, "double") self.vz = read_farray(dim, up, "double") elif self.type == 'THREE_D_PLANE': self.Nx = up.unpack_int() self.Ny = up.unpack_int() self.Nz = up.unpack_int() self.AngleSet = up.unpack_int() self.xmu = read_farray(self.Nrays, up, "double") self.ymu = read_farray(self.Nrays, up, "double") self.wmu = read_farray(self.Nrays, up, "double") self.dx = up.unpack_double() self.dy = up.unpack_double() self.z = read_farray(self.Nz, up, "double") dim = [self.Nx, self.Ny, self.Nz] self.vx = read_farray(dim, up, "double") self.vy = read_farray(dim, up, "double") self.vz = read_farray(dim, up, "double") up.done()
def read(self, waveno, rayno): SIZE_OF_DOUBLE = 8 if waveno >= self.spectrum.Nspect: print("waveno {0} >= " "spectrum.Nspect = {1}".format(waveno, self.spectrum.Nspect)) waveno = 0 if rayno >= self.geometry.Nrays: print("rayno {0} >= " "geometry.Nrays = {1}".format(rayno, self.geometry.Nrays)) rayno = 0 self.waveno = waveno self.rayno = rayno if self.geometry.type == "ONE_D_PLANE": reclen_as = 2 * self.geometry.Ndep * SIZE_OF_DOUBLE reclen_bg = self.geometry.Ndep * SIZE_OF_DOUBLE dim1 = self.geometry.Ndep elif self.geometry.type == 'SPHERICAL_SYMMETRIC': reclen_as = 2 * self.geometry.Nradius * SIZE_OF_DOUBLE reclen_bg = self.geometry.Nradius * SIZE_OF_DOUBLE dim1 = self.geometry.Nradius elif self.geometry.type == 'TWO_D_PLANE': reclen_as = 2 * (self.geometry.Nx * self.geometry.Nz) * SIZE_OF_DOUBLE reclen_bg = (self.geometry.Nx * self.geometry.Nz) * SIZE_OF_DOUBLE dim1 = self.geometry.Nx * self.geometry.Nz elif self.geometry.type == 'THREE_D_PLANE': reclen_as = 2 * (self.geometry.Nx*self.geometry.Ny*\ self.geometry.Nz) * SIZE_OF_DOUBLE reclen_bg = (self.geometry.Nx*self.geometry.Ny*\ self.geometry.Nz) * SIZE_OF_DOUBLE dim1 = self.geometry.Nx * self.geometry.Ny * self.geometry.Nz if self.atmos.moving or self.atmos.stokes or \ self.inputs.PRD_angle_dep: index_as = waveno * self.geometry.Nrays + rayno else: index_as = waveno if self.atmos.moving or self.atmos.stokes: index_bg = 2 * (waveno * self.geometry.Nrays + rayno) + 1 else: index_bg = waveno file_as = open('{0}/opacity.out'.format(self.rhdir), 'rb') offset_as = self.as_recno[index_as] * reclen_as chunk_as = 2 * dim1 * SIZE_OF_DOUBLE file_as.seek(offset_as, 0) up_as = xdrlib.Unpacker(file_as.read(chunk_as)) self.chi_as = read_farray(dim1, up_as, "double") self.eta_as = read_farray(dim1, up_as, "double") file_as.close() up_as.done() file_bg = open('{0}/background.dat'.format(self.rhdir), 'rb') offset_bg = self.bg_recno[index_bg] * reclen_bg file_bg.seek(offset_bg, 0) if self.atmos.stokes and self.backgrflags.ispolarized[waveno]: chunk_bg = 9 * dim1 * SIZE_OF_DOUBLE if self.inputs.magneto_optical: chunk_bg += 3 * dim1 * SIZE_OF_DOUBLE else: chunk_bg = 3 * dim1 * SIZE_OF_DOUBLE buffer_bg = file_bg.read(chunk_bg) self.chi_c = np.frombuffer(buffer_bg, dtype='float', count=dim1) if self.atmos.stokes and self.backgrflags.ispolarized[waveno]: offset = 4 * dim1 * SIZE_OF_DOUBLE if self.inputs.magneto_optical: offset += 3 * dim1 * SIZE_OF_DOUBLE else: offset = dim1 * SIZE_OF_DOUBLE self.eta_c = np.frombuffer(buffer_bg, dtype='float', count=dim1, \ offset=offset) if self.atmos.stokes and self.backgrflags.ispolarized[waveno]: offset += 3 * dim1 * SIZE_OF_DOUBLE else: offset += dim1 * SIZE_OF_DOUBLE self.scatt = np.frombuffer(buffer_bg, dtype='float', count=dim1, \ offset=offset) if self.geometry.type == 'TWO_D_PLANE': np.reshape(self.chi_as, [self.geometry.Nx, self.geometry.Nz]) np.reshape(self.eta_as, [self.geometry.Nx, self.geometry.Nz]) np.reshape(self.chi_c, [self.geometry.Nx, self.geometry.Nz]) np.reshape(self.eta_c, [self.geometry.Nx, self.geometry.Nz]) np.reshape(self.scatt, [self.geometry.Nx, self.geometry.Nz]) elif self.geometry.type == 'THREE_D_PLANE': np.reshape(self.chi_as, [self.geometry.Nx, self.geometry.Ny,\ self.geometry.Nz]) np.reshape(self.eta_as, [self.geometry.Nx, self.geometry.Ny,\ self.geometry.Nz]) np.reshape(self.chi_c, [self.geometry.Nx, self.geometry.Ny,\ self.geometry.Nz]) np.reshape(self.eta_c, [self.geometry.Nx, self.geometry.Ny,\ self.geometry.Nz]) np.reshape(self.scatt, [self.geometry.Nx, self.geometry.Ny,\ self.geometry.Nz]) self.read_J()
def read(self, dim, up): self.nspect = up.unpack_int() self.chi = read_farray(dim, up, "double") self.S = read_farray(dim, up, "double")
def read(self, geometrytype, atmosfile, Bfile): self.type = geometrytype if self.type == "ONE_D_PLANE" or self.type == "SPHERICAL_SYMMETRIC": CM_TO_M = 1.0E-2 G_TO_KG = 1.0E-3 data = [] with open(atmosfile, 'r') as file: for line in file: if line.startswith('*'): continue data.append(line.strip()) self.ID = data[0] scale = data[1][0] if self.type == "ONE_D_PLANE": self.grav = float(data[2]) self.Ndep = int(data[3]) Nd = self.Ndep else: self.grav, self.radius = [float(x) for x in data[2].split()] self.Nradius, self.Ncore, self.Ninter = \ [int(x) for x in data[3].split()] Nd = self.Nradius self.grav = np.power(10.0, self.grav) * CM_TO_M self.NHydr = 6 hscale = np.array(range(Nd), dtype="float") self.T = np.array(range(Nd), dtype="float") self.n_elec = np.array(range(Nd), dtype="float") self.v = np.array(range(Nd), dtype="float") self.vturb = np.array(range(Nd), dtype="float") for n in range(Nd): hscale[n], self.T[n],\ self.n_elec[n], self.v[n], self.vturb[n] =\ [float(x) for x in data[n+4].split()] if scale == 'M': self.scale = 'MASS_SCALE' self.cmass = np.power(10.0, hscale) self.cmass *= G_TO_KG / CM_TO_M**2 elif scale == 'T': self.scale = 'TAU500_SCALE' self.tau500 = np.power(10.0, hscale) elif scale == 'H': self.scale = 'GEOMETRIC_SCALE' self.height = hscale if len(data) > (4 + Nd): self.HLTE = False self.nH = np.array(range(Nd * self.NHydr),\ dtype="float").reshape([Nd,\ self.NHydr],\ order='F') for n in range(Nd): self.nH[n,:] =\ [float(x) for x in data[n+4+Nd].split()] else: self.HLTE = True self.nH /= CM_TO_M**3 self.n_elec /= CM_TO_M**3 dim1 = [Nd] elif self.type == "TWO_D_PLANE" or self.type == "THREE_D_PLANE": f = open(atmosfile, 'rb') up = xdrlib.Unpacker(f.read()) f.close() if self.type == "TWO_D_PLANE": self.Nx = up.unpack_int() self.Nz = up.unpack_int() self.NHydr = up.unpack_int() self.boundary = read_farray([3], up, "int") self.dx = read_farray([self.Nx], up, "double") self.z = read_farray([self.Nz], up, "double") dim1 = [self.Nx, self.Nz] dim2 = [self.Nx, self.Nz, self.NHydr] elif self.type == "THREE_D_PLANE": self.Nx = up.unpack_int() self.Ny = up.unpack_int() self.Nz = up.unpack_int() self.NHydr = up.unpack_int() self.boundary = read_farray([2], up, "int") self.dx = up.unpack_double() self.dy = up.unpack_double() self.z = read_farray([self.Nz], up, "double") dim1 = [self.Nx, self.Ny, self.Nz] dim2 = [self.Nx, self.Ny, self.Nz, self.NHydr] self.T = read_farray(dim1, up, "double") self.n_elec = read_farray(dim1, up, "double") self.vturb = read_farray(dim1, up, "double") self.vx = read_farray(dim1, up, "double") if self.type == "THREE_D_PLANE": self.vy = read_farray(dim1, up, "double") self.vz = read_farray(dim1, up, "double") self.nH = read_farray(dim2, up, "double") up.done() else: print("Not a valid input atmosphere type: {0}".format(self.type)) return if Bfile != None: f = open(Bfile, 'rb') up = xdrlib.Unpacker(f.read()) f.close() self.B = read_farray(dim1, up, "double") self.gamma = read_farray(dim1, up, "double") self.chi = read_farray(dim1, up, "double") up.done()