new numerical gradient calculation

new numerical gradient calculation

#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
#pragma OPENCL EXTENSION cl_amd_printf : enable

__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;

__kernel void GVFInit(__read_only image3d_t volume, __write_only image3d_t vector_field ) {
    // Calculate gradient using a 1D central difference for each dimension, with spacing 1
    int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0};

    float f100 = read_imagef(volume, sampler, pos + (int4)(1,0,0,0)).x;
    float f_100 = read_imagef(volume, sampler, pos - (int4)(1,0,0,0)).x;
    float f010 = read_imagef(volume, sampler, pos + (int4)(0,1,0,0)).x;
    float f0_10 = read_imagef(volume, sampler, pos - (int4)(0,1,0,0)).x;
    float f001 = read_imagef(volume, sampler, pos + (int4)(0,0,1,0)).x;
    float f00_1 = read_imagef(volume, sampler, pos - (int4)(0,0,1,0)).x;

    float4 gradient = {
        0.5*(f100-f_100),
        0.5*(f010-f0_10),
        0.5*(f001-f00_1),
        0};

    gradient.w = gradient.x*gradient.x + gradient.y*gradient.y + gradient.z*gradient.z;

    write_imagef(vector_field, pos, gradient);

}

__kernel void GVFIteration(__read_only image3d_t init_vector_field, __read_only image3d_t read_vector_field, __write_only image3d_t write_vector_field, __private float mu) {
    // TODO: Enforce mirror boundary conditions

    // Update the vector field. Calculate Laplacian using a 3D central difference scheme
    int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0};

    float4 vector = read_imagef(read_vector_field, sampler, pos);
    float4 fx1 = read_imagef(read_vector_field, sampler, pos + (int4)(1,0,0,0));
    float4 fx_1 = read_imagef(read_vector_field, sampler, pos - (int4)(1,0,0,0));
    float4 fy1 = read_imagef(read_vector_field, sampler, pos + (int4)(0,1,0,0));
    float4 fy_1 = read_imagef(read_vector_field, sampler, pos - (int4)(0,1,0,0));
    float4 fz1 = read_imagef(read_vector_field, sampler, pos + (int4)(0,0,1,0));
    float4 fz_1 = read_imagef(read_vector_field, sampler, pos - (int4)(0,0,1,0));
    float4 init_vector = read_imagef(init_vector_field, sampler, pos);

    float4 laplacian = -6*vector + fx1 + fx_1 + fy1 + fy_1 + fz1 + fz_1;

    vector += mu * laplacian - (vector - init_vector)*init_vector.w;

    write_imagef(write_vector_field, pos, vector);
}

__kernel void GVFResult(__write_only image3d_t result, __read_only image3d_t vectorField) {

    int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0};
    float4 vector = read_imagef(vectorField, sampler, pos);
    //vector.w = 0;
    float magnitude = sqrt(vector.x*vector.x + vector.y*vector.y + vector.z*vector.z);
    if(magnitude > 1)
        magnitude = 1;
    write_imagef(result, pos, magnitude);
}

#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
#pragma OPENCL EXTENSION cl_amd_printf : enable

__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;

__kernel void GVFInit(__read_only image3d_t volume, __write_only image3d_t vector_field ) {
    // Calculate gradient using a 1D central difference for each dimension, with spacing 1
    int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0};

    float f100 = read_imagef(volume, sampler, pos + (int4)(1,0,0,0)).x;
    float f_100 = read_imagef(volume, sampler, pos - (int4)(1,0,0,0)).x;
    float f010 = read_imagef(volume, sampler, pos + (int4)(0,1,0,0)).x;
    float f0_10 = read_imagef(volume, sampler, pos - (int4)(0,1,0,0)).x;
    float f001 = read_imagef(volume, sampler, pos + (int4)(0,0,1,0)).x;
    float f00_1 = read_imagef(volume, sampler, pos - (int4)(0,0,1,0)).x;

    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;
    float f110 = read_imagef(volume, sampler, pos + (int4)(1,1,0,0)).x;

    float4 gradient = {
        0,
        0,
        4*(f00_1 - f001) + 2*(f10_1 + f01_1 + f_10_1 + f0_1_1 - f101 - f011 - f_101 - f0_11) + f00_1 + f11_1 + f1_1_1 + f_11_1 - f001 - f111 - f1_11 + f_111,
        0};

    gradient.w = gradient.x*gradient.x + gradient.y*gradient.y + gradient.z*gradient.z;

    write_imagef(vector_field, pos, gradient);

}

__kernel void GVFIteration(__read_only image3d_t init_vector_field, __read_only image3d_t read_vector_field, __write_only image3d_t write_vector_field, __private float mu) {
    // TODO: Enforce mirror boundary conditions

    // Update the vector field. Calculate Laplacian using a 3D central difference scheme
    int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0};

    float4 vector = read_imagef(read_vector_field, sampler, pos);
    float4 fx1 = read_imagef(read_vector_field, sampler, pos + (int4)(1,0,0,0));
    float4 fx_1 = read_imagef(read_vector_field, sampler, pos - (int4)(1,0,0,0));
    float4 fy1 = read_imagef(read_vector_field, sampler, pos + (int4)(0,1,0,0));
    float4 fy_1 = read_imagef(read_vector_field, sampler, pos - (int4)(0,1,0,0));
    float4 fz1 = read_imagef(read_vector_field, sampler, pos + (int4)(0,0,1,0));
    float4 fz_1 = read_imagef(read_vector_field, sampler, pos - (int4)(0,0,1,0));
    float4 init_vector = read_imagef(init_vector_field, sampler, pos);

    float4 laplacian = -6*vector + fx1 + fx_1 + fy1 + fy_1 + fz1 + fz_1;

    vector += mu * laplacian - (vector - init_vector)*init_vector.w;

    write_imagef(write_vector_field, pos, vector);
}

__kernel void GVFResult(__write_only image3d_t result, __read_only image3d_t vectorField) {

    int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0};
    float4 vector = read_imagef(vectorField, sampler, pos);
    //vector.w = 0;
    float magnitude = sqrt(vector.x*vector.x + vector.y*vector.y + vector.z*vector.z);
    if(magnitude > 1)
        magnitude = 1;
    write_imagef(result, pos, magnitude);
}


Updating pysalt.cl to the 0.45 version

Updating pysalt.cl to the 0.45 version

################################# LICENSE ##################################
# Copyright (c) 2009, South African Astronomical Observatory (SAAO)        #
# All rights reserved.                                                     #
#                                                                          #
# Redistribution and use in source and binary forms, with or without       #
# modification, are permitted provided that the following conditions       #
# are met:                                                                 #
#                                                                          #
#     * Redistributions of source code must retain the above copyright     #
#       notice, this list of conditions and the following disclaimer.      #
#     * Redistributions in binary form must reproduce the above copyright  #
#       notice, this list of conditions and the following disclaimer       #
#       in the documentation and/or other materials provided with the      #
#       distribution.                                                      #
#     * Neither the name of the South African Astronomical Observatory     #
#       (SAAO) nor the names of its contributors may be used to endorse    #
#       or promote products derived from this software without specific    #
#       prior written permission.                                          #
#                                                                          #
# THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR       #
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED           #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE   #
# DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY                 #
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL       #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS  #
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)    #
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,      #
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          #
# POSSIBILITY OF SUCH DAMAGE.                                              #
############################################################################

# Package script for the PySALT package

# IRAF patch level V2.12.2a or greater is required.
if (defpar ("release")) {
    if (release <= "2.12.1") {
        printf ("WARNING: IRAF patch level V2.12.2 or greater is required\n")
        printf ("         to run the SALT IRAF package\n")
        sleep 1
    }
} else {
    printf ("WARNING: IRAF patch level V2.12.2 or greater is required\n")
    printf ("         to run the SALT IRAF package\n")
    sleep 1
}
;

# Load necessary packages - only those that are used by all packages

# Set the imtype to fits
reset imtype = "fits"
flpr

# Set up tasks which report on PyRAF-based tasks
task pyexecute = "pysalt$pyexecute.cl"
hidetask pyexecute

# This task simply prints a message stating that a task needs PyRAF to run
task nopyraf = "pysalt$nopyraf.cl"
hidetask nopyraf

# Add python tree to default Python path, if running PyRAF
pyexecute("pysalt$addpath.py",verbose=no)

#define the different tasks

set saltred = "pysalt$saltred/"
set slottools = "pysalt$slottools/"
set bvittools = "pysalt$bvittools/"
set saltfp = "pysalt$saltfp/"
set saltspec = "pysalt$saltspec/"
set proptools = "pysalt$proptools/"

package pysalt

task saltred.pkg = saltred$saltred.cl

task slottools.pkg = slottools$slottools.cl

if (access('saltfp$saltfp.cl')) {
  task saltfp.pkg = saltfp$saltfp.cl
}

if (access('saltspec$saltspec.cl')) {
   task saltspec.pkg = saltspec$saltspec.cl
}

if (access('proptools$proptools.cl')) {
   task proptools.pkg = proptools$proptools.cl
}

if (access('bvittools$bvittools.cl')) {
   task bvittools.pkg = bvittools$bvittools.cl
}

task $sed = $foreign
hidetask sed

print(" ")
print("     +----------------------------------------------------+")
print("     |                  _ _                               |")
print("     |   __ _ _  __ __ | | |_    http://www.salt.ac.za    |")
print("     |  | _\ | || _| _`| |  _|   Southern African Large   |")
print("     |  |  /__ |__|\_,_|_|\__|   Telescope PyRAF Package  |")
print("     |  |_| \__'                                          |")
print("     |               STABLE PRERELEASE                    |")
print("     |               Version 0.45 27 Sep 2013             |")
print("     |               Recommend IRAF 2.14/PyRAF 1.8.1      |")
print("     |               Bug reports: salthelp@salt.ac.za     |")
print("     +----------------------------------------------------+")
print(" ")
print("     Setting imtype=fits")
print(" ")

;
clbye()

################################# LICENSE ##################################
# Copyright (c) 2009, South African Astronomical Observatory (SAAO)        #
# All rights reserved.                                                     #
#                                                                          #
# Redistribution and use in source and binary forms, with or without       #
# modification, are permitted provided that the following conditions       #
# are met:                                                                 #
#                                                                          #
#     * Redistributions of source code must retain the above copyright     #
#       notice, this list of conditions and the following disclaimer.      #
#     * Redistributions in binary form must reproduce the above copyright  #
#       notice, this list of conditions and the following disclaimer       #
#       in the documentation and/or other materials provided with the      #
#       distribution.                                                      #
#     * Neither the name of the South African Astronomical Observatory     #
#       (SAAO) nor the names of its contributors may be used to endorse    #
#       or promote products derived from this software without specific    #
#       prior written permission.                                          #
#                                                                          #
# THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR       #
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED           #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE   #
# DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY                 #
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL       #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS  #
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)    #
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,      #
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          #
# POSSIBILITY OF SUCH DAMAGE.                                              #
############################################################################

# Package script for the PySALT package

# IRAF patch level V2.12.2a or greater is required.
if (defpar ("release")) {
    if (release <= "2.12.1") {
        printf ("WARNING: IRAF patch level V2.12.2 or greater is required\n")
        printf ("         to run the SALT IRAF package\n")
        sleep 1
    }
} else {
    printf ("WARNING: IRAF patch level V2.12.2 or greater is required\n")
    printf ("         to run the SALT IRAF package\n")
    sleep 1
}
;

# Load necessary packages - only those that are used by all packages

# Set the imtype to fits
reset imtype = "fits"
flpr

# Set up tasks which report on PyRAF-based tasks
task pyexecute = "pysalt$pyexecute.cl"
hidetask pyexecute

# This task simply prints a message stating that a task needs PyRAF to run
task nopyraf = "pysalt$nopyraf.cl"
hidetask nopyraf

# Add python tree to default Python path, if running PyRAF
pyexecute("pysalt$addpath.py",verbose=no)

#define the different tasks

set saltred = "pysalt$saltred/"
set slottools = "pysalt$slottools/"
set bvittools = "pysalt$bvittools/"
set saltfp = "pysalt$saltfp/"
set saltspec = "pysalt$saltspec/"
set proptools = "pysalt$proptools/"

package pysalt

task saltred.pkg = saltred$saltred.cl

task slottools.pkg = slottools$slottools.cl

if (access('saltfp$saltfp.cl')) {
  task saltfp.pkg = saltfp$saltfp.cl
}

if (access('saltspec$saltspec.cl')) {
   task saltspec.pkg = saltspec$saltspec.cl
}

if (access('proptools$proptools.cl')) {
   task proptools.pkg = proptools$proptools.cl
}

if (access('bvittools$bvittools.cl')) {
   task bvittools.pkg = bvittools$bvittools.cl
}

task $sed = $foreign
hidetask sed

print(" ")
print("     +----------------------------------------------------+")
print("     |                  _ _                               |")
print("     |   __ _ _  __ __ | | |_    http://www.salt.ac.za    |")
print("     |  | _\ | || _| _`| |  _|   Southern African Large   |")
print("     |  |  /__ |__|\_,_|_|\__|   Telescope PyRAF Package  |")
print("     |  |_| \__'                                          |")
print("     |               STABLE PRERELEASE                    |")
print("     |               Version 0.45a 01 May 2013            |")
print("     |               Recommend IRAF 2.14/PyRAF 1.8.1      |")
print("     |               Bug reports: salthelp@salt.ac.za     |")
print("     +----------------------------------------------------+")
print(" ")
print("     Setting imtype=fits")
print(" ")

;
clbye()