Open xiangyi-wang opened 5 years ago
Hi there,
Unfortunately I have not experienced this Warning. Could you give an example of the code you used which produced this warning?
I don't use this module with name == 'main': so cannot comment on this. Does the module import properly when you use "from enwofost import enwofost" and can you generate 1 single ensemble e.g. num_of_ensembles = 1.
the PDF_Image method does not require you to use plt.show if you are working in an interactive environment like jupyter. But if you are working through the command line and using plt.show(), then I can see why this is experiencing issues. Matplotlib is struggling when handling the enwofost object. There are two workarounds:
a). edit the PDF_Image method to save the figure as as an image to disk at the end of the plotting code. eg plt.savefig('pdf_image_output.png') on line 760.
b). the PDF_Image returns the 2D array of the PDF distribution, so you could build the plot yourself. using the return of the method:
ens = enwofost(num_of_ensembles, 'potential') if name == 'main': ens.Generate_With_Dists_From_Objects(woroot + 'par_prior.csv', crop, soil, site, weather, agromanagement) image = ens.PDF_Image('LAI') plt.imshow(image, origin='lower') plt.show()
This is my code and still reporting errors when i try num_of_ensembles = 1,and from enwofost import enwofost have no error;
if I don't use this module with name == 'main',will multiprocess Error: Traceback (most recent call last):
File "
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.
`import numpy as np import datetime as dt import matplotlib.pyplot as plt import copy
import dill from pcse.fileinput import CABOFileReader from pcse.models import Wofost71_PP from pcse.fileinput import CABOWeatherDataProvider from pcse.base.parameter_providers import ParameterProvider from pcse.util import WOFOST71SiteDataProvider from pcse.fileinput import YAMLAgroManagementReader from enwofost import enwofost ############################################################# woroot ="D:\work\wofost_tools-master\wofost_tools-master\" crop = CABOFileReader(woroot+'data/henan_crop_params.CAB') soil = CABOFileReader(woroot+'data/Hengshui.soil') site = WOFOST71SiteDataProvider(WAV=100, CO2=360) parameters = ParameterProvider(crop,soil,site) weather = CABOWeatherDataProvider(woroot+'data/henan_s01HB') agromanagement = YAMLAgroManagementReader(woroot+'data/timer.amgt') parameter_object = ParameterProvider(crop,soil,site) ############################################################# num_of_ensembles = 1 ens = enwofost(num_of_ensembles, 'potential') if name == 'main':
ens.Generate_With_Dists_From_Objects(woroot + 'par_prior.csv', crop, soil, site, weather, agromanagement)
image = ens.PDF_Image('LAI')
plt.imshow(image, origin='lower')
plt.show()`
I tried to run on Linux system without any problems,Here are the reasons I found on the Internet“Because there is no fork (the mechanism of creating process in Linux operating system) in Windows operating system, this file will be automatically imported to start the child process when it is created, and the whole file will be executed when it is imported. So if process () is written directly in a file, it will create subprocess error infinitely recursively. So you have to protect the part that created the child process by using if_name=='main'. When importing, it will not run recursively.”
Thanks for investigating this. I developed this on Linux and had no such problems. I think, if it is run on windows I will either develop and windows friendly multiprocessing version or add a single threading version of running WOFOST to avoid the multiprocessing.
and, No problem when I use Generate_With_Dists_From_Objects , but, Generate_With_MC_From_Objects: ens.Generate_With_MC_From_Objects(distribution_file, crop, soil, site, weather, agromanagement) File "/home/wangxiangyi/wofost_tools-master/enwofost.py", line 516, in Generate_With_MC_From_Objects distributions = np.load(numpy_repo)['retval'][0] File "/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py", line 451, in load raise ValueError("Cannot load file containing pickled data " ValueError: Cannot load file containing pickled data when allow_pickle=False Generate_With_Dists_From_Scratch: ens.Generate_With_Dists_From_Scratch(distribution_file, crop, soil, site, weather, agromanagement,central_value = 'absolute') TypeError: Generate_With_Dists_From_Scratch() got multiple values for argument 'central_value'
I don't quite understand the description of these three methods. - Generate_With_Dists_From_Scratch、Generate_With_Dists_From_Objects、 Generate_With_MC_From_Objects;What is the difference between the from strings of file locations、from wofost objects and from wofost objects and Monte Carlo parameter sets.
The 'Generate_With_MC_From_Objects' method will not work as I have not uploaded any of the MC results. If you have your own MC results, this method will have to be adapted to fit your scenario.
The 'Generate_With_Dists_From_Scratch' method does not support passing in a 'site' object or string. This error is caused by passing too many argument to the method. Therefore to us this method try this: ens.Generate_With_Dists_From_Scratch('par_prior.csv', 'data/henan_crop_params.CAB', 'data/Hengshui.soil' , 'data/henan_s01*', 'data/timer.amgt', central_value = 'absolute')
All the method create ensembles, but how they do it is different. -From_Objects creates ensembles using established WOFOST objects, so you can edit them in python. -From_Scratch creates ensembles from strings pointing to the location of WOFOST components saved to disk. -With_Dists creates ensemble by drawing parameters from a normal distribution parameterized by the 'par_prior.csv' file. -With_MC generates ensembles by randomly selecting a parameter set from and Monte Carlo calibration. No normal distribution is established.
非常感谢你和你的项目,我在这里面学到很多。 Thank you for your project, which has taught me a lot.The following problems occurred when I used the enwofost module.I don't know how to modify it.
multiprocess module have some problems if name == 'main': freeze_support() ...