def fix_spe(spe_file): entry = NXentry() entry.title = spe_file.nxname entry.incident_energy = spe_file['data/NXSPE_info/fixed_energy'] entry.data = spe_file.data.data entry.data.error.rename('errors') s = raw_input("Emin Emax Phimin Phimax dPhi: ") xmin, xmax, ymin, ymax, dy = [float(i) for i in s.split(' ')] mfit(entry.data, xmin, xmax, ymin, ymax, dy) return entry
def NXspectrum(self, eps=None, sigma=None, T=None, Hx=None, Hz=None): """Returns the neutron scattering cross section as a NXentry group""" from nexusformat.nexus import NXfield, NXentry, NXsample, NXdata if T is None: T = self.T S = self.spectrum(eps, sigma, T, Hx, Hz) entry = NXentry() entry.title = "Crystal Field Spectra for %s at %s K" % (self.title, T) entry.sample = NXsample() entry.sample.temperature = T entry.sample.temperature.units = "K" entry.data = NXdata(NXfield(S, name="intensity", units="mb/sr/meV"), NXfield(eps, name="energy_transfer", units="meV")) return entry
def get_nxspe(self): spe_file = nxload(self.import_file) entry = NXentry() entry.title = self.get_title() Ei = self.get_energy() if Ei and Ei > 0.0: entry.instrument = NXinstrument() entry.instrument.monochromator = NXmonochromator( NXfield(Ei, name="incident_energy", units="meV")) entry.data = spe_file.NXentry[0].data entry.data.nxsignal = entry.data.data if 'energy' in entry.data.entries: entry.data.energy.rename('energy_transfer') entry.data.nxaxes = [entry.data.polar, entry.data.energy_transfer] if 'error' in entry.data.entries: entry.data.error.rename('errors') return entry
def get_spe(self, phxfile=None): entry = NXentry() phi, omega, spw, errors = readspe(self.get_filename()) if phxfile: theta, phi, dtheta, dpsi = readphx(phxfile) phip, psi = angles(theta, phi) instrument = NXinstrument(NXdetector()) instrument.detector.polar_angle = NXfield(theta, units="degrees") Ei = self.get_energy() if Ei and Ei > 0.0: instrument.monochromator = NXmonochromator( NXfield(Ei, name="incident_energy", units="meV")) if phi.ptp() > 1.0: # i.e., the azimuthal angle is specified instrument.detector.azimuthal_angle = NXfield( phi, units="degrees") instrument.detector.rotation_angle = NXfield( phip, units="degrees") instrument.detector.tilt_angle = NXfield(psi, units="degrees") data = NXdata( NXfield( spw, name="intensity", long_name="Neutron Intensity"), ( NXfield( np.arange(1, len(theta) + 1), name="spectrum_index", long_name="Spectrum Index"), NXfield( omega, name="energy_transfer", units="meV", long_name="Energy Transfer")), errors=NXfield( np.sqrt(errors), name="errors", long_name="Errors")) if np.median(dtheta) > 0.0 and np.median(dpsi) > 0.0: data2D = rebin2D( spw, phip, psi, omega, np.median(dtheta), np.median(dpsi)) return NXentry(instrument, data, data2D=data2D) else: return NXentry(instrument, data) else: phi = np.zeros(theta.size+1) phi[:-1] = theta - 0.5*dtheta phi[-1] = theta[-1] + 0.5*dtheta[-1] data = NXdata( NXfield( spw, name="intensity", long_name="Neutron Intensity"), ( NXfield( phi, name="polar_angle", long_name="Polar Angle", units="degrees"), NXfield( omega, name="energy_transfer", units="meV", long_name="Energy Transfer")), errors=NXfield( np.sqrt(errors), name="errors", long_name="Errors")) return NXentry(instrument, data) else: Ei = self.get_energy() if Ei and Ei > 0.0: entry = NXentry( NXinstrument( NXmonochromator( NXfield( Ei, name="incident_energy", units="meV")))) else: entry = NXentry() if phi.ptp() > 1.0: entry.data = NXdata( NXfield(spw, name="intensity", long_name="Neutron Intensity"), (NXfield(phi, name="polar_angle", units="degrees", long_name="Polar Angle"), NXfield(omega, name="energy_transfer", units="meV", long_name="Energy Transfer")), errors=NXfield(np.sqrt(errors), name="errors", long_name="Errors")) else: entry.data = NXdata( NXfield(spw, name="intensity", long_name="Neutron Intensity"), (NXfield(np.arange(1, len(phi)+1), name="spectrum_index", long_name="Spectrum Index"), NXfield(omega, name="energy_transfer", units="meV", long_name="Energy Transfer")), errors=NXfield(np.sqrt(errors), name="errors", long_name="Errors")) return entry