def save_step_to_disk(step):
    """
    Save a model step to disk, over-writing the previous file. The file will be named
    'model-name.yaml' and will be saved to the initialization directory. 
    
    """
    if _disk_store is None:
        print(
            "Please run 'modelmanager.initialize()' before registering new model steps"
        )
        return

    print("Saving '{}.yaml': {}".format(step.name,
                                        os.path.join(os.getcwd(),
                                                     _disk_store)))

    d = step.to_dict()

    # Save supplemental objects
    if 'supplemental_objects' in d:
        for item in filter(None, d['supplemental_objects']):
            save_supplemental_object(step.name, **item)
            del item['content']

    # Save main yaml file
    headers = {'modelmanager_version': __version__}

    content = OrderedDict(headers)
    content.update({'saved_object': d})

    yamlio.convert_to_yaml(content,
                           os.path.join(_disk_store, step.name + '.yaml'))
Example #2
0
def save_steps_to_disk():
    """
    Save current representation of model steps to disk, over-writing the previous file.
    
    """
    headers = {'modelmanager_version': MODELMANAGER_VERSION}

    content = OrderedDict(headers)
    for k in sorted(_STEPS.keys()):
        content.update({k: _STEPS[k]})

    yamlio.convert_to_yaml(content, DISK_STORE)
Example #3
0
    def from_dict(cls, d):
        """
        Create an object instance from a saved dictionary representation.
        
        Parameters
        ----------
        d : dict
        
        Returns
        -------
        OLSRegressionStep
        
        """
        # Pass values from the dictionary to the __init__() method
        obj = cls(tables=d['tables'],
                  model_expression=d['model_expression'],
                  filters=d['filters'],
                  out_tables=d['out_tables'],
                  out_column=d['out_column'],
                  out_transform=d['out_transform'],
                  out_filters=d['out_filters'],
                  name=d['name'],
                  tags=d['tags'])

        obj.summary_table = d['summary_table']
        obj.fitted_parameters = d['fitted_parameters']

        # Unpack the urbansim.models.RegressionModel() sub-object and resuscitate it
        model_config = yamlio.convert_to_yaml(d['model'], None)
        obj.model = RegressionModel.from_yaml(model_config)

        return obj
def save_step(d):
    """
    Save a model step to disk, over-writing the previous file. The file will be named
    'model-name.yaml' and will be saved to the initialization directory.
    
    Note: This function is for internal use. In a model building workflow, it's better to
    use an object's `register()` method to register it with ModelManager and save it to 
    disk at the same time.
    
    """
    if _DISK_STORE is None:
        print("Please run 'mm.initialize()' before registering new model steps")
        return
    
    print("Saving '{}.yaml': {}".format(d['name'], 
            os.path.join(os.getcwd(), _DISK_STORE)))
    
    headers = {'modelmanager_version': MODELMANAGER_VERSION}

    content = OrderedDict(headers)
    content.update({'saved_object': d})
    
    yamlio.convert_to_yaml(content, os.path.join(_DISK_STORE, d['name']+'.yaml'))
Example #5
0
 def to_yaml(self, str_or_buffer=None):
     """
     Save a model respresentation to YAML.
     Parameters
     ----------
     str_or_buffer : str or file like, optional
         By default a YAML string is returned. If a string is
         given here the YAML will be written to that file.
         If an object with a ``.write`` method is given the
         YAML will be written to that object.
     Returns
     -------
     j : str
         YAML is string if `str_or_buffer` is not given.
     """
     logger.debug('serializing LCM model {} to YAML'.format(self.name))
     #if (not isinstance(self.probability_mode, str) or
     #        not isinstance(self.choice_mode, str)):
     #    raise TypeError(
     #        'Cannot serialize model with non-string probability_mode '
     #        'or choice_mode attributes.')
     return yamlio.convert_to_yaml(self.to_dict(), str_or_buffer)
Example #6
0
def create_proforma_config(proforma_settings):
    yaml_file = misc.config("proforma_user.yaml")
    user_cfg = yamlio.yaml_to_dict(str_or_buffer=yaml_file)
    config = psrcdev.update_sqftproforma(user_cfg, proforma_settings)
    yamlio.convert_to_yaml(config, "proforma.yaml")