satmo.geo module¶
-
satmo.geo.
geo_dict_from_nc
(nc_file, proj4string=None)[source]¶ Retrieves the georeferencing parameters from a netcdf file produced with l3mapgen
See https://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?tid=6429 for justification of the approach used in this function to retrieve the projected extent.
Parameters: - nc_file (str) – Path to netcdf file
- proj4string (str) – Optional. proj4string previously passed to l3mapgen (projection=) retrieved from the file metadata if not provided
Returns: Dictionary with georeferencing parameters
Examples
# Given a netcdf file produced with: # $l3mapgen ifile=T2016292.L3b_DAY_OC ofile=T2016292.L3B_DAY_RRS_laea.nc resolution=1km south=26 north=40 west=-155 east=-140 projection=”+proj=laea +lat_0=33 +lon_0=-147”
>>> import rasterio >>> from pprint import pprint >>> >>> geo_dict = geo_dict_from_nc('T2016292.L3B_DAY_RRS_laea.nc', "+proj=laea +lat_0=33 +lon_0=-147") >>> pprint(geo_dict) {'affine': Affine(1160.0, 0.0, -800596.8665952191, 0.0, -1160.0, -746017.3077247943), 'crs': CRS({'lon_0': -147, 'proj': 'laea', 'lat_0': 33}), 'height': 1361, 'width': 1295} >>> geo_dict.update(driver = u'GTiff', dtype = rasterio.float32, count = 1, nodata = -32767) >>> >>> import numpy as np >>> >>> nc_con = nc.Dataset(file_path) >>> rrs_555 = nc_con.variables['Rrs_555'][:] >>> nc_con.close() >>> >>> with rasterio.open('rrs_555.tif', 'w', **geo_dict) as dst: >>> dst.write_band(1, rrs_555.astype(rasterio.float32))
-
satmo.geo.
get_raster_meta
(x, **kwargs)[source]¶ Retrieve a full meta dict as required by rasterio from a nc or tiff file
driver is always assigned geoTiff, and lzw tiff compression is enabled
Parameters: - x (str) – Level L3m filename (tif or netcdf). Must comply with OC standards defined in CONVENTIONS.md
- **kwargs – ONly one implemented: proj4string (str): OPtional, passed to geo_dict_from_nc()
Returns: A dictionary as used by rasterio
Return type: dict