smashbox.init.smashbox
1from smashbox.init import param 2from smashbox.model import model 3from smashbox.stats import mystats 4from smashbox.plot import myplot 5from smashbox.init import multimodel_statistics 6import smashbox 7 8import os 9import shutil 10import copy 11 12 13class SmashBox: 14 """ 15 Main class which store main parameters 'myparam' and functions to create or delete 16 models. 17 """ 18 19 def __init__(self): 20 21 if not os.path.exists( 22 os.path.join(os.path.expanduser("~"), ".smashbox", "asset") 23 ): 24 shutil.copytree( 25 os.path.join(smashbox.__path__[0], "asset"), 26 os.path.join(os.path.expanduser("~"), ".smashbox", "asset"), 27 ) 28 29 self.myparam = param.param() 30 if os.path.exists( 31 os.path.join(os.path.expanduser("~"), ".smashbox", "param.yaml") 32 ): 33 self.myparam.load_param( 34 os.path.join(os.path.expanduser("~"), ".smashbox", "default_param.yaml") 35 ) 36 else: 37 self.myparam.write_param( 38 os.path.join(os.path.expanduser("~"), ".smashbox", "default_param.yaml") 39 ) 40 41 def help(self): 42 """Display help...""" 43 44 print("! Welcome to SmashBox !") 45 print( 46 "First of all, you must configure main parameters stored in 'myparam' attribute." 47 ) 48 print( 49 " - self.myparam.list_param() : list all parameters to configure in self.myparam.param." 50 ) 51 print(" - self.myparam.set_param(attr, value) : set value to attribute attr.") 52 print(" - self.myparam.get_param(attr) : get the value of attribute attr.") 53 print(" - self.myparam.list_asset_files() : list data available with SmashBox.") 54 print(" - self.myparam.param : attribute which contains all parameters.") 55 print("") 56 print("When ready, you will able to create a new model attribute:") 57 print(" - self.newmodel('mymodel')") 58 print("") 59 print( 60 "After the model 'mymodel' has been created, you can adjust the model setup 'self.mymodel.mysetup':" 61 ) 62 print(" - self.mymodel.mysetup.setup: dictionnary which contain the setup") 63 print( 64 " - self.mymodel.mysetup.list_available_setup(): list preconfigured and ready to use setup in SmashBox" 65 ) 66 print( 67 " - self.mymodel.mysetup.update_setup(dict): update the smash setup with the input dictionary dict." 68 ) 69 print("") 70 print( 71 "When ready, you will be able to create the mesh, the Smash model and run a simulation:" 72 ) 73 print(" - self.mymodel.make_mesh()") 74 print(" - self.mymodel.make_model()") 75 76 def newmodel(self, name="mymodel"): 77 """ 78 Create a new model attribute. This attribute will handle meshing, hydrological modelisation, plot and stattistics. 79 80 Parameters 81 ---------- 82 83 name : str 84 The name of the attribute. 85 86 Examples 87 -------- 88 89 >>> es=smashbox.SmashBox() 90 >>> sb.newmodel("RealCollobrier") 91 92 """ 93 94 name=name.replace(' ','_') 95 96 if not hasattr(self, name): 97 98 setattr(self, name, model.model(name, self.myparam)) 99 100 else: 101 raise ValueError( 102 f"Error: Cannot create model '{name}', model attribute '{name}' already exist" 103 ) 104 105 if not hasattr(self, "multimodel_statistics"): 106 107 setattr( 108 self, 109 "multimodel_statistics", 110 multimodel_statistics.multimodel_statistics(self), 111 ) 112 113 def delmodel(self, modelname): 114 """ 115 Delete a model attribute. 116 117 Parameters 118 ---------- 119 120 modelname : str 121 The name of the attribute to delete. 122 123 Examples 124 -------- 125 126 >>> es=smashbox.SmashBox() 127 >>> sb.newmodel("RealCollobrier") 128 >>> sb.delmodel("RealCollobrier") 129 130 """ 131 if hasattr(self, modelname) and isinstance(getattr(self, modelname), model.model): 132 delattr(self, modelname) 133 134 else: 135 136 raise ValueError(f"Error: {modelname} is not a valid model name.") 137 138 def copymodel(self, modelsource, modelname, copy_smash_model=True): 139 """ 140 Copy a model contener 141 142 Parameters 143 ---------- 144 145 modelsource : str 146 The name of the source model attribute 147 modelname : str 148 The name of the new model attribute. 149 150 Examples 151 -------- 152 153 >>> es=smashbox.SmashBox() 154 >>> sb.newmodel("RealCollobrier") 155 >>> sb.copymodel("RealCollobrier", RealCollobrier2") 156 """ 157 if not hasattr(self, modelsource): 158 raise ValueError(f"Error: Source model '{modelsource}' does not exist") 159 160 if not hasattr(self, modelname): 161 162 self.newmodel(modelname) 163 164 source = getattr(self, modelsource) 165 destination = getattr(self, modelname) 166 167 setattr( 168 destination, 169 "_myparam", 170 copy.deepcopy(getattr(source, "_myparam")), 171 ) 172 setattr(destination, "mymesh", copy.deepcopy(getattr(source, "mymesh"))) 173 setattr(destination, "mysetup", copy.deepcopy(getattr(source, "mysetup"))) 174 175 if copy_smash_model: 176 177 setup_update={"read_prcp":False, "read_pet": False, "read_snow": False, "read_qobs":False, "read_temp":False} 178 destination.mysetup.update_setup(setup_update) 179 180 if source.mysmashmodel is not None: 181 setattr( 182 destination, 183 "mysmashmodel", 184 source.mysmashmodel.copy(), 185 ) 186 for key,value in setup_update.items(): 187 setattr(destination.mysmashmodel.setup, key, value) 188 189 if source.warmup_model is not None: 190 setattr( 191 destination, 192 "warmup_model", 193 source.warmup_model.copy(), 194 ) 195 for key,value in setup_update.items(): 196 setattr(destination.warmup_model.setup, key, value) 197 198 if source.optimize_model is not None: 199 setattr( 200 destination, 201 "optimize_model", 202 source.optimize_model.copy(), 203 ) 204 for key,value in setup_update.items(): 205 setattr(destination.optimize_model.setup, key, value) 206 207 if hasattr(source, "_fstates"): 208 setattr( 209 destination, 210 "_fstates", 211 copy.deepcopy(getattr(source, "_fstates")), 212 ) 213 if hasattr(source, "_istates"): 214 setattr( 215 destination, 216 "_istates", 217 copy.deepcopy(getattr(source, "_istates")), 218 ) 219 if hasattr(source, "_myatmos_data_connector"): 220 setattr( 221 destination, 222 "_myatmos_data_connector", 223 copy.deepcopy(getattr(source, "_myatmos_data_connector")), 224 ) 225 226 else: 227 raise ValueError( 228 f"Error: Cannot copy model '{modelsource}', model attribute '{modelname}' already exist" 229 ) 230 231 # get new model object 232 # mynewmodel = getattr(self, modelname) 233 234 # reset attributes 235 # mynewmodel.mysmashmodel = None 236 # mynewmodel.extra_smash_results = None 237 # mynewmodel._fstates = None 238 # mynewmodel._istates = None 239 # mynewmodel._myatmos_data_connector = None 240 # mynewmodel.warmup_model = None 241 # mynewmodel.mystats = mystats.mystats(self) 242 # mynewmodel.myplot = myplot.myplot(self) 243 244 def copymodeldata(self, modelsource, modelname): 245 """ 246 Copy a model data 247 248 Parameters 249 ---------- 250 251 modelsource : str 252 The name of the source model attribute 253 modelname : str 254 The name of the new model attribute. 255 256 Examples 257 -------- 258 259 >>> es=smashbox.SmashBox() 260 >>> sb.newmodel("RealCollobrier") 261 >>> sb.copymodeldata("RealCollobrier", RealCollobrier2") 262 """ 263 if not hasattr(self, modelsource): 264 raise ValueError(f"Error: Source model '{modelsource}' does not exist") 265 266 if not hasattr(self, modelname): 267 raise ValueError(f"Error: destination model '{modelname}' does not exist") 268 269 source = getattr(self, modelsource) 270 destination = getattr(self, modelname) 271 272 if source.mysmashmodel is not None and destination.mysmashmodel is not None: 273 destination.mysmashmodel.atmos_data = source.mysmashmodel.atmos_data.copy() 274 destination.mysmashmodel.response_data = ( 275 source.mysmashmodel.response_data.copy() 276 ) 277 if source.warmup_model is not None and destination.warmup_model is not None: 278 destination.warmup_model.atmos_data = source.warmup_model.atmos_data.copy() 279 destination.warmup_model.response_data = ( 280 source.warmup_model.response_data.copy() 281 ) 282 if source.optimize_model is not None and destination.optimize_model is not None: 283 destination.optimize_model.atmos_data = source.optimize_model.atmos_data.copy() 284 destination.optimize_model.response_data = ( 285 source.optimize_model.response_data.copy() 286 )
class
SmashBox:
14class SmashBox: 15 """ 16 Main class which store main parameters 'myparam' and functions to create or delete 17 models. 18 """ 19 20 def __init__(self): 21 22 if not os.path.exists( 23 os.path.join(os.path.expanduser("~"), ".smashbox", "asset") 24 ): 25 shutil.copytree( 26 os.path.join(smashbox.__path__[0], "asset"), 27 os.path.join(os.path.expanduser("~"), ".smashbox", "asset"), 28 ) 29 30 self.myparam = param.param() 31 if os.path.exists( 32 os.path.join(os.path.expanduser("~"), ".smashbox", "param.yaml") 33 ): 34 self.myparam.load_param( 35 os.path.join(os.path.expanduser("~"), ".smashbox", "default_param.yaml") 36 ) 37 else: 38 self.myparam.write_param( 39 os.path.join(os.path.expanduser("~"), ".smashbox", "default_param.yaml") 40 ) 41 42 def help(self): 43 """Display help...""" 44 45 print("! Welcome to SmashBox !") 46 print( 47 "First of all, you must configure main parameters stored in 'myparam' attribute." 48 ) 49 print( 50 " - self.myparam.list_param() : list all parameters to configure in self.myparam.param." 51 ) 52 print(" - self.myparam.set_param(attr, value) : set value to attribute attr.") 53 print(" - self.myparam.get_param(attr) : get the value of attribute attr.") 54 print(" - self.myparam.list_asset_files() : list data available with SmashBox.") 55 print(" - self.myparam.param : attribute which contains all parameters.") 56 print("") 57 print("When ready, you will able to create a new model attribute:") 58 print(" - self.newmodel('mymodel')") 59 print("") 60 print( 61 "After the model 'mymodel' has been created, you can adjust the model setup 'self.mymodel.mysetup':" 62 ) 63 print(" - self.mymodel.mysetup.setup: dictionnary which contain the setup") 64 print( 65 " - self.mymodel.mysetup.list_available_setup(): list preconfigured and ready to use setup in SmashBox" 66 ) 67 print( 68 " - self.mymodel.mysetup.update_setup(dict): update the smash setup with the input dictionary dict." 69 ) 70 print("") 71 print( 72 "When ready, you will be able to create the mesh, the Smash model and run a simulation:" 73 ) 74 print(" - self.mymodel.make_mesh()") 75 print(" - self.mymodel.make_model()") 76 77 def newmodel(self, name="mymodel"): 78 """ 79 Create a new model attribute. This attribute will handle meshing, hydrological modelisation, plot and stattistics. 80 81 Parameters 82 ---------- 83 84 name : str 85 The name of the attribute. 86 87 Examples 88 -------- 89 90 >>> es=smashbox.SmashBox() 91 >>> sb.newmodel("RealCollobrier") 92 93 """ 94 95 name=name.replace(' ','_') 96 97 if not hasattr(self, name): 98 99 setattr(self, name, model.model(name, self.myparam)) 100 101 else: 102 raise ValueError( 103 f"Error: Cannot create model '{name}', model attribute '{name}' already exist" 104 ) 105 106 if not hasattr(self, "multimodel_statistics"): 107 108 setattr( 109 self, 110 "multimodel_statistics", 111 multimodel_statistics.multimodel_statistics(self), 112 ) 113 114 def delmodel(self, modelname): 115 """ 116 Delete a model attribute. 117 118 Parameters 119 ---------- 120 121 modelname : str 122 The name of the attribute to delete. 123 124 Examples 125 -------- 126 127 >>> es=smashbox.SmashBox() 128 >>> sb.newmodel("RealCollobrier") 129 >>> sb.delmodel("RealCollobrier") 130 131 """ 132 if hasattr(self, modelname) and isinstance(getattr(self, modelname), model.model): 133 delattr(self, modelname) 134 135 else: 136 137 raise ValueError(f"Error: {modelname} is not a valid model name.") 138 139 def copymodel(self, modelsource, modelname, copy_smash_model=True): 140 """ 141 Copy a model contener 142 143 Parameters 144 ---------- 145 146 modelsource : str 147 The name of the source model attribute 148 modelname : str 149 The name of the new model attribute. 150 151 Examples 152 -------- 153 154 >>> es=smashbox.SmashBox() 155 >>> sb.newmodel("RealCollobrier") 156 >>> sb.copymodel("RealCollobrier", RealCollobrier2") 157 """ 158 if not hasattr(self, modelsource): 159 raise ValueError(f"Error: Source model '{modelsource}' does not exist") 160 161 if not hasattr(self, modelname): 162 163 self.newmodel(modelname) 164 165 source = getattr(self, modelsource) 166 destination = getattr(self, modelname) 167 168 setattr( 169 destination, 170 "_myparam", 171 copy.deepcopy(getattr(source, "_myparam")), 172 ) 173 setattr(destination, "mymesh", copy.deepcopy(getattr(source, "mymesh"))) 174 setattr(destination, "mysetup", copy.deepcopy(getattr(source, "mysetup"))) 175 176 if copy_smash_model: 177 178 setup_update={"read_prcp":False, "read_pet": False, "read_snow": False, "read_qobs":False, "read_temp":False} 179 destination.mysetup.update_setup(setup_update) 180 181 if source.mysmashmodel is not None: 182 setattr( 183 destination, 184 "mysmashmodel", 185 source.mysmashmodel.copy(), 186 ) 187 for key,value in setup_update.items(): 188 setattr(destination.mysmashmodel.setup, key, value) 189 190 if source.warmup_model is not None: 191 setattr( 192 destination, 193 "warmup_model", 194 source.warmup_model.copy(), 195 ) 196 for key,value in setup_update.items(): 197 setattr(destination.warmup_model.setup, key, value) 198 199 if source.optimize_model is not None: 200 setattr( 201 destination, 202 "optimize_model", 203 source.optimize_model.copy(), 204 ) 205 for key,value in setup_update.items(): 206 setattr(destination.optimize_model.setup, key, value) 207 208 if hasattr(source, "_fstates"): 209 setattr( 210 destination, 211 "_fstates", 212 copy.deepcopy(getattr(source, "_fstates")), 213 ) 214 if hasattr(source, "_istates"): 215 setattr( 216 destination, 217 "_istates", 218 copy.deepcopy(getattr(source, "_istates")), 219 ) 220 if hasattr(source, "_myatmos_data_connector"): 221 setattr( 222 destination, 223 "_myatmos_data_connector", 224 copy.deepcopy(getattr(source, "_myatmos_data_connector")), 225 ) 226 227 else: 228 raise ValueError( 229 f"Error: Cannot copy model '{modelsource}', model attribute '{modelname}' already exist" 230 ) 231 232 # get new model object 233 # mynewmodel = getattr(self, modelname) 234 235 # reset attributes 236 # mynewmodel.mysmashmodel = None 237 # mynewmodel.extra_smash_results = None 238 # mynewmodel._fstates = None 239 # mynewmodel._istates = None 240 # mynewmodel._myatmos_data_connector = None 241 # mynewmodel.warmup_model = None 242 # mynewmodel.mystats = mystats.mystats(self) 243 # mynewmodel.myplot = myplot.myplot(self) 244 245 def copymodeldata(self, modelsource, modelname): 246 """ 247 Copy a model data 248 249 Parameters 250 ---------- 251 252 modelsource : str 253 The name of the source model attribute 254 modelname : str 255 The name of the new model attribute. 256 257 Examples 258 -------- 259 260 >>> es=smashbox.SmashBox() 261 >>> sb.newmodel("RealCollobrier") 262 >>> sb.copymodeldata("RealCollobrier", RealCollobrier2") 263 """ 264 if not hasattr(self, modelsource): 265 raise ValueError(f"Error: Source model '{modelsource}' does not exist") 266 267 if not hasattr(self, modelname): 268 raise ValueError(f"Error: destination model '{modelname}' does not exist") 269 270 source = getattr(self, modelsource) 271 destination = getattr(self, modelname) 272 273 if source.mysmashmodel is not None and destination.mysmashmodel is not None: 274 destination.mysmashmodel.atmos_data = source.mysmashmodel.atmos_data.copy() 275 destination.mysmashmodel.response_data = ( 276 source.mysmashmodel.response_data.copy() 277 ) 278 if source.warmup_model is not None and destination.warmup_model is not None: 279 destination.warmup_model.atmos_data = source.warmup_model.atmos_data.copy() 280 destination.warmup_model.response_data = ( 281 source.warmup_model.response_data.copy() 282 ) 283 if source.optimize_model is not None and destination.optimize_model is not None: 284 destination.optimize_model.atmos_data = source.optimize_model.atmos_data.copy() 285 destination.optimize_model.response_data = ( 286 source.optimize_model.response_data.copy() 287 )
Main class which store main parameters 'myparam' and functions to create or delete models.
def
help(self):
42 def help(self): 43 """Display help...""" 44 45 print("! Welcome to SmashBox !") 46 print( 47 "First of all, you must configure main parameters stored in 'myparam' attribute." 48 ) 49 print( 50 " - self.myparam.list_param() : list all parameters to configure in self.myparam.param." 51 ) 52 print(" - self.myparam.set_param(attr, value) : set value to attribute attr.") 53 print(" - self.myparam.get_param(attr) : get the value of attribute attr.") 54 print(" - self.myparam.list_asset_files() : list data available with SmashBox.") 55 print(" - self.myparam.param : attribute which contains all parameters.") 56 print("") 57 print("When ready, you will able to create a new model attribute:") 58 print(" - self.newmodel('mymodel')") 59 print("") 60 print( 61 "After the model 'mymodel' has been created, you can adjust the model setup 'self.mymodel.mysetup':" 62 ) 63 print(" - self.mymodel.mysetup.setup: dictionnary which contain the setup") 64 print( 65 " - self.mymodel.mysetup.list_available_setup(): list preconfigured and ready to use setup in SmashBox" 66 ) 67 print( 68 " - self.mymodel.mysetup.update_setup(dict): update the smash setup with the input dictionary dict." 69 ) 70 print("") 71 print( 72 "When ready, you will be able to create the mesh, the Smash model and run a simulation:" 73 ) 74 print(" - self.mymodel.make_mesh()") 75 print(" - self.mymodel.make_model()")
Display help...
def
newmodel(self, name='mymodel'):
77 def newmodel(self, name="mymodel"): 78 """ 79 Create a new model attribute. This attribute will handle meshing, hydrological modelisation, plot and stattistics. 80 81 Parameters 82 ---------- 83 84 name : str 85 The name of the attribute. 86 87 Examples 88 -------- 89 90 >>> es=smashbox.SmashBox() 91 >>> sb.newmodel("RealCollobrier") 92 93 """ 94 95 name=name.replace(' ','_') 96 97 if not hasattr(self, name): 98 99 setattr(self, name, model.model(name, self.myparam)) 100 101 else: 102 raise ValueError( 103 f"Error: Cannot create model '{name}', model attribute '{name}' already exist" 104 ) 105 106 if not hasattr(self, "multimodel_statistics"): 107 108 setattr( 109 self, 110 "multimodel_statistics", 111 multimodel_statistics.multimodel_statistics(self), 112 )
Create a new model attribute. This attribute will handle meshing, hydrological modelisation, plot and stattistics.
Parameters
name : str The name of the attribute.
Examples
>>> es=smashbox.SmashBox()
>>> sb.newmodel("RealCollobrier")
def
delmodel(self, modelname):
114 def delmodel(self, modelname): 115 """ 116 Delete a model attribute. 117 118 Parameters 119 ---------- 120 121 modelname : str 122 The name of the attribute to delete. 123 124 Examples 125 -------- 126 127 >>> es=smashbox.SmashBox() 128 >>> sb.newmodel("RealCollobrier") 129 >>> sb.delmodel("RealCollobrier") 130 131 """ 132 if hasattr(self, modelname) and isinstance(getattr(self, modelname), model.model): 133 delattr(self, modelname) 134 135 else: 136 137 raise ValueError(f"Error: {modelname} is not a valid model name.")
Delete a model attribute.
Parameters
modelname : str The name of the attribute to delete.
Examples
>>> es=smashbox.SmashBox()
>>> sb.newmodel("RealCollobrier")
>>> sb.delmodel("RealCollobrier")
def
copymodel(self, modelsource, modelname, copy_smash_model=True):
139 def copymodel(self, modelsource, modelname, copy_smash_model=True): 140 """ 141 Copy a model contener 142 143 Parameters 144 ---------- 145 146 modelsource : str 147 The name of the source model attribute 148 modelname : str 149 The name of the new model attribute. 150 151 Examples 152 -------- 153 154 >>> es=smashbox.SmashBox() 155 >>> sb.newmodel("RealCollobrier") 156 >>> sb.copymodel("RealCollobrier", RealCollobrier2") 157 """ 158 if not hasattr(self, modelsource): 159 raise ValueError(f"Error: Source model '{modelsource}' does not exist") 160 161 if not hasattr(self, modelname): 162 163 self.newmodel(modelname) 164 165 source = getattr(self, modelsource) 166 destination = getattr(self, modelname) 167 168 setattr( 169 destination, 170 "_myparam", 171 copy.deepcopy(getattr(source, "_myparam")), 172 ) 173 setattr(destination, "mymesh", copy.deepcopy(getattr(source, "mymesh"))) 174 setattr(destination, "mysetup", copy.deepcopy(getattr(source, "mysetup"))) 175 176 if copy_smash_model: 177 178 setup_update={"read_prcp":False, "read_pet": False, "read_snow": False, "read_qobs":False, "read_temp":False} 179 destination.mysetup.update_setup(setup_update) 180 181 if source.mysmashmodel is not None: 182 setattr( 183 destination, 184 "mysmashmodel", 185 source.mysmashmodel.copy(), 186 ) 187 for key,value in setup_update.items(): 188 setattr(destination.mysmashmodel.setup, key, value) 189 190 if source.warmup_model is not None: 191 setattr( 192 destination, 193 "warmup_model", 194 source.warmup_model.copy(), 195 ) 196 for key,value in setup_update.items(): 197 setattr(destination.warmup_model.setup, key, value) 198 199 if source.optimize_model is not None: 200 setattr( 201 destination, 202 "optimize_model", 203 source.optimize_model.copy(), 204 ) 205 for key,value in setup_update.items(): 206 setattr(destination.optimize_model.setup, key, value) 207 208 if hasattr(source, "_fstates"): 209 setattr( 210 destination, 211 "_fstates", 212 copy.deepcopy(getattr(source, "_fstates")), 213 ) 214 if hasattr(source, "_istates"): 215 setattr( 216 destination, 217 "_istates", 218 copy.deepcopy(getattr(source, "_istates")), 219 ) 220 if hasattr(source, "_myatmos_data_connector"): 221 setattr( 222 destination, 223 "_myatmos_data_connector", 224 copy.deepcopy(getattr(source, "_myatmos_data_connector")), 225 ) 226 227 else: 228 raise ValueError( 229 f"Error: Cannot copy model '{modelsource}', model attribute '{modelname}' already exist" 230 ) 231 232 # get new model object 233 # mynewmodel = getattr(self, modelname) 234 235 # reset attributes 236 # mynewmodel.mysmashmodel = None 237 # mynewmodel.extra_smash_results = None 238 # mynewmodel._fstates = None 239 # mynewmodel._istates = None 240 # mynewmodel._myatmos_data_connector = None 241 # mynewmodel.warmup_model = None 242 # mynewmodel.mystats = mystats.mystats(self) 243 # mynewmodel.myplot = myplot.myplot(self)
Copy a model contener
Parameters
modelsource : str The name of the source model attribute modelname : str The name of the new model attribute.
Examples
>>> es=smashbox.SmashBox()
>>> sb.newmodel("RealCollobrier")
>>> sb.copymodel("RealCollobrier", RealCollobrier2")
def
copymodeldata(self, modelsource, modelname):
245 def copymodeldata(self, modelsource, modelname): 246 """ 247 Copy a model data 248 249 Parameters 250 ---------- 251 252 modelsource : str 253 The name of the source model attribute 254 modelname : str 255 The name of the new model attribute. 256 257 Examples 258 -------- 259 260 >>> es=smashbox.SmashBox() 261 >>> sb.newmodel("RealCollobrier") 262 >>> sb.copymodeldata("RealCollobrier", RealCollobrier2") 263 """ 264 if not hasattr(self, modelsource): 265 raise ValueError(f"Error: Source model '{modelsource}' does not exist") 266 267 if not hasattr(self, modelname): 268 raise ValueError(f"Error: destination model '{modelname}' does not exist") 269 270 source = getattr(self, modelsource) 271 destination = getattr(self, modelname) 272 273 if source.mysmashmodel is not None and destination.mysmashmodel is not None: 274 destination.mysmashmodel.atmos_data = source.mysmashmodel.atmos_data.copy() 275 destination.mysmashmodel.response_data = ( 276 source.mysmashmodel.response_data.copy() 277 ) 278 if source.warmup_model is not None and destination.warmup_model is not None: 279 destination.warmup_model.atmos_data = source.warmup_model.atmos_data.copy() 280 destination.warmup_model.response_data = ( 281 source.warmup_model.response_data.copy() 282 ) 283 if source.optimize_model is not None and destination.optimize_model is not None: 284 destination.optimize_model.atmos_data = source.optimize_model.atmos_data.copy() 285 destination.optimize_model.response_data = ( 286 source.optimize_model.response_data.copy() 287 )
Copy a model data
Parameters
modelsource : str The name of the source model attribute modelname : str The name of the new model attribute.
Examples
>>> es=smashbox.SmashBox()
>>> sb.newmodel("RealCollobrier")
>>> sb.copymodeldata("RealCollobrier", RealCollobrier2")