def modify_faimms_netcdf(netcdf_file_path, channel_id_info): """ Modify the downloaded netCDF file so it passes both CF and IMOS checker input: netcdf_file_path(str) : path of netcdf file to modify channel_id_index(tupple) : information from xml for the channel """ modify_aims_netcdf(netcdf_file_path, channel_id_info) netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') netcdf_file_obj.aims_channel_id = int(channel_id_info['channel_id']) if not (channel_id_info['metadata_uuid'] == 'Not Available'): netcdf_file_obj.metadata_uuid = channel_id_info['metadata_uuid'] # some weather stations channels don't have a depth variable if sensor above water if 'depth' in netcdf_file_obj.variables.keys(): var = netcdf_file_obj.variables['depth'] var.long_name = 'nominal depth' var.positive = 'down' var.axis = 'Z' var.reference_datum = 'sea surface' var.valid_min = -10.0 var.valid_max = 30.0 netcdf_file_obj.renameVariable('depth', 'NOMINAL_DEPTH') if 'DEPTH' in netcdf_file_obj.variables.keys(): var = netcdf_file_obj.variables['DEPTH'] var.coordinates = "TIME LATITUDE LONGITUDE NOMINAL_DEPTH" var.long_name = 'actual depth' var.reference_datum = 'sea surface' var.positive = 'down' var.valid_min = -10.0 var.valid_max = 30.0 netcdf_file_obj.close() netcdf_file_obj = Dataset( netcdf_file_path, 'a', format='NETCDF4' ) # need to close to save to file. as we call get_main_netcdf_var just after main_var = get_main_netcdf_var(netcdf_file_path) # DEPTH, LATITUDE and LONGITUDE are not dimensions, so we make them into auxiliary cooordinate variables by adding this attribute if 'NOMINAL_DEPTH' in netcdf_file_obj.variables.keys(): netcdf_file_obj.variables[ main_var].coordinates = "TIME LATITUDE LONGITUDE NOMINAL_DEPTH" else: netcdf_file_obj.variables[ main_var].coordinates = "TIME LATITUDE LONGITUDE" netcdf_file_obj.close() if not convert_time_cf_to_imos(netcdf_file_path): return False remove_dimension_from_netcdf( netcdf_file_path) # last modification to do in this order! return True
def modify_faimms_netcdf(netcdf_file_path, channel_id_info): """ Modify the downloaded netCDF file so it passes both CF and IMOS checker input: netcdf_file_path(str) : path of netcdf file to modify channel_id_index(tupple) : information from xml for the channel """ modify_aims_netcdf(netcdf_file_path, channel_id_info) netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') netcdf_file_obj.aims_channel_id = int(channel_id_info['channel_id']) if not (channel_id_info['metadata_uuid'] == 'Not Available'): netcdf_file_obj.metadata_uuid = channel_id_info['metadata_uuid'] # some weather stations channels don't have a depth variable if sensor above water if 'depth' in netcdf_file_obj.variables.keys(): var = netcdf_file_obj.variables['depth'] var.long_name = 'nominal depth' var.positive = 'down' var.axis = 'Z' var.reference_datum = 'sea surface' var.valid_min = -10.0 var.valid_max = 30.0 netcdf_file_obj.renameVariable('depth', 'NOMINAL_DEPTH') if 'DEPTH' in netcdf_file_obj.variables.keys(): var = netcdf_file_obj.variables['DEPTH'] var.coordinates = "TIME LATITUDE LONGITUDE NOMINAL_DEPTH" var.long_name = 'actual depth' var.reference_datum = 'sea surface' var.positive = 'down' var.valid_min = -10.0 var.valid_max = 30.0 netcdf_file_obj.close() netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') # need to close to save to file. as we call get_main_faimms_var just after main_var = get_main_faimms_var(netcdf_file_path) # DEPTH, LATITUDE and LONGITUDE are not dimensions, so we make them into auxiliary cooordinate variables by adding this attribute if 'NOMINAL_DEPTH' in netcdf_file_obj.variables.keys(): netcdf_file_obj.variables[main_var].coordinates = "TIME LATITUDE LONGITUDE NOMINAL_DEPTH" else: netcdf_file_obj.variables[main_var].coordinates = "TIME LATITUDE LONGITUDE" netcdf_file_obj.close() if not convert_time_cf_to_imos(netcdf_file_path): return False remove_dimension_from_netcdf(netcdf_file_path) # last modification to do in this order! return True
def modify_soop_trv_netcdf(netcdf_file_path, channel_id_info): """ Modify the downloaded NetCDF file so it passes both CF and IMOS checker input: netcdfFile_path(str) : path of netcdf file to modify channel_id_index(tupple) : information from xml for the channel """ logger = logging_aims() modify_aims_netcdf(netcdf_file_path, channel_id_info) netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') ship_code = netcdf_file_obj.platform_code vessel_name = ship_callsign(ship_code) if vessel_name is None: logger.error(' UNKNOWN SHIP - channel %s' % str(channel_id_info['channel_id'])) netcdf_file_obj.close() return False # add gatts to net_cDF netcdf_file_obj.cdm_data_type = 'Trajectory' netcdf_file_obj.vessel_name = vessel_name netcdf_file_obj.trip_id = channel_id_info['trip_id'] netcdf_file_obj.cdm_data_type = "Trajectory" coordinates_att = "TIME LATITUDE LONGITUDE DEPTH" # depth depth = netcdf_file_obj.variables['depth'] depth.positive = 'down' depth.axis = 'Z' depth.reference_datum = 'sea surface' depth.valid_max = 30.0 depth.valid_min = -10.0 netcdf_file_obj.renameVariable('depth', 'DEPTH') # latitude longitude latitude = netcdf_file_obj.variables['LATITUDE'] latitude.ancillary_variables = 'LATITUDE_quality_control' longitude = netcdf_file_obj.variables['LONGITUDE'] longitude.ancillary_variables = 'LONGITUDE_quality_control' latitude_qc = netcdf_file_obj.variables['LATITUDE_quality_control'] latitude_qc.long_name = 'LATITUDE quality control' latitude_qc.standard_name = 'latitude status_flag' longitude_qc = netcdf_file_obj.variables['LONGITUDE_quality_control'] longitude_qc.long_name = 'LONGITUDE quality control' longitude_qc.standard_name = 'longitude status_flag' netcdf_file_obj.close() netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') main_var = get_main_soop_trv_var(netcdf_file_path) netcdf_file_obj.variables[main_var].coordinates = coordinates_att netcdf_file_obj.close() if not convert_time_cf_to_imos(netcdf_file_path): return False remove_dimension_from_netcdf(netcdf_file_path) # last modification to do ! return True
def modify_soop_trv_netcdf(netcdf_file_path, channel_id_info): """ Modify the downloaded NetCDF file so it passes both CF and IMOS checker input: netcdfFile_path(str) : path of netcdf file to modify channel_id_index(tupple) : information from xml for the channel """ modify_aims_netcdf(netcdf_file_path, channel_id_info) netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') ship_code = netcdf_file_obj.platform_code vessel_name = ship_callsign(ship_code) if vessel_name is None: logger.error(' UNKNOWN SHIP - channel %s' % str(channel_id_info['channel_id'])) netcdf_file_obj.close() return False # add gatts to net_cDF netcdf_file_obj.cdm_data_type = 'Trajectory' netcdf_file_obj.vessel_name = vessel_name netcdf_file_obj.trip_id = channel_id_info['trip_id'] netcdf_file_obj.cdm_data_type = "Trajectory" coordinates_att = "TIME LATITUDE LONGITUDE DEPTH" # depth depth = netcdf_file_obj.variables['depth'] depth.positive = 'down' depth.axis = 'Z' depth.reference_datum = 'sea surface' depth.valid_max = 30.0 depth.valid_min = -10.0 netcdf_file_obj.renameVariable('depth', 'DEPTH') # latitude longitude latitude = netcdf_file_obj.variables['LATITUDE'] latitude.ancillary_variables = 'LATITUDE_quality_control' longitude = netcdf_file_obj.variables['LONGITUDE'] longitude.ancillary_variables = 'LONGITUDE_quality_control' latitude_qc = netcdf_file_obj.variables['LATITUDE_quality_control'] latitude_qc.long_name = 'LATITUDE quality control' latitude_qc.standard_name = 'latitude status_flag' longitude_qc = netcdf_file_obj.variables['LONGITUDE_quality_control'] longitude_qc.long_name = 'LONGITUDE quality control' longitude_qc.standard_name = 'longitude status_flag' netcdf_file_obj.close() netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4') main_var = get_main_soop_trv_var(netcdf_file_path) netcdf_file_obj.variables[main_var].coordinates = coordinates_att netcdf_file_obj.close() if not convert_time_cf_to_imos(netcdf_file_path): return False remove_dimension_from_netcdf(netcdf_file_path) # last modification to do ! return True