<commit_before># lnprob evaluation for V4046Sgr

const global keylist = Int[i for i=1:23]

# go through any previously created directories and remove them before the start
# of the run
function cleardirs!(keylist::Vector{Int})
    println("Removing old directories")
    for key in keylist
        keydir = "jud$key"
        run(`rm -rf $keydir`)
    end
    println("Removed directories")
end

# Clear all directories
cleardirs!(keylist)

nchild = length(keylist)
addprocs(nchild)

# Optionally regenerate static files here
#write_grid()

@everywhere using constants
@everywhere using parallel
@everywhere using visibilities
@everywhere using image
@everywhere using gridding
@everywhere using model


@everywhere function initfunc(key)

    # Load the relevant chunk of the dataset
    dset = DataVis("data/V4046Sgr.hdf5", key)

    # Create a directory where all RADMC files will reside and be driven from
    keydir = "jud$key"
    mkdir(keydir)

    # Copy all relevant configuration scripts to this subdirectory
    # these are mainly setup files which will not change throughout the run
    run(`cp radmc3d.inp $keydir`)
    run(`cp amr_grid.inp $keydir`)
    run(`cp lines.inp $keydir`)
    run(`cp molecule_co.inp $keydir`)
    run(`cp wavelength_micron.inp $keydir`)

    # change the subprocess to reside in this directory for the remainder of the run
    # where it will drive its own independent RADMC3D process
    cd(keydir)

    # return the dataset
    return dset
end

# This is the likelihood function called by each individual process
@everywhere function f(dv::DataVis, key::Int, p::Parameters)

    # Unpack these variables from p
    incl = p.incl # [deg]
    vel = p.vel # [km/s]
    PA = 90. - p.PA # [deg] Position angle runs counter clockwise, due to looking at sky.
    npix = 96 # number of pixels, can alternatively specify x and y separately

    # Doppler shift the dataset wavelength to rest-frame wavelength
    beta = vel/c_kms
    lam0 =  dv.lam * sqrt((1. - beta) / (1. + beta)) # [microns]

    # Run RADMC3D, redirect output to /dev/null
    run(`radmc3d image incl $incl posang $PA npix $npix lambda $lam0`) # |> DevNull)

    # Read the RADMC3D image from disk (we should already be in sub-directory)
    im = imread()

    # Convert raw image to the appropriate distance
    skim = imToSky(im, p.dpc)

    # Apply the gridding correction function before doing the FFT
    corrfun!(skim, 1.0) #alpha = 1.0

    # FFT the appropriate image channel
    vis_fft = transform(skim)

    # Interpolate the `vis_fft` to the same locations as the DataSet
    mvis = ModelVis(dv, vis_fft)

    # Apply the phase correction here, since there are fewer data points
    phase_shift!(mvis, p.mu_x, p.mu_y)

    # Calculate chi^2 between these two
    return lnprob(dv, mvis)
end

# Write the new grid, then copy
write_grid()

pipes = initialize(nchild, keylist, initfunc, f)
gather!(pipes)<commit_msg>pipe to /dev/null<commit_after># lnprob evaluation for V4046Sgr

const global keylist = Int[i for i=1:23]

# go through any previously created directories and remove them before the start
# of the run
function cleardirs!(keylist::Vector{Int})
    println("Removing old directories")
    for key in keylist
        keydir = "jud$key"
        run(`rm -rf $keydir`)
    end
    println("Removed directories")
end

# Clear all directories
cleardirs!(keylist)

nchild = length(keylist)
addprocs(nchild)

# Optionally regenerate static files here
#write_grid()

@everywhere using constants
@everywhere using parallel
@everywhere using visibilities
@everywhere using image
@everywhere using gridding
@everywhere using model


@everywhere function initfunc(key)

    # Load the relevant chunk of the dataset
    dset = DataVis("data/V4046Sgr.hdf5", key)

    # Create a directory where all RADMC files will reside and be driven from
    keydir = "jud$key"
    mkdir(keydir)

    # Copy all relevant configuration scripts to this subdirectory
    # these are mainly setup files which will not change throughout the run
    run(`cp radmc3d.inp $keydir`)
    run(`cp amr_grid.inp $keydir`)
    run(`cp lines.inp $keydir`)
    run(`cp molecule_co.inp $keydir`)
    run(`cp wavelength_micron.inp $keydir`)

    # change the subprocess to reside in this directory for the remainder of the run
    # where it will drive its own independent RADMC3D process
    cd(keydir)

    # return the dataset
    return dset
end

# This is the likelihood function called by each individual process
@everywhere function f(dv::DataVis, key::Int, p::Parameters)

    # Unpack these variables from p
    incl = p.incl # [deg]
    vel = p.vel # [km/s]
    PA = 90. - p.PA # [deg] Position angle runs counter clockwise, due to looking at sky.
    npix = 96 # number of pixels, can alternatively specify x and y separately

    # Doppler shift the dataset wavelength to rest-frame wavelength
    beta = vel/c_kms
    lam0 =  dv.lam * sqrt((1. - beta) / (1. + beta)) # [microns]

    # Run RADMC3D, redirect output to /dev/null
    run(`radmc3d image incl $incl posang $PA npix $npix lambda $lam0` |> DevNull)

    # Read the RADMC3D image from disk (we should already be in sub-directory)
    im = imread()

    # Convert raw image to the appropriate distance
    skim = imToSky(im, p.dpc)

    # Apply the gridding correction function before doing the FFT
    corrfun!(skim, 1.0) #alpha = 1.0

    # FFT the appropriate image channel
    vis_fft = transform(skim)

    # Interpolate the `vis_fft` to the same locations as the DataSet
    mvis = ModelVis(dv, vis_fft)

    # Apply the phase correction here, since there are fewer data points
    phase_shift!(mvis, p.mu_x, p.mu_y)

    # Calculate chi^2 between these two
    return lnprob(dv, mvis)
end

# Write the new grid, then copy
write_grid()

pipes = initialize(nchild, keylist, initfunc, f)
gather!(pipes)
{'fraction_non_alphanumeric': 0.08329066393582522, 'fraction_numerical': 0.010240655401945725, 'mean_word_length': 3.4801223241590216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5583589', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1805, 'n_words': 697}