Create gif

I need to create an animated image (gif) from this script from a set of temperatures
[ T0 -|- T2 ]:

[EvptTemp CndsTemp]
55 33
55 34
55 35
55 36
55 37
55 38
55 39
55 40
55 41
55 42
55 43
55 44
55 45
55 46
55 47
55 48
55 49

The problem for me is that CoolProop
generates alerts during the run, before generating the diagram.

using PyCall

pyimport("sys").executable

@pyimport CoolProp.CoolProp as CP

@pyimport CoolProp.Plots as CPP #StateContainer

pp = CPP.PropertyPlot("R32", "PH", unit_system="KSI")

pp.title("R32 log p-h Diagramm")

pp.set_axis_limits([-40, 700, 0, 15000])

pp.xlabel("h [kJ/kg]")

pp.ylabel("P [kPa]")

pp.calc_isolines(num=20)

cycle = CPP.SimpleCompressionCycle("R32", "PH", unit_system="KSI")

T0 = 33+273.15

pp.state.update(CP.QT_INPUTS,0.0,T0-0.02) 

p0 = pp.state.keyed_output(CP.iP)

T2 = 55+273.15

pp.state.update(CP.QT_INPUTS,1.0,T2+0.02)

p2 = pp.state.keyed_output(CP.iP)

pp.calc_isolines(CP.iT, [T0-273.15,T2-273.15], num=2)

cycle.simple_solve(T0, p0, T2, p2, 0.7, SI=true)

cycle.steps = 50

sc = cycle.get_state_changes()

pp.draw_process(sc)

@pyimport matplotlib.pyplot as plt

plt.close(cycle.figure)

pp.show()


What “alerts” do you get?


C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 11639762.774893, 55.000000 with index (244,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root.  Function values are [18200507441268.304688,17.009243]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 12245416.329262, 55.000000 with index (245,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root.  Function values are [17300317384293.095703,16.118513]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 12882583.947535, 55.000000 with index (246,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root.  Function values are [16444650379287.328125,15.271838]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 13552905.405813, 55.000000 with index (247,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root.  Function values are [15631304333324.744141,14.467039]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 14258105.802918, 55.000000 with index (248,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root.  Function values are [14858186068143.455078,13.702045]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 15000000.000000, 55.000000 with index (249,): Inputs in Brent [22158.340067,32600.338400] do not bracket the root.  Function values are [14123305933268.613281,12.974888]
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:683: UserWarning: Poor data quality, there are not enough valid entries for x (0.000000/250.000000) or y (250.000000/250.000000).
  warnings.warn(

You might try doing animations and gifs with the Plots package. I’ve found that very simple and easy. Animations · Plots

3 Likes

How to save PyCall’s pp.show () object, as a Julia image or plot object? And in this way use the gif macro

In this way the images are created and saved in a file. how to get a gif from these images?

using PyCall

pyimport("sys").executable

@pyimport CoolProp.CoolProp as CP

@pyimport CoolProp.Plots as CPP #StateContainer

TT = [[55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55];

 [33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]]

n=size(TT,2)

for i in 1:n

pp = CPP.PropertyPlot("R32", "PH", unit_system="KSI")

pp.title("R32 log p-h Diagramm")

pp.set_axis_limits([-40, 700, 0, 15000])

pp.xlabel("h [kJ/kg]")

pp.ylabel("P [kPa]")

pp.calc_isolines(num=20)

cycle = CPP.SimpleCompressionCycle("R32", "PH", unit_system="KSI")

T0 = TT[2,i]+273.15

pp.state.update(CP.QT_INPUTS,0.0,T0-0.02) 

p0 = pp.state.keyed_output(CP.iP)

T2 = TT[1,i]+273.15

pp.state.update(CP.QT_INPUTS,1.0,T2+0.02)

p2 = pp.state.keyed_output(CP.iP)

pp.calc_isolines(CP.iT, [T0-273.15,T2-273.15], num=2)

cycle.simple_solve(T0, p0, T2, p2, 0.7, SI=true)

cycle.steps =50

sc = cycle.get_state_changes()

pp.draw_process(sc)

@pyimport matplotlib.pyplot as plt

plt.close(cycle.figure)

#pp.show()

file=string("C:/Users/hermesr/Documents/R32_",i,".jpg")

pp.savefig(file)

end

Thanks to reading the link Plotting a sequence of images as a gif

test

using FileIO, ImageMagick
using PyCall
pyimport("sys").executable
@pyimport CoolProp.CoolProp as CP
@pyimport CoolProp.Plots as CPP #StateContainer

TT = [[55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55];
[33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]]
n=size(TT,2)
file=""
i=1

for i in 1:n
pp = CPP.PropertyPlot("R32", "PH", unit_system="KSI")
pp.title("R32 log p-h Diagramm")
pp.set_axis_limits([-40, 700, 0, 15000])
pp.xlabel("h [kJ/kg]")
pp.ylabel("P [kPa]")
pp.calc_isolines(num=20)

cycle = CPP.SimpleCompressionCycle("R32", "PH", unit_system="KSI")
T0 = TT[2,i]+273.15
pp.state.update(CP.QT_INPUTS,0.0,T0-0.02) 
p0 = pp.state.keyed_output(CP.iP)
T2 = TT[1,i]+273.15
pp.state.update(CP.QT_INPUTS,1.0,T2+0.02)
p2 = pp.state.keyed_output(CP.iP)
pp.calc_isolines(CP.iT, [T0-273.15,T2-273.15], num=2)
cycle.simple_solve(T0, p0, T2, p2, 0.7, SI=true)
cycle.steps =50
sc = cycle.get_state_changes()

pp.draw_process(sc)
@pyimport matplotlib.pyplot as plt
plt.close(cycle.figure)
#pp.show()
ss=string("C:/Users/hermesr/Documents/R32_",i,".jpg")
pp.savefig(ss)
end

A = load("C:/Users/hermesr/Documents/R32_1.jpg");
for i in 2:n
A = cat(A, load("C:/Users/hermesr/Documents/R32_"*string(i)*".jpg"), dims=3)
end
save("C:/Users/hermesr/Documents/test.gif", A)

Help Me!
In the first run the script I receive the following alert:

#pp.show()
       ss="C:/Users/hermesr/Documents/R410A_stM_"*string(i)*".jpg"
       pp.savefig(ss)
       end
ERROR: syntax: unsupported `const` declaration on local variable around C:\Users\hermesr\.julia\packages\PyCall\BD546\src\PyCall.jl:594
Stacktrace:
 [1] top-level scope at REPL[12]:1

I have solved it as follows:
i = 1 is initialized.
the line # pp.show () is activated, that is, pp.show ().
And I run the content inside the for loop.
after that # pp.show (), and performed the run of the for loop and the following lines.

  1. Don’t use @pyimport within the for loop.
  2. You might want to do something like plt = pyimport("matplotlib.pyplot"). I still recommend putting that outside of the for loop.

How to close figure 1 from the script?