BioSTEAMDevelopmentGroup / Bioindustrial-Park

BioSTEAM's Premier Repository for Biorefinery Models and Results
MIT License
36 stars 17 forks source link

Error regarding model call #130

Open zasddsgg opened 1 month ago

zasddsgg commented 1 month ago

Hello, I have installed biorefineries, biosteam and thermosteam with code pip install . and git clone. However, when I call the following code, I will encounter the following error. May I ask you how to solve it? I use git clone https://github.com/BioSTEAMDevelopmentGroup/Bioindustrial-Park.git, git clone https://github.com/BioSTEAMDevelopmentGroup/biosteam.git and git clone https://github.com/BioSTEAMDevelopmentGroup/thermosteam.git, and cd Bioindustrial-Park folder, use pip install ., cd biosteam folder, use pip install ., cd thermosteam folder, use pip install . to install biorefineries, biosteam and thermosteam.

The code is as follows:

from biorefineries import cellulosic
import biosteam as bst
from biosteam import settings 
from biorefineries.tea import create_cellulosic_ethanol_tea
from biosteam.report import voc_table
bst.nbtutorial()
cs = cellulosic.Biorefinery('corn stover ethanol')
cs.cornstover_sys.diagram(format='png')
tea=create_cellulosic_ethanol_tea(cs.cornstover_sys)
cs.cornstover_sys.save_report('cornstover.xlsx')

The error information is as follows:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File D:\anaconda\envs\zddd\lib\site-packages\biorefineries\cellulosic\biorefinery.py:32, in Biorefinery.chemicals(self)
     31 try:
---> 32     chemicals = self._chemicals
     33 except AttributeError:

AttributeError: 'Biorefinery' object has no attribute '_chemicals'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[1], line 7
      5 from biosteam.report import voc_table
      6 bst.nbtutorial()
----> 7 cs = cellulosic.Biorefinery('corn stover ethanol')
      8 cs.cornstover_sys.diagram(format='png')
      9 tea=create_cellulosic_ethanol_tea(cs.cornstover_sys)

File D:\anaconda\envs\zddd\lib\site-packages\biorefineries\cellulosic\biorefinery.py:53, in Biorefinery.__new__(cls, name, cache, chemicals, include_blowdown_recycle, feedstock_kwargs, prices, GWP_CFs)
     51 self.flowsheet = bst.Flowsheet(name)
     52 F.set_flowsheet(self.flowsheet)
---> 53 bst.settings.set_thermo(self.chemicals)
     54 load_process_settings()
     55 sys = self.sys = create_cellulosic_ethanol_system(
     56     include_blowdown_recycle=include_blowdown_recycle
     57 )

File D:\anaconda\envs\zddd\lib\site-packages\biorefineries\cellulosic\biorefinery.py:34, in Biorefinery.chemicals(self)
     32     chemicals = self._chemicals
     33 except AttributeError:
---> 34     self._chemicals = chemicals = create_cellulosic_ethanol_chemicals()
     35 return chemicals

File D:\anaconda\envs\zddd\lib\site-packages\thermosteam\utils\decorators\chemical_cache.py:19, in chemical_cache.<locals>.h(cache, *args, **kwargs)
     17     caching = Chemical.cache
     18     Chemical.cache = True
---> 19     value = g(*args, **kwargs)
     20     Chemical.cache = caching
     21 else:

File D:\anaconda\envs\zddd\lib\site-packages\biorefineries\cellulosic\chemicals.py:124, in create_cellulosic_ethanol_chemicals()
    122 @chemical_cache
    123 def create_cellulosic_ethanol_chemicals():
--> 124     from biorefineries import cane
    125     chems = tmo.Chemicals([])
    126     oilcane_chemicals = cane.create_oilcane_chemicals()

File D:\anaconda\envs\zddd\lib\site-packages\biorefineries\cane\__init__.py:13
     11 from . import evaluation
     12 from . import results
---> 13 from . import contour_plots
     14 from . import feature_mockups
     15 from . import uncertainty_plots

File D:\anaconda\envs\zddd\lib\site-packages\biorefineries\cane\contour_plots.py:85
     69 CABBI_colors = (colors.CABBI_yellow.tint(75).RGBn, 
     70                 colors.CABBI_yellow.tint(30).RGBn,
     71                 colors.CABBI_yellow.RGBn,
     72                 colors.CABBI_green.tint(5).RGBn,
     73                 colors.CABBI_teal_green.shade(40).RGBn,
     74                 colors.CABBI_teal_green.shade(60).RGBn)
     76 CABBI_colors_x = (colors.CABBI_blue_light.tint(90).RGBn,
     77                   colors.CABBI_blue_light.tint(40).RGBn, 
     78                   colors.CABBI_blue_light.RGBn, 
   (...)
     81                   colors.CABBI_teal_green.tint(40).shade(15).RGBn,
     82                   colors.CABBI_teal_green.shade(45).RGBn)
     84 diverging_colormaps = [
---> 85     plt.cm.get_cmap('RdYlGn')
     86 ]
     88 colormaps = [
     89     plt.cm.get_cmap('viridis'),
     90     plt.cm.get_cmap('copper_r'),
   (...)
     95     plt.cm.get_cmap('bone_r'),
     96 ] * 2
     98 light_letter_color = colors.neutral.tint(98).RGBn

AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'
yoelcortes commented 1 month ago

@zasddsgg, thanks for posting this issue!

Recently matplotlib restructured their imports. Yesterday I made updates to the bioindustrial-park and fixed this issue. Could you try updating your local bioindustrial-park, biosteam, and thermosteam again?

Updating should take care of the error... Note that the code lines in the repo are different (since just yesterday):

https://github.com/BioSTEAMDevelopmentGroup/Bioindustrial-Park/blob/4a24069177b3b8b8de738b7622710b3fc8d17367/biorefineries/cane/contour_plots.py#L84-L96

zasddsgg commented 1 month ago

I re-used git clone to download the latest Bioindustrial-Park, biosteam and thermosteam. After installation, when the code ran to cs.cornstover_sys.save_report('cornstover.xlsx'), The following errors are reported.

FileNotFoundError                         Traceback (most recent call last)
File D:\anaconda\envs\zddd\lib\site-packages\biosteam\_system.py:3346, in System.save_report(self, file, dpi, **stream_properties)
   3345 worksheet = writer.book.create_sheet('Flowsheet')
-> 3346 flowsheet = openpyxl.drawing.image.Image('flowsheet.png')
   3347 worksheet.add_image(flowsheet, anchor='A1')

File D:\anaconda\envs\zddd\lib\site-packages\openpyxl\drawing\image.py:32, in Image.__init__(self, img)
     31 mark_to_close = isinstance(img, str)
---> 32 image = _import_image(img)
     33 self.width, self.height = image.size

File D:\anaconda\envs\zddd\lib\site-packages\openpyxl\drawing\image.py:16, in _import_image(img)
     15 if not isinstance(img, PILImage.Image):
---> 16     img = PILImage.open(img)
     18 return img

File D:\anaconda\envs\zddd\lib\site-packages\PIL\Image.py:3277, in open(fp, mode, formats)
   3276 if filename:
-> 3277     fp = builtins.open(filename, "rb")
   3278     exclusive_fp = True

FileNotFoundError: [Errno 2] No such file or directory: 'D:\\biosteam_study\\flowsheet.png'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[1], line 10
      8 cs.cornstover_sys.diagram(format='png')
      9 tea=create_cellulosic_ethanol_tea(cs.cornstover_sys)
---> 10 cs.cornstover_sys.save_report('cornstover.xlsx') 
     11 print(tea._DPI(tea.installed_equipment_cost)/1000000)
     12 print(tea._TDC(tea._DPI(tea.installed_equipment_cost))/1000000)

File D:\anaconda\envs\zddd\lib\site-packages\biosteam\_system.py:3359, in System.save_report(self, file, dpi, **stream_properties)
   3356         except:
   3357             warn("problem in saving flowsheet; please submit issue to BioSTEAM with"
   3358                  "your current version of openpyxl and xlsx writer", RuntimeWarning)
-> 3359         worksheet.insert_image('A1', 'flowsheet.png')
   3360     diagram_completed = True
   3362 tea = self.TEA

AttributeError: 'Worksheet' object has no attribute 'insert_image'
zasddsgg commented 1 month ago

Besides, after running the code cs.cornstover_sys.diagram(format='png'), there is no diagram appears.

zasddsgg commented 1 month ago

Could I consult you If I only use cd Bioindustrial-Park, pip install . to install. Is it OK (this process seems to automatically install biosteam and thermosteam)? Or do I have to use the cd biosteam, pip install . , cd thermosteam, pip install . after cd Bioindustrial-Park, pip install . to reinstall biosteam and thermosteam?

yoelcortes commented 1 month ago

@zasddsgg, did you get a new computer or reset your old one? Please follow these steps to install graphviz on your computer: https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224#format-svg-not-recognized-use-one-of

You may need to add graphviz to your system path as well.

If the problem persists, run the following and send me the traceback:

>>> from biosteam import preferences
>>> preferences.raise_exception = True
>>> from biorefineries import cornstover as cs
>>> cs.cornstover_sys.diagram(format='png')

Thanks,

zasddsgg commented 1 month ago

I got it. The problem has been solved.

For installation by git clone , could I consult you If I only use cd Bioindustrial-Park, pip install . to install. Is it OK (this process seems to automatically install biosteam and thermosteam)? Or do I have to use the cd biosteam, pip install . , cd thermosteam, pip install . after cd Bioindustrial-Park, pip install . to reinstall biosteam and thermosteam?

In my process, do I need to set preferences.raise_exception = True.

Thanks for your help again.