Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help wanted, the external file #53

Open
daxiang415 opened this issue May 12, 2021 · 11 comments
Open

Help wanted, the external file #53

daxiang415 opened this issue May 12, 2021 · 11 comments

Comments

@daxiang415
Copy link

daxiang415 commented May 12, 2021

Dear author,

Thanks a lot for your work.

I just try to set the external weather file(.tm2) to type 15-2 for processing the weather data.

I could not find any detailed example in this, could you please give me an instance?

Further, I just run the type 15 in trnsystor, the tm2 file will decrease from 1232kb to 563kb. I do not know if there is any problem to damage the weather file.

image

Here some of the files just became 563kb

I also tested the type9e, still facing the problem of the setting of external_files, would you please give an example for how to config the external files for a model

image

@samuelduchesne
Copy link
Owner

This seems like a TRNSYS question. Please refer to the TRNSYS documentation on how to use weather readers.

As for any issues with Trnsystor, please provide the full code (with comments) to help me help you.

@daxiang415
Copy link
Author

from trnsystor import TrnsysModel
import trnsystor
from trnsystor.statement import Equation
from trnsystor.collections import EquationCollection
from trnsystor import Deck, ControlCards
import subprocess

import type9e for the weather_data, the xmltmf file just directly saving from the trnsys studio

weather_xml = "./all_xml/Type9e.xmltmf"

weather_model = TrnsysModel.from_xml(weather_xml)

changing of the parameters for the txt file I just need to load, this setting is working in trnsys studio

weather_model.parameters["Mode"] = 4
weather_model.parameters["Header_Lines_to_Skip"] = 1
weather_model.parameters["No_of_values_to_read"] = 7
weather_model.parameters["Interpolate_or_not_1"] = -1
weather_model.parameters["Interpolate_or_not_2"] = -1
weather_model.parameters["Interpolate_or_not_3"] = -1
weather_model.parameters["Interpolate_or_not_4"] = -1
weather_model.parameters["Interpolate_or_not_5"] = -1
weather_model.parameters["Interpolate_or_not_6"] = -1
weather_model.parameters["Interpolate_or_not_7"] = -1

using type 65c to plot the weather information,

type65_xml = "./all_xml/Type65c.xmltmf"
monitor_test = TrnsysModel.from_xml(type65_xml)
monitor_test.parameters["Left_axis_minimum"] = 0
monitor_test.parameters["Left_axis_maximum"] = 30000
monitor_test.parameters["Nb_of_left_axis_variables"] = 1

#connected between those two model
weather_model.connect_to(monitor_test, mapping={"Output_2": "Left_axis_variable_1"})

simulation card

cc = ControlCards.all()
cc.set_statement(trnsystor.statement.Simulation(start=3800, stop=4000, step=1))

deck_file = Deck(name='mytest', control_cards=cc, author='gaoyuan')

list_models = [weather_model, monitor_test]

deck_file.update_models(list_models)

deck_file.save('my_project.dck')

running simulation through dck file

subprocess.call(r'"D:\TRNSYS18\Exe\TrnEXE64.exe" "my_project.dck"', cwd=r'C:\Users\asus\Desktop\trnsys')

Here is my code file, I am a little bit confused for the introduction of external_files for the model, especially for type9e model. Since I could not find an coding example for how to deal with the external_files of trnsys model, I just change the XML text for the path of external_files, but still not work.

@daxiang415
Copy link
Author

I think the most difficult part is for the external_files in trnsystor. I could not find out how to deal with this part. The doc seems a little bit confusing to me and there is no coding example.

@samuelduchesne
Copy link
Owner

samuelduchesne commented May 15, 2021

Thank you for sharing the example; this was very helpfull. The path of an external file must be set on the "value" attribute of the ExternalFile object. Must be set on the ExternalFile object itself, eg.: weather_model.external_files["Input_file_name"]. In the case of the weather_model, you can set the path this way:

weather_model.external_files["Input_file_name"] = "tests/input_files/US-CO-Boulder-94018.tm2"

Btw, why don't you use the Type15-2 to read the weather data?

@daxiang415
Copy link
Author

Thanks a lot for your help, I may use the real measured data to replace the other data, so I used the .txt file. Currently, I change to the type15-2, however, it just raises the KeyError when I modify my coding, here is the result.

weather_xml = "./all_xml/Type15-2.xmltmf"

weather_model = TrnsysModel.from_xml(weather_xml)

weather_model.external_files["Input_file_name"].value = "C:/Users/asus/Desktop/trnsys/Weather/US-TMY2/US-CA-San-Francisco-23234.tm2"

I rebuild the xmltmf file from trnsys 18, and try again, but it is till not working.

@daxiang415
Copy link
Author

Also I try to change the code into
weather_model.external_files.values = "C:/Users/asus/Desktop/trnsys/all_xml/weather/tianqi.txt"

I still try the .txt case because I just want to ensure the type of file does not include any further problems. However, the log says that the type9e still could not read from the supplied data file.

*** Fatal Error at time : 3800.000000
Generated by Unit : 1
Generated by Type : 9
Message : Unable to correctly read from the supplied data file. Please check the file and re-run the simulation. The most likely cause of this problem is an empty or non-existent file.

@daxiang415
Copy link
Author

Also, try some in the type15-2 case, still not working.

*** Fatal Error at time : 3000.000000
Generated by Unit : 1
Generated by Type : 15
Message : Unable to correctly read from the supplied data file - please check the file and re-run the simulation.

weather_xml = "./all_xml/Type15-2.xmltmf"

weather_model = TrnsysModel.from_xml(weather_xml)

weather_model.external_files.values = r"C:\Users\asus\Desktop\trnsys\CN-Beijing-545110.tm2"

Also, I notice that the file address is not changed

image

But your code example will raise KeyError:

image

@samuelduchesne
Copy link
Owner

samuelduchesne commented May 15, 2021

The ExternalFiles attribute is a dict-like object. Make sure you index the external file with the correct key name:

import trnsystor
from trnsystor import Deck, ControlCards, TrnsysModel
from trnsystor.collections import EquationCollection

# create weather model
weather_xml = "tests/input_files/Type15-2.xml"
weather_model = TrnsysModel.from_xml(weather_xml)

# assign external file and logic number
weather_model.external_files["Which_file_contains_the_TMY_2_weather_data_"] = "tests/input_files/US-CO-Boulder-94018.tm2"
# The logical unit needs to be assigned manually
weather_model.parameters["Logical_unit"] = weather_model.external_files["Which_file_contains_the_TMY_2_weather_data_"].logical_unit

# Create online plotter
monitor_test = TrnsysModel.from_xml("tests/input_files/Type65c.xml")
monitor_test.parameters["Left_axis_minimum"] = 0
monitor_test.parameters["Left_axis_maximum"] = 30000
monitor_test.parameters["Nb_of_left_axis_variables"] = 1

# connect the two models
weather_model.connect_to(monitor_test, mapping={"Global_horizontal_radiation_not_interpolated_": "Left_axis_variable_1"})
cc = ControlCards.all()
cc.set_statement(trnsystor.statement.Simulation(start=3800, stop=4000, step=1))

deck_file = Deck(name='mytest', control_cards=cc )

list_models = [weather_model, monitor_test]

deck_file.update_models(list_models)

deck_file.save('my_project.dck')

A fix [#54] regarding printing of inputs has just been pushed; That should also make sure you can run the file. See https://github.com/samuelduchesne/trnsystor/releases/tag/v1.3.7

@daxiang415
Copy link
Author

Really apprecaite your help!!!! It could run in my env firstly. But there will be still some problems.

Firstly, after running the first time, the .tm2 file will become 1kb, which means a damage in the file?
Secondly, I try to output the dry_bulb_temperature of .tm2 file, but it only a stright line in the trnsys plot.

Besides, the .txt case still not work, the type9e seems do not have the logical_unit here.

import trnsystor
from trnsystor import Deck, ControlCards, TrnsysModel
from trnsystor.collections import EquationCollection

create weather model

weather_xml = "C:/Users/asus/Desktop/trnsys/all_xml/Type15-2.xml"
weather_model = TrnsysModel.from_xml(weather_xml)

assign external file and logic number

weather_model.external_files["Which_file_contains_the_TMY_2_weather_data_"] = "C:/Users/asus/Desktop/trnsys/CN-Beijing-545110.tm2"

The logical unit needs to be assigned manually

weather_model.parameters["Logical_unit"] = weather_model.external_files["Which_file_contains_the_TMY_2_weather_data_"].logical_unit

Create online plotter

monitor_test = TrnsysModel.from_xml("C:/Users/asus/Desktop/trnsys/all_xml/Type65c.xml")
monitor_test.parameters["Left_axis_minimum"] = 0
monitor_test.parameters["Left_axis_maximum"] = 30
monitor_test.parameters["Nb_of_left_axis_variables"] = 1

connect the two models

weather_model.connect_to(monitor_test, mapping={"Dry_bulb_temperature": "Left_axis_variable_1"})
cc = ControlCards.all()
cc.set_statement(trnsystor.statement.Simulation(start=3800, stop=8760, step=1))

deck_file = Deck(name='mytest', control_cards=cc )

list_models = [weather_model, monitor_test]

deck_file.update_models(list_models)

deck_file.save('my_project.dck')

import subprocess

Running TRNSYS in interactive mode

subprocess.call(r'"D:\TRNSYS18\Exe\TrnEXE64.exe" "my_project.dck"', cwd=r'C:\Users\asus\Desktop\trnsys')

image

After, running one file, it became 1kb, and the output value is not correct.
image

It worked in trnsys studio, seems not the problem from the file.
image

@samuelduchesne
Copy link
Owner

It looks like the weather file reader is eating bytes out of the input file when the logical_unit number is not correct. At this point, this is an issue with TRNSYS, not trnsystor.

@daxiang415
Copy link
Author

But for the type9e, the logical_unit could not be set in the parameters. How to deal with this part to make sure the external file is read correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants