コード例 #1
0
def read_xfaster_newdata_output( file, pol=False, win=1, old=False, otit="XF T-P spectra", res=False, xpol=False, lmax=2000, chkbb=False, verbose=False ):
    code = ' > read_xfaster_newdata_output: '
    xfdir = '/global/scratch2/sd/dpietrob/Software/XFaster/'
    if verbose:
        print code+'XFaster folder = '+xfdir
    tcl = hp.fitsfunc.read_cl(xfdir+'data/planck_lcdm_cl_uK_xf1.e-3.fits')
    tcl[4] = 0.
    tcl[5] = 0.
    nl = len( tcl[0] )
    l = np.arange( len( tcl[0] ) )
    ll = l * (l+1)/2./np.pi
### NB consistent with my definition of .newdat
    if old:
        nbtt,nbee,nbbb,nbtb,nbte,nbeb = readcol(file, format=np.arange(6)+1, skipline=1, numline=1, verbose=verbose)
    else:
        nbtt,nbee,nbbb,nbte,nbtb,nbeb = readcol(file, format=np.arange(6)+1, skipline=1, numline=1, verbose=verbose)
    
    print ' TT # bin = ', nbtt
    print ' EE # bin = ', nbee
    print ' TE # bin = ', nbte
    print ' BB # bin = ', nbbb
    print ' TB # bin = ', nbtb
    print ' EB # bin = ', nbeb

    #if verbose:
    #print code+'binning theoretical power spectrum...'
    btcltt = bp_binning( tcl[0]*ll, xfdir+'data/bins/ctp/CTP_bin_TT', verbose=verbose )
コード例 #2
0
ファイル: bp_binning.py プロジェクト: daddeptr/py_library
def bp_binning( cls, bin_file, verbose=False):
    code = ' > bp_binning: '
    if verbose:
        print code+'Assuming l=0, len(cl)-1; lmax=len(cl)-1'
        print code+'Reading bin_file %s' %bin_file
    nl = len(cls)
    fl,ll = readcol(bin_file, verbose=verbose)
    nb = len(ll)
    if verbose:
        print nb, ll[nb-1], ll[nb]
    lmax = np.min( [nl-1,ll[nb]] )
    if verbose:
        print 'lmax = %s' %lmax
    #bok = (ll - lmax) > 0
    #bmax = nb-1
    #if bok[0] > 0:
    #    bmax = bok[0]-1
    bin_cls = np.zeros( nb )
# for ib=0,bmax do bin_cls[ib] = total( cls[fl[ib]:ll[ib]] ) / (ll[ib]-fl[ib]+1)
    for ib in np.arange( nb ):
        #bin_cls[ib] = np.sum( cls[fl[ib]:ll[ib]] ) / (ll[ib]-fl[ib]+1)
        bnl = np.sum( np.nonzero( cls[fl[ib]:ll[ib]] ) )
        bin_cls[ib] = np.sum( cls[fl[ib]:ll[ib]] ) / bnl #(ll[ib]-fl[ib]+1)
        if verbose:
            print ib, fl[ib], ll[ib], bin_cls[ib]
    tnl = np.sum( np.nonzero( bin_cls ) )
    return bin_cls[0:tnl]
コード例 #3
0
ファイル: items.py プロジェクト: Stochast1c/ac_catalog
def items():
   csv_path = "csvs"+os.sep
   pickle_path = "pickles"+os.sep

   files = glob.glob(csv_path+"*.csv")
   for f in files:
      dict = readcol(f,asdict=True,fsep="`")
      dict.pop("\n", None)    #for some reason readcol grabs the newline character

      for k in dict.keys():
         if "\n" in k:
            dict[k.rstrip()] = dict.pop(k)
      
      unique_dict = {}
      key_list = ["name","Sells For","Purchase Price","reorderable","cataloged"]    #keys that aren't useful to sort by

      for k,v in dict.iteritems():
         if k not in key_list:      #keys that I want to sort by
            unique_dict[k] = list(collections.OrderedDict.fromkeys(v))     #list removes non-unique values
            if unique_dict[k] == ['-']:      #if the only value is -, then that is not something useful to sort by
               unique_dict.pop(k, None)      
         
      with open(pickle_path+f[len(csv_path):-3]+"pickle", 'wb') as handle:
         pickle.dump((collections.OrderedDict(sorted(dict.items())), collections.OrderedDict(sorted(unique_dict.items()))), handle)     #depositing dict by pickle, lazy and this is fast
コード例 #4
0
#!bin/python
from readcol import *
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
from matplotlib.colors import LogNorm
num=1
LUNIT=1.49597871e13

rad0=readcol("rad_chart.txt")
size0=readcol("size_chart.txt");
n_rad=len(rad0)
n_size=len(size0)
print n_rad,n_size
dens_grid=np.ndarray(shape=(n_size,n_rad),dtype=float)
dr=rad0[1]-rad0[0]
dens=np.ndarray(shape=(n_size,n_rad),dtype=float)
print dens
#print np.shape(dens)
#print np.shape(dens[0])
rad,size=np.meshgrid(rad0,size0)

X = 10*np.random.rand(5,3)
dens=np.random.rand(n_size,n_rad)
print dens
fig, ax = plt.subplots()
ax.imshow(X, cmap=cm.jet)#, interpolation='nearest')
print X
plt.show()
コード例 #5
0
#!bin/python
from readcol import *
import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
from matplotlib.colors import LogNorm
import sys
num=1
LUNIT=1.49597871e13

rad0=readcol("rad_chart.txt")
size0=readcol("size_chart.txt");
n_rad=len(rad0)
n_size=len(size0)
print n_rad,n_size
dens_grid=np.ndarray(shape=(n_size,n_rad),dtype=float)
dr=rad0[1]-rad0[0]
v_rel=np.ndarray(shape=(n_size,n_size),dtype=float)
print v_rel
#print np.shape(dens)
#print np.shape(dens[0])
rad,size=np.meshgrid(size0,size0)

lev=np.linspace(0,0,256)
lev2=np.linspace(0,10000,256)
plt.rc('text',usetex=True)
for i in range(0,256):
	lev[i]=0.00001*np.exp(i*1.0/256*np.log(0.1/0.00001))
for i in range(0000,0001,50):
コード例 #6
0
ファイル: CS_JWST_dev.py プロジェクト: cosmosz5/JWST_CS
    b[nvis:, 0] = np.rad2deg(np.arctan(np.tan(np.deg2rad(b[nvis:, 0]))))

    f1 = functions.norm_l1(lambda_=l)
    f2 = functions.norm_l2(y=b, A=A)
    step = 0.5 / np.linalg.norm(A, ord=2)**2
    solver = solvers.forward_backward(step=step)
    ret = solvers.solve([f1, f2], x, solver, rtol=1e-6, maxit=maxit)
    return ret


oi_data = 'CALIB_SIM_DATA_uncalib_t_disk_small2_0__PSF_MASK_NRM_F430M_x11_0.82_ref__00.oifits'
#input_path = ['/Users/donut/Library/Mobile Documents/com~apple~CloudDocs/JWST_CS/dataset/disks_clean/']
input_path = [
    '/Users/donut/Library/Mobile Documents/com~apple~CloudDocs/JWST_CS/dataset/forms/'
]
input_files = readcol(input_path[0] + 'data_cgauss.txt', twod=True)
scale = 10.0  ## mas
hyperparameter = 0.05
maxit = 10000

for i in range(len(input_files)):
    temp = input_path[0] + input_files[i][0]
    im_atom = pyfits.getdata(temp)
    if i == 0:
        v_model, phi_model, t3phi_model = oitools.compute_obs(
            oi_data, im_atom, scale)
    else:
        v_model_temp, phi_model_temp, t3phi_model_temp = oitools.compute_obs(
            oi_data, im_atom, scale)
        v_model = np.dstack((v_model, v_model_temp))
        phi_model = np.dstack((phi_model, phi_model_temp))
コード例 #7
0
# if ERROR: PLIO: reference out of bounds on mask error happen then use image[*,*,1] in input image as ur image may be more then 2 dim or [*,*,1]
# if ERROR: segmentation violation in xgterm use terminal or use linux machine
os.system("sed s/F.fits/F.fits[*,*,1]/g rm_cosmic.in> rm_cosmic_ind.in")

crmasks = '0, 0, 0, 0, 0'  # total 5 frames: 2 AGN frame and 3 standard frames.
iraf.crutil.cosmicrays("@rm_cosmic_ind.in",
                       "@rm_cosmic.out",
                       interactive='no',
                       crmasks=crmasks)

#os.system("sed s/bfc.fits/bfc.fits[10:507,10:507]/g rm_cosmic.out> trim.in")
# Note: Check the limits. This is for 512 times 512 image size
#os.system("sed s/bfc.fits/bfct.fits/g rm_cosmic.out > trim.out")

filenames = readcol('rm_cosmic.out')

photometry(filenames)

os.chdir('..')
'''
dirlist=glob.glob('*2015*')
file1=open('mag.out', 'w')
day=np.array([1, 2, 3, 4, 5, 6, 8, 9, 10, 14])
for i in range(len(dirlist)):
    Bmagfile=glob.glob(strcompress(dirlist[i]+'/'+'mcg*_b1*phot*'))
    print("Bmagfile:", Bmagfile[0])
    ap=readcol(Bmagfile[0], skipline=107)
    Bmag  = float(ap[0, 4])
    Bemag = float(ap[0, 5])
    Vmagfile=glob.glob(strcompress(dirlist[i]+'/'+'mcg*_v1*phot*'))
コード例 #8
0
                        qualflag)
            else:
                return np.array(line_pos_fitted), np.array(
                    line_sigma_fitted), np.array(line_amp_fitted)
    else:
        if return_qualflag:
            return np.array(line_pos_fitted), np.array(qualflag)
        else:
            return np.array(line_pos_fitted)


###########################################

###########################################
thar_refwlord01, thar_relintord01, flag = readcol(
    '/Users/christoph/UNSW/linelists/test_thar_list_order_01.dat',
    fsep=';',
    twod=False)
thar_refwlord01 *= 1e3
refdata = {}
refdata['order_01'] = {}
refdata['order_01']['wl'] = thar_refwlord01[np.argwhere(
    flag ==
    ' resolved')][::-1]  #note the array is turned around to match other arrays
refdata['order_01']['relint'] = thar_relintord01[np.argwhere(
    flag ==
    ' resolved')][::-1]  #note the array is turned around to match other arrays
###########################################


def get_dispsol_from_thar(thardata,
                          refdata,
コード例 #9
0
ファイル: imfit-sources.py プロジェクト: nkern/Serpens_South
     #line = str(separations[j])+ " "+str(e_separations[j])+ " "+str(separations[j]*dist) + " "+str(e_separations[j]*dist) +"\n"
     # outputfileseps.writelines(line)
   cl.close()
#   outputfilefits.close()
#   outputfileseps.close()
   print 'end of extract'


dist=230.0

#sources=['Per2','Per11','Per12','Per17','Per18','Per22','Per26','Per27','Per33','Per35','Per36','Per40','Per44','Per48','Per49','Per55','Per106','Per107','Per120','Per122']

#comps=[2,3,2,2,3,2,2,2,4,2,2,2,5,2,2,2,2,2,2,2]
inp(taskname='imfit')
cl.close()
imagelisttemp=readcol("images.txt")
#imagelist=imagelisttemp.array().tolist()
imagelist=[]
for image in imagelisttemp:
   imagelist.append(image[:][0])
#   print image

#print imagelist

sourcestemp=[line.replace('.B.Ka.cont.image.tt0','') for line in imagelist]
sources=[source.replace('../','') for source in sourcestemp]
#print imagelist
#print sources

sources.append('Per110')
sources.append('Per21')
コード例 #10
0
        t0 = t
        t = (1. + sqrt(1. + 4. * t**2)) / 2.
        z = x + ((t0 - 1.) / t) * (x - xold)
        this_pobj = 0.5 * linalg.norm(A.dot(x) - b)**2 + l * linalg.norm(x, 1)
        pobj.append((time.time() - time0, this_pobj))
        print(this_pobj)
    times, pobj = map(np.array, zip(*pobj))
    return x, pobj, times


### INPUT PARAMETERS ###

oi_data = 'COMB_JWST_SAM_tot.fits'
dict_filename = 'Dict3.npy'
input_path = ['dataset/']
input_files = readcol(input_path[0] + 'ring_gauss.txt', twod=True)
scale = 10.0  ## mas
hyperparameter = 0.01
maxit = 10000

output_filename = 'recovered_im_lasso.fits'  #Output filename

####### AUTOMATIC FROM HERE #################

### Append, normalize and reshape the data :
obs = oitools.extract_data(oi_data)
v2_data = obs['vis2'].reshape(-1)
phi_data = obs['phi'].reshape(-1)
t3phi_data = obs['t3'].reshape(-1)

v2_data = prepro.scale(v2_data)
コード例 #11
0
#!bin/python
import matplotlib.pyplot as plt
from readcol import *

a1, a2 = readcol("vr_estimate.txt", twod=False)
plt.plot(a1, a2, ls="--", label="estimate")

a1, a2 = readcol("drift_velocity.txt", twod=False)
plt.plot(a1, a2, label="calculate")

plt.show()
コード例 #12
0
import numpy as np
import matplotlib.pyplot as plt
import pdb
import astropy.io.fits as pyfits
import oitools
from readcol import *
import matplotlib.cm as cm
import matplotlib.colors as colors
from matplotlib import gridspec

oi_data = 's0_a200_COMB_pa_2018_HD163296.fits'

[ims] = readcol('new_mean_ims_ring_2018.txt', twod=False)
tit = 'Observables from BSMEM Images [Ring Model 2019]'
year = 2019

#wave_range = [2.30e-6, 2.40e-6]
scale = 0.1  ## mas

oidata = pyfits.open(oi_data)
oi_wave = oidata['OI_WAVELENGTH'].data
#oi_vis = oidata['OI_VIS'].data
oi_vis2 = oidata['OI_VIS2'].data
oi_t3 = oidata['OI_T3'].data
waves = oi_wave['EFF_WAVE']
#vis = oi_vis['VISAMP']
#vis_err = oi_vis['VISAMPERR']
#phase = oi_vis['VISPHI']
#phase_err = oi_vis['VISPHIERR']
vis2 = oi_vis2['VIS2DATA']
vis2_err = oi_vis2['VIS2ERR']
コード例 #13
0
import matplotlib.pyplot as plt
from readcol import *

for i in range(0, 40, 1):
    in_name = "pebble_num_" + str(i) + ".txt"
    rad, yr, a1, a2 = readcol(in_name, twod=False)

    plt.plot(rad, yr)
plt.yscale("log")
# plt.xscale("log")
plt.xlabel("r (AU)")
plt.ylabel("time (yr)")
plt.show()
コード例 #14
0
ファイル: oi_combine.py プロジェクト: cosmosz5/CASSINI
from readcol import *

cd = True
if cd == True:
    import oi_merge as oi_merge
else:
    import oi_merge2 as oi_merges  #
import importlib
importlib.reload(oi_merge)

data = 'combine_data_tot.txt'
[files] = readcol(data, twod=False)
merged = oi_merge.oi_merge(files)
merged.write('COMB_JWST_SAM_tot.fits')
コード例 #15
0
from matplotlib.colors import LogNorm

LUNIT = 1.49597871e13
TUNIT = 3.15569e7
m_earth = 5.97219e27
rho_peb = 1.4

TWO_POP = False

name = sys.argv[1]
num = sys.argv[2]

fig = plt.figure(figsize=(10, 6))
gs = gridspec.GridSpec(2, 2)  #,width_ratios=[1,1])

r = readcol(name + "/rad.txt")

sig0 = readcol(name + "/dust_sigma0.txt")
sig = readcol(name + "/dust_sigma" + num + ".txt")

size0 = readcol(name + "/dust_size0.txt")
size = readcol(name + "/dust_size" + num + ".txt")

if TWO_POP:
    a_drift = readcol(name + "/dust_drift" + num + ".txt")
    a_frag = readcol(name + "/dust_frag" + num + ".txt")
    a_df = readcol(name + "/dust_df" + num + ".txt")
    a_gr = readcol(name + "/dust_gr" + num + ".txt")
    tau_gr = readcol(name + "/tau_gr" + num + ".txt")

rB = np.load('rB.npy')