|
| 1 | +import numbers |
1 | 2 | import numpy as np |
2 | 3 | from numpy.polynomial.polynomial import polyfit |
3 | 4 |
|
@@ -307,7 +308,7 @@ def read_finite_radius_waveform_rpxmb_or_rpdmb(filename, |
307 | 308 | sxs_format = json_data.get("sxs_format","") |
308 | 309 | if sxs_format in rpdmb_formats: |
309 | 310 | read_rpdmb=True |
310 | | - elif sxs_format in rpdmb_formats: |
| 311 | + elif sxs_format in rpxmb_formats: |
311 | 312 | read_rpxmb=True |
312 | 313 |
|
313 | 314 | # Note that groupname begins with a '/' so |
@@ -429,6 +430,13 @@ def read_finite_radius_data(ChMass=0.0, |
429 | 430 | from re import compile as re_compile |
430 | 431 | import scri |
431 | 432 |
|
| 433 | + def extract_radius_string_from_waveform_name(name): |
| 434 | + # Expected names like "R0247.dir" |
| 435 | + m = re_compile(r"""R(?P<r>.*?)\.dir""").search(str(name)) |
| 436 | + if not m: |
| 437 | + raise ValueError(f"Could not parse radius from waveform name {name!r}") |
| 438 | + return m.group("r") |
| 439 | + |
432 | 440 | YLMRegex = re_compile(mode_regex) |
433 | 441 |
|
434 | 442 | # If 'filename' is of the form "h5_file_name.h5/groupname" then we have an |
@@ -456,23 +464,45 @@ def read_finite_radius_data(ChMass=0.0, |
456 | 464 | WaveformNames.remove("VersionHist.ver") |
457 | 465 | else: |
458 | 466 | WaveformNames = list(f[groupname]) |
| 467 | + AllWaveformNames = list(WaveformNames) |
459 | 468 | if not CoordRadii: |
460 | 469 | # If the list of Radii is empty, figure out what they are |
461 | 470 | CoordRadii = [ |
462 | 471 | m.group("r") for Name in WaveformNames for m in [re_compile(r"""R(?P<r>.*?)\.dir""").search(Name)] if m |
463 | 472 | ] |
464 | 473 | else: |
465 | 474 | # Pare down the WaveformNames list appropriately |
466 | | - if type(CoordRadii[0]) == int: |
| 475 | + if isinstance(CoordRadii[0], numbers.Integral): |
467 | 476 | WaveformNames = [WaveformNames[i] for i in CoordRadii] |
468 | | - CoordRadii = [ |
469 | | - m.group("r") for Name in CoordRadii |
470 | | - for m in |
471 | | - [ re_compile(r"""R(?P<r>.*?)\.dir""").search(Name)] if m ] |
| 477 | + # Convert selected waveform names into radius strings, keeping the same order |
| 478 | + CoordRadii = [extract_radius_string_from_waveform_name(Name) for Name in WaveformNames] |
472 | 479 | else: |
473 | 480 | WaveformNames = [ |
474 | 481 | Name for Name in WaveformNames for Radius in |
475 | 482 | CoordRadii for m in [re_compile(Radius).search(Name)] if m] |
| 483 | + # Best-effort: If user gave explicit radii strings, keep them; otherwise derive |
| 484 | + # parsed radii corresponding to selected names for consistent sorting later. |
| 485 | + try: |
| 486 | + CoordRadii = [extract_radius_string_from_waveform_name(Name) for Name in WaveformNames] |
| 487 | + except Exception: |
| 488 | + # Fall back to whatever the user provided (for backwards compatibility) |
| 489 | + pass |
| 490 | + |
| 491 | + if not WaveformNames: |
| 492 | + raise ValueError( |
| 493 | + "No waveform groups matched the requested CoordRadii. " |
| 494 | + f"Requested CoordRadii={CoordRadii}; available groups={AllWaveformNames}." |
| 495 | + ) |
| 496 | + if len(WaveformNames) != len(CoordRadii): |
| 497 | + raise ValueError( |
| 498 | + "Mismatch between requested radii and matched waveform groups. " |
| 499 | + f"Requested CoordRadii={CoordRadii}; matched groups={WaveformNames}." |
| 500 | + ) |
| 501 | + try: |
| 502 | + [float(r) for r in CoordRadii] |
| 503 | + except Exception as e: |
| 504 | + raise ValueError(f"Could not convert CoordRadii entries to float: CoordRadii={CoordRadii}") from e |
| 505 | + |
476 | 506 | NWaveforms = len(WaveformNames) |
477 | 507 |
|
478 | 508 | # Check input data for NRAR format |
@@ -727,7 +757,7 @@ def extrapolate(**kwargs): |
727 | 757 | D['DataFile'] = {DataFile} |
728 | 758 | D['ChMass'] = {ChMass} |
729 | 759 | D['HorizonsFile'] = {HorizonsFile} |
730 | | - D['CoordRadii'] = {CoordRadii} |
| 760 | + D['CoordRadii'] = {CoordRadiiKwarg} |
731 | 761 | D['ExtrapolationOrders'] = {ExtrapolationOrders} |
732 | 762 | D['UseOmega'] = {UseOmega} |
733 | 763 | D['OutputFrame'] = {OutputFrame} |
@@ -826,7 +856,8 @@ def extrapolate(**kwargs): |
826 | 856 |
|
827 | 857 | # Append the relevant information to the history |
828 | 858 | ExtrapolatedWaveforms[i]._append_history(str(InputArguments)) |
829 | | - ExtrapolatedWaveforms[i].extrapolate_coord_radii = CoordRadiiKwarg |
| 859 | + # Record the actual radii used for extrapolation so downstream code has the normalized set |
| 860 | + ExtrapolatedWaveforms[i].extrapolate_coord_radii = list(CoordRadii) |
830 | 861 |
|
831 | 862 | # Output the data |
832 | 863 | if OutputDirectory: |
|
0 commit comments