Skip to content

Commit 9d6dfe1

Browse files
author
Unknown
committed
Some final updates for v1.3.
1 parent a13d690 commit 9d6dfe1

9 files changed

Lines changed: 76 additions & 131 deletions

rss_ringoccs/diffrec/src/__diffraction_functions.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
******************************************************************************
7878
* Author: Ryan Maguire, Wellesley College *
7979
* Date: June 21, 2019 *
80-
*****************************************************************************/
80+
******************************************************************************/
8181
#include "__diffraction_functions.h"
8282

8383
/******************************************************************************
@@ -329,7 +329,8 @@ complex double Fresnel_Transform_Norm_Double(double *x_arr,
329329
complex double Fresnel_Legendre_Double(double *x_arr, complex double *T_in,
330330
double *w_func, double D, double *coeffs,
331331
double dx, double F, double kd,
332-
long n_pts, int order, long center)
332+
long n_pts, unsigned char order,
333+
long center)
333334
{
334335
/* Declare all necessary variables. i, j, and k are used for indexing. */
335336
long i, j, k;
@@ -396,8 +397,8 @@ complex double Fresnel_Legendre_Double(double *x_arr, complex double *T_in,
396397
complex double Fresnel_Legendre_Norm_Double(double *x_arr, complex double *T_in,
397398
double *w_func, double D,
398399
double *coeffs, double dx, double F,
399-
double kd, long n_pts, int order,
400-
long center)
400+
double kd, long n_pts,
401+
unsigned char order, long center)
401402
{
402403
/* Declare all necessary variables. i and j are used for indexing. */
403404
long i, j, k;
@@ -716,7 +717,7 @@ void DiffractionCorrectionLegendre(DLPObj dlp)
716717
double Legendre_Coeff;
717718
double (*fw)(double, double);
718719
complex double (*FresT)(double*, complex double*, double*, double, double *,
719-
double, double, double, long, int, long);
720+
double, double, double, long, unsigned char, long);
720721

721722
/* Cast the selected window type to the fw pointer. */
722723
if (dlp.wtype == 0){fw = &Rect_Window_Double;}

rss_ringoccs/diffrec/src/__diffraction_functions.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#ifndef RSS_RINGOCCS_DIFFRACTION_FUNCTIONS_H
33
#define RSS_RINGOCCS_DIFFRACTION_FUNCTIONS_H
44

5-
/* Various trig functions, complex variables, and more found here. */
5+
/* Various functions, complex variables, and more found here. */
66
#include <stdlib.h>
7-
#include <math.h>
87
#include <complex.h>
98
#include "__math_functions.h"
109
#include "__window_functions.h"
1110
#include "__fresnel_kernel.h"
1211

12+
/* Structure that contains all of the necessary data. */
1313
typedef struct _dlpdataobj {
1414
complex double *T_in;
1515
double *rho_km_vals;
@@ -21,20 +21,14 @@ typedef struct _dlpdataobj {
2121
double *w_km_vals;
2222
long start;
2323
long n_used;
24-
int wtype;
25-
int use_norm;
26-
int use_fwd;
27-
int psitype;
28-
int order;
24+
unsigned char wtype;
25+
unsigned char use_norm;
26+
unsigned char use_fwd;
27+
unsigned char order;
2928
complex double *T_out;
3029
} DLPObj;
3130

32-
/* Coefficients and constants defined here. */
33-
#include "__math_constants.h"
34-
35-
/* Functions for computing the Fresnel Kernel and Newton's Method. */
36-
#include "__fresnel_kernel.h"
37-
31+
/* Functions defined in __diffraction_functions.c */
3832
extern complex double Fresnel_Transform_Double(
3933
double *x_arr, complex double *T_in, double *w_func, double F, double dx,
4034
long n_pts, long center
@@ -48,13 +42,13 @@ extern complex double Fresnel_Transform_Norm_Double(
4842
extern complex double Fresnel_Legendre_Double(
4943
double *x_arr, complex double *T_in, double *w_func, double D,
5044
double *coeffs, double dx, double F, double kd, long n_pts,
51-
int order, long center
45+
unsigned char order, long center
5246
);
5347

5448
extern complex double Fresnel_Legendre_Norm_Double(
5549
double *x_arr, complex double *T_in, double *w_func, double D,
5650
double *coeffs, double dx, double F, double kd, long n_pts,
57-
int order, long center
51+
unsigned char order, long center
5852
);
5953

6054
extern complex double Fresnel_Transform_Newton_Double(

rss_ringoccs/diffrec/src/__fraunhofer_diffraction_double_slit.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "__fraunhofer_diffraction.h"
22

33
float Double_Slit_Fraunhofer_Diffraction_Float(float x, float z,
4-
float a, float d){
4+
float a, float d)
5+
{
56
float var_1, var_2, var_3;
67

78
var_1 = Sinc_Float(a*x/z);
@@ -17,7 +18,8 @@ float Double_Slit_Fraunhofer_Diffraction_Float(float x, float z,
1718
}
1819

1920
double Double_Slit_Fraunhofer_Diffraction_Double(double x, double z,
20-
double a, double d){
21+
double a, double d)
22+
{
2123
double var_1, var_2, var_3;
2224

2325
var_1 = Sinc_Double(a*x/z);
@@ -35,7 +37,8 @@ double Double_Slit_Fraunhofer_Diffraction_Double(double x, double z,
3537
long double Double_Slit_Fraunhofer_Diffraction_Long_Double(long double x,
3638
long double z,
3739
long double a,
38-
long double d){
40+
long double d)
41+
{
3942
long double var_1, var_2, var_3;
4043

4144
var_1 = Sinc_Long_Double(a*x/z);
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
#include "__fraunhofer_diffraction.h"
22

3-
float Single_Slit_Fraunhofer_Diffraction_Float(float x, float z, float a){
3+
float Single_Slit_Fraunhofer_Diffraction_Float(float x, float z, float a)
4+
{
45
float result = Sinc_Float(a*x/z);
56
return result*result;
67
}
78

8-
double Single_Slit_Fraunhofer_Diffraction_Double(double x, double z, double a){
9+
double Single_Slit_Fraunhofer_Diffraction_Double(double x, double z, double a)
10+
{
911
double result = Sinc_Double(a*x/z);
1012
return result*result;
1113
}
1214

1315
long double Single_Slit_Fraunhofer_Diffraction_Long_Double(long double x,
1416
long double z,
15-
long double a){
17+
long double a)
18+
{
1619
long double result = Sinc_Long_Double(a*x/z);
1720
return result*result;
1821
}

rss_ringoccs/diffrec/src/__fresnel_diffraction_inverted_square_well.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
* 1.) This function relies on the C99 standard, or higher. *
2222
******************************************************************************/
2323
complex float Inverted_Square_Well_Diffraction_Float(float x, float a,
24-
float b, float F){
24+
float b, float F)
25+
{
2526
float arg1 = SQRT_PI_BY_2*(a-x)/F;
2627
float arg2 = SQRT_PI_BY_2*(b-x)/F;
2728
complex float result = Fresnel_Heald_Rational_EPS_Minus_Eight_Func(arg2) -
@@ -49,7 +50,8 @@ complex float Inverted_Square_Well_Diffraction_Float(float x, float a,
4950
* 1.) This function relies on the C99 standard, or higher. *
5051
******************************************************************************/
5152
complex double Inverted_Square_Well_Diffraction_Double(double x, double a,
52-
double b, double F){
53+
double b, double F)
54+
{
5355
double arg1 = SQRT_PI_BY_2*(a-x)/F;
5456
double arg2 = SQRT_PI_BY_2*(b-x)/F;
5557
complex double result = Fresnel_Heald_Rational_EPS_Minus_Eight_Func(arg2) -

rss_ringoccs/diffrec/src/__fresnel_diffraction_left_straightedge.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
/***********Left Straightedge Diffraction Using Fresnel Approximation**********/
44

5-
complex float Left_Straightedge_Diffraction_Float(float x, float edge, float F){
5+
complex float Left_Straightedge_Diffraction_Float(float x, float edge, float F)
6+
{
67
complex float T_hat;
78
float re, im;
89

@@ -16,7 +17,8 @@ complex float Left_Straightedge_Diffraction_Float(float x, float edge, float F){
1617
}
1718

1819
complex double Left_Straightedge_Diffraction_Double(double x, double edge,
19-
double F){
20+
double F)
21+
{
2022
complex double T_hat;
2123
double re, im;
2224

@@ -30,7 +32,8 @@ complex double Left_Straightedge_Diffraction_Double(double x, double edge,
3032
}
3133

3234
complex long double Left_Straightedge_Diffraction_Long_Double(
33-
long double x, long double edge, long double F){
35+
long double x, long double edge, long double F)
36+
{
3437
complex long double T_hat;
3538
long double re, im;
3639

rss_ringoccs/diffrec/src/_diffraction_functions.c

Lines changed: 23 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,8 @@
22
* Diffraction Functions *
33
******************************************************************************
44
* Purpose: *
5-
* This file contains functions used for computing the Fresnel Inverse *
6-
* Transform on a set of diffraction limited data. There are several *
7-
* Methods of performing this: *
8-
* Fresnel Quadratic Approximation: *
9-
* Classic quadratic approximation from Fourier Optics. *
10-
* Legendre Expansions: *
11-
* Uses Legendre polynomials to approximate the Fresnel kernel. *
12-
* Newton-Raphon Method: *
13-
* Uses Newton-Raphson root finding method to compute the *
14-
* stationary value of the Fresnel kernel. *
15-
******************************************************************************
16-
* The Inverse Fresnel Transform: *
17-
* *
18-
* W/2 *
19-
* - *
20-
* | | *
21-
* T(rho) = | T_hat(r_0)w(r-r_0)exp(-i psi(r,r_0)) dr_0 *
22-
* | | *
23-
* - *
24-
* -W/2 *
25-
* *
26-
* Where T_hat is the diffracted data, w is the window function, r is *
27-
* the ring intercept point, and r_0 is a dummy variable of integration. *
28-
* psi is the Fresnel Kernel, and exp is simply the exponential function. *
29-
******************************************************************************
30-
* The Normalization Scheme: *
31-
* As the resolution get's too high, say 10 km or greater, the window *
32-
* width quickly shrinks to zero. Thus the integral will be close to *
33-
* zero. To account for this the option to normalize the integral by the *
34-
* window width is offered. The normalization is defined as follows: *
35-
* *
36-
* | _ +infinity | *
37-
* | | | | *
38-
* | | exp(-i psi(x)) dx | *
39-
* | | | | *
40-
* | - -infinity | *
41-
* Norm = __________________________________ *
42-
* | - +W/2 | *
43-
* | | | | *
44-
* | | w(x) exp(-i psi(x)) dx | *
45-
* | | | | *
46-
* | - -W/2 | *
47-
* *
48-
* This has the effect of making the free-space regions, or regions which*
49-
* were not affected by diffraction, evaluate to approximately one, *
50-
* regardless of what resolution was chosen. *
51-
******************************************************************************
52-
* DEFINED FUNCTIONS *
53-
******************************************************************************
54-
* complex_double_fresnel_transform_quadratic: *
55-
* Computes the Fresnel Inverse Transform using Fresnel's approximation. *
56-
* This is the fastest, but can be inaccurate for certain geometries. *
57-
******************************************************************************
58-
* complex_double_fresnel_legendre_transform: *
59-
* Approximates the transform using Legendre polynomials. This is very *
60-
* fast and accurate. It is the default method called from Python. *
61-
******************************************************************************
62-
* complex_double_fresnel_transform_newton: *
63-
* Uses Newton-Raphson to compute the stationary value of the Fresnel *
64-
* Kernel. This is the most accurate, but also the slowest. *
5+
* This file contains wrappers for the routines found in *
6+
* __diffraction_functions.c to allow use with the Python interpreter. *
657
******************************************************************************
668
* A FRIENDY WARNING *
679
******************************************************************************
@@ -101,10 +43,10 @@ static void complex_double_fresnel_transform(char **args, npy_intp *dimensions,
10143
dlp.w_km_vals = (double *)args[7];
10244
dlp.start = *(long *)args[8];
10345
dlp.n_used = *(long *)args[9];
104-
dlp.wtype = *(int *)args[10];
105-
dlp.use_norm = *(int *)args[11];
106-
dlp.use_fwd = *(int *)args[12];
107-
dlp.order = *(int *)args[13];
46+
dlp.wtype = *(unsigned char *)args[10];
47+
dlp.use_norm = *(unsigned char *)args[11];
48+
dlp.use_fwd = *(unsigned char *)args[12];
49+
dlp.order = *(unsigned char *)args[13];
10850
dlp.T_out = (complex double *)args[14];
10951

11052
if (dlp.order == 0){
@@ -118,19 +60,12 @@ static void complex_double_fresnel_transform(char **args, npy_intp *dimensions,
11860
}
11961
}
12062

121-
/******************************************************************************
122-
*----------------------------C Python API Stuff------------------------------*
123-
******************************************************************************/
124-
12563
static PyMethodDef _diffraction_functions_methods[] = {{NULL, NULL, 0, NULL}};
12664

12765
/* Define pointers to the C functions. */
128-
PyUFuncGenericFunction funcs[1] = {
129-
&complex_double_fresnel_transform
130-
};
66+
PyUFuncGenericFunction funcs[1] = {&complex_double_fresnel_transform};
13167

132-
133-
/* Input and return types for Quartic Fresnel Transform */
68+
/* Input and return types for the Fresnel Transform */
13469
static char data_types[15] = {
13570
NPY_CDOUBLE,
13671
NPY_DOUBLE,
@@ -142,24 +77,23 @@ static char data_types[15] = {
14277
NPY_DOUBLE,
14378
NPY_LONG,
14479
NPY_LONG,
145-
NPY_LONG,
146-
NPY_LONG,
147-
NPY_LONG,
148-
NPY_LONG,
80+
NPY_UBYTE,
81+
NPY_UBYTE,
82+
NPY_UBYTE,
83+
NPY_UBYTE,
14984
NPY_CDOUBLE
15085
};
15186

15287
static void *PyuFunc_data[1] = {NULL};
15388

15489
#if PY_VERSION_HEX >= 0x03000000
155-
static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT,
156-
"_diffraction_functions",
157-
NULL,
158-
-1,
159-
_diffraction_functions_methods,
160-
NULL, NULL, NULL, NULL};
161-
162-
PyMODINIT_FUNC PyInit__diffraction_functions(void){
90+
static struct PyModuleDef moduledef = {
91+
PyModuleDef_HEAD_INIT, "_diffraction_functions", NULL, -1,
92+
_diffraction_functions_methods, NULL, NULL, NULL, NULL
93+
};
94+
95+
PyMODINIT_FUNC PyInit__diffraction_functions(void)
96+
{
16397
PyObject *fresnel_transform;
16498
PyObject *m, *d;
16599

@@ -183,7 +117,8 @@ PyMODINIT_FUNC PyInit__diffraction_functions(void){
183117
return m;
184118
}
185119
#else
186-
PyMODINIT_FUNC init__diffraction_functions(void){
120+
PyMODINIT_FUNC init__diffraction_functions(void)
121+
{
187122
PyObject *fresnel_transform;
188123
PyObject *m, *d;
189124

@@ -197,7 +132,7 @@ PyMODINIT_FUNC init__diffraction_functions(void){
197132

198133
fresnel_transform = PyUFunc_FromFuncAndData(
199134
funcs, PyuFunc_data, data_types, 1, 14, 1, PyUFunc_None,
200-
"fresnel_transform_", "fresnel_transform", 0
135+
"fresnel_transform_", "fresnel_transform_docstring", 0
201136
);
202137

203138
d = PyModule_GetDict(m);
@@ -206,4 +141,4 @@ PyMODINIT_FUNC init__diffraction_functions(void){
206141
Py_DECREF(fresnel_transform);
207142
return m;
208143
}
209-
#endif
144+
#endif

0 commit comments

Comments
 (0)