aasensio / hazel2

Hazel v2.0: synthesis and inversion of Stokes profiles caused by the joint action of atomic level polarization and the Hanle and Zeeman effects
https://aasensio.github.io/hazel2/index.html
MIT License
21 stars 6 forks source link

syn_obs.py #4

Closed reza35 closed 6 years ago

reza35 commented 6 years ago

Can you run syn_obs.py? the init file has the wavelength information but it instantly crashes with

In [2]: mod = hazel.Model('conf_synobs.ini') Adding spectral region spec1

/data/miniconda/envs/rpy3/lib/python3.6/site-packages/hazelinv-1.9.0-py3.6-linux-x86_64.egg/hazel/model.py in init(self, config, working_mode, verbose) 44 self.configuration = Configuration(config) 45 ---> 46 self.use_configuration(self.configuration.config_dict) 47 48 # Initialize pyhazel

/data/miniconda/envs/rpy3/lib/python3.6/site-packages/hazelinv-1.9.0-py3.6-linux-x86_64.egg/hazel/model.py in use_configuration(self, config_dict) 75 # Add spectral regions 76 for key, value in config_dict['spectral regions'].items(): ---> 77 self.add_spectral(value) 78 79 # Set number of cycles if present

/data/miniconda/envs/rpy3/lib/python3.6/site-packages/hazelinv-1.9.0-py3.6-linux-x86_64.egg/hazel/model.py in add_spectral(self, spectral) 262 if (self.verbose): 263 print(' - Setting all weights to 1') --> 264 weights = np.ones(len(wvl)) 265 else: 266 if (self.verbose):

UnboundLocalError: local variable 'wvl' referenced before assignment

aasensio commented 6 years ago

Fixed.

reza35 commented 6 years ago

Thank you. With the latest upgrades to the code, the "Basic Usage" example does not work anymore. it complains like this:

Exception                                 Traceback (most recent call last)
<ipython-input-1-a198a398a488> in <module>()
      2 import matplotlib.pyplot as plt
      3 mod = hazel.Model(working_mode='synthesis')
----> 4 mod.add_spectral({'Name': 'spec1', 'Wavelength': [10826, 10833, 150], 'topology': 'ch1'})
      5 mod.add_chromosphere({'Name': 'ch1', 'Spectral region': 'spec1', 'Height': 3.0, 'Line': '10830', 'Wavelength': [10826, 10833]})
      6 mod.setup()

/data/miniconda/envs/rpy3/lib/python3.6/site-packages/hazelinv-1.9.0-py3.6-linux-x86_64.egg/hazel/model.py in add_spectral(self, spectral)
    309         if (value['los'] is None):
    310             if (self.working_mode == 'synthesis'):
--> 311                 raise Exception("You need to provide the LOS for spectral region {0}".format(value['name']))
    312             los = None
    313         else:

Exception: You need to provide the LOS for spectral region spec1

adding 'LOS': [0.0,0.0,90.0], 'Boundary condition': [1.0,0.0,0.0,0.0] to the line of add_spectral solves the problem.

aasensio commented 6 years ago

Thanks! I forgot to update this part of the docs. Done.