def create_grid_mapping_variable(nco, crs): if crs.geographic: crs_var = _create_latlon_grid_mapping_variable(nco, crs) elif crs.projected: crs_var = _create_projected_grid_mapping_variable(nco, crs) else: raise ValueError('Unknown CRS') crs_var.semi_major_axis = crs.semi_major_axis crs_var.semi_minor_axis = crs.semi_minor_axis crs_var.inverse_flattening = crs.inverse_flattening crs_var.crs_wkt = crs.wkt crs_var.spatial_ref = crs.wkt dims = crs.dimensions xres, xoff = data_resolution_and_offset(nco[dims[1]]) yres, yoff = data_resolution_and_offset(nco[dims[0]]) crs_var.GeoTransform = [xoff, xres, 0.0, yoff, 0.0, yres] left, right = nco[dims[1]][0] - 0.5 * xres, nco[dims[1]][-1] + 0.5 * xres bottom, top = nco[dims[0]][0] - 0.5 * yres, nco[dims[0]][-1] + 0.5 * yres points = [[left, bottom], [left, top], [right, top], [right, bottom]] _write_geographical_extents_attributes(nco, GeoPolygon(points, crs)) return crs_var
def _make_dataset(labels, sources): return make_dataset(product=output_type, sources=sources, extent=tile.geobox.extent, center_time=labels['time'], uri=file_path.absolute().as_uri(), app_info=get_app_metadata(config, config['filename']), valid_data=GeoPolygon.from_sources_extents(sources, tile.geobox))
def _make_dataset(labels, sources_): return make_dataset(product=stat.product, sources=sources_, extent=geobox.extent, center_time=labels['time'], uri=uri, app_info=app_info, valid_data=GeoPolygon.from_sources_extents( sources_, geobox))
def _make_dataset(labels, sources): assert sources dataset = make_dataset(product=output_product, sources=sources, extent=nbar.geobox.extent, center_time=labels['time'], uri=file_path.absolute().as_uri(), app_info=get_app_metadata(config), valid_data=GeoPolygon.from_sources_extents(sources, nbar.geobox)) return dataset
def _make_dataset(labels, sources): sources_union = union_points( *[source.extent.to_crs(geobox.crs).points for source in sources]) valid_data = intersect_points(geobox.extent.points, sources_union) dataset = make_dataset(dataset_type=output_type, sources=sources, extent=geobox.extent, center_time=labels['time'], uri=file_path.absolute().as_uri(), app_info=get_app_metadata( config, config['filename']), valid_data=GeoPolygon(valid_data, geobox.crs)) return dataset
def set_geobox_info(doc, crs, extent): bb = extent.boundingbox gp = GeoPolygon([(bb.left, bb.top), (bb.right, bb.top), (bb.right, bb.bottom), (bb.left, bb.bottom)], crs).to_crs(CRS('EPSG:4326')) doc.update({ 'extent': { 'coord': { 'ul': { 'lon': gp.points[0][0], 'lat': gp.points[0][1] }, 'ur': { 'lon': gp.points[1][0], 'lat': gp.points[1][1] }, 'lr': { 'lon': gp.points[2][0], 'lat': gp.points[2][1] }, 'll': { 'lon': gp.points[3][0], 'lat': gp.points[3][1] }, } }, 'grid_spatial': { 'projection': { 'spatial_reference': str(crs), 'geo_ref_points': { 'ul': { 'x': bb.left, 'y': bb.top }, 'ur': { 'x': bb.right, 'y': bb.top }, 'll': { 'x': bb.left, 'y': bb.bottom }, 'lr': { 'x': bb.right, 'y': bb.bottom }, } } } })
def _make_dataset(labels, sources): assert len(sources) geobox = nbar.geobox source_data = union_points( *[dataset.extent.to_crs(geobox.crs).points for dataset in sources]) valid_data = intersect_points(geobox.extent.points, source_data) dataset = make_dataset(product=output_type, sources=sources, extent=geobox.extent, center_time=labels['time'], uri=file_path.absolute().as_uri(), app_info=get_app_metadata(config), valid_data=GeoPolygon(valid_data, geobox.crs)) return dataset
def solar_vector(p, time, crs): poly = GeoPolygon([p, (p[0], p[1] + 100)], crs).to_crs(CRS('EPSG:4326')) lon, lat = poly.points[0] dlon = poly.points[1][0] - lon dlat = poly.points[1][1] - lat # azimuth north to east of the vertical direction of the crs vert_az = math.atan2(dlon * math.cos(math.radians(lat)), dlat) observer = ephem.Observer() observer.lat = math.radians(lat) observer.lon = math.radians(lon) observer.date = time sun = ephem.Sun(observer) sun_az = sun.az - vert_az x = math.sin(sun_az) * math.cos(sun.alt) y = -math.cos(sun_az) * math.cos(sun.alt) z = math.sin(sun.alt) return x, y, z, sun_az, sun.alt
def test_geobox(): points_list = [ [(148.2697, -35.20111), (149.31254, -35.20111), (149.31254, -36.331431), (148.2697, -36.331431)], [(148.2697, 35.20111), (149.31254, 35.20111), (149.31254, 36.331431), (148.2697, 36.331431)], [(-148.2697, 35.20111), (-149.31254, 35.20111), (-149.31254, 36.331431), (-148.2697, 36.331431)], [(-148.2697, -35.20111), (-149.31254, -35.20111), (-149.31254, -36.331431), (-148.2697, -36.331431)], ] for points in points_list: polygon = GeoPolygon(points, CRS('EPSG:3577')) resolution = (-25, 25) geobox = GeoBox.from_geopolygon(polygon, resolution) assert abs(resolution[0]) > abs(geobox.extent.boundingbox.left - polygon.boundingbox.left) assert abs(resolution[0]) > abs(geobox.extent.boundingbox.right - polygon.boundingbox.right) assert abs(resolution[1]) > abs(geobox.extent.boundingbox.top - polygon.boundingbox.top) assert abs(resolution[1]) > abs(geobox.extent.boundingbox.bottom - polygon.boundingbox.bottom)