dran.fits package#
Submodules#
dran.fits.backends module#
- class dran.fits.backends.FitsBackendHandle(*args, **kwargs)[source]#
Bases:
ProtocolBackend handle interface used by FITSReader.
This keeps FITSReader independent from astropy or fitsio APIs.
- dran.fits.backends.select_backend()[source]#
Select a FITS backend.
Preference order: 1) fitsio 2) astropy
- Return type:
dran.fits.computed_columns module#
- dran.fits.computed_columns.build_computed_column_names(log, band, src='', seed=None)[source]#
Build the unified computed column list for a given band and optional source.
Ordering: 1. COMM 2. COMM_WEATHER 3. band-specific weather groups (from WEATHER_BY_BAND) 4. computed labels (from build_computed_column_labels)
Special case: - If band is K and src is JUPITER, append JUP_WEATHER to the band weather groups.
dran.fits.conversion module#
- dran.fits.conversion.counts_to_kelvin(counts, hz_per_k)[source]#
Convert raw detector counts to Kelvin using a Hz-per-K scale factor.
The conversion used mirrors the original behavior: (counts - counts[0]) / scale
If conversion fails for any reason (missing scale, invalid scale, scale=0), the function returns a zero array of the same length.
dran.fits.hdu_rules module#
- dran.fits.hdu_rules.scan_hdu_indices(hdu_len)[source]#
Return HDU indices that contain scan data based on your known file layouts.
Existing rules preserved: - If HDULEN == 5, scan index is [3] - If HDULEN == 7, scan indices are [3, 4, 5] - if HDULEN == 6, for older systems, scan indices are [3, 4, 5]
For unknown HDU lengths, return an empty list.
dran.fits.init_fits_processing module#
dran.fits.labels module#
- dran.fits.labels.build_computed_column_labels(log, pol=('L', 'R'), pos=('O',), beam=('',), cols=('RMS', 'BSLOPE', 'BRMS', 'FLAG', 'S2N', 'TA', 'TAPEAKLOC'))[source]#
Generate computed column labels.
Rules: - Labels are built from beam + position + polarization + base column name. - For TA, append TAERR. - If position codes include multiple entries and include “O”, append:
PC
corrected TA (prefixed with C)
corrected TAERR
- Parameters:
- Returns:
Flattened list of label strings.
- Return type:
dran.fits.lazy_reader module#
- class dran.fits.lazy_reader.LazyFITSReader(path, *, memmap=True, cache_data=True)[source]#
Bases:
objectLazy FITS reader.
Responsibilities: - Open and close a FITS file. - Provide header access immediately. - Load HDU data only when requested. - Offer HDU summaries without forcing data reads.
- property handle: FitsBackendHandle#
dran.fits.observation_extractor module#
- dran.fits.observation_extractor.build_observation_record(path, paths, source_name, frequency_mhz, band, hdu_len, logger)[source]#
Build an observation result record with common file metadata fields.
Notes - Keys are uppercase to match a “record schema” style used by CSV/DB exports. - “band” is accepted for schema completeness, even if not used yet.
- Parameters:
path (Path) – Input FITS file path.
source_name (str) – Source name. Stored in normalized form for folder conventions.
frequency_mhz (float) – Center frequency derived from directory or context. Rounded to int for folder naming.
band (str) – Band label (e.g., L/S/C/X). Stored for completeness.
hdu_len (int) – Number of HDUs in the FITS file.
logger (Logger) – Application logger.
paths (ProjectPaths)
- Return type:
- dran.fits.observation_extractor.extract_observation(path, paths, band, log)[source]#
Extract one observation record from a FITS file path.
This preserves your existing behavior: - Uses headers to determine SRCNAME, CENTFREQ, BAND, HDULEN. - Populates a dict record using init_obs_row and get_complete_header_set. - Extracts scan arrays and derives weather quantities.
- Returns:
A populated observation record dict.
- Return type:
- Parameters:
path (Path)
paths (ProjectPaths)
band (str)
log (Logger)
dran.fits.observed_keys module#
- dran.fits.observed_keys.build_observed_header_key_groups(band, log)[source]#
Build observed header key groups for a given band.
The indices reflect the existing downstream expectations in your pipeline.
- For L/S:
0: PR_KEYS 1: FS_KEYS 2: ND_KEYS 3: [] 4: C_KEYS 5: [] (reserved for computed injection)
- For other bands:
0: PR_KEYS 1: FS_KEYS 2: ND_KEYS 3: [] 4: [] 5: [] 6: C_KEYS 7: []
dran.fits.populate module#
- dran.fits.populate.populate_scan_arrays(obs, scans_table, hdu_index, header_name, column_names, log)[source]#
Populate observation fields from a scans table. Extracts metadata and scan data for the given HDU, computes derived quantities for ZC headers, converts LCP and RCP counts to Kelvin, and stores results on the observation object.
dran.fits.processing_fit module#
- dran.fits.processing_fit.to_jsonable(value)[source]#
Convert a value into a JSON-serializable form. Handles dataclasses, objects with to_dict, scalars, collections, mappings, and plain objects, replacing non-finite floats with null equivalents.
dran.fits.schema module#
dran.fits.types module#
- class dran.fits.types.ObsRecord[source]#
Bases:
TypedDictObservation record produced by extraction.
This matches the existing behavior where keys are added dynamically. It stays flexible, while still providing a named type for clarity.
- class dran.fits.types.ScanArrays(x, y, scan_id, band, source, meta, series)[source]#
Bases:
objectNormalized, analysis-ready arrays for one scan.
Notes - x is the independent axis. For example frequency, offset, or sample index. - y is the primary dependent series. For example TA or power. - meta keeps scalar values that you want to show in UI or logs. - series lets you store multiple named arrays if you have more than one y.
- Parameters: