Skip to content

Add optional duration parameter to make_extended_trapezoid_area#351

Merged
schuenke merged 19 commits into
imr-framework:masterfrom
JosephGWoods:make_extended_trapezoid_duration
May 20, 2026
Merged

Add optional duration parameter to make_extended_trapezoid_area#351
schuenke merged 19 commits into
imr-framework:masterfrom
JosephGWoods:make_extended_trapezoid_duration

Conversation

@JosephGWoods

Copy link
Copy Markdown
Contributor

Modified make_extended_trapezoid_area to take duration as an optional input parameter. This is so that extended trapezoids for a given duration, area and gradient start and end points can be created. If no duration is provided, or if duration <=0, the existing minimum duration search is performed.

JosephGWoods and others added 2 commits January 29, 2026 13:11
…al input parameter. This is so that extended trapezoids for a given duration, area and gradient start and end points can be created. If no duration is provided, or if duration <=0, the existing minimum duration search is performed.
@github-actions

github-actions Bot commented Jan 29, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
/home/runner/.local/lib/python3.12/site-packages/pypulseq
   add_gradients.py1376056%44, 52, 58, 61, 75–86, 92, 125–128, 135–136, 155, 162, 167–263
   add_ramps.py36360%1–92
   align.py35489%41, 45, 69, 73
   calc_duration.py25196%37
   calc_ramp.py2202162%48–359
   calc_rf_bandwidth.py372824%45–81, 85–89
   check_timing.py962970%78, 82, 107, 180, 199, 232, 239, 249–293
   compress_shape.py30197%28
   convert.py40880%42, 48, 66, 72–73, 82, 88–89
   event_lib.py961485%6–9, 48–51, 70–71, 205–210
   make_adc.py981486%77, 80, 90–94, 97, 146, 149, 153, 159, 163, 202, 204, 206, 214
   make_adiabatic_pulse.py1323970%204–208, 228–232, 240–241, 264, 270, 339–358, 462–471, 509–517
   make_arbitrary_grad.py531572%71, 74, 77, 80, 96–98, 107, 109, 117–121, 130
   make_arbitrary_rf.py756316%95–179
   make_block_pulse.py48394%121–125, 128
   make_delay.py9189%27
   make_digital_output_pulse.py16288%42, 50
   make_extended_trapezoid.py561279%67, 70, 76, 82, 85, 88, 91, 94, 116, 134, 136, 139
   make_extended_trapezoid_area.py104496%68, 71, 261, 264
   make_gauss_pulse.py732073%139–143, 146–170, 177, 180
   make_label.py22482%64, 66, 68, 75
   make_sigpy_pulse.py1193075%12–13, 121, 124, 128, 165–169, 173, 176–177, 180–181, 196, 203, 208, 220, 223, 248–258, 272, 275, 305–315
   make_sinc_pulse.py701086%102, 108, 136–140, 144, 147–148, 151–152, 174
   make_soft_delay.py26292%107, 125
   make_trapezoid.py111794%177, 190, 196, 214, 232, 237, 255
   make_trigger.py16288%47, 55
   opts.py66986%78, 83, 102, 142, 166–170
   points_to_waveform.py9189%27
   rotate.py691480%15, 55, 66–69, 85–90, 112, 119–120
   scale_grad.py30197%65
   sigpy_pulse_opts.py26773%34–41
   split_gradient.py393121%46–103
   split_gradient_at.py702761%63–90, 110, 114, 118–120, 154–156
   traj_to_grad.py13931%26–40
/home/runner/.local/lib/python3.12/site-packages/pypulseq/SAR
   SAR_calc.py5180%9
/home/runner/.local/lib/python3.12/site-packages/pypulseq/Sequence
   block.py4697983%63, 66, 74, 80, 95, 103, 109, 120, 123, 126, 134, 139, 148, 159, 167, 207, 209, 213, 225, 274, 278, 294, 319–345, 382–385, 421–429, 436, 466–470, 512, 518, 551, 587–594, 611, 621, 647, 685, 703, 706, 724, 738, 765, 844, 881, 905
   calc_grad_spectrum.py81766%68–190
   calc_pns.py403122%45–96
   ext_test_report.py1671193%79, 156, 167–168, 337–343
   install.py754244%31, 52, 69, 71, 112–131, 148, 181–184, 200–212, 254–278
   parula.py4250%19–86
   read_seq.py4003990%44–45, 110, 117, 130, 133–134, 138, 184, 228, 401, 422–439, 502, 505, 590, 614, 654, 685, 701–705, 712, 823, 834
   sequence.py63312880%10–13, 105–115, 136–149, 196, 261–264, 311, 355, 431, 458–463, 500, 528–531, 622, 650–659, 671, 693, 734–737, 791, 829, 840–841, 847, 858, 864, 866, 874, 907–915, 1047, 1145, 1151, 1154, 1157, 1194, 1319–1332, 1390, 1412–1414, 1435, 1498, 1506, 1604, 1615–1628, 1697–1698, 1709–1727, 1751, 1781–1789, 1825, 1839–1849
   write_seq.py362798%45, 77–79, 313, 347–349, 499
/home/runner/.local/lib/python3.12/site-packages/pypulseq/utils
   cumsum.py14193%17
   paper_plot.py63588%49–132
   safe_pns_prediction.py12611310%50–87, 102–189, 197–214, 222, 244–250, 279–286, 310–336, 344–383, 396–411, 415
   seq_plot.py40718654%22, 106, 138–139, 159, 176–178, 183–225, 235–242, 249–314, 318–324, 328–336, 359, 361, 363, 390–412, 457–458, 461–464, 487–496, 508, 523–533, 542–544, 563–565, 567–568, 570–571, 655–656, 672–689, 737–741
   tracing.py16662%33–34, 42, 54–55, 75
/home/runner/.local/lib/python3.12/site-packages/pypulseq/utils/siemens
   asc_to_hw.py58539%21–28, 48–106
   readasc.py59788%103–104, 110–111, 122–124
TOTAL5187156470% 

Tests Skipped Failures Errors Time
1284 24 💤 0 ❌ 0 🔥 4m 50s ⏱️

@schuenke schuenke left a comment

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.

I will have a look at the exact changes later. Unfortunately, the changes are not tracked as say are supposed to be.

However, it would definitely be good to have tests for this new feature.

@schuenke

Copy link
Copy Markdown
Collaborator

I will open a PR to fix this automatically, but for future commits here and other repositories, I highly recommend to switch your git configuration to use Unix style instead of Windows style line endings.

As far as I know, you should be able to do so using:
git config --global core.autocrlf true

For the moment, to see the code changes ignoring whitespaces / line endings, just use this link:
https://github.com/imr-framework/pypulseq/pull/351/changes?w=1

@schuenke schuenke mentioned this pull request Jan 29, 2026
@JosephGWoods

JosephGWoods commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi Patrick. I will add some tests, as you asked.

In terms of the line endings, I hadn't realised they would be crlf. I was making these changes on macOS so assumed it would be lf by default. Sorry about that.

@schuenke

Copy link
Copy Markdown
Collaborator

Hi Patrick. I will add some tests, as you asked.

In terms of the line endings, I hadn't realised they would be crlf. I was making these changes on macOS so assumed it would be lf by default. Sorry about that.

Well.... I was wrong. This isn't a EOL issue, but just a confusing diff output due to the additional indentation. Sorry for the confusion.

@mcencini

Copy link
Copy Markdown
Collaborator

Hi Patrick. I will add some tests, as you asked.
In terms of the line endings, I hadn't realised they would be crlf. I was making these changes on macOS so assumed it would be lf by default. Sorry about that.

Well.... I was wrong. This isn't a EOL issue, but just a confusing diff output due to the additional indentation. Sorry for the confusion.

Still, I think #354 is not bad to have anyway :)

Comment thread src/pypulseq/make_extended_trapezoid_area.py Outdated
Comment thread src/pypulseq/make_extended_trapezoid_area.py Outdated
mcencini and others added 6 commits January 29, 2026 17:16
…_area

- Add duration parameter to make_extended_trapezoid_area function
- Add max_grad and max_slew optional parameters to match other gradient functions
- Fix test_make_extended_trapezoid_area_recreate area calculation bug (which one test to fail)
- Add tests for duration functionality
- Add test for invalid duration error handling
@JosephGWoods

Copy link
Copy Markdown
Contributor Author

Hi Patrick and Matteo, I've added the requested changes and unit tests. I don't understand why some sequence code test failed or why my changes would have caused the reported changes. Are these changes caused by some other commits that have since been merged in?

Comment thread src/pypulseq/make_extended_trapezoid_area.py
@schuenke

schuenke commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

I just re-run the tests in #353, which is up to date and all tests pass there. So the breaking changes are from this PR. See my comment above for the potential source of error.

@schuenke

schuenke commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

@mcencini maybe you want to have a quick look at my changes in 11276dd and 52008b3 before we merge this.

@schuenke schuenke self-requested a review February 2, 2026 17:00
@schuenke schuenke requested a review from mcencini February 2, 2026 17:01
mcencini

This comment was marked as duplicate.

Comment thread src/pypulseq/make_extended_trapezoid_area.py Outdated
Comment thread src/pypulseq/make_extended_trapezoid_area.py
Comment thread src/pypulseq/make_extended_trapezoid_area.py Outdated
Comment thread src/pypulseq/make_extended_trapezoid_area.py Outdated
Comment thread tests/test_make_extended_trapezoid_area.py Outdated
Comment thread tests/test_make_extended_trapezoid_area.py Outdated
Comment thread tests/test_make_extended_trapezoid_area.py Outdated
Comment thread src/pypulseq/make_extended_trapezoid_area.py Outdated
JosephGWoods and others added 3 commits March 16, 2026 13:13
…em.max_slew * 0.99 behaviour to match other gradient functions such as make_trapezoid.

1) Saved new versions of tests/expected_output/write_epi_se_rs.seq and tests/expected_output/write_mprage.seq to account for new max_grad and max_slew behaviour.
2) Updated tests/test_make_extended_trapezoid_area.py to remove system.max_grad * 0.99 behaviour.
3) Removed test_zoo_random in tests/test_make_extended_trapezoid_area.py.
4) Removed assert g.tt.shape[0] <= g_arb.tt.shape[0] and assert g.waveform.shape[0] <= g_arb.waveform.shape[0] checks because this fails when a simple short triangular gradient is passed into points_to_waveform (i.e. when convert_to_arbitrary = True) because points_to_waveform will compress this to 2 points at the centre of the gradient raster periods, rather than 3 points (which is output when convert_to_arbitrary = False). These checks failed with (0, 100000, 1) from the test zoo, for example.
@JosephGWoods

Copy link
Copy Markdown
Contributor Author

Hi @schuenke and @mcencini, could you approve the additional changes I made? In particular, the code no longer uses 99% of max_grad or max_slew, bringing it inline with other pypulseq code, with the corresponding seq file unit test being updated accordingly. Additionally, the input parameter ordering has been returned to the original order to preserve previous behavior, with the new input parameters added at the end.

@schuenke schuenke left a comment

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.

lgtm now

@schuenke schuenke self-assigned this May 20, 2026
@schuenke schuenke changed the title Extended make_extended_trapezoid_area functionality Add optional duration parameter to make_extended_trapezoid_area May 20, 2026
@schuenke schuenke added the enhancement New feature or request label May 20, 2026
@schuenke schuenke merged commit 9f2e06c into imr-framework:master May 20, 2026
8 checks passed
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.

3 participants