def get_area_from_acq_location(geojson, aoi_location): logger.info("geojson : %s" % geojson) land_area = 0 water_area = 0 intersection, int_env = util.get_intersection(aoi_location, geojson) logger.info("intersection : %s" % intersection) polygon_type = intersection['type'] logger.info("get_area_from_acq_location : intersection polygon_type : %s" % polygon_type) if polygon_type == "MultiPolygon": logger.info("\n\nMULTIPOLIGON\n\n") land_area = lightweight_water_mask.get_land_area(intersection) water_area = lightweight_water_mask.get_water_area(intersection) logger.info("covers_land : %s " % lightweight_water_mask.covers_land(geojson)) logger.info("covers_water : %s " % lightweight_water_mask.covers_water(geojson)) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_water_area(geojson) : %s " % water_area) return land_area, water_area
def get_area_from_orbit_file(tstart, tend, mision, orbit_file, orbit_dir, aoi_location): water_area = 0 land_area = 0 logger.info("tstart : %s tend : %s" % (tstart, tend)) geojson = get_groundTrack_footprint(tstart, tend, mission, orbit_file, orbit_dir) land_area = 0 water_area = 0 intersection, int_env = util.get_intersection(aoi_location, geojson) logger.info("intersection : %s" % intersection) polygon_type = intersection['type'] logger.info("intersection polygon_type : %s" % polygon_type) if polygon_type == "MultiPolygon": logger.info("\n\nMULTIPOLIGON\n\n") land_area = lightweight_water_mask.get_land_area(intersection) logger.info("get_land_area(geojson) : %s " % land_area) water_area = lightweight_water_mask.get_water_area(intersection) logger.info("covers_land : %s " % lightweight_water_mask.covers_land(geojson)) logger.info("covers_water : %s " % lightweight_water_mask.covers_water(geojson)) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_water_area(geojson) : %s " % water_area) return land_area, water_area
def get_aoi_area_polygon(geojson, aoi_location): water_area = 0 land_area = 0 intersect, intersection, int_env = util.get_intersection( aoi_location, geojson) if not intersect: return land_area, water_area, None logger.info("intersection : %s" % intersection) if "coordinates" in intersection: coordinates = intersection["coordinates"] cord = change_coordinate_direction(coordinates[0]) intersection = {"type": "Polygon", "coordinates": [cord]} logger.info("get_aoi_area_polygon : cord : %s" % cord) try: land_area = lightweight_water_mask.get_land_area(intersection) logger.info("get_land_area(geojson) : %s " % land_area) except Exception as err: logger.info("Getting Land Area Failed for geojson : %s" % intersection) cord = intersection["coordinates"][0] rotated_cord = [cord[::-1]] rotated_intersection = {"type": "Polygon", "coordinates": rotated_cord} logger.info("rorated_intersection : %s" % rotated_intersection) land_area = lightweight_water_mask.get_land_area(rotated_intersection) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_water_area(geojson) : %s " % water_area) return land_area, water_area, intersection
def get_area_from_orbit_file(tstart, tend, mision, orbit_file, orbit_dir, aoi_location): water_area = 0 land_area = 0 logger.info("tstart : %s tend : %s" % (tstart, tend)) geojson = get_groundTrack_footprint(tstart, tend, mission, orbit_file, orbit_dir) land_area = 0 water_area = 0 intersect, intersection, int_env = util.get_intersection( aoi_location, geojson) if intersect: logger.info("intersection : %s" % intersection) land_area = lightweight_water_mask.get_land_area(intersection) logger.info("get_land_area(geojson) : %s " % land_area) water_area = lightweight_water_mask.get_water_area(intersection) logger.info("covers_land : %s " % lightweight_water_mask.covers_land(geojson)) logger.info("covers_water : %s " % lightweight_water_mask.covers_water(geojson)) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_water_area(geojson) : %s " % water_area) return land_area, water_area
def get_master_slave_intersect_data(ref_acq, matched_acqs, acq_dict): """Return polygon of union of acquisition footprints.""" union_geojson = get_union_geometry(acq_dict) intersect_geojson, int_env = util.get_intersection(ref_acq.location, union_geojson) starttimes = [ref_acq.starttime] endtime = ref_acq.endtime return intersect_geojson, starttime.strftime( "%Y-%m-%dT%H:%M:%S"), endtime.strftime("%Y-%m-%dT%H:%M:%S")
def get_area_from_acq_location(geojson, aoi_location): logger.info("geojson : %s" % geojson) land_area = 0 water_area = 0 intersect, intersection, int_env = util.get_intersection( aoi_location, geojson) if intersect: logger.info("intersection : %s" % intersection) land_area = lightweight_water_mask.get_land_area(intersection) water_area = lightweight_water_mask.get_water_area(intersection) logger.info("covers_land : %s " % lightweight_water_mask.covers_land(geojson)) logger.info("covers_water : %s " % lightweight_water_mask.covers_water(geojson)) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_water_area(geojson) : %s " % water_area) return land_area, water_area
def get_aoi_area_polygon(geojson, aoi_location): water_area = 0 land_area = 0 logger.info( "\nget_aoi_area_polygon : \ngeojson : %s, \naoi_location : %s" % (geojson, aoi_location)) intersection, int_env = util.get_intersection(aoi_location, geojson) logger.info("intersection : %s" % intersection) polygon_type = intersection['type'] logger.info("intersection polygon_type : %s" % polygon_type) if polygon_type == "MultiPolygon": logger.info("\n\nMULTIPOLIGON\n\n") return get_aoi_area_multipolygon(intersection, aoi_location) if "coordinates" in intersection: coordinates = intersection["coordinates"] cord = change_coordinate_direction(coordinates[0]) intersection = {"type": "Polygon", "coordinates": [cord]} logger.info("get_aoi_area_polygon : cord : %s" % cord) try: land_area = lightweight_water_mask.get_land_area(intersection) logger.info("get_land_area(geojson) : %s " % land_area) except Exception as err: logger.info("Getting Land Area Failed for geojson : %s" % intersection) cord = intersection["coordinates"][0] rotated_cord = [cord[::-1]] rotated_intersection = {"type": "Polygon", "coordinates": rotated_cord} logger.info("rorated_intersection : %s" % rotated_intersection) land_area = lightweight_water_mask.get_land_area(rotated_intersection) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_land_area(geojson) : %s " % land_area) logger.info("get_water_area(geojson) : %s " % water_area) return land_area, water_area, intersection
def iterate_batch(self, split, batch_size): ids = list(self._ids[split]) if split == 'train': print('Randomly shuffle training data ...') random.shuffle(ids) current = 0 while True: batch_feature = [] batch_sentence = [] batch_sentence_bw = [] batch_proposal = [] batch_boundary = [] # anchor mask: to mask out neither positive nor negative samples batch_anchor_mask = [] max_sample_len = 0 for sample_id in range(batch_size): unique_id = ids[sample_id + current] vid = self._grounding[split][unique_id]['video_id'] grounding = self._grounding[split][unique_id] anno_id = grounding['anno_id'] timestamp = grounding['timestamp'] sentence = grounding['sentence'] raw_sentence = grounding['raw_sentence'] n_anchors = self._num_anchors if self._options['dataset'] == 'activitynet_captions': vid = 'v_' + vid feature = self._features[vid] feature_len = feature.shape[0] # sampling if split == 'train': sample_len = self._options['sample_len'] else: sample_len = feature_len max_sample_len = max(sample_len, max_sample_len) start_feat_id = random.randint( 0, max((feature_len - sample_len), 0)) end_feat_id = min(start_feat_id + sample_len, feature_len) feature = feature[start_feat_id:end_feat_id] # get word embedding for all words in the sentence sentence_embed = np.stack([ self._glove[word_id] for word_id in sentence[:self._options['max_sentence_len']] ]) if self._options['bidirectional_lstm_sentence']: sentence_embed_bw = sentence_embed[::-1] batch_sentence_bw.append(sentence_embed_bw) batch_feature.append(feature) batch_sentence.append(sentence_embed) # generate proposal ground-truth data gt_proposal = np.zeros(shape=(sample_len, n_anchors), dtype=np.int32) gt_boundary = np.zeros(shape=(sample_len, 1), dtype=np.int32) anchor_mask = np.ones(shape=(sample_len, n_anchors), dtype=np.float32) gt_start_time, gt_end_time = timestamp gt_start_feature, gt_end_feature = \ int(gt_start_time // self._options['feature_to_second']), \ int(gt_end_time // self._options['feature_to_second']) start_point = max((gt_start_feature + gt_end_feature) // 2, 0) end_point = gt_end_feature + (gt_end_feature - gt_start_feature + 1) # only need to check whether proposals that have end point falling at the region of # (feat_check_start, feat_check_end) are "correct" proposals feat_check_start, feat_check_end = get_intersection( (start_point, end_point), (start_feat_id, end_feat_id)) for feat_id in range(feat_check_start, feat_check_end): for anchor_id, anchor in enumerate(self._anchors): end_feat = feat_id + 0.5 start_feat = end_feat - anchor end_time = self._options['feature_to_second'] * end_feat start_time = self._options[ 'feature_to_second'] * start_feat tiou = get_iou((start_time, end_time), (gt_start_time, gt_end_time)) if tiou > self._options['proposal_tiou_threshold']: gt_proposal[feat_id - start_feat_id, anchor_id] = 1 elif tiou < self._options['negative_tiou_threshold']: gt_proposal[feat_id - start_feat_id, anchor_id] = 0 else: anchor_mask[feat_id - start_feat_id, anchor_id] = 0 if gt_start_feature in range(start_feat_id, end_feat_id): gt_boundary[gt_start_feature - start_feat_id] = 1 if gt_end_feature in range(start_feat_id, end_feat_id): gt_boundary[gt_end_feature - start_feat_id] = 1 batch_proposal.append(gt_proposal) batch_boundary.append(gt_boundary) batch_anchor_mask.append(anchor_mask) batch_feature, batch_feature_mask = self.process_batch_data( batch_feature, max_sample_len) batch_sentence, batch_sentence_mask = self.process_batch_data( batch_sentence, self._options['max_sentence_len']) if self._options['bidirectional_lstm_sentence']: batch_sentence_bw, _ = self.process_batch_data( batch_sentence_bw, self._options['max_sentence_len']) batch_proposal = np.array(batch_proposal) batch_boundary = np.array(batch_boundary) batch_anchor_mask = np.array(batch_anchor_mask) # serve as a tuple batch_data = { 'video_feat': batch_feature, 'video_feat_mask': batch_feature_mask, 'sentence': batch_sentence, 'sentence_mask': batch_sentence_mask, 'proposal': batch_proposal, 'proposal_weight': np.array(self._proposal_weight), 'anchor_mask': batch_anchor_mask } if self._options['bidirectional_lstm_sentence']: batch_data['sentence_bw'] = batch_sentence_bw yield batch_data current = current + batch_size if split != 'train' and current + batch_size > self._options[ 'eval_batch_num']: current = 0 break if current + batch_size > self.get_size(split): # at the end of list, shuffle it if split == 'train': print('Randomly shuffle training data ...') random.shuffle(ids) print('The new shuffled ids are:') print('%s, %s, %s, ..., %s' % (ids[0], ids[1], ids[2], ids[-1])) time.sleep(3) current = 0 else: if current < self.get_size(split): # few samples left, so use smaller batch batch_size = self.get_size(split) - current else: current = 0 break
def impedence_matching_exp(ref_mat, tar_mat, ref_Us, tar_Us, showplot=False): """Simulate an impedance matching experiment Args --- ref_mat (EOS) tar_mat (EOS) ref_Us (flaot) : measured Shock velocity in the reference material tar_Us (flaot) : measured Shock velocity in the target material showplot (Bool) : output a plot of the impedance matching experiment Returns ------- Up_interface (float) : the particle velocity at the reference-sample interface P_interface (float) : the pressure at the reference-sample interface """ # Particle speed points, used in retrieving info from interpolated functions up = np.linspace(0, 50, 100) # Find the pressure state in the reference material, given the measured shock # speed refh_PvUp = ref_mat.hugoniot.fYvX("Up", "P", bounds_error=False) ref_rayleigh = ref_mat.hugoniot.get_rayleigh(ref_Us) Up_ref, P_ref = get_intersection(ref_rayleigh, refh_PvUp, near_x=.75 * ref_Us) # Calculate the release from the pressure state in the reference material ref_rels = ref_mat.hugoniot.release(P_ref) # ref_rels = ref_mat.hugoniot.release(P_ref, model="mg", # method="hammel-integral", gamma=.66) #var_gamma(ref_Us)) # Find the Rayleigh line in the sample target material given the measure # shock speed in that material tar_rayleigh = tar_mat.hugoniot.get_rayleigh(tar_Us) Up_interface, P_interface = get_intersection(tar_rayleigh, ref_rels, near_x=.7 * tar_Us) # Show a plot of the impedance matching experiment if showplot: # Check to make sure the intersection of the reference Rayleigh line # matches with the point on the known hugoniot for that material refh_PvUs = ref_mat.hugoniot.fYvX("Us", "P") P_test = refh_PvUs(ref_Us) plt.figure("IME") plt.plot(up, refh_PvUp(up), label="Reference") plt.axhline(P_test, c='g', ls='--') plt.plot(up, ref_rels(up), label="Release") plt.plot(up, ref_rayleigh(up), label="Ref Rayleigh line") plt.plot(up, tar_rayleigh(up), label="Target Rayleigh line") plt.scatter(Up_ref, P_ref, color='g', marker='o') plt.scatter(Up_interface, P_interface, color='r', marker='o') plt.xlabel("Up [km s-1]") plt.ylabel("Pressure [GPa]") plt.xlim(0, 1.5 * Up_interface) plt.ylim(0, 1.2 * P_ref) plt.legend() plt.grid() return Up_interface, P_interface
def monte_carlo_error_prop(ref_mat, tar_mat, _ref_Us, _tar_Us): """Preform a monte carlo run for a given experiments Args ____ ref_mat (EOS) tar_mat (EOS) ref_Us (MoneteCarloVariable) tar_Us (MoneteCarloVariable) Returns ------- mean of particle speed standard deviation of particle speed mean of pressure standard deviation of pressure mean of density standard deviation of density """ # Particle speed points, used in retrieving info from interpolated functions up = np.linspace(0, 50, 100) # Find the pressure state in the reference material, given the measured shock # speed refh_PvUp = ref_mat.hugoniot.fYvX("Up", "P", bounds_error=False) epochs = range(100) Up_collection = [] P_collection = [] rho_collection = [] for _ in epochs: # re-randomize inputs ref_Us = _ref_Us.generate() tar_Us = _tar_Us.generate() ref_rayleigh = ref_mat.hugoniot.get_rayleigh(ref_Us) Up_ref, P_ref = get_intersection(ref_rayleigh, refh_PvUp, near_x=.75 * ref_Us) # Calculate the release from the pressure state in the reference material ref_rels = ref_mat.hugoniot.release(P_ref) # Find the Rayleigh line in the sample target material given the measure # shock speed in that material tar_rayleigh = tar_mat.hugoniot.get_rayleigh(tar_Us) Up_interface, P_interface = get_intersection(tar_rayleigh, ref_rels, near_x=.7 * tar_Us) rho = tar_mat.rho0 * tar_Us / (tar_Us - Up_interface) Up_collection.append(Up_interface) P_collection.append(P_interface) rho_collection.append(rho) return (np.mean(Up_collection), np.std(Up_collection), np.mean(P_collection), np.std(P_collection), np.mean(rho_collection), np.std(rho_collection))
def check_match(ref_acq, matched_acqs, aoi_location, direction, ref_type="master"): matched = False candidate_pair = {} master_slave_union_loc = None orbitNumber = [] overlapped_matches = util.find_overlap_match(ref_acq, matched_acqs) logger.info("overlapped_matches count : %s" % len(overlapped_matches)) if len(overlapped_matches) > 0: overlapped_acqs = [] logger.info("Overlapped Acq exists") #logger.info("Overlapped Acq exists for track: %s orbit_number: %s process version: %s. Now checking coverage." %(track, orbitnumber, pv)) union_loc = get_union_geometry(overlapped_matches) logger.info("union loc : %s" % union_loc) #is_ref_truncated = util.ref_truncated(ref_acq, overlapped_matches, covth=.99) is_covered = util.is_within(ref_acq.location["coordinates"], union_loc["coordinates"]) is_overlapped = False overlap = 0 try: is_overlapped, overlap = util.find_overlap_within_aoi( ref_acq.location, union_loc, aoi_location) except Exception as err: logger.warn(str(err)) traceback.print_exc() #logger.warn("Traceback: {}".format(traceback.format_exc())) #logger.info("is_ref_truncated : %s" %is_ref_truncated) logger.info("is_within : %s" % is_covered) logger.info("is_overlapped : %s, overlap : %s" % (is_overlapped, overlap)) for acq_id in overlapped_matches.keys(): overlapped_acqs.append(acq_id[0]) if overlap <= 0.98 or not is_overlapped: logger.info("ERROR ERROR, overlap is %s " % overlap) if is_overlapped: # and overlap>=0.98: # and overlap >=covth: logger.info("MATCHED") matched = True orbitNumber = get_orbit_number_list(ref_acq, overlapped_matches) #starttime = ref_acq.starttime #endtime = ref_acq.endtime starttime, endtime = get_time_data(ref_acq, overlapped_matches) pair_intersection_loc, pair_intersection_env = util.get_intersection( ref_acq.location, union_loc) if ref_type == "master": candidate_pair = { "master_acqs": [ref_acq.acq_id[0]], "slave_acqs": overlapped_acqs, "intersect_geojson": pair_intersection_loc, "starttime": starttime, "endtime": endtime, "orbitNumber": orbitNumber, "direction": direction } else: candidate_pair = { "master_acqs": overlapped_acqs, "slave_acqs": [ref_acq.acq_id[0]], "intersect_geojson": pair_intersection_loc, "starttime": starttime, "endtime": endtime, "orbitNumber": orbitNumber, "direction": direction } return matched, candidate_pair