Skip to content

Better Scenario class#32

Merged
RemDelaporteMathurin merged 11 commits into
mainfrom
scenario
Nov 2, 2024
Merged

Better Scenario class#32
RemDelaporteMathurin merged 11 commits into
mainfrom
scenario

Conversation

@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Nov 2, 2024

This PR extends the current Scenario class so that users can create a scenario from python instead of having to write a txt file by hand.
Features:

  • add pulses programmatically
  • get info like maximum time, what's the current pulse, starting time of current pulse, etc.
  • write to txt
  • read from txt

This will make testing much easier and give more flexibility to run different cases.

Example usage

from hisp import Scenario, Pulse

fp1 = Pulse(
    pulse_type="FP",
    nb_pulses=2,
    ramp_up=0.1,
    steady_state=0.2,
    ramp_down=0.3,
    waiting=0.4,
)

icwc1 = Pulse(
    pulse_type="ICWC",
    nb_pulses=3,
    ramp_up=0.5,
    steady_state=0.6,
    ramp_down=0.7,
    waiting=0.8,
)
my_scenario = Scenario([fp1, icwc1])

# get info on scenario
print(my_scenario.get_maximum_time())  # 9.8

pulse_at_specific_time = my_scenario.get_pulse(t=1.2)  # returns a Pulse object
print(pulse_at_specific_time.pulse_type)  # FP

print(my_scenario.get_time_start_current_pulse(t=1.2))

# save scenario to txt file
my_scenario.to_txt_file("test_scenario.txt")

This will produce the following txt file:

pulse_type,nb_pulses,ramp_up,steady_state,ramp_down,waiting
FP,2,0.1,0.2,0.3,0.4
ICWC,3,0.5,0.6,0.7,0.8

It is also possible to read a scenario from a txt file:

my_scenario2 = Scenario.from_txt_file("test_scenario.txt")

Afraid of backwards compatibility with this horrible txt format? I got you covered:

# PULSE TYPE, NUMBER OF PULSES, RAMP UP, RAMP DOWN, STEADY STATE, WAITING
FP 2 455 455 650 1000
ICWC 2 36 36 180 1000
my_scenario2 = Scenario.from_txt_file("test_scenario.txt", old_format=True)

@RemDelaporteMathurin RemDelaporteMathurin added the enhancement New feature or request label Nov 2, 2024
Comment thread src/hisp/scenario.py

@staticmethod
def from_txt_file(filename: str, old_format=False) -> "Scenario":
if old_format:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully this will become obsolete when we expand to new users

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Copy link
Copy Markdown
Collaborator

@kaelyndunnell kaelyndunnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing, thank you so much Remi. Was thinking about the adjustability for RISP and it's seems easy from our end with the caveat that the user has RISP data files for each timestep...but that's already outside the scope. Maybe can think about this more in depth down the line if we decide to expand the package to include taking data directly from certain plasma codes, converting them to .txt files, and going from there...

@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator Author

expand the package to include taking data directly from certain plasma codes, converting them to .txt files, and going from there

I think this Scenario class would apply for every plasma code and can be "code agnostic".

See dina-class branch for how we would have a subdomule to treat DINA files. Then we would have another module to treat SOLPS files, etc. Down the line we can even provide the users the possibility to write their own file readers

@RemDelaporteMathurin RemDelaporteMathurin merged commit 5d11106 into main Nov 2, 2024
@RemDelaporteMathurin RemDelaporteMathurin deleted the scenario branch November 2, 2024 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants