In [1]:
import os
import sys
import matplotlib.pyplot as plt
import numpy as np
from astropy.table import Table
import desispec.io
from scipy import constants
%matplotlib inline
c = constants.speed_of_light/1000. #- km/s
In [7]:
def plot_zinfo(zbest,ztrue,label=None):
dv = c * (zbest['Z'] - ztrue['Z']) / (1.0 + ztrue['Z'])
err=(zbest['Z']/ztrue['Z']-1.)*100
plt.figure(figsize=(20,6),dpi=100)
plt.subplot(1,3,1)
plt.scatter(ztrue['Z'],dv)
plt.xlabel('z_true')
plt.ylabel('dv')
plt.title(label)
plt.subplot(1,3,2)
plt.scatter(ztrue['Z'],zbest['Z'],marker='.')
plt.xlabel('z_true')
plt.ylabel('z_best')
plt.title(label)
plt.subplot(1,3,3)
plt.scatter(ztrue['Z'],err)
plt.ylim(-0.5,0.5)
plt.xlim(1,4)
plt.xlabel('z_true')
plt.ylabel(r'$\epsilon(\%)$')
plt.title(label)
In [9]:
#Only if you are using your local version of desisim. If using master you can comment this cell
os.environ['PYTHONPATH']='/global/homes/a/alxogm/desi/code/desisim/py:'+os.environ['PYTHONPATH']
os.environ['PATH']='/global/homes/a/alxogm/desi/code/desisim/bin/:'+os.environ['PATH']
In [12]:
exptime=4000 #Exposure time
#ifile='/project/projectdirs/desi/mocks/lya_forest/london/v2.0/0/0/transmission-16-0.fits' #Transmission file to read, v3 cointains metals, most of the notebook works also with v2.0, except the part corresponding to the metal addition from transrmision file.
ifile='/project/projectdirs/desi/mocks/lya_forest/london/v2.0/0/0/transmission-16-0.fits' #Choose one pixel to simulate the quasars.
outdir='/project/projectdirs/desi/users/alxogm/desi/lya_forest/random_errors_lya/' #Where do you want to save the files, although in this particular notebook we will be overwritring the files.
zmin=1.8
seed=123 #Seed to ensure reproducibility.
specfile=outdir+'spectra-16-0.fits'
In [15]:
cmd ='quickquasars --exptime {exptime} -i {ifile} -o {outfile} --zmin {zmin} --zbest 0 --mags --desi-footprint --overwrite \
--seed {seed} --downsampling 0.4'.format(exptime=exptime,ifile=ifile,outfile=specfile,zmin=zmin,seed=seed)
!time $cmd
ztrue=Table.read('/project/projectdirs/desi/users/alxogm/desi/lya_forest/random_errors_lya/zbest-16-0.fits')
In [17]:
cmd ='quickquasars --exptime {exptime} -i {ifile} -o {outfile} --zmin {zmin} --zbest 200 --mags --desi-footprint --overwrite \
--seed {seed} --downsampling 0.4'.format(exptime=exptime,ifile=ifile,outfile=specfile,zmin=zmin,seed=seed)
!time $cmd
zbest=Table.read('/project/projectdirs/desi/users/alxogm/desi/lya_forest/random_errors_lya/zbest-16-0.fits')
In [18]:
plot_zinfo(zbest,ztrue,'random_zbest_vs_ztrue')
In [19]:
rrzbestfile=outdir+'zbest_rr-16-0.fits'
cmd = 'rrdesi_mpi {} --zbest {}'.format(specfile,rrzbestfile) if 'NERSC_HOST' in os.environ: print('Running on a batch node:') print(cmd) print()
#srun = 'srun -N 12 -n 384 -c 1 -t 00:01:30 -C haswell --qos interactive'
srun = 'srun -N 4 -n 128 -c 1 -t 00:05:00 -C haswell --qos interactive'
cmd = '{srun} {cmd}'.format(srun=srun, cmd=cmd)
!$cmd
In [23]:
rrzbest=Table.read(rrzbestfile)
In [24]:
plot_zinfo(zbest,ztrue,'random_zbest_vs_ztrue')
plot_zinfo(rrzbest,ztrue,'rrzbest_vs_ztrue')
In [ ]:
In [ ]: