Copying a NXtomo#

With recent software version#

Usually the NXtomo contains relative links to copy this file you cannot simply copy / paste it.

From nxtomomill 1.0 you can access the nxtomomill nx-copy function You can also use directly the nxtomo python API of the NXtomo object: copy_nxtomo_file like:

from nxtomo.application.nxtomo import copy_nxtomo_file
copy_nxtomo_file(
    input_file="/path/to/my_nx.nx",
    output_file="/new/path/new_nx.nx",
    entries=None,  # or a tuple of existing NXotmo
)

with old software version#

The simplest way to copy such a file is to pass by the nxtomomill.nexus module. Then you can load it within the default parameters (detector_data_as=”as_data_url”) and then save it somewhere else.

from nxtomo.application.nxtomo import NXtomo
from tomwer.core.scan.nxtomoscan import NXtomoScan

if in_data is not None:
    scan = in_data
    nx_tomo = NXtomo().load(scan.master_file, scan.entry)  # load data
    new_location = "/my/path/to/nexus.nx"
    new_entry = scan.entry  # or any data path in the hdf5 file you like
    nx_tomo.save(new_location, new_entry)
    print(f"created new NXtomo to {new_entry}@{new_location}")
    # provide the new scan in output if some processing must be done on this new NXtomo
    out_data = NXtomoScan(scan=new_location, entry=new_entry)

Warning

Be carreful the saved file will still contains relative links to the original data. You can avoid it by setting the load function option detector_data_as to as_numpy_array. But this will load all the data in memory.

Warning

only the frame are shared, other dataset (rotation angle, energy…) will be decouple. So if you edit one dataset of the NXtomo this won’t affect the other one.