Skip to content

Read calfits files without memory-mapping - #1724

Merged
bhazelton merged 8 commits into
RadioAstronomySoftwareGroup:mainfrom
tyler-a-cox:calfits-memmap
Sep 29, 2026
Merged

bhazelton merged 8 commits into
RadioAstronomySoftwareGroup:mainfrom
tyler-a-cox:calfits-memmap

Conversation

@tyler-a-cox

@tyler-a-cox tyler-a-cox commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

UVCal.read_calfits now opens calfits files with memmap=False. The calfits reader always reads the data in full (select happens after the read) or, with read_data=False, doesn't read it at all, so memory-mapping doesn't buy anything here. Metadata-only reads still only read the headers and the antenna table.

The gain-type quality_array is copied out of the FITS data array so the rest of that array can be freed once the gains and flags are built.

I added a test (test_read_not_memmapped in tests/uvcal/test_calfits.py) that checks the arrays aren't memory-mapped after a read and that the gain quality array doesn't hold onto the FITS data. I also added a CHANGELOG entry.

Motivation and Context

For HERA phase II we read about 1850 calfits files per night off of NRAO's Lustre file system during calibration smoothing, and a lot of that time is spent in memory-mapped reads. On a network file system, memory-mapping pulls in the file a piece at a time as the arrays are accessed, and each of those pieces has to wait on the network. Reading without memory-mapping grabs the data in one big read.

I timed read_calfits on some of our calfits files on Lustre, clearing the page cache first. The median read took 2.1 s per file with memory-mapping and 0.23 s per file without it, so about 9x faster. Peak memory was the same either way (about 60 MB per read), and the arrays were identical. On local disk the two were about the same.

This follows #1651, which stopped read_uvfits from memory-mapping full reads.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change (documentation changes only)
  • Version change
  • Build or continuous integration change
  • Other

Checklist:

Other:

tyler-a-cox and others added 6 commits September 28, 2026 15:18
Clarify the description of the memmap option in the docstring.
Updated docstring to clarify memory-mapping behavior.
Added a 'memmap' keyword option to UVCal.read_calfits and UVCal.read for optimized file reading.
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (63203e5) to head (474308f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1724   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           71        71           
  Lines        23912     23912           
=========================================
  Hits         23912     23912           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bhazelton bhazelton added Calibration performance A performance improvement. labels Sep 29, 2026
@bhazelton

bhazelton commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

@tyler-a-cox thank you for this!

My reading of the astropy docs is that setting memmap=True is what lets you read in part of the data. So I think we should only use memmap=True when we're only reading in a portion of the data. I thought that's what we did on uvfits, but looking at it now it seems like memmap is always False, so there may be a bug there.

I'm not sure we need a read parameter for this if we set it sensibly based on whether or not there's a select, but I could be convinced otherwise with a good use case.

@tyler-a-cox

Copy link
Copy Markdown
Contributor Author

@bhazelton thanks for giving this a look over! I'm definitely open to removing memmap as a argument and only setting it to True when there is a partial read. I'll make some changes and ping when that's done.

@tyler-a-cox

Copy link
Copy Markdown
Contributor Author

@bhazelton after reviewing the code, I realized that calfits never actually does partial reads. read_calfits doesn't take any select arguments, and UVCal.read reads the whole file and then calls select afterwards. So I don't think there is a case where memmap=True would help right now.

I can either implement select on read for calfits, which feels like a pretty large structural change, or just always open calfits files with memmap=False and remove the argument. Do you have a preference?

@bhazelton

Copy link
Copy Markdown
Member

Ah, I had forgotten that we hadn't implemented partial read on cal fits. Let's just set to always be False.

@tyler-a-cox

Copy link
Copy Markdown
Contributor Author

Okay, looks like that simplified things a little. Should be ready to look at now!

@tyler-a-cox tyler-a-cox changed the title Add a memmap option to UVCal.read_calfits Read calfits files without memory-mapping Sep 29, 2026

@bhazelton bhazelton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great, thank you @tyler-a-cox !

@bhazelton
bhazelton merged commit e92957f into RadioAstronomySoftwareGroup:main Sep 29, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Calibration performance A performance improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants