Skip to main content

A parser for Texas RRC field data in EBCDIC format

Project description

rrc-fields

A comprehensive Python parser for Texas Railroad Commission (RRC) field data in EBCDIC format.

This library parses the raw EBCDIC tape files from the Texas Railroad Commission's Oil & Gas Division, converting them into structured, human-readable JSON. It supports 30 distinct record segments, handling complex COBOL data types like signed zoned decimals, packed decimals (COMP-3), and implied decimal scaling.

Note: This project was created completely with minimal effort and Gemini 3 Pro.

Installation

pip install rrc-fields

Usage Examples

1. Basic Usage (Simple Parsing)

The simplest way to use rrc-fields is to parse a file and get the raw records.

from rrc_fields import RRCFieldParser
import json

parser = RRCFieldParser()
# Parse the tape file
# Returns a generator or list of dictionaries
records = parser.parse_file('path/to/field_tape.ebc')

for record in records:
    print(record)

2. Advanced Usage (Value Conversion & Filtering)

You can enable value conversion to get human-readable labels instead of raw codes, and filter by record type to process only specific data segments (e.g., just the Field Root records).

from rrc_fields import RRCFieldParser

parser = RRCFieldParser()

# 'convert_values=True': Converts codes like 'G' to 'GAS FIELD'
# 'include': Only return records with these IDs
# Note: layout is optional and defaults to loading all known segments
records = parser.parse_file(
    'path/to/field_tape.ebc', 
    convert_values=True,
    include=['01']  # Only get Field Root (01) records
)

for record in records:
    print(f"Field: {record.get('FL_FIELD_NAME')} ({record.get('FL_FIELD_TYPE')})")

3. Complex Example: Generating a Hierarchical JSON

In many cases, you want to group related records (like Gas Info segments) under their parent Field record. Here is how you might structure the data.

from rrc_fields import RRCFieldParser
import json

def process_tape_to_hierarchy(file_path):
    parser = RRCFieldParser()
    all_records = parser.parse_file(file_path, convert_values=True)
    
    fields = {}
    current_field_id = None
    
    for rec in all_records:
        rec_id = rec.get('RRC_TAPE_RECORD_ID')
        
        # Record 01 is the Field Root
        if rec_id == '01':
            field_no = rec.get('FL_FIELD_NUMBER')
            current_field_id = field_no
            fields[field_no] = {
                'info': rec,
                'gas_segments': [],
                'oil_segments': [],
                'remarks': []
            }
            
        # Other records belong to the current field
        elif current_field_id:
            if rec_id == '02': # Gas Segment
                fields[current_field_id]['gas_segments'].append(rec)
            elif rec_id == '19': # Oil Segment
                fields[current_field_id]['oil_segments'].append(rec)
            elif rec_id in ['05', '06', '10']: # Remarks
                fields[current_field_id]['remarks'].append(rec)

    return fields

# Run the processing
hierarchy = process_tape_to_hierarchy('field_tape.ebc')

# Save to file
with open('fields_hierarchy.json', 'w') as f:
    json.dump(hierarchy, f, indent=2)

Output Format

The parser returns a flat list of dictionaries by default. Below is an expanded example of what a parsed record looks like.

Example Output (JSON)

[
  {
    "RRC_TAPE_RECORD_ID": "01",
    "FL_FIELD_DISTRICT": "01",
    "FL_FIELD_NUMBER": 123456,
    "FL_FIELD_NAME": "EXAMPLE FIELD",
    "FL_FIELD_TYPE": "GAS FIELD",
    "FL_FIELD_CLASS": "GAS",
    "FL_RAILROAD_COMM_DISTRICT": "01",
    "FL_FIELD_RULE_TYPE": "REGULAR"
  },
  {
    "RRC_TAPE_RECORD_ID": "02",
    "FL_GAS_DISC_COUNTY_CODE": "123",
    "FL_GAS_DISCOVERY_DATE": "19950101",
    "FL_GAS_AVG_GRAVITY": 0.65,
    "FL_GAS_AVG_BTU": 1050,
    "FL_GAS_ALLOCATION_FORMULA": "100% ACREAGE",
    "FL_GAS_WELL_COUNT": 5
  }
]

Supported Record Segments

This parser supports all 30 documented field tape record usage types:

ID Segment Name Description
01 FLDROOT Field Root Information (District, Field Name, Type)
02 GASSEG Gas Field Information
03 FLMKTDMD Field Market Demand Forecast
04 OPRMKTDM Operator Market Demand Forecast
05 FLMKTRMK Field Market Demand Remarks
06 FLSUPRMK Field Market Demand Supplement Remarks
07 GASCYCLE Field Gas Cycle Information
08 GSFLDRUL Field Gas Rules (Spacing, allocation)
09 GASAFORM Field Gas Allocation Formula
10 GASRMRKS Field Gas Remarks
11 GSCOUNTY Field Gas County Codes
12 GASAFACT Field Gas Allocation Factors
13 ASHEET Allowable Sheet Root
14 ASHEETMO Allowable Sheet Monthly Information
15 FLT3ROOT Field T-3 Form Root
16 FLDT3 Field T-3 Form Data
17 FLDMO Field Monthly Stats
18 CALC49B 49(b) Calculation Information
19 OILSEG Oil Field Information
20 OILCYCLE Oil Cycle Information
21 OLFLDRUL Oil Field Rules
22 OILAFORM Oil Allocation Formula
23 OILRMRKS Oil Remarks
24 OILFTROT Oil Factors Root
25 OILAFACT Oil Allocation Factors
26 OLCOUNTY Oil Field County
27 ASSOCGAS Associated Gas Fields
28 FLDMAP Field Map Index
29 GSOPTRUL Gas Optional Rules
30 OLOPTRUL Oil Optional Rules

Getting sample ebc from large.ebc

dd if=main.ebc of=sample.ebc bs=1024 count=100

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rrc_fields-1.1.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rrc_fields-1.1.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file rrc_fields-1.1.0.tar.gz.

File metadata

  • Download URL: rrc_fields-1.1.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for rrc_fields-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ff91fcbb3bf74a09acb943fca65e389e55baea59c2a9849ec4782f7b5f34cfb1
MD5 c2161862869e40d6ab038310d8bc4917
BLAKE2b-256 59c6096a8f1edfc8a65ed38a2012f45bdf8d334e5a8329907e94687404af3d13

See more details on using hashes here.

File details

Details for the file rrc_fields-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: rrc_fields-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for rrc_fields-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a221b980c1eb28fd7234954ce2092d5d154bbe7afe6f3962bb5e25f885118bb
MD5 f42f8b0d440b2322e5d072f7cffdfb45
BLAKE2b-256 294e184792edada2ffab453f7c62e6b375f9d201d539e17fe64f977d088310aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page