This package implements the CommonDataModel.jl interface for TIFF files, which means that the datasets can be accessed in the same way as netCDF files opened with NCDatasets.jl or GRIB files opened with GRIBDatasets. For GeoTIFF files the project information will be available as additional variables following the CF Conventions.
using TIFFDatasets
using Downloads: download
fname = download("https://data-assimilation.net/upload/Alex/TIFF/S2_1-12-19_48MYU_0.tif")
ds = TIFFDataset(fname)
Output:
Dataset: /tmp/jl_4LSVOjATCR
Group: /
Dimensions
cols = 256
rows = 256
Variables
lon (256 × 256)
Datatype: Float64
Dimensions: cols × rows
Attributes:
standard_name = longitude
units = degrees_east
lat (256 × 256)
Datatype: Float64
Dimensions: cols × rows
Attributes:
standard_name = latitude
units = degrees_north
x (256)
Datatype: Float64
Dimensions: cols
Attributes:
standard_name = projection_x_coordinate
units = m
y (256)
Datatype: Float64
Dimensions: rows
Attributes:
standard_name = projection_y_coordinate
units = m
crs
Attributes:
grid_mapping_name = transverse_mercator
longitude_of_central_meridian = 105.0
false_easting = 500000.0
false_northing = 1.0e7
latitude_of_projection_origin = 0.0
scale_factor_at_central_meridian = 0.9996
longitude_of_prime_meridian = 0.0
semi_major_axis = 6.378137e6
inverse_flattening = 298.257223563
crs_wkt = PROJCS["WGS 84 / UTM zone 48S",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",105],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32748"]]
GeoTransform = 706740.0 10.0 0.0 9.34096e6 0.0 -10.0
band1 (256 × 256)
Datatype: Float32
Dimensions: cols × rows
Attributes:
grid_mapping = crs
[...]
The dataset ds
will also have the virtual variables x
, y
, lon
and lat
(unless there is no projection defined in the GeoTiff file)
representing the projected coordinates and the corresponding longitude and latitude.
The projection information as the so-called Well Known Text is available as attribute crs_wkt
of the virtural variable crs
following the CF Conventions.
For example, the first band and the corresponding lon/lat coordinates can be loaded with using the API of CommonDataModel.jl:
data = ds["band1"][:,:];
lon = ds["lon"][:,:];
lat = ds["lat"][:,:];
# See
# https://cfconventions.org/cf-conventions/cf-conventions.html#appendix-grid-mappings
grid_mapping_name = ds["crs"].attrib["grid_mapping_name"]
Using all bands as single 3D array can be done using catbands = true
, for example:
ds = TIFFDataset(fname,catbands = true)
size(ds["band"]);
# outputs (265, 265, 11) as there are 11 bands
data_all_bands = ds["band"][:,:,:];