Пример #1
0
def main():

    parser = argparse.ArgumentParser(
        description="Copy sample and instrument parameters to another file or entry")
    parser.add_argument('-f', '--filename', required=True,
                        help='name of the input NeXus file')
    parser.add_argument('-e', '--entry', 
                        help='path of input NXentry group')
    parser.add_argument('-t', '--target', help='path of target NXentry group')
    parser.add_argument('-o', '--output', help='output NeXus file (if different)')
    
    args = parser.parse_args()
    if args.output:
        input = nxload(args.filename)
        input_ref = NXRefine(input['entry'])
        output = nxload(args.output, 'rw')
        output_entry_ref = NXRefine(output['entry'])
        input_ref.copy_parameters(output_entry_ref, sample=True)
        for name in [entry for entry in input if entry != 'entry']:
            if name in output: 
                input_ref = NXRefine(input[name])
                output_ref = NXRefine(output[name])
                input_ref.copy_parameters(output_ref, instrument=True)
                output_entry_ref.link_sample(output_ref)
    else:
        input = nxload(args.filename, 'rw')
        input_ref = NXRefine(input[args.entry])
        output_ref = NXRefine(input[args.target])
        input_ref.copy_parameters(output_ref, instrument=True)
        if 'sample' not in input[args.target] and 'sample' in input['entry']:
            input_ref = NXRefine(input['entry'])
            input_ref.link_sample(output_ref)
Пример #2
0
 def copy_root(self):
     root = self.entry.nxroot
     other_root = self.other_entry.nxroot
     if root is other_root:
         raise NeXusError("Cannot copy to the same root")
     input = NXRefine(root["entry"])
     output_main = NXRefine(other_root["entry"])
     input.copy_parameters(output_main, sample=True)
     for name in [entry for entry in root if entry != "entry"]:
         if name in other_root:
             input = NXRefine(root[name])
             output = NXRefine(other_root[name])
             input.copy_parameters(output, instrument=True)
             output_main.link_sample(output)
Пример #3
0
 def copy_entry(self):
     if self.entry is self.other_entry:
         raise NeXusError("Cannot copy to the same entry")
     input = NXRefine(self.entry)
     output = NXRefine(self.other_entry)
     if "instrument" in self.entry:
         input.copy_parameters(output, instrument=True)
     if "sample" not in self.other_entry and "sample" in self.entry:
         if self.entry.nxname == "entry" and self.other_entry.nxname == "entry":
             input.copy_parameters(output, sample=True)
         elif (
             self.entry.nxname == "entry"
             and self.other_entry.nxname != "entry"
             and self.entry.nxroot is self.other_entry.nxroot
         ):
             input.link_sample(output)
         else:
             try:
                 self.other_entry.makelink(self.other_entry.nxroot["entry/sample"])
             except Exception:
                 pass