natashabatalha/PandExo

Unable to call jdi.run_pandexo()

An1th opened this issue · 2 comments

An1th commented

Hi, Can someone please help me out.

If I call run_pandexo() using instrument type as string, I get the below error:

result = jdi.run_pandexo(exo_dict, "NIRSpec Prism")

Instrument input is not dict so must be list. Enter in format ["NIRSpec G140M"] or ["NIRISS SOSS","MIRI LRS"]

If I give it as array, I get this following error:

result = jdi.run_pandexo(exo_dict, ["NIRSpec Prism"])

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_20806/893901556.py in <module>
----> 1 result = jdi.run_pandexo(exo_dict,["NIRSpec Prism"])

~/anaconda3/lib/python3.8/site-packages/pandexo/engine/justdoit.py in run_pandexo(exo, inst, param_space, param_range, save_file, output_path, output_file, num_cores, verbose)
    400             if verbose: print("Running Single Case for: " + inst[0])
    401             inst_dict = load_mode_dict(inst[0])
--> 402             results =wrapper({"pandeia_input": inst_dict , "pandexo_input":exo}, verbose=verbose)
    403             if output_file == '':
    404                 output_file = 'singlerun.p'

~/anaconda3/lib/python3.8/site-packages/pandexo/engine/pandexo.py in wrapper(dictinput, verbose)
     34     if telescope=='jwst':
     35         from .jwst import compute_full_sim
---> 36         return compute_full_sim(dictinput, verbose=verbose)
     37     elif telescope=='hst':
     38         from .hst import compute_sim_hst

~/anaconda3/lib/python3.8/site-packages/pandexo/engine/jwst.py in compute_full_sim(dictinput, verbose)
     83 
     84 
---> 85     i = InstrumentFactory(config=conf_temp)
     86 
     87     #detector parameters

~/anaconda3/lib/python3.8/site-packages/pandeia/engine/instrument_factory.py in InstrumentFactory(config, webapp, **kwargs)
     48         raise EngineInputError(value=msg)
     49     else:
---> 50         cls = inst_map[instrument](mode=mode, config=config, webapp=webapp, **kwargs)
     51         return cls

~/anaconda3/lib/python3.8/site-packages/pandeia/engine/jwst.py in __init__(self, mode, config, webapp, **kwargs)
     68         config['detector']['max_total_groups'] = config['detector']['nint'] * config['detector']['ngroup']
     69 
---> 70         JWSTInstrument.__init__(self, mode=mode, config=config, webapp=webapp, **kwargs)
     71 
     72         slit = self.instrument.get('slit',None)

~/anaconda3/lib/python3.8/site-packages/pandeia/engine/jwst.py in __init__(self, mode, config, webapp, **kwargs)
     31 
     32     def __init__(self, mode=None, config={}, webapp=False, **kwargs):
---> 33         telescope = JWST()
     34         # these are the required sections and need to be passed via API in webapp mode
     35         self.instrument_pars = {}

~/anaconda3/lib/python3.8/site-packages/pandeia/engine/config.py in __init__(self, config, webapp, **kwargs)
     45         # grab info from the configured defaults file, if any, from caller via a passed dict, or via keywords
     46         # clean meta blocks from the configuration files
---> 47         all_config = merge_data(self._get_config(), config, dict(**kwargs))
     48         # checking if all_config matches self._get_config() is preferable, because it handles both the case where
     49         # config={} was either empty and where it had just a single entry equivalent to the default.

~/anaconda3/lib/python3.8/site-packages/pandeia/engine/telescope.py in _get_config(self)
     31         # use this trick to key the configuration file name off the name of the instantiated subclass
     32         self.tel_name = self.__class__.__name__.lower()
---> 33         self.ref_dir = os.path.join(default_refdata_directory, self.tel_name, "telescope")
     34         config = io.read_json(os.path.join(self.ref_dir, "config.json"), raise_except=True)
     35         # add separate CR config, if it's there...

~/anaconda3/lib/python3.8/posixpath.py in join(a, *p)
     74     will be discarded.  An empty last part will result in a path that
     75     ends with a separator."""
---> 76     a = os.fspath(a)
     77     sep = _get_sep(a)
     78     path = a

TypeError: expected str, bytes or os.PathLike object, not NoneType```


Hi @An1th it looks like your reference data environment variables are not set. The instructions to do so are here. If you have followed these steps and aren't seeing the variables set, here are some trouble shooting steps:

  1. In python first test to see that environment is set. For example, I can see mine set:
>>> import os
>>> os.environ['pandeia_refdata']
'/Users/nbatalh1/Documents/data/pandeia_data-2.0'

If you get back a blank file path, then your environment will return a NoneType and lead to the problem you are seeing.

  1. Try and force the path. If you tried setting the path in bash_profile (see this tutorial here) but it didnt work, you can try forcing it before the import. For example:
>>> import os
>>> os.environ['pandeia_refdata'] = '/Users/nbatalh1/Documents/data/pandeia_data-2.0'
>>> from pandexo.engine import justdoit 

Make sure that you reset your kernel, and set the environment before importing pandexo.

Try these out and let me know what you find!

An1th commented

Hi @natashabatalha ,

Great ! It worked.. Thank you so much for the quick response !