<s> """<STR_LIT>""" <EOL> import datetime <EOL> import numpy as np <EOL> import netCDF4 <EOL> from . . config import FileMetadata <EOL> from . . io . common import make_time_unit_str <EOL> from . . core . radar import Radar <EOL> NOXP_FIELD_NAMES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def read_noxp_iphex_nc ( filename , field_names = None , additional_metadata = None , <EOL> file_field_names = False , exclude_fields = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if field_names is None : <EOL> field_names = NOXP_FIELD_NAMES <EOL> filemetadata = FileMetadata ( '<STR_LIT>' , field_names , additional_metadata , <EOL> file_field_names , exclude_fields ) <EOL> ncobj = netCDF4 . Dataset ( filename ) <EOL> ncvars = ncobj . variables <EOL> nsweeps = <NUM_LIT:1> <EOL> latitude = filemetadata ( '<STR_LIT>' ) <EOL> longitude = filemetadata ( '<STR_LIT>' ) <EOL> altitude = filemetadata ( '<STR_LIT>' ) <EOL> latitude [ '<STR_LIT:data>' ] = np . array ( ncvars [ '<STR_LIT>' ] ) <EOL> longitude [ '<STR_LIT:data>' ] = np . array ( ncvars [ '<STR_LIT>' ] ) <EOL> altitude [ '<STR_LIT:data>' ] = np . array ( ncvars [ '<STR_LIT>' ] ) <EOL> metadata = filemetadata ( '<STR_LIT>' ) <EOL> metadata [ '<STR_LIT:source>' ] = '<STR_LIT>' <EOL> metadata [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> metadata [ '<STR_LIT>' ] = ncobj . Radar <EOL> sweep_start_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> sweep_end_ray_index = filemetadata ( '<STR_LIT>' ) <EOL> rays_per_sweep = np . shape ( ncvars [ '<STR_LIT>' ] [ : ] ) <EOL> ssri = np . cumsum ( np . append ( [ <NUM_LIT:0> ] , rays_per_sweep [ : - <NUM_LIT:1> ] ) ) . astype ( '<STR_LIT>' ) <EOL> seri = np . cumsum ( rays_per_sweep ) . astype ( '<STR_LIT>' ) - <NUM_LIT:1> <EOL> sweep_start_ray_index [ '<STR_LIT:data>' ] = ssri <EOL> sweep_end_ray_index [ '<STR_LIT:data>' ] = seri <EOL> sweep_number = filemetadata ( '<STR_LIT>' ) <EOL> sweep_number [ '<STR_LIT:data>' ] = np . arange ( nsweeps , dtype = '<STR_LIT>' ) <EOL> sweep_mode = filemetadata ( '<STR_LIT>' ) <EOL> scan_type = getattr ( ncobj , '<STR_LIT>' ) . lower ( ) <EOL> if scan_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> sweep_mode [ '<STR_LIT:data>' ] = np . array ( nsweeps * [ '<STR_LIT>' + scan_type ] ) <EOL> else : <EOL> sweep_mode [ '<STR_LIT:data>' ] = np . array ( nsweeps * [ '<STR_LIT>' ] ) <EOL> fixed_angle = filemetadata ( '<STR_LIT>' ) <EOL> if scan_type == '<STR_LIT>' : <EOL> sweep_el = ncvars [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> else : <EOL> sweep_el = ncvars [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> fixed_angle [ '<STR_LIT:data>' ] = np . array ( [ sweep_el ] , dtype = '<STR_LIT>' ) <EOL> elevation = filemetadata ( '<STR_LIT>' ) <EOL> elevation [ '<STR_LIT:data>' ] = np . array ( ncvars [ '<STR_LIT>' ] ) <EOL> _range = filemetadata ( '<STR_LIT>' ) <EOL> rng = <NUM_LIT> * ncvars [ '<STR_LIT>' ] [ : ] . T <EOL> _range [ '<STR_LIT:data>' ] = rng [ <NUM_LIT:0> ] <EOL> _range [ '<STR_LIT>' ] = np . mean ( rng [ <NUM_LIT:0> ] [ <NUM_LIT:0> : <NUM_LIT:2> ] ) <EOL> _range [ '<STR_LIT>' ] = np . median ( np . diff ( _range [ '<STR_LIT:data>' ] ) ) <EOL> _range [ '<STR_LIT>' ] = False <EOL> azimuth = filemetadata ( '<STR_LIT>' ) <EOL> azimuth [ '<STR_LIT:data>' ] = np . array ( ncvars [ '<STR_LIT>' ] ) <EOL> _time = filemetadata ( '<STR_LIT:time>' ) <EOL> frac_since_basetime = ncvars [ '<STR_LIT:time>' ] [ <NUM_LIT:0> ] - <NUM_LIT> <EOL> start_time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:3> ) + datetime . timedelta ( frac_since_basetime ) <EOL> _time [ '<STR_LIT>' ] = make_time_unit_str ( start_time ) <EOL> _time [ '<STR_LIT:data>' ] = <NUM_LIT> * <NUM_LIT> * ( ncvars [ '<STR_LIT:time>' ] [ : ] - ncvars [ '<STR_LIT:time>' ] [ <NUM_LIT:0> ] ) . astype ( '<STR_LIT>' ) <EOL> keys = [ k for k , v in ncvars . items ( ) <EOL> if v . dimensions == ( '<STR_LIT>' , '<STR_LIT>' ) and <EOL> k not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> fields = { } <EOL> for key in keys : <EOL> field_name = filemetadata . get_field_name ( key ) <EOL> if field_name is None : <EOL> if exclude_fields is not None and key in exclude_fields : <EOL> continue <EOL> field_name = key <EOL> fields [ field_name ] = _ncvar_to_dict ( ncvars [ key ] ) <EOL> instrument_parameters = { } <EOL> prt = filemetadata ( '<STR_LIT>' ) <EOL> prt [ '<STR_LIT:data>' ] = <NUM_LIT:1.0> / float ( ncobj . PRF [ <NUM_LIT:0> : <NUM_LIT:5> ] ) <EOL> instrument_parameters [ '<STR_LIT>' ] = prt <EOL> frequency = filemetadata ( '<STR_LIT>' ) <EOL> frequency [ '<STR_LIT>' ] = float ( ncobj . Frequency [ <NUM_LIT:0> : <NUM_LIT:4> ] ) * <NUM_LIT> <EOL> instrument_parameters [ '<STR_LIT>' ] = frequency <EOL> hits = filemetadata ( '<STR_LIT>' ) <EOL> hits [ '<STR_LIT:data>' ] = ncobj . Hits <EOL> instrument_parameters [ '<STR_LIT>' ] = hits <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> def _ncvar_to_dict ( ncvar ) : <EOL> """<STR_LIT>""" <EOL> d = dict ( ( k , getattr ( ncvar , k ) ) for k in ncvar . ncattrs ( ) <EOL> if k not in [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> d [ '<STR_LIT:data>' ] = ncvar [ : ] . T <EOL> if np . isscalar ( d [ '<STR_LIT:data>' ] ) : <EOL> d [ '<STR_LIT:data>' ] = np . array ( d [ '<STR_LIT:data>' ] ) <EOL> d [ '<STR_LIT:data>' ] . shape = ( <NUM_LIT:1> , ) <EOL> return d </s>
