Skip to content

Instantly share code, notes, and snippets.

@MPoinelli
Last active December 18, 2023 17:13
Show Gist options
  • Save MPoinelli/8c308e579893255416413502b2c77f16 to your computer and use it in GitHub Desktop.
Save MPoinelli/8c308e579893255416413502b2c77f16 to your computer and use it in GitHub Desktop.
Create Geotiff from MITgcm output
function [info] = mitgcm2tiff(XC,YC,data,outputFilename)
% Generate a georeferenced .tiff file from a standard MITgcm grid/output
% requires MappingToolbox
%
% Poinelli Mattia, UCI, JPL
% September 2023
%
% INPUT:
%
% XC: longitude grid
% YC: latitutde grid
% data: gridded data to convert
% outputFilename (string)
%
% OUTPUT
%
% info: default information
% the function will save a .tiff file
%
% Create a GeoRasterReference object for your data.
R = georasterref('RasterSize', size(data'), ...
'LatitudeLimits', [min(YC(:)), max(YC(:))], ...
'LongitudeLimits', [min(XC(:)), max(XC(:))], ...
'ColumnsStartFrom', 'south', ... % Correct orientation
'RowsStartFrom', 'west');
% Save your data as a georeferenced TIFF file using the GeoRasterReference.
geotiffwrite(outputFilename, data', R);
% Verify the output by loading it using the geotiffread function.
info = geotiffinfo(outputFilename);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment