def read_patmosx_geoobj_hdf(patmosx_hdf, filename, cross, SETTINGS): """Read geolocation and time info from filename.""" cloudproducts = AllImagerData() name = 'latitude' temp = patmosx_hdf.select(name).get().astype(np.float) offset = patmosx_hdf.select(name).attributes()['add_offset'] gain = patmosx_hdf.select(name).attributes()['scale_factor'] latitude_v = temp * gain + offset name = 'longitude' temp = patmosx_hdf.select(name).get().astype(np.float) offset = patmosx_hdf.select(name).attributes()['add_offset'] gain = patmosx_hdf.select(name).attributes()['scale_factor'] longitude_v = temp * gain + offset cloudproducts.latitude = np.repeat(latitude_v[:, np.newaxis], len(longitude_v), axis=1) cloudproducts.longitude = np.repeat(longitude_v[np.newaxis, :], len(latitude_v), axis=0) cloudproducts.nodata = -999 date_time_start = cross.time date_time_end = cross.time + timedelta(seconds=SETTINGS['SAT_ORBIT_DURATION']) cloudproducts.sec1970_start = calendar.timegm(date_time_start.timetuple()) cloudproducts.sec1970_end = calendar.timegm(date_time_end.timetuple()) frac_hour = patmosx_hdf.select('scan_line_time').get().astype(np.float) if np.ma.is_masked(frac_hour): frac_hour = frac_hour.data seconds = frac_hour*60*60.0 time_s = patmosx_hdf.attributes()['time_coverage_start'] dt_obj = datetime.strptime(time_s, "%Y-%m-%dT%H:%M:%SZ") time_sec_1970 = calendar.timegm(dt_obj.timetuple()) cloudproducts.time = seconds + time_sec_1970 do_some_geo_obj_logging(cloudproducts) return cloudproducts
def read_maia_geoobj(maia_h5, filename): """Read geolocation and time info from filename """ cloudproducts = AllImagerData() cloudproducts.latitude = 0.0001 * maia_h5['DATA']['Latitude'].value cloudproducts.longitude = 0.0001 * maia_h5['DATA']['Longitude'].value cloudproducts.nodata = 999 cloudproducts.longitude[cloudproducts.longitude == -9999] = cloudproducts.nodata cloudproducts.latitude[cloudproducts.latitude == -9999] = cloudproducts.nodata # viiCT_npp_GL_20150711_S211124_E211248_ASC_D_La-40_Lo-108_19188.h5 # viiCT_npp_DB_20120817_S035411_E035535_DES_N_La052_Lo-027_00001.h5 sl_ = os.path.basename(filename).split('_') date_time_start = datetime.strptime(sl_[3] + sl_[4], '%Y%m%dS%H%M%S') date_time_end = datetime.strptime(sl_[3] + sl_[5], '%Y%m%dE%H%M%S') cloudproducts.sec1970_start = calendar.timegm(date_time_start.timetuple()) cloudproducts.sec1970_end = calendar.timegm(date_time_end.timetuple()) cloudproducts.num_of_lines = cloudproducts.latitude.shape[0] cloudproducts = create_imager_time(cloudproducts, values={}) do_some_geo_obj_logging(cloudproducts) return cloudproducts
def read_pps_geoobj_nc(pps_nc): """Read geolocation and time info from netcdf file.""" all_imager_obj = AllImagerData() longitude = pps_nc.variables['lon'][::] if np.ma.is_masked(longitude): all_imager_obj.longitude = pps_nc.variables['lon'][::].data all_imager_obj.longitude[longitude.mask] = -999.0 else: all_imager_obj.longitude = longitude latitude = pps_nc.variables['lat'][::] if np.ma.is_masked(latitude): all_imager_obj.latitude = pps_nc.variables['lat'][::].data all_imager_obj.latitude[latitude.mask] = -999.0 else: all_imager_obj.latitude = latitude all_imager_obj.nodata = pps_nc.variables['lon']._FillValue all_imager_obj.num_of_lines = all_imager_obj.latitude.shape[0] # import pdb # pdb.set_trace() time_temp = pps_nc.variables['time'].units # to 1970 s seconds = np.float64(pps_nc.variables['time'][::]) # from PPS often 0 if 'seconds' in time_temp: if 'T' in time_temp: time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%dT%H:%M:%S+00:00') elif time_temp == u'seconds since 1970-01-01': time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%d') else: time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%d %H:%M:%S.%f +00:00') sec_since_1970 = calendar.timegm(time_obj) all_imager_obj.sec1970_start = (sec_since_1970 + np.float64(np.min(pps_nc.variables['time_bnds'][::])) + seconds) all_imager_obj.sec1970_end = (sec_since_1970 + np.float64(np.max(pps_nc.variables['time_bnds'][::])) + seconds) else: try: all_imager_obj.sec1970_start = calendar.timegm(time.strptime(pps_nc.variables['lon'].start_time, '%Y-%m-%d %H:%M:%S.%f')) all_imager_obj.sec1970_end = calendar.timegm(time.strptime(pps_nc.variables['lon'].end_time, '%Y-%m-%d %H:%M:%S.%f')) except: all_imager_obj.sec1970_start = calendar.timegm(time.strptime(pps_nc.start_time, '%Y-%m-%d %H:%M:%S')) all_imager_obj.sec1970_end = calendar.timegm(time.strptime(pps_nc.end_time, '%Y-%m-%d %H:%M:%S')) # print type(all_imager_obj.sec1970_start) all_imager_obj.sec1970_start = np.float64(all_imager_obj.sec1970_start) all_imager_obj.sec1970_end = np.float64(all_imager_obj.sec1970_end) do_some_geo_obj_logging(all_imager_obj) return all_imager_obj
def oca_read_all(filename): if 'MYD' in os.path.basename(filename): cloudproducts = oca_read_all_nc_modis(filename) logger.info("No timeinfo in OCA-MODIS file calculate from filename + 5min") time_info = get_satid_datetime_orbit_from_fname_oca(filename) cloudproducts.sec1970_start = calendar.timegm(time_info["date_time"].timetuple()) cloudproducts.sec1970_end = cloudproducts.sec1970_start + 60*5 cloudproducts = create_imager_time(cloudproducts, values={}) cloudproducts.instrument = 'modis' do_some_geo_obj_logging(cloudproducts) return(cloudproducts) return oca_read_all_nc(filename)
def read_oca_geoobj(oca_nc, filename): """Read geolocation and time info from filename.""" cloudproducts = AllImagerData() # import pdb;pdb.set_trace() cloudproducts.longitude, cloudproducts.nodata = scale_oca_var(oca_nc['data']['measurement_data']['longitude']) cloudproducts.latitude, cloudproducts.nodata = scale_oca_var(oca_nc['data']['measurement_data']['latitude']) cloudproducts.num_of_lines = cloudproducts.longitude.shape[0] cloudproducts.nodata = -999 # sensing_start_time_utc and sensing_end_time_utc, stime = getattr(oca_nc, "sensing_start_time_utc") etime = getattr(oca_nc, "sensing_end_time_utc") cloudproducts.sec1970_start = calendar.timegm( time.strptime(stime, '%Y%m%d%H%M%S.%f')) cloudproducts.sec1970_end = calendar.timegm( time.strptime(etime, '%Y%m%d%H%M%S.%f')) cloudproducts = create_imager_time(cloudproducts, values={}) do_some_geo_obj_logging(cloudproducts) return cloudproducts
def read_patmosx_geoobj(patmosx_nc, filename, cross, SETTINGS): """Read geolocation and time info from filename.""" cloudproducts = AllImagerData() latitude_v = patmosx_nc.variables['latitude'][:].astype(np.float) longitude_v = patmosx_nc.variables['longitude'][:].astype(np.float) cloudproducts.latitude = np.repeat(latitude_v[:, np.newaxis], len(longitude_v), axis=1) cloudproducts.longitude = np.repeat(longitude_v[np.newaxis, :], len(latitude_v), axis=0) cloudproducts.nodata = -999 date_time_start = cross.time date_time_end = cross.time + timedelta(seconds=SETTINGS['SAT_ORBIT_DURATION']) cloudproducts.sec1970_start = calendar.timegm(date_time_start.timetuple()) cloudproducts.sec1970_end = calendar.timegm(date_time_end.timetuple()) frac_hour = patmosx_nc.variables['scan_line_time'][0, :, :].astype(np.float) if np.ma.is_masked(frac_hour): frac_hour = frac_hour.data seconds = frac_hour*60*60.0 cloudproducts.time = seconds + patmosx_nc.variables['time'] do_some_geo_obj_logging(cloudproducts) return cloudproducts
def read_cci_geoobj(cci_nc): """Read geolocation and time info from filename """ cloudproducts = AllImagerData() logger.debug("Min lon: %s, max lon: %d", np.min(cci_nc.variables['lon'][::]), np.max(cci_nc.variables['lon'][::])) # cci_nc.variables['lon'].add_offset # cloudproducts.longitude = cci_nc.variables['lon'][::] cloudproducts.nodata = -999.0 in_fillvalue = cci_nc.variables['lon']._FillValue cloudproducts.longitude = cci_nc.variables['lon'][::] cloudproducts.longitude[cci_nc.variables['lon'][::] == in_fillvalue] = cloudproducts.nodata cloudproducts.latitude = cci_nc.variables['lon'][::] cloudproducts.latitude[cci_nc.variables['lon'][::] == in_fillvalue] = cloudproducts.nodata np.where( np.logical_and( np.greater_equal(cci_nc.variables['lon'][::], cci_nc.variables['lon'].valid_min), np.less_equal(cci_nc.variables['lon'][::], cci_nc.variables['lon'].valid_max)), cci_nc.variables['lon'][::], cloudproducts.nodata) # cloudproducts.latitude = cci_nc.variables['lat'][::] cloudproducts.latitude = np.where( np.logical_and( np.greater_equal(cci_nc.variables['lat'][::], cci_nc.variables['lat'].valid_min), np.less_equal(cci_nc.variables['lat'][::], cci_nc.variables['lat'].valid_max)), cci_nc.variables['lat'][::], cloudproducts.nodata) # For pps these are calculated in calipso.py, but better read them # from file because time are already available on arrays in the netcdf files # dsec = calendar.timegm((1993, 1, 1, 0, 0, 0, 0, 0, 0)) # TAI to UTC time_temp = daysafter4713bc_to_sec1970(cci_nc.variables['time'][::]) cloudproducts.time = time_temp[::] # [:, 0] # time_temp[:, 0] cloudproducts.sec1970_start = np.min(cloudproducts.time) cloudproducts.sec1970_end = np.max(cloudproducts.time) do_some_geo_obj_logging(cloudproducts) return cloudproducts
def read_pps_geoobj_h5(filename): """Read geolocation and time info from filename hdf5.""" h5file = h5py.File(filename, 'r') all_imager_obj = AllImagerData() in_fillvalue1 = h5file['where/lon/what'].attrs['nodata'] in_fillvalue2 = h5file['where/lon/what'].attrs['missingdata'] all_imager_obj.nodata = -999.0 gain = h5file['where/lon/what'].attrs['gain'] intercept = h5file['where/lon/what'].attrs['offset'] all_imager_obj.longitude = h5file['where/lon']['data'].value*gain + intercept all_imager_obj.latitude = h5file['where/lat']['data'].value*gain + intercept all_imager_obj.longitude[h5file['where/lon']['data'].value == in_fillvalue1] = all_imager_obj.nodata all_imager_obj.latitude[h5file['where/lat']['data'].value == in_fillvalue1] = all_imager_obj.nodata all_imager_obj.longitude[h5file['where/lon']['data'].value == in_fillvalue2] = all_imager_obj.nodata all_imager_obj.latitude[h5file['where/lat']['data'].value == in_fillvalue2] = all_imager_obj.nodata all_imager_obj.num_of_lines = all_imager_obj.latitude.shape[0] all_imager_obj.sec1970_start = h5file['how'].attrs['startepochs'] all_imager_obj.sec1970_end = h5file['how'].attrs['endepochs'] do_some_geo_obj_logging(all_imager_obj) return all_imager_obj