@@ -46,34 +46,36 @@ def prepare_and_write(dataset, outpath, vars_df, meta_dict, time='60min', resamp
46
46
47
47
# Round all values to specified decimals places
48
48
d2 = utilities .roundValues (d2 , vars_df )
49
-
50
- # Create out directory
51
- outdir = os .path .join (outpath , d2 .attrs ['station_id' ])
52
- if not os .path .isdir (outdir ):
53
- os .mkdir (outdir )
54
-
49
+
55
50
# Get variable names to write out
56
51
col_names = write .getColNames (
57
52
vars_df ,
58
- d2 .attrs ['number_of_booms' ],
59
- d2 .attrs ['format' ],
60
- d2 .attrs ['bedrock' ],
61
- )
62
-
53
+ d2 )
54
+
63
55
# Define filename based on resample rate
64
56
t = int (pd .Timedelta ((d2 ['time' ][1 ] - d2 ['time' ][0 ]).values ).total_seconds ())
57
+ if 'station_id' in d2 .attrs .keys ():
58
+ name = d2 .attrs ['station_id' ]
59
+ else :
60
+ name = d2 .attrs ['site_id' ]
61
+
62
+ # Create out directory
63
+ outdir = os .path .join (outpath , name )
64
+ if not os .path .isdir (outdir ):
65
+ os .mkdir (outdir )
66
+
65
67
if t == 600 :
66
- out_csv = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_10min.csv' )
67
- out_nc = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_10min.nc' )
68
+ out_csv = os .path .join (outdir , name + '_10min.csv' )
69
+ out_nc = os .path .join (outdir , name + '_10min.nc' )
68
70
elif t == 3600 :
69
- out_csv = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_hour.csv' )
70
- out_nc = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_hour.nc' )
71
+ out_csv = os .path .join (outdir , name + '_hour.csv' )
72
+ out_nc = os .path .join (outdir , name + '_hour.nc' )
71
73
elif t == 86400 :
72
- out_csv = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_day.csv' )
73
- out_nc = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_day.nc' )
74
+ out_csv = os .path .join (outdir , name + '_day.csv' )
75
+ out_nc = os .path .join (outdir , name + '_day.nc' )
74
76
else :
75
- out_csv = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_month.csv' )
76
- out_nc = os .path .join (outdir , d2 . attrs [ 'station_id' ] + '_month.nc' )
77
+ out_csv = os .path .join (outdir , name + '_month.csv' )
78
+ out_nc = os .path .join (outdir , name + '_month.nc' )
77
79
if not os .path .isdir (outdir ):
78
80
os .mkdir (outdir )
79
81
# Write to csv file
@@ -150,7 +152,38 @@ def writeNC(outfile, Lx, col_names=None):
150
152
names = list (Lx .keys ())
151
153
Lx [names ].to_netcdf (outfile , mode = 'w' , format = 'NETCDF4' , compute = True )
152
154
153
- def getColNames (vars_df , booms = None , data_type = None , bedrock = False ):
155
+ def getColNames (vars_df , ds ):
156
+ '''Get all variable names for a given data type, based on a variables
157
+ look-up table. This is mainly for exporting purposes
158
+
159
+ Parameters
160
+ ----------
161
+ vars_df : pd.DataFrame
162
+ Variables look-up table
163
+ ds: xr.dataset
164
+ Dataset to write
165
+ Returns
166
+ -------
167
+ list
168
+ Variable names
169
+ '''
170
+ if 'data_type' in ds .attrs .keys ():
171
+ if ds .attrs ['data_type' ]== 'TX' :
172
+ vars_df = vars_df .loc [vars_df ['data_type' ].isin (['TX' ,'all' ])]
173
+ elif ds .attrs ['data_type' ]== 'STM' or ds .attrs ['data_type' ]== 'raw' :
174
+ vars_df = vars_df .loc [vars_df ['data_type' ].isin (['raw' ,'all' ])]
175
+
176
+ var_list = list (vars_df .index )
177
+ for v in var_list :
178
+ if v not in ds .keys ():
179
+ var_list .remove (v )
180
+ continue
181
+ if ds [v ].isnull ().all ():
182
+ var_list .remove (v )
183
+ return var_list
184
+
185
+
186
+ def getColNames_old (vars_df , booms = None , data_type = None , bedrock = False ):
154
187
'''Get all variable names for a given data type, based on a variables
155
188
look-up table. This is mainly for exporting purposes
156
189
0 commit comments