diff --git a/README.md b/README.md index 7c3b5b7..bf4d12a 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ You can add these lines to your ``.bashrc`` file or other startup profile if you ``` OSIRIS_VERBOSE=0 -source scripts/osirisSetup.sh -osirisSetup /my/path/to/osiris/drp/ +source /my/path/to/osiris/drp/scripts/osirisSetup.sh +osirisSetup /my/path/to/osiris/drp ``` diff --git a/modules/source/drp_structs.h b/modules/source/drp_structs.h index 2468a82..f9d430a 100644 --- a/modules/source/drp_structs.h +++ b/modules/source/drp_structs.h @@ -19,7 +19,7 @@ #define MAXFRAMESINDATASETS 30 #define DATA 2048 // Equivalent to BIGFRAMES' FRAMESIZE -#define MAXSLICE 16 // Maximum slice of image in pixels +#define MAXSLICE 16 // Maximum slice of image in pixels; original value = 16 #define numspec 1216 // numspec and numcolumn are same for BB and NB. #define numcolumn 19 // ... final NB frames will have 51 columns and (51*66)=3366 spectra! #define specpercol (numspec/numcolumn) // # of spectra per lenslet column diff --git a/modules/source/mkrecmatrx_000.c b/modules/source/mkrecmatrx_000.c index 7cf7d7e..e1ddefe 100644 --- a/modules/source/mkrecmatrx_000.c +++ b/modules/source/mkrecmatrx_000.c @@ -322,7 +322,8 @@ int mkrecmatrx_000(int argc, void* argv[]) { } } } - } + + } // Look at the upper and lower edges of each strip. Set them to 0, if they are too large if ( fabs(basis_vectors[sp][0][i]) > (pretotal/2.0) ) basis_vectors[sp][0][i]=0.0; if ( fabs(basis_vectors[sp][(basesize-1)][i]) > (pretotal/2.0) ) basis_vectors[sp][(basesize-1)][i]=0.0; diff --git a/modules/source/spatrectif_000.c b/modules/source/spatrectif_000.c index 3e8b2ec..e5fe5d3 100644 --- a/modules/source/spatrectif_000.c +++ b/modules/source/spatrectif_000.c @@ -1,366 +1,321 @@ -/* spatrectif_000.c */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -int errno; -#include "drp_structs.h" -#include "fitsio.h" - -float blame[DATA][numspec][MAXSLICE]; // Kernal for applying blame to lenslets for the first portion of the iterations -float weight[numspec][DATA]; // Weight normalization factor for distributing blame -float good[numspec][DATA]; // Weighted version of quality to decide if a pixel is valid. -float cmp[numspec][DATA]; // Weights for good - -float fblame[DATA][numspec][MAXSLICE]; // Kernal for applying blame during the final iterations -float fbasisv[DATA][numspec][MAXSLICE]; // influence matrix -float fweight[numspec][DATA]; // Weight factor for distributing final blame -float *fw; // Weight factor for distributing final blame -float *w; // Weight factor for distributing final blame -float t_image[DATA][numspec]; -float c_image[DATA][numspec]; -float *ti; -float *ci; -float dummy[DATA]; -float residual[DATA]; -float new_image[numspec][DATA]; -float adjust[MAXSLICE]; -float maxi; -int where; - -int spatrectif_000(int argc, void* argv[]) -{ - // Parameters input in IDL calling program - short int totalParmCount; - short int numiter; - float scale; - float relaxation; - float relax; - short int basesize; - short int (*hilo)[2]; - short int bottom[numspec]; - short int *effective; - float *bv; - float *bl, *fbl, *fbv; - float (*basis_vectors)[MAXSLICE][DATA]; - Module *pModule; - DataSet *pDataSet; - float (*Frames)[DATA]; - IDL_STRING *Headers; - float (*Noise)[DATA]; - unsigned char (*Quality)[DATA]; - float (*image)[DATA]; - float (*noise)[DATA]; - unsigned char (*quality)[DATA]; - // End of parameters input in IDL calling program - - double t1, t2, t3, t4, t5, t6; // Time counters used to examine execution time - short int i=0, ii=0, j=0, jj=0, sp=0, l=0; - long int in1=0, in2=0, in3=0, index[numspec]; - - // Make a temporary residual matrix - long naxes[3]; - naxes[0] = DATA; - naxes[1] = DATA; - naxes[2] = (21); - // ******************************* - - // These parameters should be set in the same order as theay are passed - // from the IDL code. This is not yet automated, and I'm not sure how to - // do it. - i = 0; - totalParmCount = *(short int * )argv[i++]; - numiter = *(short int * )argv[i++]; - relaxation = *(float * )argv[i++]; - basesize = *(short int * )argv[i++]; - hilo = (short int (*)[2] )argv[i++]; - effective = (short int * )argv[i++]; - basis_vectors = (float (*)[MAXSLICE][DATA])argv[i++]; - pModule = (Module * )argv[i++]; - pDataSet = (DataSet * )argv[i++]; - Frames = (float (*)[DATA] )argv[i++]; - Headers = (IDL_STRING * )argv[i++]; - Noise = (float (*)[DATA] )argv[i++]; - Quality = (unsigned char (*)[DATA] )argv[i++]; - image = (float (*)[DATA] )argv[i++]; - noise = (float (*)[DATA] )argv[i++]; - quality = (unsigned char (*)[DATA] )argv[i++]; - scale = *(float * )argv[i++]; // Plate scale - - /* - * Start placing items from the original rectification code here. - * This code will rectify an input data frame. - */ - // printf("Image is spatrectif is %x.\n",image); - printf( "spatrectif_000.c: Now processing RAW data...\n"); - printf("Number of iterations = %d.\n",numiter); - /* printf("Relaxation Parameter = %f.\n",relaxation); - printf("Platescale = %f.\n",scale); */ - (void)fflush(stdout); - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Iterate on each lenslet. - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - memset((void *)image,0, IMAGECNT ); // initial guess of the solution - - t1=systime(); - - // Set the local pointer bv equal to the address of the lowest member of the basis_vector - bv = basis_vectors[0][0]; - for (sp = 0; sp< numspec; sp++) - { - bottom[sp]=hilo[sp][0]; - } - - printf("Calculating weights.\n"); - (void)fflush(stdout); - - for (sp=0; sp maxi ) - // { - // maxi = fbv[l]; - // where = l; - // } - // } - // bl[where]= maxi; // Alternative initial blame where only peak pixel is used. - // w[i] = bl[where]; - for (l=0; l 0.0 ) - { - for (l=0; l 0.0 ) - { - for (l=0; l 14) { - // After first set of iterations, settle down to stable solution - ci[sp]+=relax*residual[j]* fbl[jj]; - } - // if ( ii > 20) { - // After first set of iterations, settle down to stable solution - // ci[sp]+=2.0*relax*residual[j]* fbl[jj]; - //} - j++; - } - } - // For the first iterations, correction is sharpened and applied. - if ( ii < 10 ) { - for (sp=0; sp< numspec; sp++) { // Correct middle rows - if ( weight[sp][i] > 0.0 ) {// Increment guess image - ci[sp]+= ti[sp]; - if ( sp > 63 ) - if ( weight[sp-64][i] > 0.0 ) // Increment guess image - ci[sp]+= 0.4*(ti[sp]-ti[sp-64]); - if ( sp < numspec-64 ) - if ( weight[sp+64][i] > 0.0 ) // Increment guess image - ci[sp]+= 0.4*(ti[sp]-ti[sp+64]); - } - } - } - if ( (ii > 9) && (ii < 15) ) { - for (sp=0; sp< numspec; sp++) { // Correct middle rows - if ( weight[sp][i] > 0.0 ) {// Increment guess image - ci[sp]+= ti[sp]; - if ( sp > 63 ) - if ( weight[sp-64][i] > 0.0 ) // Increment guess image - ci[sp]-= 0.2*(ti[sp]-ti[sp-64]); - if ( sp < numspec-64 ) - if ( weight[sp+64][i] > 0.0 ) // Increment guess image - ci[sp]-= 0.2*(ti[sp]-ti[sp+64]); - } - } - } - - // if ( (scale > 0.099) && (ii < 2) ) { - - } // end of loop over image. - // Smooth early iterations along the spectral direction. - if ( (ii > 11) && (ii < 18) ) - { - for (sp = 0; sp 4.5 ) quality[sp][i]=9; // Implies over have of the weights have good pixels. - } // for each spectral channel sp ... - } - printf("\n"); - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - t2 = systime(); - // (void)printf("Total Time = %lf\n", t2-t1 ); - - // writefitsimagefile("!/sdata1101/osiris-data/osiris2/050224/SPEC/ORP/resid.fits", FLOAT_IMG, 3, naxes, resid); - // free(resid); - - -#ifdef SAVE_INTERMEDIATE_FILES - //naxes[0] = DATA; - //naxes[1] = numspec; - //writefitsimagefile("testimage.fits", FLOAT_IMG, 2, naxes, image); -#endif - // printf("Image is spatrectif is %x.\n",image); - - return 0; -} +/* spatrectif_000.c */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +int errno; +#include "drp_structs.h" +#include "fitsio.h" + +float blame[DATA][numspec][MAXSLICE]; // Kernal for applying blame to lenslets for the first portion of the iterations +float weight[numspec][DATA]; // Weight normalization factor for distributing blame +float good[numspec][DATA]; // Weighted version of quality to decide if a pixel is valid. +float cmp[numspec][DATA]; // Weights for good +float fblame[DATA][numspec][MAXSLICE]; // Kernal for applying blame during the final iterations +float fbasisv[DATA][numspec][MAXSLICE]; // influence matrix (basis vector) +float fweight[numspec][DATA]; // Weight factor for distributing final blame +float *fw; // Weight factor for distributing final blame +float *w; // Weight factor for distributing final blame +float t_image[DATA][numspec]; // Temporary extracted spectra +float c_image[DATA][numspec]; // Cumulative extracted spectra +float *ti; // For each column accumulate delta to lenslet value +float *ci; // For each column best current estimate of lenslet value +float t_fbv[MAXSLICE]; // Temporary basis vector to manipulate if necessary +float dummy[DATA]; // Model of the flux given current lenslet estimate +float residual[DATA]; // Residual between data - model + +int where; + +int spatrectif_000(int argc, void* argv[]) +{ + // Parameters input in IDL calling program + short int totalParmCount; + short int numiter; + float scale; + float relaxation; + float relax; + short int basesize; + short int (*hilo)[2]; + short int bottom[numspec]; + short int *effective; + float *bv; + float *bl, *fbl, *fbv; + float (*basis_vectors)[MAXSLICE][DATA]; + Module *pModule; + DataSet *pDataSet; + float (*Frames)[DATA]; + IDL_STRING *Headers; + float (*Noise)[DATA]; + unsigned char (*Quality)[DATA]; + float (*image)[DATA]; + float (*noise)[DATA]; + unsigned char (*quality)[DATA]; + // End of parameters input in IDL calling program + + double t1, t2, t3, t4, t5, t6; // Time counters used to examine execution time + short int i=0, ii=0, j=0, jj=0, sp=0, l=0; + long int in1=0, in2=0, in3=0, index[numspec]; + + // Make a temporary residual matrix + long naxes[3]; + naxes[0] = DATA; + naxes[1] = DATA; + naxes[2] = (21); + // ******************************* + + // These parameters should be set in the same order as theay are passed + // from the IDL code. This is not yet automated, and I'm not sure how to + // do it. + i = 0; + totalParmCount = *(short int * )argv[i++]; + numiter = *(short int * )argv[i++]; + relaxation = *(float * )argv[i++]; + basesize = *(short int * )argv[i++]; + hilo = (short int (*)[2] )argv[i++]; + effective = (short int * )argv[i++]; + basis_vectors = (float (*)[MAXSLICE][DATA])argv[i++]; + pModule = (Module * )argv[i++]; + pDataSet = (DataSet * )argv[i++]; + Frames = (float (*)[DATA] )argv[i++]; + Headers = (IDL_STRING * )argv[i++]; + Noise = (float (*)[DATA] )argv[i++]; + Quality = (unsigned char (*)[DATA] )argv[i++]; + image = (float (*)[DATA] )argv[i++]; + noise = (float (*)[DATA] )argv[i++]; + quality = (unsigned char (*)[DATA] )argv[i++]; + scale = *(float * )argv[i++]; // Plate scale + + /* + * Start placing items from the original rectification code here. + * This code will rectify an input data frame. + */ + // printf("Image is spatrectif is %x.\n",image); + printf( "spatrectif_000.c: Now processing RAW data...\n"); + printf("Number of iterations = %d.\n",numiter); + /* printf("Relaxation Parameter = %f.\n",relaxation); + printf("Platescale = %f.\n",scale); */ + (void)fflush(stdout); + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Iterate on each lenslet. + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + memset((void *)image,0, IMAGECNT ); // initial guess of the solution + + t1=systime(); + + // Set the local pointer bv equal to the address of the lowest member of the basis_vector + bv = basis_vectors[0][0]; + for (sp = 0; sp< numspec; sp++) + { + bottom[sp]=hilo[sp][0]; + } + + printf("Calculating weights.\n"); + (void)fflush(stdout); + + // Making local copies of the basis vector + for (sp=0; sp 0.0 ) + { + for (l=0; l 0.0 ) + { + for (l=0; l 14) { + // After first set of iterations, settle down to stable solution + ti[sp]+=relax*residual[j]* fbl[jj]; + //ti[sp]+=relax*residual[j]* bl[jj]; + } + j++; // march up column to match PSF location + } + } + // Correction is applied. + for (sp=0; sp< numspec; sp++) { + if ( weight[sp][i] > 0.0 ) { + ci[sp]+= ti[sp]; + } + } + + } // end of loop over image. + } // for each iteration + + for (i=0; i 4.5 ) quality[sp][i]=9; // Implies over have of the weights have good pixels. + } // for each spectral channel sp ... + } + printf("\n"); + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + t2 = systime(); + // (void)printf("Total Time = %lf\n", t2-t1 ); + // writefitsimagefile("!/sdata1101/osiris-data/osiris2/050224/SPEC/ORP/resid.fits", FLOAT_IMG, 3, naxes, resid); + // free(resid); + + +#ifdef SAVE_INTERMEDIATE_FILES + //naxes[0] = DATA; + //naxes[1] = numspec; + //writefitsimagefile("testimage.fits", FLOAT_IMG, 2, naxes, image); +#endif + // printf("Image is spatrectif is %x.\n",image); + + return 0; +} diff --git a/modules/spatrectif_000.pro b/modules/spatrectif_000.pro index d7f86a8..ede685a 100644 --- a/modules/spatrectif_000.pro +++ b/modules/spatrectif_000.pro @@ -28,12 +28,15 @@ CASE BranchID OF RETURN, ERR_BADCASE END ; CASE BadType ENDCASE - ; Now perform the common code execution for spatial rectification - ; Read in the Calibration file that will contain: - ; BASESIZE Keyword - ; hilo short int array[NUMSPEC][2] - ; effective short int array[NUMSPEC] - ; basis_vectors float array[NUMSPEC][MAXSLICE][DATAFRAMEDIM] + ; Now perform the common code execution for spatial rectification + ; Read in the Calibration file that will contain: + ; BASESIZE Keyword + ; hilo short int array[NUMSPEC][2] -- The row index of the bottom (low) and the top (high) raw for each spectral slice. + ; effective short int array[NUMSPEC] -- A flag to indicate whether this spaxel is sufficiently illuminated (0=bad, 1=good) + ; basis_vectors float array[NUMSPEC][MAXSLICE][DATAFRAMEDIM] -- The actual influence matrix. + ; Note NUMSPEC = typically 1216 spectra + ; Note MAXSLICE = 16 (default) but up to 32 (height of slice, orthogonal to dispersion direction) + ; Note DATAFRAMEDIM = 2048 (width of slice in dispersion direction) thisModuleIndex = drpModuleIndexFromCallSequence(Modules, functionName) FileName = drpXlateFileName(Modules[thisModuleIndex].CalibrationFile) pHilo = PTR_NEW(/ALLOCATE_HEAP) diff --git a/testing_scripts/flux_misassign/misflux_singlearc_wrapper.pro b/testing_scripts/flux_misassign/misflux_singlearc_wrapper.pro deleted file mode 100644 index 18f62d2..0000000 --- a/testing_scripts/flux_misassign/misflux_singlearc_wrapper.pro +++ /dev/null @@ -1,9 +0,0 @@ -pro misflux_singlearc_wrapper - -infile = getenv('OSIRIS_ROOT')+'/tests/test_misflux_singlearc/s160318_c017026_Kbb_050.fits' - -refchannel = 904 - -misflux_single,infile,refchannel=refchannel - -end diff --git a/tests/drptestbones/checkSkylines.py b/tests/drptestbones/checkSkylines.py new file mode 100644 index 0000000..318d094 --- /dev/null +++ b/tests/drptestbones/checkSkylines.py @@ -0,0 +1,39 @@ +import pyfits +import sys +import numpy as np + +def checkSkylines(filename,min_lambda,max_lambda,sumRow,outname): + + file = pyfits.open(filename) + data = file[0].data + hdr = file[0].header + sizeLambda = data.shape[2] + + min_image_lambda = hdr['CRVAL1'] + delta_lambda = hdr['CDELT1'] + + min_pixel = int(round((min_lambda - min_image_lambda) / delta_lambda)) + max_pixel = int(round((max_lambda - min_image_lambda) / delta_lambda)) + + if (min_pixel >= max_pixel): + sys.exit("Max lambda needs to be greater than min lambda") + + if (min_pixel < 0): + sys.exit("Selected minimum wavelength is off detector") + + if (max_pixel > sizeLambda): + sys.exit("Selected maximum wavelength is off detector") + + onlyLine = data[:,:,min_pixel:max_pixel] + + sumLine = np.sum(onlyLine,axis=2) + + sumRowOnly = sumLine[:,sumRow] + + totalRMS = np.std(sumLine) + rowRMS = np.std(sumRowOnly) + + + pyfits.writeto(outname,sumLine,clobber=True) + + return totalRMS, rowRMS diff --git a/tests/test_checkskylines/sky.xml b/tests/test_checkskylines/sky.xml new file mode 100644 index 0000000..3dc84eb --- /dev/null +++ b/tests/test_checkskylines/sky.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tests/test_checkskylines/test_checkskylines.py b/tests/test_checkskylines/test_checkskylines.py new file mode 100644 index 0000000..4cba850 --- /dev/null +++ b/tests/test_checkskylines/test_checkskylines.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +import pytest +import os +import glob + +from drptestbones.backbone import consume_queue_directory +from drptestbones.diff import fits_osiris_allclose +from drptestbones.fetchdata import get_test_file + +from drptestbones.checkSkylines import checkSkylines + + +def test_skyline(drf_queue): + """Test FITS sky lines""" + consume_queue_directory(drf_queue) + output_file = os.path.join(drf_queue, "s160711_a013002_Kbb_035.fits") + expected_file = os.path.join(drf_queue, "s160711_a013002_Kbb_035_ref.fits") + rms_fits = os.path.join(drf_queue,'s160711_a013002_Kbb_035_RMS.fits') + + totalRMS,lineRMS = checkSkylines(output_file,2071,2075,41,rms_fits) + fractRMS = lineRMS/totalRMS + + fits_osiris_allclose(output_file, expected_file) + assert ((fractRMS > 0.97) & (fractRMS <= 1.0)) + diff --git a/tests/test_misflux_singlearc/000.Kbb_050_1col_201603.drf b/tests/test_misflux_singlearc/000.Kbb_050_1col_201603.drf new file mode 100755 index 0000000..6deccc5 --- /dev/null +++ b/tests/test_misflux_singlearc/000.Kbb_050_1col_201603.drf @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/test_misflux_singlearc/misflux_singlearc_wrapper.pro b/tests/test_misflux_singlearc/misflux_singlearc_wrapper.pro new file mode 100644 index 0000000..7047a75 --- /dev/null +++ b/tests/test_misflux_singlearc/misflux_singlearc_wrapper.pro @@ -0,0 +1,9 @@ +pro misflux_singlearc_wrapper + +infile = getenv('OSIRIS_ROOT')+'/tests/test_misflux_singlearc/data_misflux_single/s160318_c017026_Kbb_050.fits' + +refchannel = 904 + +misflux_single,infile,refchannel=refchannel + +end diff --git a/tests/test_mkrecmatrx/make_rectmat.py b/tests/test_mkrecmatrx/make_rectmat.py new file mode 100644 index 0000000..b3aca7d --- /dev/null +++ b/tests/test_mkrecmatrx/make_rectmat.py @@ -0,0 +1,148 @@ +import os +import pyfits + +# location of OSIRIS DRP: +drp_dir = '/Users/aboehle/osiris_dev/OsirisDRP/' + +source_dir = drp_dir + '/modules/source/' +RPB_dir = drp_dir + '/backbone/SupportFiles/' + +# location of rect mat raw scans and created rect mats +reduce_dir = '/Users/aboehle/research/irlab/projects/osiris_rectmat_tests/images/160412/reduce/' # from here, raw dir is: ../SPEC/raw/ +rectmat_outdir = 'rectmat/' # sub-directory of reduce_dir above + + +def make_rectmat(slice,maxslice,weightlimit,dir_suffix='', xml_filename = 'Kbb_050.xml', xml_test_filename = 'testrectmat_Kbb_50_newpipeline.xml'): + ''' + Make a rect mat with a given slice, maxslice, and weight limit value. Save the rect mat into a sub-directory of the reduce_dir (reduce_dir is hard-coded above). This sub-directory is named with the weightlimit, slice, and maxslice values followed by an optional dir_suffix. + + To make rect mat: updates the given rect mat xml file (named "xml_filename") with new output dir and the appropriate drp files with new maxslice, slice, and weight limit values. Prompts the user to close the OSIRIS DRP so it can be reopened with the new drp parameter values. Recompiles the c code in drp modules/source/ directory. + + Also updates the given test filename (named "xml_test_filename") with the new data directory + ''' + + if dir_suffix and dir_suffix[0] != '_': + dir_suffix = '_'+dir_suffix + + # Check that output directories exist + if not os.path.exists(reduce_dir + rectmat_outdir + '/weightlimit%1.2f_slice%i_maxslice%i%s/' % (weightlimit, slice, maxslice,dir_suffix)): + os.mkdir(reduce_dir + rectmat_outdir + '/weightlimit%1.2f_slice%i_maxslice%i%s/' % (weightlimit, slice, maxslice,dir_suffix)) + if not os.path.exists(reduce_dir + '/cubed_frames_newpipeline/weightlimit%1.2f_slice%i_maxslice%i%s/' % (weightlimit, slice, maxslice,dir_suffix)): + os.mkdir(reduce_dir + '/cubed_frames_newpipeline/weightlimit%1.2f_slice%i_maxslice%i%s/' % (weightlimit, slice, maxslice,dir_suffix)) + + setup_drp_files(slice,maxslice,weightlimit) + setup_xml_files(reduce_dir, xml_filename, xml_test_filename, rectmat_outdir, slice, maxslice, weightlimit ,dir_suffix) + recompile_ccode() + + raw_input("\n\nClose the OSIRIS DRP if it is currently running!\nThen press enter to drop the new xml files. ") + + os.chdir(reduce_dir + '/xml/') + cmds = ['run_odrp &','osirisDropDRF '+xml_filename + ' 1','osirisDropDRF '+xml_test_filename + ' 2'] + for cmd in cmds: + print cmd + os.system(cmd) + +def check_rectmats(rectmat_name = 's160412_c006___infl_Kbb_050.fits', slice_arr = [[14,16],[20,22],[28,30]], weight_lim_arr = [0,0.01]): #'s160318_c003___infl_Hn3_100.fits'): + + for slice,maxslice in slice_arr: + for lmt in weight_lim_arr: + filename = reduce_dir +rectmat_outdir + '/weightlimit%1.2f_slice%i_maxslice%i/' % (lmt, slice, maxslice) + rectmat_name + print filename + mat_hdu = pyfits.open(filename) + hdr = mat_hdu[0].header + + if slice == hdr['slice']: + print 'slice test: passed' + slicefailed = False + else: + print 'slice test: FAILED' + slicefailed = True + + if lmt == hdr['wtlimit']: + print 'weightlimit test: passed' + lmtfailed = False + else: + print 'weightlimit test: FAILED' + lmtfailed = True + + if maxslice == mat_hdu[2].data.shape[1]: + print 'maxslice test: passed' + maxslice_failed = False + else: + print 'maxslice test: FAILED' + maxslice_failed = True + + if maxslice_failed or slicefailed or lmtfailed: + print 'ERROR with rectmat: '+filename + else: + print 'rectmat passed!' + + print + + #print '\nInput value/Rectmat Value:' + #print slice,hdr['slice'] + #print lmt,hdr['wtlimit'] + #print maxslice,mat_hdu[2].data.shape[1] + #print + + +def setup_drp_files(slice,maxslice,weightlimit): + + rpb_file = open(RPB_dir+'RPBconfig.xml','r') + drp_file = open(source_dir+'drp_structs.h','r') + + # Edit RPB_file lines + rpb_lines = rpb_file.readlines() + rpb_lines[74] = ' mkrecmatrx_COMMON___slice="%i"\n' % (slice) + rpb_lines[76] = ' mkrecmatrx_COMMON___weight_limit="%1.2f"\n' % (weightlimit) + rpb_file.close() + + rpb_file = open(RPB_dir+'RPBconfig.xml','w') + rpb_file.writelines(rpb_lines) + rpb_file.close() + + # Edit drp file lines + drp_lines = drp_file.readlines() + drp_lines[21] = '#define MAXSLICE %i // Maximum slice of image in pixels; original value = 16\n' % (maxslice) + drp_file.close() + + drp_file = open(source_dir+'drp_structs.h','w') + drp_file.writelines(drp_lines) + drp_file.close() + +def setup_xml_files(reduce_dir, xml_filename, xml_test_filename, rectmat_outdir, slice, maxslice, weightlimit, dir_suffix): + + xml_file = open(reduce_dir + '/xml/'+xml_filename,'r') + xml_lines = xml_file.readlines() + xml_lines[8] = ' OutputDir="'+reduce_dir + '/' +rectmat_outdir+'/weightlimit%1.2f_slice%i_maxslice%i%s/">\n' % (weightlimit, slice, maxslice, dir_suffix) + xml_lines[31] = ' OutputDir="/Users/aboehle/research/IRLab/Projects/osiris_rectmat_tests/images/160412/reduce/'+rectmat_outdir+'/weightlimit%1.2f_slice%i_maxslice%i%s/"\n' % (weightlimit, slice, maxslice, dir_suffix) + xml_file.close() + + xml_file = open(reduce_dir + '/xml/'+xml_filename,'w') # xml file to make rect mat + xml_file.writelines(xml_lines) + xml_file.close() + + xml_test_file = open(reduce_dir + '/xml/'+xml_test_filename,'r') # xml file to reduce single column scan + xml_test_lines = xml_test_file.readlines() + xml_test_lines[3] = '\n' % (weightlimit, slice, maxslice, dir_suffix) + xml_test_lines[8] = '\n' % (weightlimit, slice, maxslice, dir_suffix) + xml_test_file.close() + + xml_test_file = open(reduce_dir + '/xml/'+xml_test_filename,'w') + xml_test_file.writelines(xml_test_lines) + xml_test_file.close() + + +def recompile_ccode(): + + current_dir = os.getcwd() + + os.chdir(source_dir) + cmds = ['rm *.o','rm libosiris_drp_ext_null.so.0.0','make -f local_Makefile'] + + for cmd in cmds: + print cmd + os.system(cmd) + + os.chdir(current_dir) +