fmaussion / salem

Add geolocalised subsetting, masking, and plotting operations to xarray
http://salem.readthedocs.io
Other
186 stars 44 forks source link

RuntimeError salem.wrf_zlevel #218

Open James-96 opened 2 years ago

James-96 commented 2 years ago
import salem
from salem.utils import get_demo_file

ds = salem.open_wrf_dataset(get_demo_file('wrfout_d01.nc'))
ws_h = ds.isel(time=1).salem.wrf_zlevel('WS', levels=10000.)

This is the exactly code in the example. My salem version is 0.3.7, working on windows10. The same error appears when using wrf_plevel

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 114, in _main
    prepare(preparation_data)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\past1000 sim\test.py", line 7, in <module>
    ws_h = ds.isel(time=1).salem.wrf_zlevel('WS', levels=10000.)
  File "C:\Users\73900\AppData\Roaming\Python\Python37\site-packages\salem\sio.py", line 864, in wrf_zlevel
    use_multiprocessing)
  File "C:\Users\73900\AppData\Roaming\Python\Python37\site-packages\salem\sio.py", line 776, in interpz
    use_multiprocessing=use_multiprocessing)
  File "C:\Users\73900\AppData\Roaming\Python\Python37\site-packages\salem\wrftools.py", line 537, in interp3d
    _init_pool()
  File "C:\Users\73900\AppData\Roaming\Python\Python37\site-packages\salem\wrftools.py", line 25, in _init_pool
    POOL = mp.Pool()
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 119, in Pool
    context=self.get_context())
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\pool.py", line 176, in __init__
    self._repopulate_pool()
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\pool.py", line 241, in _repopulate_pool
    w.start()
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "C:\Users\73900\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
fmaussion commented 2 years ago

Mh, that's really weird but did you try this:

https://stackoverflow.com/questions/18204782/runtimeerror-on-windows-trying-python-multiprocessing

James-96 commented 2 years ago

This works well , but it appears another error: RuntimeError: main thread is not in main loop Which can be solved by matplotlib.use('Agg') I'm writing down this if someone have the same error in the future.