<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import datetime <EOL> import warnings <EOL> import numpy as np <EOL> from . . config import FileMetadata , get_fillvalue <EOL> from . . core . radar import Radar <EOL> from . common import make_time_unit_str , _test_arguments , prepare_for_read <EOL> from . _sigmetfile import SigmetFile , bin4_to_angle , bin2_to_angle <EOL> from . import _sigmet_noaa_hh <EOL> from . . util import mean_of_two_angles_deg <EOL> SPEED_OF_LIGHT = <NUM_LIT> <EOL> def read_sigmet ( filename , field_names = None , additional_metadata = None , <EOL> file_field_names = False , exclude_fields = None , <EOL> time_ordered = '<STR_LIT:none>' , full_xhdr = None , noaa_hh_hdr = None , <EOL> debug = False , ignore_xhdr = False , ignore_sweep_start_ms = None , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _test_arguments ( kwargs ) <EOL> filemetadata = FileMetadata ( '<STR_LIT>' , field_names , additional_metadata , <EOL> file_field_names , exclude_fields ) <EOL> sigmetfile = SigmetFile ( prepare_for_read ( filename ) , debug = debug ) <EOL> ingest_config = sigmetfile . ingest_header [ '<STR_LIT>' ] <EOL> task_config = sigmetfile . ingest_header [ '<STR_LIT>' ] <EOL> if noaa_hh_hdr is True : <EOL> full_xhdr = True <EOL> if full_xhdr is None : <EOL> type_mask = task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if type_mask [ '<STR_LIT>' ] == <NUM_LIT:2> : <EOL> full_xhdr = True <EOL> else : <EOL> full_xhdr = False <EOL> sigmet_data , sigmet_metadata = sigmetfile . read_data ( full_xhdr = full_xhdr ) <EOL> first_data_type = sigmetfile . data_type_names [ <NUM_LIT:0> ] <EOL> if first_data_type == '<STR_LIT>' : <EOL> first_data_type = sigmetfile . data_type_names [ <NUM_LIT:1> ] <EOL> sigmetfile . close ( ) <EOL> nsweeps , nrays , nbins = sigmet_data [ first_data_type ] . shape <EOL> if nsweeps == <NUM_LIT:0> : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> if ignore_xhdr : <EOL> if '<STR_LIT>' in sigmet_data : <EOL> sigmet_data . pop ( '<STR_LIT>' ) <EOL> sigmet_metadata . pop ( '<STR_LIT>' ) <EOL> if full_xhdr and '<STR_LIT>' in sigmet_data : <EOL> xhdr = sigmet_data . pop ( '<STR_LIT>' ) <EOL> sigmet_data [ '<STR_LIT>' ] = xhdr [ : , : , : <NUM_LIT:2> ] . copy ( ) . view ( '<STR_LIT>' ) <EOL> sigmet_data [ '<STR_LIT>' ] = xhdr <EOL> xhdr_metadata = { } <EOL> for key in sigmet_metadata [ '<STR_LIT>' ] . keys ( ) : <EOL> xhdr_metadata [ key ] = sigmet_metadata [ '<STR_LIT>' ] [ key ] . copy ( ) <EOL> sigmet_metadata [ '<STR_LIT>' ] = xhdr_metadata <EOL> good_rays = ( sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] != - <NUM_LIT:1> ) <EOL> rays_missing = ( sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] == - <NUM_LIT:1> ) . sum ( ) <EOL> for field_name in sigmet_data . keys ( ) : <EOL> sigmet_data [ field_name ] = sigmet_data [ field_name ] [ good_rays ] <EOL> field_metadata = sigmet_metadata [ field_name ] <EOL> for key in field_metadata . keys ( ) : <EOL> field_metadata [ key ] = field_metadata [ key ] [ good_rays ] <EOL> rays_per_sweep = good_rays . sum ( axis = <NUM_LIT:1> ) <EOL> if time_ordered == '<STR_LIT>' : <EOL> if task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:2> : <EOL> if _is_time_ordered_by_reversal ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) : <EOL> time_ordered = '<STR_LIT>' <EOL> else : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> time_ordered = '<STR_LIT:none>' <EOL> else : <EOL> if _is_time_ordered_by_roll ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) : <EOL> time_ordered = '<STR_LIT>' <EOL> elif _is_time_ordered_by_reverse_roll ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) : <EOL> time_ordered = '<STR_LIT>' <EOL> else : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> time_ordered = '<STR_LIT:none>' <EOL> if time_ordered == '<STR_LIT>' : <EOL> _time_order_data_and_metadata_full ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) <EOL> if time_ordered == '<STR_LIT>' : <EOL> _time_order_data_and_metadata_reverse ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) <EOL> if time_ordered == '<STR_LIT>' : <EOL> _time_order_data_and_metadata_roll ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) <EOL> if time_ordered == '<STR_LIT>' : <EOL> _time_order_data_and_metadata_reverse ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) <EOL> _time_order_data_and_metadata_roll ( <EOL> sigmet_data , sigmet_metadata , rays_per_sweep ) <EOL> ray_count = good_rays . sum ( axis = <NUM_LIT:1> ) <EOL> total_rays = ray_count . sum ( ) <EOL> sweep_start_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> sweep_end_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> ssri = np . cumsum ( np . append ( [ <NUM_LIT:0> ] , ray_count [ : - <NUM_LIT:1> ] ) ) . astype ( '<STR_LIT>' ) <EOL> sweep_start_ray_index [ '<STR_LIT:data>' ] = ssri <EOL> sweep_end_ray_index [ '<STR_LIT:data>' ] = np . cumsum ( ray_count ) . astype ( '<STR_LIT>' ) - <NUM_LIT:1> <EOL> if '<STR_LIT>' in sigmet_data : <EOL> tdata = sigmet_data . pop ( '<STR_LIT>' ) <EOL> tdata = ( tdata . flatten ( ) / <NUM_LIT> ) . astype ( '<STR_LIT>' ) <EOL> sigmet_extended_header = True <EOL> else : <EOL> tdata = sigmet_metadata [ first_data_type ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> sigmet_extended_header = False <EOL> dts = [ ymds_time_to_datetime ( d [ '<STR_LIT>' ] ) <EOL> for d in sigmetfile . ingest_data_headers [ first_data_type ] ] <EOL> if ignore_sweep_start_ms is None : <EOL> ignore_sweep_start_ms = not sigmet_extended_header <EOL> if ignore_sweep_start_ms : <EOL> dts = [ d . replace ( microsecond = <NUM_LIT:0> ) for d in dts ] <EOL> dt_start = dts [ <NUM_LIT:0> ] . replace ( microsecond = <NUM_LIT:0> ) <EOL> for i , dt in enumerate ( dts ) : <EOL> start = sweep_start_ray_index [ '<STR_LIT:data>' ] [ i ] <EOL> end = sweep_end_ray_index [ '<STR_LIT:data>' ] [ i ] <EOL> td = ( dt - dt_start ) <EOL> tdata [ start : end + <NUM_LIT:1> ] += ( td . microseconds + ( td . seconds + td . days * <EOL> <NUM_LIT> * <NUM_LIT> ) * <NUM_LIT:10> ** <NUM_LIT:6> ) / <NUM_LIT:10> ** <NUM_LIT:6> <EOL> time = filemetadata ( '<STR_LIT:time>' ) <EOL> time [ '<STR_LIT:data>' ] = tdata <EOL> time [ '<STR_LIT>' ] = make_time_unit_str ( dt_start ) <EOL> _range = filemetadata ( '<STR_LIT>' ) <EOL> range_info = task_config [ '<STR_LIT>' ] <EOL> gate_0 = range_info [ '<STR_LIT>' ] / <NUM_LIT> <EOL> gate_nbin = range_info [ '<STR_LIT>' ] / <NUM_LIT> <EOL> gate_size = round ( ( gate_nbin - gate_0 ) / ( nbins ) ) <EOL> _range [ '<STR_LIT:data>' ] = gate_0 + gate_size * np . arange ( nbins , dtype = '<STR_LIT>' ) <EOL> _range [ '<STR_LIT>' ] = np . array ( [ gate_0 ] , <EOL> dtype = '<STR_LIT>' ) <EOL> _range [ '<STR_LIT>' ] = np . array ( [ gate_size ] , dtype = '<STR_LIT>' ) <EOL> fields = { } <EOL> for data_type_name , fdata in sigmet_data . items ( ) : <EOL> if data_type_name == '<STR_LIT>' : <EOL> continue <EOL> field_name = filemetadata . get_field_name ( data_type_name ) <EOL> if field_name is None : <EOL> continue <EOL> field_dic = filemetadata ( field_name ) <EOL> field_dic [ '<STR_LIT:data>' ] = fdata . reshape ( - <NUM_LIT:1> , nbins ) <EOL> field_dic [ '<STR_LIT>' ] = get_fillvalue ( ) <EOL> fields [ field_name ] = field_dic <EOL> metadata = filemetadata ( '<STR_LIT>' ) <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> metadata [ '<STR_LIT>' ] = ingest_config [ '<STR_LIT>' ] . strip ( ) <EOL> metadata [ '<STR_LIT>' ] = ( <EOL> sigmetfile . product_hdr [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if sigmet_extended_header : <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> else : <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT:false>' <EOL> metadata [ '<STR_LIT>' ] = time_ordered <EOL> metadata [ '<STR_LIT>' ] = rays_missing <EOL> if task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:2> : <EOL> scan_type = '<STR_LIT>' <EOL> else : <EOL> scan_type = '<STR_LIT>' <EOL> latitude = filemetadata ( '<STR_LIT>' ) <EOL> lat = bin4_to_angle ( ingest_config [ '<STR_LIT>' ] ) <EOL> if lat > <NUM_LIT> : <EOL> lat -= <NUM_LIT> <EOL> latitude [ '<STR_LIT:data>' ] = np . array ( [ lat ] , dtype = '<STR_LIT>' ) <EOL> longitude = filemetadata ( '<STR_LIT>' ) <EOL> lon = bin4_to_angle ( ingest_config [ '<STR_LIT>' ] ) <EOL> if lon > <NUM_LIT> : <EOL> lon -= <NUM_LIT> <EOL> longitude [ '<STR_LIT:data>' ] = np . array ( [ lon ] , dtype = '<STR_LIT>' ) <EOL> altitude = filemetadata ( '<STR_LIT>' ) <EOL> alt = sigmetfile . product_hdr [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> altitude [ '<STR_LIT:data>' ] = np . array ( [ alt ] , dtype = '<STR_LIT>' ) <EOL> sweep_number = filemetadata ( '<STR_LIT>' ) <EOL> sweep_number [ '<STR_LIT:data>' ] = np . arange ( nsweeps , dtype = '<STR_LIT>' ) <EOL> fixed_angle = filemetadata ( '<STR_LIT>' ) <EOL> fa = [ d [ '<STR_LIT>' ] for d in <EOL> sigmetfile . ingest_data_headers [ first_data_type ] ] <EOL> fixed_angle [ '<STR_LIT:data>' ] = bin2_to_angle ( np . array ( fa ) ) . astype ( '<STR_LIT>' ) <EOL> azimuth = filemetadata ( '<STR_LIT>' ) <EOL> az0 = sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] <EOL> az1 = sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] <EOL> az_data = mean_of_two_angles_deg ( az0 , az1 ) . astype ( '<STR_LIT>' ) <EOL> az_data [ az_data < <NUM_LIT:0> ] += <NUM_LIT> <EOL> azimuth [ '<STR_LIT:data>' ] = az_data <EOL> elevation = filemetadata ( '<STR_LIT>' ) <EOL> el0 = sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] <EOL> el1 = sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] <EOL> elevation [ '<STR_LIT:data>' ] = mean_of_two_angles_deg ( el0 , el1 ) . astype ( '<STR_LIT>' ) <EOL> prt = filemetadata ( '<STR_LIT>' ) <EOL> prt_mode = filemetadata ( '<STR_LIT>' ) <EOL> nyquist_velocity = filemetadata ( '<STR_LIT>' ) <EOL> unambiguous_range = filemetadata ( '<STR_LIT>' ) <EOL> beam_width_h = filemetadata ( '<STR_LIT>' ) <EOL> beam_width_v = filemetadata ( '<STR_LIT>' ) <EOL> pulse_width = filemetadata ( '<STR_LIT>' ) <EOL> prt_ratio = filemetadata ( '<STR_LIT>' ) <EOL> prt_value = <NUM_LIT:1.> / sigmetfile . product_hdr [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> prt [ '<STR_LIT:data>' ] = prt_value * np . ones ( total_rays , dtype = '<STR_LIT>' ) <EOL> ur_value = SPEED_OF_LIGHT * prt_value / <NUM_LIT> <EOL> unambiguous_range [ '<STR_LIT:data>' ] = ur_value * np . ones ( total_rays , dtype = '<STR_LIT>' ) <EOL> multi_prf_flag = task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> prf_multiplier = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] [ multi_prf_flag ] <EOL> if prf_multiplier != <NUM_LIT:1> : <EOL> prt_mode [ '<STR_LIT:data>' ] = np . array ( nsweeps * [ '<STR_LIT>' ] , dtype = '<STR_LIT:S>' ) <EOL> ratio = ( prf_multiplier + <NUM_LIT:1> ) / ( prf_multiplier ) <EOL> prt_ratio [ '<STR_LIT:data>' ] = ratio * np . ones ( total_rays , dtype = '<STR_LIT>' ) <EOL> else : <EOL> prt_mode [ '<STR_LIT:data>' ] = np . array ( nsweeps * [ '<STR_LIT>' ] , dtype = '<STR_LIT:S>' ) <EOL> prt_ratio [ '<STR_LIT:data>' ] = np . ones ( total_rays , dtype = '<STR_LIT>' ) <EOL> wavelength_cm = sigmetfile . product_hdr [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> nv_value = wavelength_cm / ( <NUM_LIT> * <NUM_LIT> * prt_value ) * prf_multiplier <EOL> nyquist_velocity [ '<STR_LIT:data>' ] = nv_value * np . ones ( total_rays , dtype = '<STR_LIT>' ) <EOL> beam_width_h [ '<STR_LIT:data>' ] = np . array ( [ bin4_to_angle ( <EOL> task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ] , <EOL> dtype = '<STR_LIT>' ) <EOL> beam_width_v [ '<STR_LIT:data>' ] = np . array ( [ bin4_to_angle ( <EOL> task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ] , <EOL> dtype = '<STR_LIT>' ) <EOL> pulse_width [ '<STR_LIT:data>' ] = np . array ( <EOL> [ task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] * <NUM_LIT> ] * <EOL> len ( time [ '<STR_LIT:data>' ] ) , dtype = '<STR_LIT>' ) <EOL> instrument_parameters = { '<STR_LIT>' : unambiguous_range , <EOL> '<STR_LIT>' : prt_mode , <EOL> '<STR_LIT>' : prt , <EOL> '<STR_LIT>' : prt_ratio , <EOL> '<STR_LIT>' : nyquist_velocity , <EOL> '<STR_LIT>' : beam_width_h , <EOL> '<STR_LIT>' : beam_width_v , <EOL> '<STR_LIT>' : pulse_width } <EOL> if prf_multiplier != <NUM_LIT:1> : <EOL> prf_flag = filemetadata ( '<STR_LIT>' ) <EOL> prf_flag [ '<STR_LIT:data>' ] = sigmet_metadata [ first_data_type ] [ '<STR_LIT>' ] <EOL> instrument_parameters [ '<STR_LIT>' ] = prf_flag <EOL> extended_header_params = { } <EOL> if noaa_hh_hdr is None : <EOL> type_mask = task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> htype = type_mask [ '<STR_LIT>' ] <EOL> if full_xhdr and htype == <NUM_LIT:2> and sigmet_data [ '<STR_LIT>' ] [ <NUM_LIT:0> , <NUM_LIT:3> ] == <NUM_LIT> : <EOL> noaa_hh_hdr = True <EOL> else : <EOL> noaa_hh_hdr = False <EOL> if noaa_hh_hdr : <EOL> t = _sigmet_noaa_hh . _decode_noaa_hh_hdr ( <EOL> sigmet_data [ '<STR_LIT>' ] , filemetadata , azimuth , elevation ) <EOL> ( latitude , longitude , altitude , extended_header_params ) = t <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> noaa_hh_scan_modes = { <NUM_LIT:4> : '<STR_LIT>' , <NUM_LIT:7> : '<STR_LIT>' } <EOL> scan_mode = task_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if scan_mode not in noaa_hh_scan_modes : <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> scan_type = '<STR_LIT>' <EOL> else : <EOL> scan_type = noaa_hh_scan_modes [ scan_mode ] <EOL> sweep_mode = filemetadata ( '<STR_LIT>' ) <EOL> if scan_type == '<STR_LIT>' : <EOL> sweep_mode [ '<STR_LIT:data>' ] = np . array ( <EOL> nsweeps * [ '<STR_LIT>' ] , dtype = '<STR_LIT:S>' ) <EOL> else : <EOL> sweep_mode [ '<STR_LIT:data>' ] = np . array ( nsweeps * [ '<STR_LIT>' ] , dtype = '<STR_LIT:S>' ) <EOL> return Radar ( <EOL> time , _range , fields , metadata , scan_type , <EOL> latitude , longitude , altitude , <EOL> sweep_number , sweep_mode , fixed_angle , sweep_start_ray_index , <EOL> sweep_end_ray_index , <EOL> azimuth , elevation , <EOL> instrument_parameters = instrument_parameters , <EOL> ** extended_header_params ) <EOL> def _is_time_ordered_by_reversal ( data , metadata , rays_per_sweep ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in data : <EOL> ref_time = data [ '<STR_LIT>' ] . copy ( ) <EOL> ref_time . shape = ref_time . shape [ : - <NUM_LIT:1> ] <EOL> else : <EOL> ref_time = metadata [ metadata . keys ( ) [ <NUM_LIT:0> ] ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:0> <EOL> for nrays in rays_per_sweep : <EOL> if nrays == <NUM_LIT:0> or nrays == <NUM_LIT:1> : <EOL> continue <EOL> s = slice ( start , start + nrays ) <EOL> start += nrays <EOL> sweep_time_diff = np . diff ( ref_time [ s ] ) <EOL> if np . all ( sweep_time_diff >= <NUM_LIT:0> ) or np . all ( sweep_time_diff <= <NUM_LIT:0> ) : <EOL> continue <EOL> else : <EOL> return False <EOL> return True <EOL> def _is_time_ordered_by_roll ( data , metadata , rays_per_sweep ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in data : <EOL> ref_time = data [ '<STR_LIT>' ] . copy ( ) <EOL> ref_time . shape = ref_time . shape [ : - <NUM_LIT:1> ] <EOL> else : <EOL> ref_time = metadata [ metadata . keys ( ) [ <NUM_LIT:0> ] ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:0> <EOL> for nrays in rays_per_sweep : <EOL> if nrays == <NUM_LIT:0> or nrays == <NUM_LIT:1> : <EOL> continue <EOL> s = slice ( start , start + nrays ) <EOL> first = ref_time [ start ] <EOL> last = ref_time [ start + nrays - <NUM_LIT:1> ] <EOL> start += nrays <EOL> sweep_time_diff = np . diff ( ref_time [ s ] ) <EOL> count = np . count_nonzero ( sweep_time_diff < <NUM_LIT:0> ) <EOL> if ( first - last ) < <NUM_LIT:0> : <EOL> count += <NUM_LIT:1> <EOL> if count != <NUM_LIT:0> and count != <NUM_LIT:1> : <EOL> return False <EOL> return True <EOL> def _is_time_ordered_by_reverse_roll ( data , metadata , rays_per_sweep ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in data : <EOL> ref_time = data [ '<STR_LIT>' ] . copy ( ) <EOL> ref_time . shape = ref_time . shape [ : - <NUM_LIT:1> ] <EOL> else : <EOL> ref_time = metadata [ metadata . keys ( ) [ <NUM_LIT:0> ] ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:0> <EOL> for nrays in rays_per_sweep : <EOL> if nrays == <NUM_LIT:0> or nrays == <NUM_LIT:1> : <EOL> continue <EOL> s = slice ( start , start + nrays ) <EOL> first = ref_time [ start ] <EOL> last = ref_time [ start + nrays - <NUM_LIT:1> ] <EOL> start += nrays <EOL> sweep_time_diff = np . diff ( ref_time [ s ] ) <EOL> if sweep_time_diff . min ( ) < <NUM_LIT:0> : <EOL> sweep_time_diff = np . diff ( ref_time [ s ] [ : : - <NUM_LIT:1> ] ) <EOL> first , last = last , first <EOL> count = np . count_nonzero ( sweep_time_diff < <NUM_LIT:0> ) <EOL> if ( first - last ) < <NUM_LIT:0> : <EOL> count += <NUM_LIT:1> <EOL> if count != <NUM_LIT:0> and count != <NUM_LIT:1> : <EOL> return False <EOL> return True <EOL> def _time_order_data_and_metadata_roll ( data , metadata , rays_per_sweep ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in data : <EOL> ref_time = data [ '<STR_LIT>' ] . copy ( ) <EOL> ref_time . shape = ref_time . shape [ : - <NUM_LIT:1> ] <EOL> else : <EOL> ref_time = metadata [ metadata . keys ( ) [ <NUM_LIT:0> ] ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:0> <EOL> for nrays in rays_per_sweep : <EOL> if nrays == <NUM_LIT:0> or nrays == <NUM_LIT:1> : <EOL> continue <EOL> s = slice ( start , start + nrays ) <EOL> start += nrays <EOL> sweep_time = ref_time [ s ] <EOL> sweep_time_diff = np . diff ( sweep_time ) <EOL> if sweep_time_diff . min ( ) >= <NUM_LIT:0> : <EOL> continue <EOL> shift = - ( sweep_time_diff . argmin ( ) + <NUM_LIT:1> ) <EOL> for field in data . keys ( ) : <EOL> data [ field ] [ s ] = np . roll ( data [ field ] [ s ] , shift , axis = <NUM_LIT:0> ) <EOL> field_metadata = metadata [ field ] <EOL> for key in field_metadata . keys ( ) : <EOL> field_metadata [ key ] [ s ] = np . roll ( field_metadata [ key ] [ s ] , shift ) <EOL> return <EOL> def _time_order_data_and_metadata_reverse ( data , metadata , rays_per_sweep ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in data : <EOL> ref_time = data [ '<STR_LIT>' ] . copy ( ) <EOL> ref_time . shape = ref_time . shape [ : - <NUM_LIT:1> ] <EOL> else : <EOL> ref_time = metadata [ metadata . keys ( ) [ <NUM_LIT:0> ] ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:0> <EOL> for nrays in rays_per_sweep : <EOL> if nrays == <NUM_LIT:0> or nrays == <NUM_LIT:1> : <EOL> continue <EOL> s = slice ( start , start + nrays ) <EOL> start += nrays <EOL> sweep_time = ref_time [ s ] <EOL> sweep_time_diff = np . diff ( sweep_time ) <EOL> if sweep_time_diff . min ( ) >= <NUM_LIT:0> : <EOL> continue <EOL> for field in data . keys ( ) : <EOL> data [ field ] [ s ] = data [ field ] [ s ] [ : : - <NUM_LIT:1> ] <EOL> field_metadata = metadata [ field ] <EOL> for key in field_metadata . keys ( ) : <EOL> field_metadata [ key ] [ s ] = field_metadata [ key ] [ s ] [ : : - <NUM_LIT:1> ] <EOL> return <EOL> def _time_order_data_and_metadata_full ( data , metadata , rays_per_sweep ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in data : <EOL> ref_time = data [ '<STR_LIT>' ] . copy ( ) <EOL> ref_time . shape = ref_time . shape [ : - <NUM_LIT:1> ] <EOL> else : <EOL> ref_time = metadata [ metadata . keys ( ) [ <NUM_LIT:0> ] ] [ '<STR_LIT:time>' ] . astype ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:0> <EOL> for nrays in rays_per_sweep : <EOL> if nrays == <NUM_LIT:0> or nrays == <NUM_LIT:1> : <EOL> continue <EOL> s = slice ( start , start + nrays ) <EOL> start += nrays <EOL> sweep_time = ref_time [ s ] <EOL> sweep_time_diff = np . diff ( ref_time [ s ] ) <EOL> if sweep_time_diff . min ( ) >= <NUM_LIT:0> : <EOL> continue <EOL> sort_idx = np . argsort ( sweep_time , kind = '<STR_LIT>' ) <EOL> for field in data . keys ( ) : <EOL> data [ field ] [ s ] = data [ field ] [ s ] [ sort_idx ] <EOL> field_metadata = metadata [ field ] <EOL> for key in field_metadata . keys ( ) : <EOL> field_metadata [ key ] [ s ] = field_metadata [ key ] [ s ] [ sort_idx ] <EOL> return <EOL> def ymds_time_to_datetime ( ymds ) : <EOL> """<STR_LIT>""" <EOL> dt = datetime . datetime ( ymds [ '<STR_LIT>' ] , ymds [ '<STR_LIT>' ] , ymds [ '<STR_LIT>' ] ) <EOL> microsec = <NUM_LIT> * ( ymds [ '<STR_LIT>' ] & <NUM_LIT> ) <EOL> delta = datetime . timedelta ( seconds = ymds [ '<STR_LIT>' ] , microseconds = microsec ) <EOL> return dt + delta </s>
