-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMOF_dataformat_HVPS_v1_2.py
More file actions
506 lines (415 loc) · 24.9 KB
/
AMOF_dataformat_HVPS_v1_2.py
File metadata and controls
506 lines (415 loc) · 24.9 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# -*- coding: utf-8 -*-
# Put psd in AMOF format
# Need to read in psd (with dimensions time and index) from separate file. Needs to include
# DataFlag, Psd, Counts, Size_mid, Size_edge, Time_mid, Time_edge
# There are examples for .nc and .h5 files, but these need to altered for specific files.
import numpy as np
import h5py
import os
import datetime
import netCDF4
import matplotlib.pyplot as plt
import pandas as pd
# v1.0 21/01/2021
# Original
# Generate AMOF file format for upload to CEDA.
# Needs processed data file and faam core file as input.
#v1.1 8/02/2021
# Apply UnitConversion before filling missing values.
#v1.2 4/2/2021
# Can accept pre AMOF .nc file.
# Change "_" to "-" as requested by CEDA
#_________________________________________________________________
#Load HVPS .nc that is preAMOFformat
def LoadHVPS_preAMOFformat(DataPath, DataFileName):
Data_h5 = netCDF4.Dataset(DataPath+DataFileName)
DataFlag = np.array(Data_h5['Data_Flag']).astype(np.uint32)
Psd= np.array(Data_h5['PSD_Num_All'])
Counts= np.array(Data_h5['PSD_Counts_All'])
Size_mid= np.array(Data_h5['Size_mid'])
Size_edge= np.array(Data_h5['Size_edge'])
Time_edge= np.array(Data_h5['Time_edge'])
Time_mid= np.array(Data_h5['Time_mid'])
Data_h5.close()
return DataFlag, Psd, Counts, Size_mid, Size_edge, Time_mid, Time_edge
#_________________________________________________________________
#load .h5 that has been generated using OASIS containing PSDs and data flags
def LoadOAPH5(DataPath, DataFileName):
Data_h5 = h5py.File(DataPath+DataFileName, 'r')
DataFlag = np.array(Data_h5['DataFlag']).astype(np.uint32)
Psd= np.array(Data_h5['PSD_All_accept_submit'])
Counts= np.array(Data_h5['PSD_Counts_All_accept_submit'])
Size_mid= np.array(Data_h5['Size_mid_submit'])
Size_edge= np.array(Data_h5['Size_submit'])
Time_edge= np.array(Data_h5['Time_edge_submit'])
Time_mid= np.array(Data_h5['Time_mid_submit'])
Data_h5.close()
return DataFlag, Psd, Counts, Size_mid, Size_edge, Time_mid, Time_edge
#_________________________________________________________________
# Change timebase of FAAM core variable to OAP timebase
# Also change data fill values to FillValueNew
def CovertTimeBase2NC(FAAMCore, VariableStr, TimeIndex, TimeDiff, FillValueOld,FillValueNew):
tmp = np.array(FAAMCore[VariableStr][:])
tmp_nc = tmp[TimeIndex]
#tmp_nc[TimeDiff>=1] = FillValueNew
NanIdx = TimeIndex[TimeDiff>=1]
tmp_nc[NanIdx] = FillValueNew
tmp_nc[tmp_nc == FillValueOld]= FillValueNew
return tmp_nc
#_________________________________________________________________
# Load faam core file and change time base and format ready for AMOF data submisison
def LoadCoreVariables4AMOF(CorePath,CoreFileName,Time_mid):
#Time_mid is the time base of returned array
FAAMCore = netCDF4.Dataset(CorePath+CoreFileName)
TimeCore=np.array(FAAMCore['Time'][:])
FlightDate= datetime.datetime(int(CoreFileName[10:14]), int(CoreFileName[14:16]), int(CoreFileName[16:18]), 0, 0, 0)
# index to change core timebase to Oap timebase
TimeIndex = np.searchsorted(TimeCore,Time_mid)
TimeDiff = np.absolute(Time_mid-TimeCore[TimeIndex])
FillValueOld = -9999
FillValueNew = -1E20
LAT_GIN_nc = CovertTimeBase2NC(FAAMCore, 'LAT_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
LON_GIN_nc = CovertTimeBase2NC(FAAMCore, 'LON_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
ALT_GIN_nc = CovertTimeBase2NC(FAAMCore, 'ALT_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
TAS_RVSM_nc = CovertTimeBase2NC(FAAMCore, 'TAS_RVSM', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
TRCK_GIN_nc = CovertTimeBase2NC(FAAMCore, 'TRCK_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
GSPD_GIN_nc = CovertTimeBase2NC(FAAMCore, 'GSPD_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
PTCH_GIN_nc = CovertTimeBase2NC(FAAMCore, 'PTCH_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
PITR_GIN_nc = CovertTimeBase2NC(FAAMCore, 'PITR_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
ROLL_GIN_nc = CovertTimeBase2NC(FAAMCore, 'ROLL_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
ROLR_GIN_nc = CovertTimeBase2NC(FAAMCore, 'ROLR_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
HDG_GIN_nc = CovertTimeBase2NC(FAAMCore, 'HDG_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
HDGR_GIN_nc = CovertTimeBase2NC(FAAMCore, 'HDGR_GIN', TimeIndex, TimeDiff,FillValueOld,FillValueNew)
FAAMCore.close()
return LAT_GIN_nc, LON_GIN_nc, ALT_GIN_nc, TAS_RVSM_nc, TRCK_GIN_nc, GSPD_GIN_nc, PTCH_GIN_nc, PITR_GIN_nc, ROLL_GIN_nc, ROLR_GIN_nc, HDG_GIN_nc, HDGR_GIN_nc
#_________________________________________________________________
#FlightNumberStr = 'c174'
#FlightDate = datetime.datetime(2019,5,23)
#CorePath = 'C:/Users/mbexjso2/OneDrive - The University of Manchester/Documents/Work/Picasso/rawData/C174/' #Paths to core data file
#CoreFileName = 'core_faam_20190523_v004_r0_c174_1hz.nc'
#DataPath = 'C:/Users/mbexjso2/OneDrive - The University of Manchester/Documents/Work/Picasso/rawData/C174/' #Path to HVPS data file
#DataFileName = 'HVPS_C174.h5'
#FlightNumberStr = 'c174'
#FlightDate = datetime.datetime(2019,5,23)
#CoreFileName = 'core_faam_20190523_v004_r0_c174_1hz.nc'
#DataFileName = 'UMAN-HVPS_20190523_r1_C174.nc'
#FlightNumberStr = 'c172'
#FlightDate = datetime.datetime(2019,5,7)
#CoreFileName = 'core_faam_20190507_v004_r0_c172_1hz.nc'
#DataFileName = 'UMAN-HVPS_20190507_r1_C172.nc'
#FlightNumberStr = 'c171'
#FlightDate = datetime.datetime(2019,5,1)
#CoreFileName = 'core_faam_20190501_v004_r0_c171_1hz.nc'
#DataFileName = 'UMAN-HVPS_20190501_r1_C171.nc'
#FlightNumberStr = 'c170'
#FlightDate = datetime.datetime(2019,4,26)
#CoreFileName = 'core_faam_20190426_v004_r0_c170_1hz.nc'
#DataFileName = 'UMAN-HVPS_20190426_r1_C170.nc'
# FlightNumberStr = 'c169'
# FlightDate = datetime.datetime(2019,4,16)
# CoreFileName = 'core_faam_20190416_v004_r0_c169_1hz.nc'
# DataFileName = 'UMAN-HVPS_20190416_r1_C169.nc'
# FlightNumberStr = 'c098'
# FlightDate = datetime.datetime(2018,4,24)
# CoreFileName = 'core_faam_20180424_v004_r0_c098_1hz.nc'
# DataFileName = 'UMAN-HVPS_20180424_r2_C098.nc'
# FlightNumberStr = 'c097'
# FlightDate = datetime.datetime(2018,4,23)
# CoreFileName = 'core_faam_20180423_v004_r0_c097_1hz.nc'
# DataFileName = 'UMAN-HVPS_20180423_r1_C097.nc'
# FlightNumberStr = 'c082'
# FlightDate = datetime.datetime(2018,2,14)
# CoreFileName = 'core_faam_20180214_v004_r0_c082_1hz.nc'
# DataFileName = 'UMAN-HVPS_20180214_r2_C082.nc'
# FlightNumberStr = 'c081'
# FlightDate = datetime.datetime(2018,2,13)
# CoreFileName = 'core_faam_20180213_v004_r0_c081_1hz.nc'
# DataFileName = 'UMAN-HVPS_20180213_r1_C081.nc'
# FlightNumberStr = 'c080'
# FlightDate = datetime.datetime(2018,2,8)
# CoreFileName = 'core_faam_20180208_v004_r0_c080_1hz.nc'
# DataFileName = 'UMAN-HVPS_20180208_r1_C080.nc'
FlightNumberStr = 'c079'
FlightDate = datetime.datetime(2018,2,8)
CoreFileName = 'core_faam_20180208_v004_r0_c079_1hz.nc'
DataFileName = 'UMAN-HVPS_20180208_r1_C079.nc'
CorePath = 'D:/PICASSO/rawdata/FAAM_Data/AllCoreFaam/' #Paths to core data file
DataPath = 'D:/PICASSO/Processed/NewestVersionHVPS/' #Path to HVPS data file
rnumber = 0 # revision number
vnumber = '001'# Don't change relates to versions of processing software (currently not defined)
NormFlag = 0 # is the data normalised, 0 = dN, 1 = dN/dD
UnitConversion =1E-3 # Factor to convert input PSD to cm-3
FlagConversion = 0 # Conversion so that flag data is '0 = not used, 1 = valid data, 2 = reduced quality data. 3 = missing data'
FillValue = -1E20 # Fill value of output data file
#Load PSDs file
#DataFlag, Psd, Counts, Size_mid, Size_edge, Time_mid, Time_edge = LoadOAPH5(DataPath, DataFileName)
DataFlag, Psd, Counts, Size_mid, Size_edge, Time_mid, Time_edge = LoadHVPS_preAMOFformat(DataPath, DataFileName)
DataFlag += FlagConversion # Conversion so that flag data '0 = not used, 1 = valid data, 2 = reduced quality data. 3 = missing data'
DataFlag_2D = np.array([DataFlag,]*len(Size_mid)).transpose()
# Load variables from core files
LAT_GIN_nc, LON_GIN_nc, ALT_GIN_nc, TAS_RVSM_nc, TRCK_GIN_nc, GSPD_GIN_nc, PTCH_GIN_nc, PITR_GIN_nc, ROLL_GIN_nc, ROLR_GIN_nc, HDG_GIN_nc, HDGR_GIN_nc = LoadCoreVariables4AMOF(CorePath,CoreFileName,Time_mid)
#Convert time to seconds since 1970
DateTime_df = pd.to_datetime(FlightDate) + pd.to_timedelta(Time_mid, unit='s')
TimeSecondsSince = np.array((DateTime_df-datetime.datetime(1970,1,1)) / np.timedelta64(1,'s'))
year = np.array((DateTime_df.year)).astype(np.int32)
month = np.array((DateTime_df.month)).astype(np.int32)
day = np.array((DateTime_df.day)).astype(np.int32)
hour = np.array((DateTime_df.hour)).astype(np.int32)
minute = np.array((DateTime_df.minute)).astype(np.int32)
second = np.array((DateTime_df.second))
day_of_year = np.array((DateTime_df.dayofyear)) + Time_mid/86400 # day of year with fraction of day
#Convert to cm-3
Psd *= UnitConversion
#Use chosen FillValue
Psd[Psd < 0] = FillValue
Counts[Counts < 0] = FillValue
#######################
#Save data as netcdf
Nc_filename='ncas-hvps3-1_faam_'+FlightDate.strftime("%Y%m%d")+'_v'+vnumber+'_r'+str(rnumber)+'_'+FlightNumberStr+'_particle-size-distribution.nc'
print(Nc_filename)
NcFile= netCDF4.Dataset(DataPath+Nc_filename,'w', format='NETCDF4') #'w' stands for write
# Global attributes
NcFile.conventions ='CF-1.6, NCAS-AMF-2.0.0'
NcFile.source = 'NCAS High Volume Precipitation Spectrometer unit 1'
NcFile.instrument_manufacturer = 'Spec Inc., USA'
NcFile.instrument_model = 'HVPS-3'
NcFile.instrument_serial_number = 'Not available'
NcFile.instrument_software = 'spec2d.exe'
NcFile.instrument_software_version ='Not available'
NcFile.creator_name = 'Sebastian OShea'
NcFile.creator_email = 'sebastian.oshea@manchester.ac.uk'
NcFile.url = 'https://orcid.org/0000-0002-0489-1723'
NcFile.institution = 'University of Manchester'
NcFile.processing_software_url = 'Not available'
NcFile.processing_software_version = 'OASIS_routines_v1.49962'
NcFile.calibration_sensitivity = 'The instrument counting uncertainty for each time and size bin is given by (100% / N^(1/2)), where N is the number of counts in the bin.'
NcFile.calibration_certification_date ='not applicable'
NcFile.calibration_certification_url ='not applicable'
NcFile.sampling_interval='1 second'
NcFile.averaging_interval='1 second'
NcFile.product_version='v'+str(rnumber+1)+'.0'
NcFile.processing_level= int(1)
NcFile.last_revised_date= datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
NcFile.project='Parameterizing Ice Clouds using Airborne obServationS and triple-frequency dOppler radar (PICASSO)'
NcFile.project_principal_investigator='Jonathan Crosier'
NcFile.project_principal_investigator_email='jonathan.crosier@manchester.ac.uk'
NcFile.project_principal_investigator_url='https://orcid.org/0000-0002-3086-4729'
NcFile.licence='Data usage licence - UK Government Open Licence agreement: http://www.nationalarchives.gov.uk/doc/open-government-licence'
NcFile.acknowledgement='Acknowledgement of NCAS as the data provider is required whenever and wherever these data are used.'
NcFile.platform='faam'
NcFile.platform_type='mobile'
NcFile.deployment_mode='air'
NcFile.title='In situ measurement of particle size distributions from the FAAM BAe-146 research aircraft.'
NcFile.featureType='timeSeries'
NcFile.time_coverage_start=FlightDate.strftime("%Y-%m-%dT%H:%M:%S")
NcFile.time_coverage_end=(FlightDate+datetime.timedelta(seconds=int(Time_mid[-1]))).strftime("%Y-%m-%dT%H:%M:%S")
NcFile.geospatial_bounds= str(np.around(np.min(LAT_GIN_nc[LAT_GIN_nc != FillValue]),2))+'N '+str(np.around(np.min(LON_GIN_nc[LON_GIN_nc != FillValue]),2))+'E, '+str(np.around(np.max(LAT_GIN_nc[LAT_GIN_nc != FillValue]),2))+'N '+str(np.around(np.max(LON_GIN_nc[LON_GIN_nc != FillValue]),2))+'E'
NcFile.platform_altitude='Not applicable'
NcFile.location_keywords = 'Chilbolton, UK'
NcFile.amf_vocabularies_release = 'https://github.com/ncasuk/AMF_CVs/releases/tag/v2.0.0'
NcFile.history = FlightDate.strftime("%Y-%m-%dT%H:%M:%SZ")+' - Data collected.'
NcFile.comment = 'Data processing was performed to derive size segregated number concentrations as in OShea et al. (https://doi.org/10.5194/amt-2020-265). Particle size has been calculated as the mean particle extent parallel and perpendicular to the probe optical array. Particles with inter-arrival times < 1E-5 s have been rejected. Particles in contact with the edge of the sample array have been rejected. Other aircraft variables have been extracted from the file '+CoreFileName+'. The instrument counting uncertainty for each time and size bin is given by (100% / N^(1/2)), where N is the number of counts in the bin.'
NcFile.measurement_technique = 'optical'
#Dimensions
time = NcFile.createDimension('time', len(TimeSecondsSince))
latitude = NcFile.createDimension('latitude', len(TimeSecondsSince))
longitude = NcFile.createDimension('longitude', len(TimeSecondsSince))
index = NcFile.createDimension('index', len(Size_mid))
# Probe variables
time = NcFile.createVariable(varname='time', dimensions=('time',),datatype='float64')
time[:] = TimeSecondsSince
time.units = 'seconds since 1970-01-01 00:00:00'
time.long_name = 'Time (seconds since 1970-01-01)'
time.calendar = 'standard'
time.axis = 'T'
time.valid_min= np.min(TimeSecondsSince)
time.valid_max= np.max(TimeSecondsSince)
ambient_particle_diameter= NcFile.createVariable(varname='ambient_particle_diameter', dimensions=('index',),datatype='float32')
ambient_particle_diameter[:] = Size_mid
ambient_particle_diameter.long_name = 'Ambient Particle Diameter'
ambient_particle_diameter.units = 'um'
ambient_particle_diameter.valid_min= np.min(Size_mid[Size_mid!=FillValue])
ambient_particle_diameter.valid_max= np.max(Size_mid[Size_mid!=FillValue])
ambient_particle_diameter.coordinates = 'latitude longitude'
measurement_channel_lower_limit = NcFile.createVariable(varname='measurement_channel_lower_limit', dimensions=('index',),datatype='float32')
measurement_channel_lower_limit[:] = Size_edge[:-1]
measurement_channel_lower_limit.long_name = 'Lower Limit of Spectrometer Measurement Channel'
measurement_channel_lower_limit.units = 'um'
measurement_channel_lower_limit.valid_min= np.min(Size_edge[:-1])
measurement_channel_lower_limit.valid_max= np.max(Size_edge[:-1])
measurement_channel_lower_limit.coordinates = 'latitude longitude'
measurement_channel_upper_limit = NcFile.createVariable(varname='measurement_channel_upper_limit', dimensions=('index',),datatype='float32')
measurement_channel_upper_limit[:] = Size_edge[1:]
measurement_channel_upper_limit.long_name = 'Upper Limit of Spectrometer Measurement Channel'
measurement_channel_upper_limit.units = 'um'
measurement_channel_upper_limit.valid_min= np.min(Size_edge[1:])
measurement_channel_upper_limit.valid_max= np.max(Size_edge[1:])
measurement_channel_upper_limit.coordinates = 'latitude longitude'
if NormFlag == 0 :
ambient_particle_number_per_channel = NcFile.createVariable(varname='ambient_particle_number_per_channel', dimensions=('time','index'),datatype='float32', fill_value = FillValue)
ambient_particle_number_per_channel[:,:] = Psd
ambient_particle_number_per_channel.long_name = 'Ambient Particle Number per Channel (dN)'
ambient_particle_number_per_channel.units = 'cm-3'
ambient_particle_number_per_channel.valid_min= np.min(Psd[Psd!=FillValue])
ambient_particle_number_per_channel.valid_max= np.max(Psd[Psd!=FillValue])
ambient_particle_number_per_channel.coordinates = 'latitude longitude'
ambient_particle_number_per_channel.cell_methods = 'time: mean'
if NormFlag == 1:
ambient_particle_size_distribution = NcFile.createVariable(varname='ambient_particle_size_distribution', dimensions=('time','index'),datatype='float32', fill_value = FillValue)
ambient_particle_size_distribution[:,:] = Psd
ambient_particle_size_distribution.long_name = 'Ambient Particle Size Distribution (dN\dD)'
ambient_particle_size_distribution.units = 'cm-3 um-1'
ambient_particle_size_distribution.valid_min= np.min(Psd[Psd!=FillValue])
ambient_particle_size_distribution.valid_max= np.max(Psd[Psd!=FillValue])
ambient_particle_size_distribution.coordinates = 'latitude longitude'
ambient_particle_size_distribution.cell_methods = 'time: mean'
number_of_instrument_counts_per_channel = NcFile.createVariable(varname='number_of_instrument_counts_per_channel', dimensions=('time','index'),datatype='float32', fill_value = FillValue)
number_of_instrument_counts_per_channel[:,:] = Counts
number_of_instrument_counts_per_channel.long_name = 'Number of Instrument Counts per Channel'
number_of_instrument_counts_per_channel.units = '1'
number_of_instrument_counts_per_channel.valid_min= np.min(number_of_instrument_counts_per_channel[number_of_instrument_counts_per_channel!=FillValue])
number_of_instrument_counts_per_channel.valid_max= np.max(number_of_instrument_counts_per_channel[number_of_instrument_counts_per_channel!=FillValue])
number_of_instrument_counts_per_channel.coordinates = 'latitude longitude'
number_of_instrument_counts_per_channel.cell_methods = 'time: point'
qc_flag_ambient_particle_number_per_channel = NcFile.createVariable(varname='qc_flag_ambient_particle_number_per_channel', dimensions=('time','index'),datatype='u4')
qc_flag_ambient_particle_number_per_channel[:,:] = DataFlag_2D
qc_flag_ambient_particle_number_per_channel.long_name = 'Data Quality flag: Ambient Particle Number per Channel'
qc_flag_ambient_particle_number_per_channel.flag_values = '0b, 1b, 2b, 3b'
qc_flag_ambient_particle_number_per_channel.flag_meanings = 'not_used \n\rvalid_data \n\rreduced_quality_data \n\rmissing_data'
# Core variables
altitude = NcFile.createVariable(varname='altitude', dimensions=('time',),datatype='float32', fill_value = FillValue)
altitude[:] = ALT_GIN_nc
altitude.long_name = 'Geometric height above geoid (WGS84)'
altitude.units = 'm'
altitude.axis = 'Z'
altitude.valid_min = np.min(ALT_GIN_nc[ALT_GIN_nc!=FillValue])
altitude.valid_max = np.max(ALT_GIN_nc[ALT_GIN_nc!=FillValue])
altitude.cell_methods = 'time:point'
latitude = NcFile.createVariable(varname='latitude', dimensions=('latitude',),datatype='float32', fill_value = FillValue)
latitude[:] = LAT_GIN_nc
latitude.long_name = 'Latitude'
latitude.units = 'degrees_north'
latitude.axis = 'Y'
latitude.valid_min = np.min(LAT_GIN_nc[LAT_GIN_nc!=FillValue])
latitude.valid_max = np.max(LAT_GIN_nc[LAT_GIN_nc!=FillValue])
latitude.cell_methods= 'time:point'
longitude = NcFile.createVariable(varname='longitude', dimensions=('longitude',),datatype='float32', fill_value = FillValue)
longitude[:] = LON_GIN_nc
longitude.long_name = 'Longitude'
longitude.units = 'degrees_east'
longitude.axis= 'X'
longitude.valid_min= np.min(LON_GIN_nc[LON_GIN_nc!=FillValue])
longitude.valid_max= np.min(LAT_GIN_nc[LAT_GIN_nc!=FillValue])
longitude.cell_methods= 'time:point'
platform_speed_wrt_air = NcFile.createVariable(varname='platform_speed_wrt_air', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_speed_wrt_air[:] = TAS_RVSM_nc
platform_speed_wrt_air.long_name = 'Platform speed with respect to air (air speed)'
platform_speed_wrt_air.units = 'm s-1'
platform_speed_wrt_air.valid_min= np.min(TAS_RVSM_nc[TAS_RVSM_nc!=FillValue])
platform_speed_wrt_air.valid_max= np.max(TAS_RVSM_nc[TAS_RVSM_nc!=FillValue])
platform_speed_wrt_air.cell_methods = 'time: mean'
platform_speed_wrt_air.coordinates = 'latitude longitude'
platform_course = NcFile.createVariable(varname='platform_course', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_course[:] = TRCK_GIN_nc
platform_course.long_name = 'Direction in which the platform is travelling'
platform_course.units = 'degree'
platform_course.valid_min= np.min(TRCK_GIN_nc[TRCK_GIN_nc!=FillValue])
platform_course.valid_max= np.max(TRCK_GIN_nc[TRCK_GIN_nc!=FillValue])
platform_course.cell_methods = 'time: mean'
platform_course.coordinates = 'latitude longitude'
platform_speed_wrt_ground = NcFile.createVariable(varname='platform_speed_wrt_ground', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_speed_wrt_ground[:] = GSPD_GIN_nc
platform_speed_wrt_ground.long_name = 'Platform speed with respect to ground (ground speed)'
platform_speed_wrt_ground.units = 'm s-1'
platform_speed_wrt_ground.valid_min= np.min(GSPD_GIN_nc[GSPD_GIN_nc!=FillValue])
platform_speed_wrt_ground.valid_max= np.max(GSPD_GIN_nc[GSPD_GIN_nc!=FillValue])
platform_speed_wrt_ground.cell_methods = 'time: mean'
platform_speed_wrt_ground.coordinates = 'latitude longitude'
platform_pitch_angle = NcFile.createVariable(varname='platform_pitch_angle', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_pitch_angle[:] = PTCH_GIN_nc
platform_pitch_angle.long_name = 'Pitch Angle'
platform_pitch_angle.units = 'degree'
platform_pitch_angle.valid_min= np.min(PTCH_GIN_nc[PTCH_GIN_nc!=FillValue])
platform_pitch_angle.valid_max= np.max(PTCH_GIN_nc[PTCH_GIN_nc!=FillValue])
platform_pitch_angle.cell_methods = 'time: mean'
platform_pitch_angle.coordinates = 'latitude longitude'
platform_pitch_rate = NcFile.createVariable(varname='platform_pitch_rate', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_pitch_rate[:] = PITR_GIN_nc
platform_pitch_rate.long_name = 'Pitch Angle Rate of Change'
platform_pitch_rate.units = 'degree s-1'
platform_pitch_rate.valid_min= np.min(PITR_GIN_nc[PITR_GIN_nc!=FillValue])
platform_pitch_rate.valid_max= np.max(PITR_GIN_nc[PITR_GIN_nc!=FillValue])
platform_pitch_rate.cell_methods = 'time: mean'
platform_pitch_rate.coordinates = 'latitude longitude'
platform_yaw_angle = NcFile.createVariable(varname='platform_yaw_angle', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_yaw_angle[:] = HDG_GIN_nc
platform_yaw_angle.long_name = 'Yaw Angle'
platform_yaw_angle.units = 'degree'
platform_yaw_angle.valid_min= np.min(HDG_GIN_nc[HDG_GIN_nc!=FillValue])
platform_yaw_angle.valid_max= np.max(HDG_GIN_nc[HDG_GIN_nc!=FillValue])
platform_yaw_angle.cell_methods = 'time: mean'
platform_yaw_angle.coordinates = 'latitude longitude'
platform_yaw_rate = NcFile.createVariable(varname='platform_yaw_rate', dimensions=('time',),datatype='float32', fill_value = FillValue)
platform_yaw_rate[:] = HDGR_GIN_nc
platform_yaw_rate.long_name = 'Yaw Angle Rate of Change'
platform_yaw_rate.units = 'degree s-1'
platform_yaw_rate.valid_min= np.min(HDGR_GIN_nc[HDGR_GIN_nc!=FillValue])
platform_yaw_rate.valid_max= np.max(HDGR_GIN_nc[HDGR_GIN_nc!=FillValue])
platform_yaw_rate.cell_methods = 'time: mean'
platform_yaw_rate.coordinates = 'latitude longitude'
DayOfYear = NcFile.createVariable(varname='day_of_year', dimensions=('time',),datatype='float32')
DayOfYear[:] = day_of_year
DayOfYear.long_name = 'Day of Year'
DayOfYear.units = '1'
DayOfYear.valid_min = np.float32(np.nanmin(day_of_year))
DayOfYear.valid_max = np.float32(np.nanmax(day_of_year))
Year = NcFile.createVariable(varname='year', dimensions=('time',),datatype='u4')
Year[:] = year
Year.long_name = 'Year'
Year.units = '1'
Year.valid_min = np.nanmin(year)
Year.valid_max = np.nanmax(year)
Month = NcFile.createVariable(varname='month', dimensions=('time',),datatype='u4')
Month[:] = month
Month.long_name = 'Month'
Month.units = '1'
Month.valid_min = np.nanmin(month)
Month.valid_max = np.nanmax(month)
Day = NcFile.createVariable(varname='day', dimensions=('time',),datatype='u4')
Day[:] = day
Day.long_name = 'Day'
Day.units = '1'
Day.valid_min = np.nanmin(day)
Day.valid_max = np.nanmax(day)
Hour = NcFile.createVariable(varname='hour', dimensions=('time',),datatype='u4')
Hour[:] = hour
Hour.long_name = 'Hour'
Hour.units = '1'
Hour.valid_min = np.nanmin(hour)
Hour.valid_max = np.nanmax(hour)
Minute = NcFile.createVariable(varname='minute', dimensions=('time',),datatype='u4')
Minute[:] = minute
Minute.long_name = 'Minute'
Minute.units = '1'
Minute.valid_min = np.nanmin(minute)
Minute.valid_max = np.nanmax(minute)
Second = NcFile.createVariable(varname='second', dimensions=('time',),datatype='float32')
Second[:] = second
Second.long_name = 'Second'
Second.units = '1'
Second.valid_min = np.nanmin(second)
Second.valid_max = np.nanmax(second)
# LAT_GIN # latitude
# LON_GIN # longitude
# ALT_GIN # altitude
# TAS_RVSM # platform_speed_wrt_air
# TRCK_GIN # platform_course
# # platform_orientation
# GSPD_GIN # platform_speed_wrt_ground
# PTCH_GIN # platform_pitch_angle
# PITR_GIN # platform_pitch_rate
# ROLL_GIN # platform_roll_angle
# ROLR_GIN # platform_roll_rate
# HDG_GIN # platform_yaw_angle
# HDGR_GIN # platform_yaw_rate
NcFile.close()