def match_synop_imager(synop, cloudproducts, SETTINGS): retv = TruthImagerTrackObject(truth='synop') retv.imager_instrument = cloudproducts.instrument.lower() retv.synop = synop from atrain_match.utils.common import map_imager_distances n_neighbours = 250 if config.RESOLUTION == 5: n_neighbours = 16 mapper_and_dist = map_imager_distances(cloudproducts, synop.longitude.ravel(), synop.latitude.ravel(), radius_of_influence=SETTINGS["SYNOP_RADIUS"], n_neighbours=n_neighbours) # pdb.set_trace() cal, cap = mapper_and_dist["mapper"] distances = mapper_and_dist["distances"] cal_1 = cal[:, 0] cap_1 = cap[:, 0] calnan = np.where(cal_1 == config.NODATA, np.nan, cal_1) if (~np.isnan(calnan)).sum() == 0: logger.warning("No matches within region.") return None # check if it is within time limits: if len(cloudproducts.time.shape) > 1: imager_time_vector = [cloudproducts.time[line, pixel] for line, pixel in zip(cal_1, cap_1)] imager_lines_sec_1970 = np.where(cal_1 != config.NODATA, imager_time_vector, np.nan) else: imager_lines_sec_1970 = np.where(cal_1 != config.NODATA, cloudproducts.time[cal_1], np.nan) idx_match = elements_within_range(synop.sec_1970, imager_lines_sec_1970, SETTINGS["sec_timeThr_synop"]) if idx_match.sum() == 0: logger.warning("No matches in region within time threshold %d s.", SETTINGS["sec_timeThr_synop"]) return None retv.synop = retv.synop.extract_elements(idx=idx_match) # Synop line, pixel inside IMAGER swath (one nearest neighbour): retv.synop.imager_linnum = np.repeat(cal_1, idx_match).astype('i') retv.synop.imager_pixnum = np.repeat(cap_1, idx_match).astype('i') # Synop line, pixel inside IMAGER swath (several neighbours): retv.synop.imager_linnum_nneigh = np.repeat(cal, idx_match, axis=0) retv.synop.imager_pixnum_nneigh = np.repeat(cap, idx_match, axis=0) retv.synop.imager_synop_dist = np.repeat(distances, idx_match, axis=0) # Imager time retv.imager.sec_1970 = np.repeat(imager_lines_sec_1970, idx_match) retv.diff_sec_1970 = retv.synop.sec_1970 - retv.imager.sec_1970 do_some_logging(retv, synop) logger.debug("Extract imager along track!") retv = imager_track_from_matched(retv, SETTINGS, cloudproducts, extract_radiances=False, extract_ctth=False, extract_cpp=False, extract_aux_segments=False, aux_params=['fractionofland', 'landuse'], find_mean_data_for_x_neighbours=True) return retv
def match_calipso_imager(values, calipso, calipso_aerosol, cloudproducts, SETTINGS, res=config.RESOLUTION): from atrain_match.utils.common import map_imager retv = TruthImagerTrackObject(truth='calipso') retv.imager_instrument = cloudproducts.instrument.lower() retv.calipso = calipso cal, cap = map_imager(cloudproducts, calipso.longitude.ravel(), calipso.latitude.ravel(), radius_of_influence=config.RESOLUTION * 0.7 * 1000.0) # somewhat larger than radius... # warn if no matches calnan = np.where(cal == config.NODATA, np.nan, cal) if (~np.isnan(calnan)).sum() == 0: logger.warning("No matches within region.") return None # check if it is within time limits: if len(cloudproducts.time.shape) > 1: imager_time_vector = [ cloudproducts.time[line, pixel] for line, pixel in zip(cal, cap) ] imager_lines_sec_1970 = np.where(cal != config.NODATA, imager_time_vector, np.nan) else: imager_lines_sec_1970 = np.where(cal != config.NODATA, cloudproducts.time[cal], np.nan) idx_match = elements_within_range(calipso.sec_1970, imager_lines_sec_1970, SETTINGS["sec_timeThr"]) if idx_match.sum() == 0: logger.warning("No matches in region within time threshold %d s.", SETTINGS["sec_timeThr"]) return None retv.calipso = retv.calipso.extract_elements(idx=idx_match) # Calipso line, pixel inside IMAGER swath: retv.calipso.imager_linnum = np.repeat(cal, idx_match).astype('i') retv.calipso.imager_pixnum = np.repeat(cap, idx_match).astype('i') # Imager time retv.imager.sec_1970 = imager_lines_sec_1970[idx_match.ravel()] retv.diff_sec_1970 = retv.calipso.sec_1970 - retv.imager.sec_1970 do_some_logging(retv, calipso) logger.debug("Generate the latitude, cloudtype tracks!") from atrain_match.libs.extract_imager_along_track import imager_track_from_matched retv = imager_track_from_matched(retv, SETTINGS, cloudproducts) if calipso_aerosol is not None: retv.calipso_aerosol = calipso_aerosol.extract_elements(idx=idx_match) max_cloud_top_calipso = np.maximum.reduce( retv.calipso.layer_top_altitude.ravel()) logger.debug("max_cloud_top_calipso: %2.1f", max_cloud_top_calipso) return retv
def match_mora_imager(mora, cloudproducts, SETTINGS): retv = TruthImagerTrackObject('mora') retv.imager_instrument = cloudproducts.instrument.lower() retv.mora = mora from atrain_match.utils.common import map_imager """ import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) from atrain_match.plotting.histogram_plotting import distribution_map plt.plot(cloudproducts.longitude.ravel(), cloudproducts.latitude.ravel(), 'r.') plt.plot(mora.longitude.ravel(), mora.latitude.ravel(), 'b.') plt.show() """ cal, cap = map_imager(cloudproducts, mora.longitude.ravel(), mora.latitude.ravel(), radius_of_influence=config.RESOLUTION*0.7*1000.0) calnan = np.where(cal == config.NODATA, np.nan, cal) if (~np.isnan(calnan)).sum() == 0: logger.warning("No matches within region.") return None # check if it is within time limits: if len(cloudproducts.time.shape) > 1: imager_time_vector = [cloudproducts.time[line, pixel] for line, pixel in zip(cal, cap)] imager_lines_sec_1970 = np.where(cal != config.NODATA, imager_time_vector, np.nan) else: imager_lines_sec_1970 = np.where(cal != config.NODATA, cloudproducts.time[cal], np.nan) idx_match = elements_within_range(mora.sec_1970, imager_lines_sec_1970, SETTINGS["sec_timeThr_synop"]) if idx_match.sum() == 0: logger.warning("No matches in region within time threshold %d s.", SETTINGS["sec_timeThr_synop"]) return None retv.mora = retv.mora.extract_elements(idx=idx_match) # Mora line, pixel inside IMAGER swath (one nearest neighbour): retv.mora.imager_linnum = np.repeat(cal, idx_match).astype('i') retv.mora.imager_pixnum = np.repeat(cap, idx_match).astype('i') # Imager time retv.imager.sec_1970 = np.repeat(imager_lines_sec_1970, idx_match) retv.diff_sec_1970 = retv.mora.sec_1970 - retv.imager.sec_1970 do_some_logging(retv, mora) logger.debug("Extract imager along track!") retv = imager_track_from_matched(retv, SETTINGS, cloudproducts, extract_nwp_segments=False) return retv
def match_iss_imager(iss, cloudproducts, SETTINGS): retv = TruthImagerTrackObject(truth='iss') retv.imager_instrument = cloudproducts.instrument.lower() retv.iss = iss from atrain_match.utils.common import map_imager cal, cap = map_imager(cloudproducts, iss.longitude.ravel(), iss.latitude.ravel(), radius_of_influence=config.RESOLUTION * 0.7 * 1000.0) # larger than radius... calnan = np.where(cal == config.NODATA, np.nan, cal) if (~np.isnan(calnan)).sum() == 0: logger.warning("No matches within region.") return None # check if it is within time limits: if len(cloudproducts.time.shape) > 1: imager_time_vector = [ cloudproducts.time[line, pixel] for line, pixel in zip(cal, cap) ] imager_lines_sec_1970 = np.where(cal != config.NODATA, imager_time_vector, np.nan) else: imager_lines_sec_1970 = np.where(cal != config.NODATA, cloudproducts.time[cal], np.nan) # Find all matching Iss pixels within +/- sec_timeThr from the IMAGER data idx_match = elements_within_range(iss.sec_1970, imager_lines_sec_1970, SETTINGS["sec_timeThr"]) if idx_match.sum() == 0: logger.warning("No matches in region within time threshold %d s.", SETTINGS["sec_timeThr"]) return None retv.iss = retv.iss.extract_elements(idx=idx_match) # Calipso line, pixel inside IMAGER swath: retv.iss.imager_linnum = np.repeat(cal, idx_match).astype('i') retv.iss.imager_pixnum = np.repeat(cap, idx_match).astype('i') # Imager time retv.imager.sec_1970 = np.repeat(imager_lines_sec_1970, idx_match) retv.diff_sec_1970 = retv.iss.sec_1970 - retv.imager.sec_1970 do_some_logging(retv, iss) logger.info("Generate the latitude, cloudtype tracks!") retv = imager_track_from_matched(retv, SETTINGS, cloudproducts) return retv
def match_amsr_imager(amsr, cloudproducts, SETTINGS): retv = TruthImagerTrackObject(truth='amsr') retv.imager_instrument = cloudproducts.instrument.lower() retv.amsr = amsr if (getattr(cloudproducts.cpp, "cpp_lwp") < 0).all(): logger.warning("Not matching AMSR-E with scene with no lwp.") return None # return MatchupError("No imager Lwp.") # if only LWP matching? from atrain_match.utils.common import map_imager_distances n_neighbours = 8 if config.RESOLUTION == 5: n_neighbours = 5 mapper_and_dist = map_imager_distances(cloudproducts, amsr.longitude.ravel(), amsr.latitude.ravel(), radius_of_influence=AMSR_RADIUS, n_neighbours=n_neighbours) cal, cap = mapper_and_dist["mapper"] distances = mapper_and_dist["distances"] cal_1 = cal[:, 0] cap_1 = cap[:, 0] calnan = np.where(cal_1 == config.NODATA, np.nan, cal_1) if (~np.isnan(calnan)).sum() == 0: logger.warning("No matches within region.") return None # check if it is within time limits: if len(cloudproducts.time.shape) > 1: imager_time_vector = [ cloudproducts.time[line, pixel] for line, pixel in zip(cal_1, cap_1) ] imager_lines_sec_1970 = np.where(cal_1 != config.NODATA, imager_time_vector, np.nan) else: imager_lines_sec_1970 = np.where(cal_1 != config.NODATA, cloudproducts.time[cal_1], np.nan) # Find all matching Amsr pixels within +/- sec_timeThr from the IMAGER data imager_sunz_vector = np.array([ cloudproducts.imager_angles.sunz.data[line, pixel] for line, pixel in zip(cal_1, cap_1) ]) idx_match = np.logical_and( elements_within_range(amsr.sec_1970, imager_lines_sec_1970, SETTINGS["sec_timeThr"]), imager_sunz_vector <= 84) # something larger than 84 (max for lwp) if idx_match.sum() == 0: logger.warning( "No light (sunz<84) matches in region within time threshold %d s.", SETTINGS["sec_timeThr"]) return None retv.amsr = retv.amsr.extract_elements(idx=idx_match) # Amsr line, pixel inside IMAGER swath (one neighbour): retv.amsr.imager_linnum = np.repeat(cal_1, idx_match).astype('i') retv.amsr.imager_pixnum = np.repeat(cap_1, idx_match).astype('i') retv.amsr.imager_linnum_nneigh = np.repeat(cal, idx_match, axis=0) retv.amsr.imager_pixnum_nneigh = np.repeat(cap, idx_match, axis=0) retv.amsr.imager_amsr_dist = np.repeat(distances, idx_match, axis=0) # Imager time retv.imager.sec_1970 = np.repeat(imager_lines_sec_1970, idx_match) retv.diff_sec_1970 = retv.amsr.sec_1970 - retv.imager.sec_1970 do_some_logging(retv, amsr) logger.debug("Extract imager lwp along track!") retv = imager_track_from_matched(retv, SETTINGS, cloudproducts, extract_radiances=False, extract_aux_segments=False, extract_ctth=False, extract_ctype=False, aux_params=['fractionofland', 'landuse'], extract_some_data_for_x_neighbours=True) return retv