Commit 332925ad3ee1a2c21bda3f7b0630633752e47ca4

Authored by David Mayerich
1 parent 573a6ded

added the ability to crop agilent binary files

Showing 1 changed file with 28 additions and 7 deletions   Show diff stats
stim/envi/agilent_binary.h
@@ -44,6 +44,10 @@ public: @@ -44,6 +44,10 @@ public:
44 alloc(); 44 alloc();
45 } 45 }
46 46
  47 + char* data() {
  48 + return (char*)ptr;
  49 + }
  50 +
47 size_t dim(size_t i){ 51 size_t dim(size_t i){
48 return R[i]; 52 return R[i];
49 } 53 }
@@ -84,6 +88,11 @@ public: @@ -84,6 +88,11 @@ public:
84 return *this; //return the result 88 return *this; //return the result
85 } 89 }
86 90
  91 + operator bool() {
  92 + if (R[0] == 0 || R[1] == 0 || R[2] == 0) return false;
  93 + else return true;
  94 + }
  95 +
87 ~agilent_binary(){ 96 ~agilent_binary(){
88 free(ptr); 97 free(ptr);
89 } 98 }
@@ -189,6 +198,17 @@ public: @@ -189,6 +198,17 @@ public:
189 ptr[i] = -log10(ptr[i] / background->ptr[i]); 198 ptr[i] = -log10(ptr[i] / background->ptr[i]);
190 } 199 }
191 200
  201 + //crops the image down to a set number of samples
  202 + void crop(size_t n) {
  203 + if (n < R[2]) { //if the requested size is smaller than the image
  204 + R[2] = n; //update the number of bands
  205 + T* old_ptr = ptr; //store the old pointer
  206 + alloc(); //allocate space for the new image
  207 + memcpy(ptr, old_ptr, bytes()); //copy the old data to the new image
  208 + free(old_ptr); //free the old data
  209 + }
  210 + }
  211 +
192 //#ifdef CUDA_FOUND 212 //#ifdef CUDA_FOUND
193 /// Perform an FFT and return a binary file with bands in the specified range 213 /// Perform an FFT and return a binary file with bands in the specified range
194 agilent_binary<T> fft(double band_min, double band_max, double ELWN = 15798, int UDR = 2){ 214 agilent_binary<T> fft(double band_min, double band_max, double ELWN = 15798, int UDR = 2){
@@ -242,18 +262,19 @@ public: @@ -242,18 +262,19 @@ public:
242 HANDLE_ERROR(cudaMemcpy(cpu_fft, gpu_fft, R[0] * R[1] * (R[2]/2+1) * sizeof(cufftComplex), cudaMemcpyDeviceToHost)); //copy data from the host to the device 262 HANDLE_ERROR(cudaMemcpy(cpu_fft, gpu_fft, R[0] * R[1] * (R[2]/2+1) * sizeof(cufftComplex), cudaMemcpyDeviceToHost)); //copy data from the host to the device
243 263
244 //double int_delta = 0.00012656; //interferogram sample spacing in centimeters 264 //double int_delta = 0.00012656; //interferogram sample spacing in centimeters
245 - double int_delta = (1.0 / ELWN) * ((double)UDR / 2.0); //calculate the interferogram spacing  
246 - double int_length = int_delta * R[2]; //interferogram length in centimeters  
247 - double fft_delta = 1/int_length; //spectrum spacing (in inverse centimeters, wavenumber)  
248 - double fft_max = fft_delta * R[2]/2; //get the maximum wavenumber value supported by the specified number of interferogram samples 265 + double int_delta = (1.0 / ELWN) * ((double)UDR / 2.0); //calculate the interferogram spacing
  266 + double int_length = int_delta * R[2]; //interferogram length in centimeters
  267 + double fft_delta = 1/int_length; //spectrum spacing (in inverse centimeters, wavenumber)
  268 + double fft_max = fft_delta * R[2]/2; //get the maximum wavenumber value supported by the specified number of interferogram samples
249 269
250 - if(band_max > fft_max) band_max = fft_max; //the user gave a band outside of the FFT range, reset the band to the maximum available 270 + if(band_max > fft_max) band_max = fft_max; //the user gave a band outside of the FFT range, reset the band to the maximum available
  271 + if (band_min < 0) band_min = 0;
251 272
252 size_t start_i = (size_t)std::ceil(band_min / fft_delta); //calculate the first band to store 273 size_t start_i = (size_t)std::ceil(band_min / fft_delta); //calculate the first band to store
253 size_t size_i = (size_t)std::floor(band_max / fft_delta) - start_i; //calculate the number of bands to store 274 size_t size_i = (size_t)std::floor(band_max / fft_delta) - start_i; //calculate the number of bands to store
254 - size_t end_i = start_i + size_i; //last band number 275 + size_t end_i = start_i + size_i; //last band number
255 agilent_binary<T> result(R[0], R[1], size_i); 276 agilent_binary<T> result(R[0], R[1], size_i);
256 - result.Z[0] = start_i * fft_delta; //set the range for the FFT result 277 + result.Z[0] = start_i * fft_delta; //set the range for the FFT result
257 result.Z[1] = end_i * fft_delta; 278 result.Z[1] = end_i * fft_delta;
258 279
259 for(size_t b = start_i; b < end_i; b++){ 280 for(size_t b = start_i; b < end_i; b++){