---
# System prepended metadata

title: Flyhweel MONAI operator

---

# Flyhweel MONAI operator

## FlywheelBaseSaveOperator

```python

def is_flywheel()
    return os.path.exists("/flywheel/v0/")


@md.packages(flywheel-gear-toolkit)
class FlywheelBaseSaveOperator


    def __init__(...)
        if is_flywheel():
            self.context = GearToolkitContext(gear_path="/flywheel/v0")
            gear_inputs = self.context.manifest.get("inputs")
            self.input_filee = self.context.get_input(gear_inputs[0].get("name"))
            self.input_file_object = self.context.get_input_file_object(gear_inputs[0].get("name"))
            self.original_file_object = deepcopy(self.input_file_object)

    def update(update_file_object):
        
        # check the changes between update_file_object self.original_file_object
        
        # if classification has changed:
        self.context.metadata.update_file(self.input_file, classification=update_file_object.classification)
        
        # if file info has changed:
        self.context.metadata.update_file(input_file, info=update_file_object.info)
        
        ... etc for file.modality, file.<whatever are the attributes of the file object we have access to>
```


```python
@md.packages(flywheel-gear-toolkit)
class FlywheelSaveOperator(FlywheelBaseSaveOperator):
    
    def compute(self, input, output...):
        
        file_object = self.input_file_object
        
        if len(input_file_dict['classification'])==0: 
            classification = {"Custom": [classification_output]}
        else: 
            classification = (input_file_dict['classification'])
            key_list = list(classification) # get the list of existing keys
            key = key_list[0] # assumption: there is only one key
            val = classification[key]
            val.append(classification_output) # append the classification output
            classification[key] = val # update the classification list
        
        self.update(file_object)
```
    
```python
if os.path.exists("/flywheel/v0/"):
             with GearToolkitContext(gear_path="/flywheel/v0/") as fw_context:
                input_file = fw_context.get_input("input-file")
                input_file_dict = fw_context.get_input_file_object("input-file")
                # get the current classification for the file. 
                # if it does not exist create a custom dictionary
                # otherwise append the model output to the classification. 
                if len(input_file_dict['classification'])==0: 
                    classification = {"Custom": [classification_output]}
                else: 
                    classification = (input_file_dict['classification'])
                    key_list = list(classification) # get the list of existing keys
                    key = key_list[0] # assumption: there is only one key
                    val = classification[key]
                    val.append(classification_output) # append the classification output
                    classification[key] = val # update the classification list
                fw_context.metadata.update_file(input_file, classification=classification)

   
                classification = input_file_dict['classification'] 
                
                if "Custom" not in classification:
                    classification["Custom"] = [classification_output]
                elif classification_output is not classification["Custom"]:
                    classification["Custom"].append(classification_output)
                
                    
```
