41 from netCDF4
import Dataset
43 from solo.date
import JediDate, CoreDate
45 from goes_latlon
import GoesLatLon
50 def __init__(self, input_file_paths, latlon_file_path, output_file_path_rf, output_file_path_bt):
53 input_file_paths - A list of the absolute paths to all 16 ABI channels from the same hour
54 latlon_file_path - The path to an existing Goes LatLon file or if it does not exist the path to write the file
55 output_file_path_rf - The path to write the IODAv2 reflectance factor data file
56 output_file_path_bt - The path to write the IODAv2 brightness temperature data file
69 Checks the input arguments.
73 print(
"ERROR: input_file_paths must contain 16 GOES-16 or GOES-17 data files. One for each ABI channel.")
80 Create two local dictionaries contained the Goes class instances for brightness temperature (ABI channels 1-6)
81 and reflectance factor (ABI channels 7-16). Each Goes instance calls the load method. This function also
82 assigns the file path for a template GOES file from ABI channel 7.
88 goes =
Goes(input_file_path)
90 abi_channel =
int(goes.get_abi_channel())
99 Returns a boolean variable indicating whether the nadir has changed by comparing the lat_nadir and lon_nadir
100 attributes extracted from the GoesLatLon data file and the Goes template data file.
104 return lat_nadir_latlon == lat_nadir_template
and lon_nadir_latlon == lon_nadir_template
108 Returns the lat and lon nadir attribute from the Goes LatLon data file.
111 lat_nadir_latlon = dataset[
'MetaData'].variables[
'latitude'].getncattr(
'lat_nadir')
112 lon_nadir_latlon = dataset[
'MetaData'].variables[
'longitude'].getncattr(
'lon_nadir')
114 return lat_nadir_latlon, lon_nadir_latlon
118 Returns the lat and lon nadir attribute from the Goes template data file.
121 lat_nadir_template = dataset.variables[
'geospatial_lat_lon_extent'].getncattr(
'geospatial_lat_nadir')
122 lon_nadir_template = dataset.variables[
'geospatial_lat_lon_extent'].getncattr(
'geospatial_lon_nadir')
124 return lat_nadir_template, lon_nadir_template
128 Returns a boolean variable indicating whether the Goes LatLon file exists.
134 Creates a new Goes LatLon data file using the GoesLatLon class.
141 Closes the Goes latlon, reflectance factor, and brightness temperature netCDF4 Datasets.
149 Creates the /MetaData/latitude variable in the reflectance factor and brightness temperature netCDF4 Datasets.
151 latitude_data_array = self.
_latlon_dataset_latlon_dataset[
'MetaData'].variables[
'latitude'][:].real
152 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/MetaData/latitude',
'f4',
'nlocs', fill_value=-999)
153 self.
_output_dataset_rf_output_dataset_rf[
'/MetaData/latitude'][:] = latitude_data_array
154 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/MetaData/latitude',
'f4',
'nlocs', fill_value=-999)
155 self.
_output_dataset_bt_output_dataset_bt[
'/MetaData/latitude'][:] = latitude_data_array
159 Creates the /MetaData/longitude variable in the reflectance factor and brightness temperature netCDF4 Datasets.
161 longitude_data_array = self.
_latlon_dataset_latlon_dataset[
'MetaData'].variables[
'longitude'][:].real
162 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/MetaData/longitude',
'f4',
'nlocs', fill_value=-999)
163 self.
_output_dataset_rf_output_dataset_rf[
'/MetaData/longitude'][:] = longitude_data_array
164 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/MetaData/longitude',
'f4',
'nlocs', fill_value=-999)
165 self.
_output_dataset_bt_output_dataset_bt[
'/MetaData/longitude'][:] = longitude_data_array
169 Creates the /MetaData/scan_angle variable in the reflectance factor and brightness temperature netCDF4 Datasets.
171 scan_angle_data_array = self.
_latlon_dataset_latlon_dataset[
'MetaData'].variables[
'scan_angle'][:].real
172 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/MetaData/scan_angle',
'f4',
'nlocs', fill_value=-999)
173 self.
_output_dataset_rf_output_dataset_rf[
'/MetaData/scan_angle'][:] = scan_angle_data_array
174 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/MetaData/scan_angle',
'f4',
'nlocs', fill_value=-999)
175 self.
_output_dataset_bt_output_dataset_bt[
'/MetaData/scan_angle'][:] = scan_angle_data_array
179 Creates the /MetaData/elevation_angle variable in the reflectance factor and brightness temperature netCDF4
182 elevation_angle_data_array = self.
_latlon_dataset_latlon_dataset[
'MetaData'].variables[
'elevation_angle'][:].real
183 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/MetaData/elevation_angle',
'f4',
'nlocs', fill_value=-999)
184 self.
_output_dataset_rf_output_dataset_rf[
'/MetaData/elevation_angle'][:] = elevation_angle_data_array
185 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/MetaData/elevation_angle',
'f4',
'nlocs', fill_value=-999)
186 self.
_output_dataset_bt_output_dataset_bt[
'/MetaData/elevation_angle'][:] = elevation_angle_data_array
190 Creates the required groups in the reflectance factor and brightness temperature netCDF4 Datasets.
205 Creates the nlocs dimension in the reflectance factor and brightness temperature netCDF4 Datasets.
210 self.
_output_dataset_rf_output_dataset_rf.variables[
'nlocs'].setncattr(
'suggested_chunk_dim', nlocs)
211 self.
_output_dataset_rf_output_dataset_rf.variables[
'nlocs'][:] = np.arange(1, nlocs + 1, 1, dtype=
'int32')
214 self.
_output_dataset_bt_output_dataset_bt.variables[
'nlocs'].setncattr(
'suggested_chunk_dim', nlocs)
215 self.
_output_dataset_bt_output_dataset_bt.variables[
'nlocs'][:] = np.arange(1, nlocs + 1, 1, dtype=
'int32')
219 Creates the nchans dimension in the reflectance factor and brightness temperature netCDF4 Datasets.
228 self.
_output_dataset_bt_output_dataset_bt.variables[
'nchans'][:] = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
232 Creates the nvars dimension in the reflectance factor and brightness temperature netCDF4 Datasets.
238 self.
_output_dataset_rf_output_dataset_rf.variables[
'nvars'][:] = np.arange(1, nvars_rf + 1, 1, dtype=
'int32')
241 self.
_output_dataset_bt_output_dataset_bt.variables[
'nvars'][:] = np.arange(1, nvars_bt + 1, 1, dtype=
'int32')
245 Creates the ndatetime dimension in the reflectance factor and brightness temperature netCDF4 Datasets.
249 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'ndatetime',
'i4',
'ndatetime')
250 self.
_output_dataset_rf_output_dataset_rf.variables[
'ndatetime'][:] = np.arange(1, ndatetime + 1, 1, dtype=
'int32')
252 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'ndatetime',
'i4',
'ndatetime')
253 self.
_output_dataset_bt_output_dataset_bt.variables[
'ndatetime'][:] = np.arange(1, ndatetime + 1, 1, dtype=
'int32')
257 Creates the nstring dimension in the reflectance factor and brightness temperature netCDF4 Datasets.
262 self.
_output_dataset_rf_output_dataset_rf.variables[
'nstring'][:] = np.arange(1, nstring + 1, 1, dtype=
'int32')
265 self.
_output_dataset_bt_output_dataset_bt.variables[
'nstring'][:] = np.arange(1, nstring + 1, 1, dtype=
'int32')
270 Returns the nlocs dimension size for the provided netCDF4 Dataset.
271 dataset - the dataset to extract the nlocs size
273 return dataset.dimensions[
'nlocs'].size
277 Creates the /PreQC/reflectance_factor variable variable and associated attributes in the reflectance factor
284 temp_dict[counter] = ma.getdata(goes.get_preqc_data_array())
286 data_array = temp_dict[0]
287 for i
in range(1, counter):
288 data_array = np.column_stack((data_array, temp_dict[i]))
289 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/PreQC/reflectance_factor',
'f4', (
'nlocs',
'nchans'), fill_value=-999)
290 self.
_output_dataset_rf_output_dataset_rf[
'/PreQC/reflectance_factor'][:] = data_array
291 self.
_output_dataset_rf_output_dataset_rf[
'/PreQC/reflectance_factor'].setncattr(
'flag_values',
'0,1,2,3')
292 self.
_output_dataset_rf_output_dataset_rf[
'/PreQC/reflectance_factor'].setncattr(
'flag_meanings',
294 'conditionally_usable_pixel_qf '
295 'out_of_range_pixel_qf no_value_pixel_qf')
299 Creates the /PreQC/brightness_temperature variable and associated attributes in the brightness temperature
306 temp_dict[counter] = ma.getdata(goes.get_preqc_data_array())
308 data_array = temp_dict[0]
309 for i
in range(1, counter):
310 data_array = np.column_stack((data_array, temp_dict[i]))
311 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/PreQC/brightness_temperature',
'f4', (
'nlocs',
'nchans'),
313 self.
_output_dataset_bt_output_dataset_bt[
'/PreQC/brightness_temperature'][:] = data_array
314 self.
_output_dataset_bt_output_dataset_bt[
'/PreQC/brightness_temperature'].setncattr(
'flag_values',
'0,1,2,3')
315 self.
_output_dataset_bt_output_dataset_bt[
'/PreQC/brightness_temperature'].setncattr(
'flag_meanings',
317 'conditionally_usable_pixel_qf '
318 'out_of_range_pixel_qf no_value_pixel_qf')
322 Creates the /ObsValue/reflectance_factor variable in the reflectance factor netCDF4 Dataset.
328 temp_dict[counter] = ma.getdata(goes.get_obsvalue_rf_data_array())
330 data_array = temp_dict[0]
331 for i
in range(1, counter):
332 data_array = np.column_stack((data_array, temp_dict[i]))
333 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/ObsValue/reflectance_factor',
'f4', (
'nlocs',
'nchans'),
335 self.
_output_dataset_rf_output_dataset_rf[
'/ObsValue/reflectance_factor'][:] = data_array
339 Creates the /ObsValue/brightness_temperature variable in the brightness temperature netCDF4 Dataset.
345 temp_dict[counter] = ma.getdata(goes.get_obsvalue_bt_data_array())
347 data_array = temp_dict[0]
348 for i
in range(1, counter):
349 data_array = np.column_stack((data_array, temp_dict[i]))
350 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/ObsValue/brightness_temperature',
'f4', (
'nlocs',
'nchans'),
352 self.
_output_dataset_bt_output_dataset_bt[
'/ObsValue/brightness_temperature'][:] = data_array
353 self.
_output_dataset_bt_output_dataset_bt[
'/ObsValue/brightness_temperature'].setncattr(
'units',
'K')
357 Creates the /ObsError/reflectance_factor variable in the reflectance factor netCDF4 Dataset.
363 temp_dict[counter] = ma.getdata(goes.get_obserror_rf_data_array())
365 data_array = temp_dict[0]
366 for i
in range(1, counter):
367 data_array = np.column_stack((data_array, temp_dict[i]))
368 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/ObsError/reflectance_factor',
'f4', (
'nlocs',
'nchans'),
370 self.
_output_dataset_rf_output_dataset_rf[
'/ObsError/reflectance_factor'][:] = data_array
374 Creates the /ObsError/brightness_temperature variable in the brightness temperature netCDF4 Dataset.
380 temp_dict[counter] = ma.getdata(goes.get_obserror_bt_data_array())
382 data_array = temp_dict[0]
383 for i
in range(1, counter):
384 data_array = np.column_stack((data_array, temp_dict[i]))
385 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/ObsError/brightness_temperature',
'f4', (
'nlocs',
'nchans'),
387 self.
_output_dataset_bt_output_dataset_bt[
'/ObsError/brightness_temperature'][:] = data_array
388 self.
_output_dataset_bt_output_dataset_bt[
'/ObsError/brightness_temperature'].setncattr(
'units',
'K')
392 Creates the /MetaData/datetime and MetaData/time variables and /date_time attribute in the reflectance factor
393 and brightness temperature netCDF4 Datasets.
397 start_date =
str(JediDate(dataset.get_start_date()))
400 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/MetaData/datetime',
'str',
'nlocs')
402 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/MetaData/datetime',
'str',
'nlocs')
404 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/MetaData/time',
'f4',
'nlocs')
406 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/MetaData/time',
'f4',
'nlocs')
413 Creates the /VarMetaData/sensor_channel variable in the reflectance factor and brightness temperature netCDF4
416 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/VarMetaData/sensor_channel',
'i4',
'nchans')
418 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/VarMetaData/sensor_channel',
'i4',
'nchans')
423 Creates the /VarMetaData/variable_names variable in the reflectance factor and brightness temperature netCDF4
426 self.
_output_dataset_rf_output_dataset_rf.createVariable(
'/VarMetaData/variable_names',
'str',
'nchans')
427 temp_data_array = [
'reflectance_factor_1',
'reflectance_factor_2',
'reflectance_factor_3',
428 'reflectance_factor_4',
'reflectance_factor_5',
'reflectance_factor_6']
429 self.
_output_dataset_rf_output_dataset_rf[
'/VarMetaData/variable_names'][:] = np.array(temp_data_array)
430 self.
_output_dataset_bt_output_dataset_bt.createVariable(
'/VarMetaData/variable_names',
'str',
'nchans')
431 temp_data_array = [
'brightness_temperature_7',
'brightness_temperature_8',
'brightness_temperature_9',
432 'brightness_temperature_10',
'brightness_temperature_11',
'brightness_temperature_12',
433 'brightness_temperature_13',
'brightness_temperature_14',
'brightness_temperature_15',
434 'brightness_temperature_16']
435 self.
_output_dataset_bt_output_dataset_bt[
'/VarMetaData/variable_names'][:] = np.array(temp_data_array)
439 Creates several root group attributes in the reflectance factor and brightness temperature netCDF4 Datasets.
448 Creates the reflectance factor and brightness temperature IODAv2 data files. This functions also checks for
449 the existence and nadir change of the Goes LatLon data file.
def _create_nlocs_dimensions(self)
def _create_obserror_reflectance_factor_variable(self)
def __init__(self, input_file_paths, latlon_file_path, output_file_path_rf, output_file_path_bt)
def _create_root_group_attributes(self)
def _create_preqc_reflectance_factor_variable(self)
def _create_input_data_file_dicts(self)
def _create_varmetadata_variable_names_variables(self)
def _close_datasets(self)
def _create_nvars_dimensions(self)
def _create_obsvalue_brightness_temperature_variable(self)
def _create_preqc_brightness_temperature_variable(self)
def _create_metadata_time_variables(self)
def _create_nchans_dimensions(self)
def _create_metadata_scan_angle_variables(self)
def _create_metadata_latitude_variables(self)
def _get_nadir_attribute_latlon(self)
def _create_metadata_longitude_variables(self)
def _create_metadata_elevation_angle_variables(self)
def _create_ndatetime_dimensions(self)
def _create_obserror_brightness_temperature_variable(self)
def _check_arguments(self)
def _get_nadir_attribute_template(self)
def _create_latlon_dataset(self)
def _create_nstring_dimensions(self)
_template_input_file_path
def _check_latlon_file_path(self)
def _create_obsvalue_reflectance_factor_variable(self)
def _create_varmetadata_sensor_channel_variables(self)