|
1 | | -""" |
2 | | -McGrattan |
3 | | -10-29-2019 |
4 | | -Crown_Fires.py |
5 | 1 |
|
6 | | -Read the Crown_Fires *_cat_devc.csv files and determine the rate of spread based on the time history of front position. |
7 | | -Write the results to a file that will be plotted via dataplot.m. |
8 | | -""" |
| 2 | +# Read the Crown_Fires *_cat_devc.csv files and determine the rate of spread based on the time history of front position. |
| 3 | +# Write the results to a file that will be plotted via dataplot.py. |
9 | 4 |
|
10 | 5 | import numpy as np |
11 | 6 | import pandas as pd |
12 | 7 | import os |
13 | 8 |
|
14 | | -# Parameters |
15 | 9 | outdir = '../../../out/Crown_Fires/' |
16 | 10 |
|
17 | | -# Get only *_cat_devc.csv files (like MATLAB dir) |
18 | 11 | file_list = [f for f in os.listdir(outdir) if f.endswith('_cat_devc.csv')] |
19 | | -file_list.sort() # optional, to keep consistent ordering with MATLAB |
| 12 | +file_list.sort() |
20 | 13 |
|
21 | 14 | wind_speed = [] |
22 | 15 | slope = [] |
23 | 16 |
|
24 | 17 | for fname in file_list: |
25 | 18 | full_path = os.path.join(outdir, fname) |
26 | 19 |
|
27 | | - # Read CSV (skip 2 header rows like MATLAB importdata) |
28 | | - M = pd.read_csv(full_path, skiprows=2) |
| 20 | + M = pd.read_csv(full_path, skiprows=2, header=None) |
29 | 21 | M_data = M.to_numpy() |
30 | 22 |
|
31 | | - # Extract rows satisfying conditions (700<=col2<=900, 30<col1<300) |
| 23 | + # Extract rows satisfying conditions (700<=x<=900, 30<Time<300) |
32 | 24 | indices = np.where( |
33 | 25 | (M_data[:, 1] >= 700) & |
34 | 26 | (M_data[:, 1] <= 900) & |
35 | 27 | (M_data[:, 0] > 30) & |
36 | 28 | (M_data[:, 0] < 300) |
37 | 29 | )[0] |
38 | 30 |
|
39 | | - # Mean wind speed (col3) |
| 31 | + # Mean wind speed (U10) |
40 | 32 | wind_speed.append(np.mean(M_data[indices, 2])) |
41 | 33 |
|
42 | | - # Polyfit slope for col2 vs col1 |
| 34 | + # Polyfit slope for x vs Time |
43 | 35 | p = np.polyfit(M_data[indices, 0], M_data[indices, 1], 1) |
44 | 36 | slope.append(p[0]) |
45 | 37 |
|
46 | | -# Write output file |
47 | 38 | with open(os.path.join(outdir, 'ROS.csv'), 'w') as fid: |
48 | 39 | fid.write('km/h,m/min\n') |
49 | 40 | fid.write('U,ROS\n') |
50 | 41 | for u, s in zip(wind_speed, slope): |
51 | 42 | fid.write(f'{3.6*u:4.1f},{60*s:6.2f}\n') |
| 43 | + |
0 commit comments