Here are the examples of the python api numpy.np_empty taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: mpop Source File: nwcsaf_hrw_hdf.py
def load(satscene, calibrate=True, area_extent=None, read_basic_or_detailed='both', **kwargs):
"""Load MSG SEVIRI High Resolution Wind (HRW) data from hdf5 format.
"""
# Read config file content
conf = ConfigParser()
conf.read(os.path.join(CONFIG_PATH, satscene.fullname + ".cfg"))
values = {"orbit": satscene.orbit,
"satname": satscene.satname,
"number": satscene.number,
"instrument": satscene.instrument_name,
"satellite": satscene.fullname
}
LOG.info("assume seviri-level5")
print "... assume seviri-level5"
satscene.add_to_history("hdf5 data read by mpop/nwcsaf_hrw_hdf.py")
# end of scan time 4 min after start
end_time = satscene.time_slot + datetime.timedelta(minutes=4)
# area !!! satscene.area
filename = os.path.join( satscene.time_slot.strftime(conf.get("seviri-level5", "dir", raw=True)),
satscene.time_slot.strftime(conf.get("seviri-level5", "filename", raw=True)) % values )
# define classes before we search for files (in order to return empty class if no file is found)
HRW_basic = HRW_class()
HRW_basic.detailed = False
HRW_basic.date = satscene.time_slot
HRW_detailed = HRW_class()
HRW_detailed.detailed = True
HRW_detailed.date = satscene.time_slot
print "... search for file: ", filename
filenames=glob(str(filename))
if len(filenames) != 0:
if len(filenames) > 1:
print "*** Warning, more than 1 datafile found: ", filenames
filename = filenames[0]
print("... read data from %s" % str(filename))
# create an instant of the HRW_class
m_per_s_to_knots = 1.944
## limit channels to read
#hrw_channels=['HRV']
# limit basic or detailed or both
#read_basic_or_detailed='detailed'
#read_basic_or_detailed='basic'
with h5py.File(filename,'r') as hf:
#print hf.attrs.keys()
#print hf.attrs.values()
region_name = hf.attrs['REGION_NAME'].replace("_", "")
print "... read HRW data for region ", region_name
LOG.info("... read HRW data for region "+region_name)
sat_ID = GP_IDs[int(hf.attrs["GP_SC_ID"])]
print "... derived from Meteosat ", sat_ID
LOG.info("... derived from Meteosat "+sat_ID)
# print('List of arrays in this file: \n', hf.keys()), len(hf.keys())
if len(hf.keys()) == 0:
print "*** Warning, empty file ", filename
print ""
else:
for key in hf.keys():
if key[4:9] == "BASIC":
if 'read_basic_or_detailed' in locals():
if read_basic_or_detailed.lower() == "detailed":
continue
HRW_data = HRW_basic # shallow copy
elif key[4:12] == "DETAILED":
if 'read_basic_or_detailed' in locals():
if read_basic_or_detailed.lower() == "basic":
continue
HRW_data = HRW_detailed # shallow copy
hrw_chn = dict_channel[key[len(key)-9:]]
if 'hrw_channels' in locals():
if hrw_channels != None:
if hrw_chn not in hrw_channels:
print "... "+hrw_chn+" is not in hrw_channels", hrw_channels
print " skip reading this channel"
continue
# read all data
channel = hf.get(key)
# print '... read wind vectors of channel ', channel.name, hrw_chn
# print " i lon lat speed[kn] dir pressure"
#for i in range(channel.len()):
# print '%3d %10.7f %10.7f %7.2f %7.1f %8.1f' % (channel[i]['wind_id'], channel[i]['lon'], channel[i]['lat'], \
# channel[i]['wind_speed']*m_per_s_to_knots, \
# channel[i]['wind_direction'], channel[i]['pressure'])
# create string array with channel names
channel_chararray = np_empty(channel.len(), dtype='|S6')
channel_chararray[:] = hrw_chn
HRW_data.channel = np_append(HRW_data.channel , channel_chararray )
HRW_data.wind_id = np_append(HRW_data.wind_id , channel[:]['wind_id'] )
HRW_data.prev_wind_id = np_append(HRW_data.prev_wind_id , channel[:]['prev_wind_id'] )
HRW_data.segment_X = np_append(HRW_data.segment_X , channel[:]['segment_X'] )
HRW_data.segment_Y = np_append(HRW_data.segment_Y , channel[:]['segment_Y'] )
HRW_data.t_corr_method = np_append(HRW_data.t_corr_method , channel[:]['t_corr_method'] )
HRW_data.lon = np_append(HRW_data.lon , channel[:]['lon'] )
HRW_data.lat = np_append(HRW_data.lat , channel[:]['lat'] )
HRW_data.dlon = np_append(HRW_data.dlon , channel[:]['dlon'] )
HRW_data.dlat = np_append(HRW_data.dlat , channel[:]['dlat'] )
HRW_data.pressure = np_append(HRW_data.pressure , channel[:]['pressure'] )
HRW_data.wind_speed = np_append(HRW_data.wind_speed , channel[:]['wind_speed'] )
HRW_data.wind_direction = np_append(HRW_data.wind_direction , channel[:]['wind_direction'] )
HRW_data.temperature = np_append(HRW_data.temperature , channel[:]['temperature'] )
HRW_data.conf_nwp = np_append(HRW_data.conf_nwp , channel[:]['conf_nwp'] )
HRW_data.conf_no_nwp = np_append(HRW_data.conf_no_nwp , channel[:]['conf_no_nwp'] )
HRW_data.t_type = np_append(HRW_data.t_type , channel[:]['t_type'] )
HRW_data.t_level_method = np_append(HRW_data.t_level_method , channel[:]['t_level_method'] )
HRW_data.t_winds = np_append(HRW_data.t_winds , channel[:]['t_winds'] )
HRW_data.t_corr_test = np_append(HRW_data.t_corr_test , channel[:]['t_corr_test'] )
HRW_data.applied_QI = np_append(HRW_data.applied_QI , channel[:]['applied_QI'] )
HRW_data.NWP_wind_levels = np_append(HRW_data.NWP_wind_levels , channel[:]['NWP_wind_levels'] )
HRW_data.num_prev_winds = np_append(HRW_data.num_prev_winds , channel[:]['num_prev_winds'] )
HRW_data.orographic_index = np_append(HRW_data.orographic_index, channel[:]['orographic_index'] )
HRW_data.cloud_type = np_append(HRW_data.cloud_type , channel[:]['cloud_type'] )
HRW_data.wind_channel = np_append(HRW_data.wind_channel , channel[:]['wind_channel'] )
HRW_data.correlation = np_append(HRW_data.correlation , channel[:]['correlation'] )
HRW_data.pressure_error = np_append(HRW_data.pressure_error , channel[:]['pressure_error'] )
# sort according to wind_id
inds = HRW_data.wind_id.argsort()
HRW_data.subset(inds) # changes HRW_data itself
# sorting without conversion to numpy arrays
#[e for (wid,pwid) in sorted(zip(HRW_data.wind_id,HRW_data.prev_wind_id))]
else:
print "*** Error, no file found"
print ""
sat_ID = "no file"
# but we continue the program in order to add an empty channel below
## filter data according to the given optional arguments
#n1 = str(HRW_data.channel.size)
#HRW_data = HRW_data.filter(**kwargs)
#print " apply filters "+' ('+n1+'->'+str(HRW_data.channel.size)+')'
chn_name="HRW"
satscene[chn_name].HRW_basic = HRW_basic.filter(**kwargs) # returns new object (deepcopied and filtered)
satscene[chn_name].HRW_detailed = HRW_detailed.filter(**kwargs) # returns new object (deepcopied and filtered)
satscene[chn_name].info['units'] = 'm/s'
satscene[chn_name].info['satname'] = 'meteosat'
satscene[chn_name].info['satnumber'] = sat_ID
satscene[chn_name].info['instrument_name'] = 'seviri'
satscene[chn_name].info['time'] = satscene.time_slot
satscene[chn_name].info['is_calibrated'] = True