-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01b_apply_nodc_flags.py
More file actions
76 lines (61 loc) · 2.25 KB
/
01b_apply_nodc_flags.py
File metadata and controls
76 lines (61 loc) · 2.25 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
import pandas as pd
import os
import numpy as np
# input_file = 'C:\\Users\\HourstonH\\Documents\\charles\\' \
# 'line_P_data_products\\csv\\01_convert\\' \
# 'P4_NODC_OSD_data.csv'
# input_file = 'C:\\Users\\HourstonH\\Documents\\charles\\' \
# 'line_P_data_products\\csv\\01_convert\\' \
# 'P26_NODC_OSD_GLD_PFL_data.csv'
# P4 P26
stn = 'P4'
# parent_dir = 'C:\\Users\\HourstonH\\Documents\\charles\\' \
# 'line_P_data_products\\csv\\has_osd_ctd_flags\\'
# parent_dir = 'C:\\Users\\HourstonH\\Documents\\charles\\' \
# 'our_warming_ocean\\osp_sst\\csv\\'
parent_dir = 'D:\\lineP\\csv_data\\'
input_file = os.path.join(
parent_dir, '01_convert\\{}_NODC_OSD_CTD_data.csv'.format(stn))
output_dir = os.path.join(parent_dir, '01b_apply_nodc_flags\\')
output_file = os.path.join(output_dir,
os.path.basename(input_file))
df = pd.read_csv(input_file)
# Create masks of bad values
msk_T = df.loc[:, 'Temperature profile flag'] != 0
msk_S = df.loc[:, 'Salinity profile flag'] != 0
msk_O = df.loc[:, 'Oxygen profile flag'] != 0
# Print number of bad values for each variable
print(sum(msk_T))
print(sum(msk_S))
print(sum(msk_O))
print()
df.loc[msk_T, 'Temperature [C]'] = np.nan
df.loc[msk_S, 'Salinity [PSS-78]'] = np.nan
df.loc[msk_O, 'Oxygen [umol/kg]'] = np.nan
# Iterate through all the profiles and delete any profiles
# having all nan T and S and O
prof_start_idx = np.unique(df.loc[:, 'Profile number'],
return_index=True)[1]
prof_end_idx = np.concatenate((prof_start_idx[1:] - 1,
np.array([len(df)])))
print(len(df))
for i in range(len(prof_start_idx)):
st = prof_start_idx[i]
en = prof_end_idx[i]
# Change or to and, to be less strict
if (np.all(
pd.isna(
df.loc[
st:en, 'Temperature [C]'])) &
np.all(
pd.isna(
df.loc[
st:en, 'Salinity [PSS-78]'])) &
np.all(
pd.isna(
df.loc[st:en, 'Oxygen [umol/kg]']))
):
# print(df.loc[st:en, :])
df.drop(index=np.arange(st, en + 1), inplace=True)
print(len(df))
df.to_csv(output_file, index=False)