-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecursorSourcesReduce.py
63 lines (44 loc) · 1.78 KB
/
precursorSourcesReduce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/python3
"""Written for python 3.12 for the sowfatools package.
Jeffrey Johnston [email protected] February 2024.
Extracts a reduced dataset from sowfatools/SourceHistory for publishing and
plotting purposes"""
import argparse
import logging
import sys
import gzip
from pathlib import Path
import numpy as np
import constants as const
import utils
logger = logging.getLogger(__name__)
LEVEL = logging.DEBUG
def main(casename,N):
casedir = const.CASES_DIR / casename
utils.configure_logging((casedir / f'log.{Path(__file__).stem}'),
level=LEVEL)
srcdir = casedir / const.SOWFATOOLS_DIR / 'SourceHistory'
filename = (srcdir / f'{casename}_sourceMomentum.gz')
logger.debug(f"Reading heights from {filename}")
with gzip.open(filename, mode='rt') as file:
header = file.readline().split()[slice(0,2,4)]
header = ' '.join(header)
logger.info(f"Generating array from {filename}")
data = np.genfromtxt(filename)
logger.debug(f"Reducing dataset. {N=}")
org_size = data.shape
data = data[::N,:]
data = data[:,[0,2,4]] # keep time, mag and avgmag cols
new_size = data.shape
logger.debug(f"Reduced data from {org_size} to {new_size}")
filename = srcdir / f'{casename}_sourceMomentum_reduced.gz'
logger.info(f"Writing output to {filename}")
np.savetxt(filename, data, fmt='%.4g', header=header)
if __name__=="__main__":
parser = argparse.ArgumentParser(description="""Reduce source history to
make dataset smaller""")
parser.add_argument("casename", help="specifiy which case to use")
parser.add_argument("-n", "--sampling", help="How frequently to save data",
type=int, default=10)
args = parser.parse_args()
main(args.casename, args.sampling)