### Configure Pyresample via YAML Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/configuration.md Examples of defining configuration settings using YAML files. Supports simple key-value pairs and nested dictionaries. ```yaml some_key: "some_value" features: future_geometries: true ``` -------------------------------- ### Example netCDF/CF File Structure Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md An example structure of a netCDF file conforming to CF conventions, illustrating dimensions, variables, and attributes relevant for defining a polar stereographic projection and associated data like ice concentration. ```default netcdf cf_nh10km { dimensions: xc = 760 ; yc = 1120 ; variables: int Polar_Stereographic_Grid ; Polar_Stereographic_Grid:grid_mapping_name = "polar_stereographic" ; Polar_Stereographic_Grid:false_easting = 0. ; Polar_Stereographic_Grid:false_northing = 0. ; Polar_Stereographic_Grid:semi_major_axis = 6378273. ; Polar_Stereographic_Grid:semi_minor_axis = 6356889.44891 ; Polar_Stereographic_Grid:straight_vertical_longitude_from_pole = -45. ; Polar_Stereographic_Grid:latitude_of_projection_origin = 90. ; Polar_Stereographic_Grid:standard_parallel = 70. ; double xc(xc) ; xc:axis = "X" ; xc:units = "km" ; xc:long_name = "x coordinate in Cartesian system" ; xc:standard_name = "projection_x_coordinate" ; double yc(yc) ; yc:axis = "Y" ; yc:units = "km" ; yc:long_name = "y coordinate in Cartesian system" ; yc:standard_name = "projection_y_coordinate" ; float lat(yc, xc) ; lat:long_name = "latitude coordinate" ; lat:standard_name = "latitude" ; lat:units = "degrees_north" ; float lon(yc, xc) ; lon:long_name = "longitude coordinate" ; lon:standard_name = "longitude" ; lon:units = "degrees_east" ; short ice_conc(yc, xc) ; ice_conc:_FillValue = -999s ; ice_conc:grid_mapping = "Polar_Stereographic_Grid" ; ice_conc:coordinates = "lat lon" ; ice_conc:standard_name = "sea_ice_area_fraction" ; ice_conc:units = "%" ; ice_conc:scale_factor = 0.01f ; ice_conc:add_offset = 0.f ; ice_conc:valid_min = 0 ; ice_conc:valid_max = 10000 ; // global attributes: :Conventions = "CF-1.7" } ``` -------------------------------- ### YAML Area Definition Example Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md An example YAML file demonstrating various ways to define geospatial area information, including projection, shape, extent, and center coordinates. This format is used by pyresample for on-disk area definitions. ```yaml boundary: area_id: ease_sh description: Example of making an area definition using shape and area_extent projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m shape: [425, 425] area_extent: [-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625] boundary_2: description: Another example of making an area definition using shape and area_extent units: degrees projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m shape: height: 425 width: 425 area_extent: lower_left_xy: [-135.0, -17.516001139327766] upper_right_xy: [45.0, -17.516001139327766] corner: description: Example of making an area definition using shape, upper_left_extent, and resolution projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m shape: [425, 425] upper_left_extent: [-5326849.0625, 5326849.0625] resolution: 25067.525 corner_2: area_id: ease_sh description: Another example of making an area definition using shape, upper_left_extent, and resolution units: degrees projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m shape: [425, 425] upper_left_extent: x: -45.0 y: -17.516001139327766 resolution: dx: 25067.525 dy: 25067.525 units: meters circle: description: Example of making an area definition using center, resolution, and radius projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m center: [0, 0] resolution: [25067.525, 25067.525] radius: 5326849.0625 circle_2: area_id: ease_sh description: Another example of making an area definition using center, resolution, and radius projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m center: x: 0 y: -90 units: degrees shape: width: 425 height: 425 radius: dx: 49.4217406986 dy: 49.4217406986 units: degrees area_of_interest: description: Example of making an area definition using shape, center, and resolution projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m shape: [425, 425] center: [0, 0] resolution: [25067.525, 25067.525] area_of_interest_2: area_id: ease_sh description: Another example of making an area definition using shape, center, and resolution projection: proj: laea lat_0: -90 lon_0: 0 a: 6371228.0 units: m shape: [425, 425] center: center: [0, -90] units: deg resolution: resolution: 0.22542974631297721 units: deg epsg: area_id: ease_sh description: Example of making an area definition using EPSG codes projection: init: EPSG:3410 shape: [425, 425] area_extent: [-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625] ``` -------------------------------- ### Perform Segmented Resampling with ImageContainerQuick Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/grid.md Demonstrates how to initialize an ImageContainerQuick object with a specified number of segments to control memory usage during the resampling process. The example defines area geometries and performs a quick resample operation. ```python import numpy as np from pyresample import image, geometry area_def = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD', {'a': '6378144.0', 'b': '6356759.0', 'lat_0': '50.00', 'lat_ts': '50.00', 'lon_0': '8.00', 'proj': 'stere'}, 800, 800, [-1370912.72, -909968.64, 1029087.28, 1490031.36]) msg_area = geometry.AreaDefinition('msg_full', 'Full globe MSG image 0 degrees', 'msg_full', {'a': '6378169.0', 'b': '6356584.0', 'h': '35785831.0', 'lon_0': '0', 'proj': 'geos'}, 3712, 3712, [-5568742.4, -5568742.4, 5568742.4, 5568742.4]) data = np.ones((3712, 3712)) msg_con_quick = image.ImageContainerQuick(data, msg_area, segments=4) area_con_quick = msg_con_quick.resample(area_def) ``` -------------------------------- ### GET /pyresample/version/get_config Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.version.md Fetches the Versioneer configuration object used for project versioning settings. ```APIDOC ## GET /pyresample/version/get_config ### Description Creates, populates, and returns the VersioneerConfig object containing settings like VCS type, tag prefixes, and file paths. ### Method GET ### Endpoint pyresample.version.get_config() ### Response #### Success Response (200) - **config** (VersioneerConfig) - Object containing VCS, tag_prefix, style, and other configuration parameters. #### Response Example { "VCS": "git", "style": "pep440", "tag_prefix": "v", "verbose": false } ``` -------------------------------- ### Create Area Definition with Radius and Resolution (Pycon) Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md Demonstrates creating an AreaDefinition using a projection string, center coordinates, radius, and resolution. The projection is in Lambert Azimuthal Equal Area, with radius and resolution specified in meters. This example shows how pyproj internally manages CRS information. ```pycon >>> proj_string = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m' >>> area_def = create_area_def(area_id, proj_string, center=center, ... radius=5326849.0625, resolution=25067.525) >>> print(area_def) Area ID: ease_sh Description: ease_sh Projection: {'R': '6371228', 'lat_0': '-90', 'lon_0': '0', 'no_defs': 'None', 'proj': 'laea', 'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) ``` -------------------------------- ### Resample Swath to Grid using Nearest Neighbor (Pyresample) Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/swath.md This example demonstrates resampling swath data to a grid using the nearest neighbor method with Pyresample's ImageContainerNearest. It involves defining the target area and the source swath, then performing the resampling. Dependencies include numpy and pyresample. The input consists of data, longitude, and latitude arrays, outputting resampled image data. ```python import numpy as np from pyresample import image, geometry area_def = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD', {'a': '6378144.0', 'b': '6356759.0', 'lat_0': '50.00', 'lat_ts': '50.00', 'lon_0': '8.00', 'proj': 'stere'}, 800, 800, [-1370912.72, -909968.64, 1029087.28, 1490031.36]) data = np.fromfunction(lambda y, x: y*x, (50, 10)) lons = np.fromfunction(lambda y, x: 3 + x, (50, 10)) lats = np.fromfunction(lambda y, x: 75 - y, (50, 10)) swath_def = geometry.SwathDefinition(lons=lons, lats=lats) swath_con = image.ImageContainerNearest(data, swath_def, radius_of_influence=5000) area_con = swath_con.resample(area_def) result = area_con.image_data ``` -------------------------------- ### Create Area Definition with Degrees Units (Pycon) Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md Illustrates creating an AreaDefinition with a Mercator projection where radius and resolution are provided in degrees. The function handles unit conversion, and the projection is defined using a dictionary. This example highlights flexibility in input units. ```pycon >>> proj_dict = {'proj': 'merc', 'lon_0': 0, 'no_defs': None, 'proj': 'merc', 'R': 6371228, 'k': 1, 'units': 'm'} >>> area_def = create_area_def(area_id, proj_dict, center=(0, 0), ... radius=(47.90379019311, 43.1355420077), ... resolution=(0.22542960090875294, 0.22542901929487608), ... units='degrees', description='Antarctic EASE grid') >>> print(area_def) Area ID: ease_sh Description: Antarctic EASE grid Projection: {'R': '6371228', 'k': '1', 'lon_0': '0', 'no_defs': 'None', 'proj': 'merc', 'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) ``` -------------------------------- ### Manage Pyresample Configuration at Runtime Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/configuration.md Demonstrates how to update configuration settings programmatically using the pyresample.config object, including temporary overrides using context managers. ```python import pyresample pyresample.config.set(some_key="some_value") # Temporary override for a code block with pyresample.config.set(some_key="some_value"): # ... some pyresample code ... ``` -------------------------------- ### Initialize AreaDefinition with Dictionary Projection Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geo_def.md Demonstrates how to create an AreaDefinition object using a dictionary to define the PROJ.4 projection parameters, grid size, and spatial extent. ```python from pyresample.geometry import AreaDefinition area_id = 'ease_sh' description = 'Antarctic EASE grid' proj_id = 'ease_sh' projection = {'proj': 'laea', 'lat_0': -90, 'lon_0': 0, 'a': 6371228.0, 'units': 'm'} width = 425 height = 425 area_extent = (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) area_def = AreaDefinition(area_id, description, proj_id, projection, width, height, area_extent) ``` -------------------------------- ### GET /resamplers Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.future.resamplers.registry.md Lists all currently registered resamplers. ```APIDOC ## GET /resamplers ### Description Retrieves a sorted list of all resampler names currently available in the registry. ### Method GET ### Endpoint /resamplers ### Response #### Success Response (200) - **resamplers** (list) - A list of strings representing registered resampler names. #### Response Example ["nearest", "bilinear", "custom_resampler"] ``` -------------------------------- ### Visualize Resampled Data with Quicklook Utilities Source: https://context7.com/pytroll/pyresample/llms.txt Shows how to use save_quicklook and show_quicklook to visualize resampled swath data. It includes configuration for coastline resolution and grid lines using Cartopy. ```python import numpy as np from pyresample import save_quicklook, kd_tree, geometry area_def = geometry.AreaDefinition( 'ease_sh', 'Antarctic EASE grid', 'ease_sh', {'proj': 'laea', 'lat_0': -90, 'lon_0': 0, 'a': 6371228.0, 'units': 'm'}, 425, 425, (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) ) lons = np.fromfunction(lambda y, x: -180 + x * 3.6, (100, 100)) lats = np.fromfunction(lambda y, x: -60 - y * 0.3, (100, 100)) data = np.fromfunction(lambda y, x: 250 + y * 0.3 + x * 0.1, (100, 100)) swath_def = geometry.SwathDefinition(lons=lons, lats=lats) result = kd_tree.resample_nearest(swath_def, data, area_def, radius_of_influence=50000, fill_value=None) save_quicklook('output.png', area_def, result, label='Temperature (K)', vmin=250, vmax=280, cmap='viridis') save_quicklook('output_detailed.png', area_def, result, label='Temperature (K)', coast_res='50m', num_meridians=30, num_parallels=15) ``` -------------------------------- ### GET /pyresample/version/get_versions Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.version.md Retrieves the current version information for the package. ```APIDOC ## GET /pyresample/version/get_versions ### Description Retrieves the current version information for the package, returning a dictionary of version metadata. ### Method GET ### Endpoint pyresample.version.get_versions() ### Response #### Success Response (200) - **version_info** (Dict[str, Any]) - A dictionary containing version details such as version string, full, and other metadata. #### Response Example { "version": "1.23.0", "full": "1.23.0+4.gabc123" } ``` -------------------------------- ### Initialize AreaDefinition with PROJ.4 String Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geo_def.md Shows how to define the projection for an AreaDefinition using a standard PROJ.4 string format. ```python projection = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m' area_def = AreaDefinition(area_id, description, proj_id, projection, width, height, area_extent) ``` -------------------------------- ### GET /utils/cf/load_cf_area Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.utils.md Loads area definitions from CF-compliant netCDF files or datasets. ```APIDOC ## GET /utils/cf/load_cf_area ### Description Loads an area definition from a CF-compliant variable or file. This is used to interpret geospatial metadata within netCDF files. ### Method GET ### Endpoint pyresample.utils.cf.load_cf_area ### Parameters #### Path Parameters - **filename** (string) - Required - Path to the netCDF file. - **variable_name** (string) - Required - Name of the variable containing grid mapping information. ### Response #### Success Response (200) - **area_def** (object) - The resulting AreaDefinition object. #### Response Example { "area_def": "" } ``` -------------------------------- ### GET /spherical/distance/haversine Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.spherical.md Computes a distance matrix between coordinates using the haversine formula. ```APIDOC ## GET /spherical/distance/haversine ### Description Computes a distance matrix using the haversine formula. Inputs must be in radians. ### Method GET ### Endpoint /spherical/distance/haversine ### Parameters #### Query Parameters - **lon** (array) - Required - Longitude values in radians. - **lat** (array) - Required - Latitude values in radians. - **lon_ref** (array) - Required - Reference longitude values in radians. - **lat_ref** (array) - Required - Reference latitude values in radians. ### Response #### Success Response (200) - **matrix** (ndarray) - A distance matrix of shape (n x n_ref). ### Response Example { "matrix": [[0.1, 0.2], [0.3, 0.4]] } ``` -------------------------------- ### GET /area_config/load_area Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.area_config.md Loads area definitions from a specified file path or stream. ```APIDOC ## GET /area_config/load_area ### Description Load area(s) from an area file or stream. ### Method GET ### Endpoint /area_config/load_area ### Parameters #### Query Parameters - **area_file_name** (str) - Required - Path to the file or stream - **regions** (list) - Optional - Specific regions to parse ### Response #### Success Response (200) - **area_defs** (object/list) - A single AreaDefinition object or a list of objects. ``` -------------------------------- ### Initialize AreaDefinition Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.future.geometry.area.md Demonstrates how to instantiate an AreaDefinition object by providing a CRS, grid shape, and the spatial extent of the area. ```python from pyresample.future.geometry import AreaDefinition # Define CRS, shape (rows, columns), and extent (ll_x, ll_y, ur_x, ur_y) crs = "+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" shape = (100, 100) extent = (-1000000, -1000000, 1000000, 1000000) area = AreaDefinition(crs, shape, extent, attrs={"name": "test_area", "description": "A test grid"}) ``` -------------------------------- ### Create AreaDefinition from Circle (PyCon) Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md Demonstrates creating an AreaDefinition from a circle using either a projection dictionary or a projection string. It takes a center point, radius, and optionally a shape, and outputs the AreaDefinition details. ```python >>> proj_dict = {'proj': 'laea', 'lat_0': -90, 'lon_0': 0, 'a': 6371228.0, 'units': 'm'} >>> center = (0, 0) >>> radius = 5326849.0625 >>> area_def = AreaDefinition.from_circle(area_id, proj_dict, center, radius, shape=shape) >>> print(area_def) Area ID: ease_sh Description: ease_sh Projection: {'R': '6371228', 'lat_0': '-90', 'lon_0': '0', 'no_defs': 'None', 'proj': 'laea', 'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) ``` ```python >>> resolution = 25067.525 >>> area_def = AreaDefinition.from_circle(area_id, proj_string, center, radius, resolution=resolution) >>> print(area_def) Area ID: ease_sh Description: ease_sh Projection: {'R': '6371228', 'lat_0': '-90', 'lon_0': '0', 'no_defs': 'None', 'proj': 'laea', 'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) ``` -------------------------------- ### GET /pyresample/grid/get_resampled_image Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.md Retrieves a resampled image based on provided line and sample coordinates. ```APIDOC ## GET /pyresample/grid/get_resampled_image ### Description Performs image resampling based on grid definitions and input data. ### Method GET ### Endpoint /pyresample/grid/get_resampled_image ### Parameters #### Query Parameters - **data** (array) - Required - The input image data to be resampled. - **target_def** (object) - Required - The target area definition for the output image. ### Request Example { "data": [[0, 1], [2, 3]], "target_def": "area_definition_object" } ### Response #### Success Response (200) - **resampled_data** (array) - The resulting resampled image data. #### Response Example { "resampled_data": [[1, 2], [3, 4]] } ``` -------------------------------- ### GET /utils/rasterio/get_area_def_from_raster Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.utils.md Extracts area definition information from raster files using rasterio/GDAL. ```APIDOC ## GET /utils/rasterio/get_area_def_from_raster ### Description Reads a raster file and returns a pyresample AreaDefinition object based on the file's geotransform and CRS metadata. ### Method GET ### Endpoint pyresample.utils.rasterio.get_area_def_from_raster ### Parameters #### Path Parameters - **filename** (string) - Required - Path to the raster file. ### Response #### Success Response (200) - **area_def** (object) - The extracted AreaDefinition object. #### Response Example { "area_def": "" } ``` -------------------------------- ### Initialize Resampler via Registry Source: https://github.com/pytroll/pyresample/blob/main/docs/source/roadmap.md Shows the new unified interface for creating resampler instances. It uses a factory function that leverages a registry to select the appropriate algorithm based on source and destination geometries. ```python from pyresample import create_resampler resampler = create_resampler(src_geom, dst_geom, resampler='some-resampler-name') ``` -------------------------------- ### GET /pyresample/kd_tree/get_neighbour_info Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.kd_tree.md Retrieves neighbor information for resampling between source and target geometry definitions. ```APIDOC ## GET /pyresample/kd_tree/get_neighbour_info ### Description Calculates and returns neighbor information including indices and distances required for resampling operations. ### Method GET ### Endpoint pyresample.kd_tree.get_neighbour_info ### Parameters #### Path Parameters - **source_geo_def** (object) - Required - Geometry definition of the source data. - **target_geo_def** (object) - Required - Geometry definition of the target grid. - **radius_of_influence** (float) - Required - Cut off distance in meters. #### Query Parameters - **neighbours** (int) - Optional - Number of neighbors to consider (default: 8). - **epsilon** (float) - Optional - Allowed uncertainty in meters. - **reduce_data** (bool) - Optional - Perform coarse reduction of source data. - **nprocs** (int) - Optional - Number of processor cores to use. - **segments** (int) - Optional - Number of segments for processing. ### Request Example { "source_geo_def": "", "target_geo_def": "", "radius_of_influence": 5000.0 } ### Response #### Success Response (200) - **result** (tuple) - A tuple containing (valid_input_index, valid_output_index, index_array, distance_array). #### Response Example { "valid_input_index": [0, 1, 2], "valid_output_index": [0, 1, 2], "index_array": [[...]], "distance_array": [[...]] } ``` -------------------------------- ### Resampling from Neighbor Info Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/swath.md This section explains how to perform resampling in two steps: first, by obtaining neighbor information, and second, by using this information to retrieve resampling results. This is particularly useful when resampling multiple datasets from the same swath. ```APIDOC ## Resampling from Neighbor Info ### Description This approach allows for efficient resampling by first calculating nearest neighbor information and then using this pre-computed data to resample multiple datasets quickly. This separates the computationally intensive neighbor calculation from the data retrieval. ### Method This documentation describes a conceptual process and provides a Python code example using `pyresample`. ### Endpoint N/A (This describes a library usage pattern, not a specific API endpoint.) ### Parameters #### Neighbor Information Calculation (`kd_tree.get_neighbour_info`) - **swath_def** (SwathDefinition) - Required - Definition of the source swath. - **area_def** (AreaDefinition) - Required - Definition of the target area. - **radius_of_influence** (float) - Required - The radius to search for neighbors. - **neighbours** (int) - Optional - The number of nearest neighbors to consider. Defaults to 1 for nearest neighbor. #### Resampling from Neighbor Info (`kd_tree.get_sample_from_neighbour_info`) - **resample_method** (str) - Required - The resampling method to use (e.g., 'nn' for nearest neighbor). - **target_shape** (tuple) - Required - The shape of the target grid. - **data** (numpy.ndarray) - Required - The input data array. - **valid_input_index** (numpy.ndarray) - Required - Indices of valid input points. - **valid_output_index** (numpy.ndarray) - Required - Indices of valid output points. - **index_array** (numpy.ndarray) - Required - Array containing neighbor indices. - **distance_array** (numpy.ndarray) - Optional - Array containing distances to neighbors. ### Request Example ```python import numpy as np from pyresample import kd_tree, geometry # Define source and target areas area_def = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD', {'a': '6378144.0', 'b': '6356759.0', 'lat_0': '50.00', 'lat_ts': '50.00', 'lon_0': '8.00', 'proj': 'stere'}, 800, 800, [-1370912.72, -909968.64, 1029087.28, 1490031.36]) data = np.fromfunction(lambda y, x: y*x, (50, 10)) lons = np.fromfunction(lambda y, x: 3 + x, (50, 10)) lats = np.fromfunction(lambda y, x: 75 - y, (50, 10)) swath_def = geometry.SwathDefinition(lons=lons, lats=lats) # Get neighbor information valid_input_index, valid_output_index, index_array, distance_array = \ kd_tree.get_neighbour_info(swath_def, area_def, 50000, neighbours=1) # Resample using neighbor information res = kd_tree.get_sample_from_neighbour_info('nn', area_def.shape, data, valid_input_index, valid_output_index, index_array) ``` ### Response #### Success Response (200) - **res** (numpy.ndarray) - The resampled data array. #### Response Example (Output depends on input data and parameters. See `res` in the request example.) ### Notes - The `neighbours=1` argument in `get_neighbour_info` specifies nearest neighbor resampling. - `distance_array` is not required for nearest neighbor resampling in `get_sample_from_neighbour_info`. ``` -------------------------------- ### GET /geometry/geostationary_bounding_box Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.geometry.md Retrieves the bounding box for a geostationary area definition in either projection coordinates or longitude/latitude. ```APIDOC ## GET /geometry/geostationary_bounding_box ### Description Computes the bounding box of valid pixels within a geostationary area definition. ### Method GET ### Endpoint /geometry/geostationary_bounding_box ### Parameters #### Query Parameters - **geos_area** (object) - Required - The geostationary area definition. - **nb_points** (int) - Optional - Number of points on the polygon. Defaults to 50. ### Request Example { "geos_area": "geos_obj", "nb_points": 100 } ### Response #### Success Response (200) - **bbox** (list) - The calculated bounding box coordinates. #### Response Example { "bbox": [min_x, min_y, max_x, max_y] } ``` -------------------------------- ### GET /pyresample/_formatting_html/swath_area_attrs_section Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample._formatting_html.md Generates an HTML string containing a collapsible section of attributes for a given SwathDefinition object. ```APIDOC ## GET /pyresample/_formatting_html/swath_area_attrs_section ### Description Creates an HTML representation of the attribute section based on a provided SwathDefinition object. The output is a string containing a collapsible HTML section. ### Method GET ### Endpoint /pyresample/_formatting_html/swath_area_attrs_section ### Parameters #### Path Parameters - **area** (SwathDefinition) - Required - The Swath definition object to be formatted. ### Request Example { "area": "" } ### Response #### Success Response (200) - **result** (str) - HTML string containing the collapsible section. #### Response Example { "result": "
Swath Attributes...
" } ``` -------------------------------- ### Create AreaDefinition using Classmethods Source: https://github.com/pytroll/pyresample/blob/main/docs/source/roadmap.md Demonstrates the transition from the legacy constructor to the new classmethod-based approach for creating AreaDefinition objects in Pyresample 2.0. This approach separates metadata from geometric parameters for cleaner initialization. ```python metadata = {"name": name, "description": description} area = AreaDefinition.from_extent_shape(projection, area_extent, (height, width), metadata) ``` -------------------------------- ### GET /load_area Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md Loads area definitions from a specified file path. Supports both YAML and legacy configuration formats. ```APIDOC ## GET /load_area ### Description Loads one or more area definitions from a file. The function parses the file based on the extension and returns the corresponding AreaDefinition objects. ### Method GET (Internal Python Function) ### Endpoint pyresample.load_area(filename, *area_ids) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the configuration file (e.g., 'areas.yaml' or 'areas.cfg'). - **area_ids** (string) - Required - One or more identifiers for the regions to load from the file. ### Request Example load_area('areas.yaml', 'corner') ### Response #### Success Response (200) - **AreaDefinition** (object) - An object containing the projection, shape, and extent of the requested area. #### Response Example Area ID: corner Description: Example of making an area definition Projection: {'proj': 'laea', 'lat_0': '-90', 'lon_0': '0'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0, -5326849.0, 5326849.0, 5326849.0) ``` -------------------------------- ### Create DynamicAreaDefinition for Auto-Computed Bounds Source: https://context7.com/pytroll/pyresample/llms.txt Demonstrates how to initialize a DynamicAreaDefinition and freeze it based on swath coordinates or specific shapes. This is useful for creating area definitions that adapt to input data bounds. ```python import numpy as np from pyresample.geometry import DynamicAreaDefinition, SwathDefinition dyn_area = DynamicAreaDefinition( area_id='auto_area', description='Auto-computed area', projection={'proj': 'laea', 'lat_0': 50, 'lon_0': 10, 'ellps': 'WGS84'}, resolution=1000 ) lons = np.fromfunction(lambda y, x: -5 + x * 0.2, (200, 100)) lats = np.fromfunction(lambda y, x: 65 - y * 0.15, (200, 100)) swath_def = SwathDefinition(lons=lons, lats=lats) area_def = dyn_area.freeze((lons, lats), resolution=1000) area_def_shaped = dyn_area.freeze(swath_def, shape=(500, 500)) optimal_area = swath_def.compute_optimal_bb_area( proj_dict={'proj': 'omerc'}, resolution=1000 ) ``` -------------------------------- ### GET /utils/load_cf_area Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geometry_utils.md Loads an AreaDefinition from a netCDF CF file. Supports multiple call forms based on the specificity of the input parameters. ```APIDOC ## GET /utils/load_cf_area ### Description Loads an AreaDefinition object from a netCDF file that adheres to CF conventions. The function can automatically detect grid mapping information or accept explicit variable references. ### Method GET ### Endpoint pyresample.utils.cf.load_cf_area(filename, variable=None, x=None, y=None) ### Parameters #### Path Parameters - **filename** (string) - Required - Path to the netCDF file. #### Query Parameters - **variable** (string) - Optional - The name of the grid_mapping variable or data variable. - **x** (string) - Optional - The name of the x-axis variable. - **y** (string) - Optional - The name of the y-axis variable. ### Request Example # 1st form: Explicit mapping load_cf_area('file.nc', variable='Polar_Stereographic_Grid', x='xc', y='yc') # 2nd form: Variable-based discovery load_cf_area('file.nc', variable='ice_conc') # 3rd form: Automatic discovery load_cf_area('file.nc') ### Response #### Success Response (200) - **area_def** (AreaDefinition) - The resulting area definition object. - **cf_info** (dict) - Metadata extracted from the CF file. #### Response Example (area_def, cf_info) = load_cf_area('cf_nh10km.nc') ``` -------------------------------- ### ImageContainerQuick Class Initialization Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.image.md Details the initialization parameters for the `ImageContainerQuick` class, designed for efficient resampling within a defined area. ```APIDOC ## Class: ImageContainerQuick ### Description Holds image data with an area definition and allows for quick resampling within that area. ### Parameters #### image_data - **Type:** numpy array - **Description:** The image data to be held. #### geo_def - **Type:** object - **Description:** The area definition as an AreaDefinition object. #### fill_value - **Type:** int or None, optional - **Description:** Value to set for undetermined pixels. If None, a masked array is returned with undetermined pixels masked. #### nprocs - **Type:** int, optional - **Description:** Number of processor cores to use for geometry operations. #### segments - **Type:** int or None, optional - **Description:** Number of segments to use during resampling. If None, an estimate is calculated. ``` -------------------------------- ### Execute Two-Step Resampling with Precomputation Source: https://github.com/pytroll/pyresample/blob/main/docs/source/roadmap.md Shows how to separate the resampling process into precomputation and computation phases. This is useful for caching intermediate results that do not depend on the actual image data. ```python resampler.precompute() new_data = resampler.compute(data, **kwargs) ``` -------------------------------- ### Get projection circumference Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.ewa._ll2cr.md The projection_circumference function checks if a given projection is cylindrical and returns its circumference. Returns None if the projection is not cylindrical. ```python from pyresample.ewa._ll2cr import projection_circumference circumference = projection_circumference(proj_definition) ``` -------------------------------- ### Utility Functions Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.version.md Helper functions for system command execution and directory-based version discovery. ```APIDOC ## FUNCTION pyresample.version.run_command ### Description Executes a system command and returns the output and exit code. ### Parameters - **commands** (list) - Required - List of command parts. - **args** (list) - Required - Arguments for the command. - **cwd** (str) - Optional - Working directory. - **verbose** (bool) - Optional - Enable verbose output. ### Response - **Returns** (Tuple) - A tuple containing (output_string, exit_code). ``` -------------------------------- ### Pyresample Plotting Utilities Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/modules.md Functions for generating quicklook visualizations and map projections. ```APIDOC ## FUNCTION pyresample.plot.save_quicklook ### Description Saves a quicklook visualization of the resampled data to a file. ### Method FUNCTION ### Endpoint pyresample.plot.save_quicklook ### Parameters #### Path Parameters - **filename** (string) - Required - Path to save the image - **area_def** (object) - Required - Area definition for the plot - **data** (array) - Required - Data to visualize ### Request Example { "filename": "output.png", "area_def": "...", "data": [1, 2, 3] } ### Response #### Success Response (200) - **status** (string) - Confirmation of file save ``` -------------------------------- ### SimpleBoundary Class Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.boundary.legacy_boundary.md A container for geometry boundaries, representing a boundary with four sides. The sides are labeled starting from the upper left corner and proceeding clockwise. ```APIDOC ## class pyresample.boundary.legacy_boundary.SimpleBoundary(side1, side2, side3, side4) ### Description Container for geometry boundary. Labelling starts in upper left corner and proceeds clockwise. ### Method __init__(side1, side2, side3, side4) ### Parameters #### Path Parameters - **side1** (object) - The first side of the boundary. - **side2** (object) - The second side of the boundary. - **side3** (object) - The third side of the boundary. - **side4** (object) - The fourth side of the boundary. ``` -------------------------------- ### Get Cartesian Coordinates from AreaDefinition Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geo_def.md Extracts geocentric Cartesian (X, Y, Z) coordinates from an AreaDefinition. This is useful for 3D spatial analysis and can be subsetted for specific regions. ```python from pyresample.geometry import AreaDefinition area_id = 'ease_sh' description = 'Antarctic EASE grid' proj_id = 'ease_sh' projection = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m' width = 425 height = 425 area_extent = (-5326849.0625,-5326849.0625,5326849.0625,5326849.0625) area_def = AreaDefinition(area_id, description, proj_id, projection, width, height, area_extent) cart_subset = area_def.get_cartesian_coords()[100:200, 350:] ``` -------------------------------- ### Initialize AreaDefinition with EPSG Code Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/geo_def.md Demonstrates defining an AreaDefinition using an EPSG code for the projection, compatible with pyproj 2.0+. ```python projection = 'EPSG:3409' area_def = AreaDefinition(area_id, description, proj_id, projection, width, height, area_extent) ``` -------------------------------- ### Get Valid Index from Lon/Lat Grid Source: https://github.com/pytroll/pyresample/blob/main/docs/source/howtos/data_reduce.md Returns a boolean array indicating relevant swath data points compared to a grid, considering a buffer zone. ```APIDOC ## POST /pyresample/data_reduce/get_valid_index_from_lonlat_grid ### Description Returns a boolean array of the same size as the swath, indicating the relevant swath data points compared to the grid. A buffer zone is considered based on `radius_of_influence`. ### Method POST ### Endpoint /pyresample/data_reduce/get_valid_index_from_lonlat_grid ### Parameters #### Query Parameters - **radius_of_influence** (float) - Optional - Defines a buffer zone around the grid where swath data points are considered valid. #### Request Body - **grid_lons** (numpy.ndarray) - Required - Grid longitudes. - **grid_lats** (numpy.ndarray) - Required - Grid latitudes. - **swath_lons** (numpy.ndarray) - Required - Swath longitudes. - **swath_lats** (numpy.ndarray) - Required - Swath latitudes. ### Request Example ```json { "grid_lons": "[[3.0, 4.0, 5.0], [3.0, 4.0, 5.0]]", "grid_lats": "[[75.0, 75.0, 75.0], [74.0, 74.0, 74.0]]", "swath_lons": "[[3.0, 4.0, 5.0, 6.0], [3.0, 4.0, 5.0, 6.0]]", "swath_lats": "[[75.0, 75.0, 75.0, 75.0], [74.0, 74.0, 74.0, 74.0]]" } ``` ### Response #### Success Response (200) - **valid_index** (numpy.ndarray) - A boolean array indicating valid swath data points. #### Response Example ```json { "valid_index": "[[true, true, true, false], [true, true, true, false]]" } ``` ``` -------------------------------- ### BilinearBase Initialization Source: https://github.com/pytroll/pyresample/blob/main/docs/source/api/pyresample.bilinear._base.md Initializes the BilinearBase resampler with source and target geometry definitions and performance parameters. ```APIDOC ## POST /pyresample/bilinear/BilinearBase ### Description Initializes the resampler object to prepare for bilinear interpolation between source and target grids. ### Method POST ### Parameters #### Request Body - **source_geo_def** (object) - Required - Geometry definition of source - **target_geo_def** (object) - Required - Geometry definition of target - **radius_of_influence** (float) - Required - Cut off distance in meters - **neighbours** (int) - Optional - The number of neighbours to consider (default: 32) - **epsilon** (float) - Optional - Allowed uncertainty in meters (default: 0) - **reduce_data** (bool) - Optional - Perform initial coarse reduction (default: True) ### Request Example { "source_geo_def": "source_grid_obj", "target_geo_def": "target_grid_obj", "radius_of_influence": 5000.0, "neighbours": 32, "epsilon": 0, "reduce_data": true } ```