Exemplo n.º 1
0
void write_int_data(std::string const& filename, array_2d_t const& array)
{
    h5xx::file file(filename, h5xx::file::trunc);
    std::string name;

    // (1) create and write chunked and compressed dataset
    {
        name = "integer array";
        std::vector<size_t> chunk_dims(2,2);
        // derive dataspace and datatype from the array internally
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::chunked(chunk_dims)  /* optional argument */
                .add(h5xx::policy::filter::deflate())
        );
        h5xx::write_dataset(file, name, array);
    }

    // (2) create and write a dataset, using default settings,
    //     explicitly derive dataspace and datatype from input arrray
    {
        name = "integer array, 2";
        // construct dataspace from a Boost multi_array
        h5xx::dataspace dataspace = h5xx::create_dataspace(array);
        // pull datatype from a Boost multi_array
        h5xx::datatype datatype(array);
        h5xx::create_dataset(file, name, datatype, dataspace);
        h5xx::write_dataset(file, name, array);
    }
}
Exemplo n.º 2
0
// --- try various storage layouts and filters, integer
void write_int_data_2(std::string const& filename, array_2d_t const& array)
{
    h5xx::file file(filename, h5xx::file::out);
    std::string name;

    {
        name = "A -- integer array, compact";

        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::compact()
        );

        h5xx::write_dataset(file, name, array);
    }

    {
        name = "B -- integer array, contiguous";

        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::contiguous()
        );

        h5xx::write_dataset(file, name, array);
    }

    {
        name = "C -- integer array, compact, fill_value";
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::compact()
                .set(h5xx::policy::storage::fill_value(int(42)))
        );
//        h5xx::write_dataset(file, name, array);
    }

    {
        name = "D -- integer array, compact, track_times";
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::compact()
                .set(h5xx::policy::storage::track_times())
        );
        h5xx::write_dataset(file, name, array);
    }

    {
        name = "E -- integer array, chunked, fill_value, deflate";
        std::vector<size_t> chunk_dims(2,2);
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::chunked(chunk_dims)
                .set(h5xx::policy::storage::fill_value(42))
                .add(h5xx::policy::filter::deflate())
        );
//        h5xx::write_dataset(file, name, array);
    }

    {
        name = "F -- integer array, chunked, shuffle";
        std::vector<size_t> chunk_dims(2,2);
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::chunked(chunk_dims)
                .add(h5xx::policy::filter::shuffle())
        );
        h5xx::write_dataset(file, name, array);
    }

    {
        name = "G -- integer array, chunked, fletcher32";
        std::vector<size_t> chunk_dims(2,2);
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::chunked(chunk_dims)
                .add(h5xx::policy::filter::fletcher32())
        );
        h5xx::write_dataset(file, name, array);
    }

    {
        name = "H -- integer array, chunked, scaleoffset";
        std::vector<size_t> chunk_dims(2,2);
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::chunked(chunk_dims)
                .add(h5xx::policy::filter::scaleoffset<int>())
        );
        h5xx::write_dataset(file, name, array);
    }

    {
        name = "I -- integer array, chunked, nbit";
        std::vector<size_t> chunk_dims(2,2);
        h5xx::create_dataset(file, name, array
          , h5xx::policy::storage::chunked(chunk_dims)
                .add(h5xx::policy::filter::nbit())
        );
        h5xx::write_dataset(file, name, array);
    }
}
int SimpleReconGadget::process( GadgetContainerMessage<IsmrmrdReconData>* m1)
{
    
    //Iterate over all the recon bits
    for(std::vector<IsmrmrdReconBit>::iterator it = m1->getObjectPtr()->rbit_.begin();
        it != m1->getObjectPtr()->rbit_.end(); ++it)
    {
        //Grab a reference to the buffer containing the imaging data
        //We are ignoring the reference data
        IsmrmrdDataBuffered & dbuff = it->data_;

        //Data 7D, fixed order [E0, E1, E2, CHA, N, S, LOC]
        uint16_t E0 = dbuff.data_.get_size(0);
        uint16_t E1 = dbuff.data_.get_size(1);
        uint16_t E2 = dbuff.data_.get_size(2);
        uint16_t CHA = dbuff.data_.get_size(3);
        uint16_t N = dbuff.data_.get_size(4);
        uint16_t S = dbuff.data_.get_size(5);
        uint16_t LOC = dbuff.data_.get_size(6);
      
        //Create an image array message
        GadgetContainerMessage<IsmrmrdImageArray>* cm1 = 
                new GadgetContainerMessage<IsmrmrdImageArray>();

        //Grab references to the image array data and headers
        IsmrmrdImageArray & imarray = *cm1->getObjectPtr();

        //The image array data will be [E0,E1,E2,1,N,S,LOC] big
        //Will collapse across coils at the end
        std::vector<size_t> data_dims(7);
        data_dims[0] = E0;
        data_dims[1] = E1;
        data_dims[2] = E2;
        data_dims[3] = 1;
        data_dims[4] = N;
        data_dims[5] = S;
        data_dims[6] = LOC;        
        imarray.data_.create(&data_dims);
        
        //ImageHeaders will be [N, S, LOC]
        std::vector<size_t> header_dims(3);
        header_dims[0] = N;
        header_dims[1] = S;
        header_dims[2] = LOC;        
        imarray.headers_.create(&header_dims);

        //We will not add any meta data
        //so skip the meta_ part
        
        //Loop over S and N and LOC
        for (uint16_t loc=0; loc < LOC; loc++) {
            for (uint16_t s=0; s < S; s++) {                
                for (uint16_t n=0; n < N; n++) {
                    
                    //Set some information into the image header
                    //Use the middle acquisition header for some info
                    //[E1, E2, N, S, LOC]
                    ISMRMRD::AcquisitionHeader & acqhdr = dbuff.headers_(dbuff.sampling_.sampling_limits_[1].center_,
                                                                         dbuff.sampling_.sampling_limits_[2].center_,
                                                                         n, s, loc);                    
                    imarray.headers_(n,s,loc).matrix_size[0]     = E0;
                    imarray.headers_(n,s,loc).matrix_size[1]     = E1;
                    imarray.headers_(n,s,loc).matrix_size[2]     = E2;
                    imarray.headers_(n,s,loc).field_of_view[0]   = dbuff.sampling_.recon_FOV_[0];
                    imarray.headers_(n,s,loc).field_of_view[1]   = dbuff.sampling_.recon_FOV_[1];
                    imarray.headers_(n,s,loc).field_of_view[2]   = dbuff.sampling_.recon_FOV_[2];
                    imarray.headers_(n,s,loc).channels           = 1;                    
                    imarray.headers_(n,s,loc).average = acqhdr.idx.average;
                    imarray.headers_(n,s,loc).slice = acqhdr.idx.slice;
                    imarray.headers_(n,s,loc).contrast = acqhdr.idx.contrast;
                    imarray.headers_(n,s,loc).phase = acqhdr.idx.phase;
                    imarray.headers_(n,s,loc).repetition = acqhdr.idx.repetition;
                    imarray.headers_(n,s,loc).set = acqhdr.idx.set;
                    imarray.headers_(n,s,loc).acquisition_time_stamp = acqhdr.acquisition_time_stamp;
                    imarray.headers_(n,s,loc).position[0] = acqhdr.position[0];
                    imarray.headers_(n,s,loc).position[1] = acqhdr.position[1];
                    imarray.headers_(n,s,loc).position[2] = acqhdr.position[2];
                    imarray.headers_(n,s,loc).read_dir[0] = acqhdr.read_dir[0];
                    imarray.headers_(n,s,loc).read_dir[1] = acqhdr.read_dir[1];
                    imarray.headers_(n,s,loc).read_dir[2] = acqhdr.read_dir[2];
                    imarray.headers_(n,s,loc).phase_dir[0] = acqhdr.phase_dir[0];
                    imarray.headers_(n,s,loc).phase_dir[1] = acqhdr.phase_dir[1];
                    imarray.headers_(n,s,loc).phase_dir[2] = acqhdr.phase_dir[2];
                    imarray.headers_(n,s,loc).slice_dir[0] = acqhdr.slice_dir[0];
                    imarray.headers_(n,s,loc).slice_dir[1] = acqhdr.slice_dir[1];
                    imarray.headers_(n,s,loc).slice_dir[2] = acqhdr.slice_dir[2];
                    imarray.headers_(n,s,loc).patient_table_position[0] = acqhdr.patient_table_position[0];
                    imarray.headers_(n,s,loc).patient_table_position[1] = acqhdr.patient_table_position[1];
                    imarray.headers_(n,s,loc).patient_table_position[2] = acqhdr.patient_table_position[2];
                    imarray.headers_(n,s,loc).data_type = ISMRMRD::ISMRMRD_CXFLOAT;
                    imarray.headers_(n,s,loc).image_index = ++image_counter_;

                    //Grab a wrapper around the relevant chunk of data [E0,E1,E2,CHA] for this loc, n, and s
                    //Each chunk will be [E0,E1,E2,CHA] big
                    std::vector<size_t> chunk_dims(4);
                    chunk_dims[0] = E0;
                    chunk_dims[1] = E1;
                    chunk_dims[2] = E2;
                    chunk_dims[3] = CHA;
                    hoNDArray<std::complex<float> > chunk = hoNDArray<std::complex<float> >(chunk_dims, &dbuff.data_(0,0,0,0,n,s,loc));

                    //Do the FFTs in place
                    hoNDFFT<float>::instance()->ifft(&chunk,0);
                    hoNDFFT<float>::instance()->ifft(&chunk,1);
                    if (E2>1) {
                        hoNDFFT<float>::instance()->ifft(&chunk,2);
                    }

                    //Square root of the sum of squares
                    //Each image will be [E0,E1,E2,1] big
                    std::vector<size_t> img_dims(3);
                    img_dims[0] = E0;
                    img_dims[1] = E1;
                    img_dims[2] = E2;
                    hoNDArray<std::complex<float> > output = hoNDArray<std::complex<float> >(img_dims, &imarray.data_(0,0,0,0,n,s,loc));
                    //Zero out the output
                    clear(output);

                    //Compute d* d in place
                    multiplyConj(chunk,chunk,chunk);                    
                    //Add up
                    for (size_t c = 0; c < CHA; c++) {
                        output += hoNDArray<std::complex<float> >(img_dims, &chunk(0,0,0,c));
                    }                    
                    //Take the square root in place
                    sqrt_inplace(&output);                    
               }
            }
        }

        //Pass the image array down the chain
        if (this->next()->putq(cm1) < 0) {
	  m1->release();
          return GADGET_FAIL;
        }

    }

    m1->release();
    return GADGET_OK;  

}