Creating a time series from a Do loop script

Answered

Comments

11 comments

  • Avatar
    Jason

    Hi Mruizs,

    Thanks for posting in the GoldSim Community Forum! Let me see if I understand your question. You have an array of values that you want transposed into a time series? One way to do this is simply by using the elapsed day as the index. Here is a very simple example:

    I have an array that is defined in a Data Vector:

    In the case shown above, I have 100 rows in this Data vector. Next, I will write an expression that puts each row's value into successive time values to create a time history for each value as each day passes in the simulation:

    As each day passes, we grab the value from the next row down.

    Would something like this work for you?

    0
    Comment actions Permalink
  • Avatar
    María Claudia

    Hi Jason!

    Thanks for your prompt answer.

    I just realized that in my script It was not necessary to write lines in order to give the order to create a time series as a result.

    I just have to select the option "Time History" in Save Results, and work with "DateTime" to call the item from another time series.

    I hope you understand my answer.

     

     

    1
    Comment actions Permalink
  • Avatar
    María Claudia

    However, what you showed me is very interesting!

    Surely I will use it in my model.

    0
    Comment actions Permalink
  • Avatar
    Jason

    I'm glad you found it useful and also found your solution. Because GoldSim is a dynamic simulator, it is very easy to work with time and datetime in your model expressions. Please let me know if you need anything else.

    -Jason

    0
    Comment actions Permalink
  • Avatar
    Saeed Golian

    Hi everyone,

    I have a script in Goldsim which requires time series to be fed into it. But, I need to do some pre-analyses on the raw time series and as a results, I have expressions and not time series and it lead to an error when applying the scrip (please see the attched file for what I am looking for). Is there any way to convert back an expression to time series format?

     

    Thanks



    0
    Comment actions Permalink
  • Avatar
    Jason

    Saeed,

    You have a couple of options. You can simply run the model, right click on the Precip_Expression and select Time History and view the table of results and copy-paste them.

    If that is not what you want, then you can record the output to a time series (i.e. into your Precip_TS_out): Using a Time Series Element to Record and Play Back a History

    Please keep in mind that the first option I mentioned is by far the most common and easy to do. The recording option is typically used to pass the entire Time Series definition into a Submodel for further processing inside GoldSim.

    Does this help?

    0
    Comment actions Permalink
  • Avatar
    Saeed Golian

    Jason,

    Many thanks for your response. The point is that I need this conversion (The expression output to Time Series) to be done straight on the ‘Precip_TS_Out’ as it is the input to another Script element which only accepts time series element (e.g. in that script there is a loop which calls ‘Precip_TS_Out(~Ts)’ where Ts is an incremental time step). For that reason, I am not calling the original 'Precip_TS_In’ but need to use the output from the 'Precip_Expression' and this should be in Time series format. 

    I hope there is an appropriate solution for my case.

    Thanks in advance,

    Saeed

    0
    Comment actions Permalink
  • Avatar
    Saeed Golian

    Hi Jason, 

    I used the recording function of the time series and used it as the input to the script and now have this error, would you please help me how I can handle it? I also attached the script where the recorded time series is called (red rectangle). Again, when I use the original Precip_TS, the script runs without any error.

    Thanks

    Saeed

     

    0
    Comment actions Permalink
  • Avatar
    Jason

    Saeed,

    My guess is that you are trying to refer to the time series recording before it had a chance to finish recording. It is important that you wait until the time series has finished recording before using it. To enable this, please try changing your IF statement found on line 9 of your script to be:

    IF (ETime >= ~SimDuration) THEN....

    Does that work?

    -Jason

    0
    Comment actions Permalink
  • Avatar
    Saeed Golian

    Hi Jason,

    the solution to change the script, i.e

    IF (ETime >= ~SimDuration) THEN....

    doesn't work and I had the same issue, but you were right about this point that the model was calling the time series before the recording finishes, and I resolved this by putting it in a sub-model and then called it in the main model and it works fine now.

    Thanks for your help Jason.

    Regards,

    Saeed

    0
    Comment actions Permalink
  • Avatar
    Jason

    Saeed,

    Good idea to use a submodel. I should have realized that was the right thing to do. Glad it is working for you now.

    -Jason

    0
    Comment actions Permalink

Please sign in to leave a comment.