Skip to content

Commit

Permalink
NA
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schimel committed May 24, 2020
1 parent 1e20057 commit 3a05264
Show file tree
Hide file tree
Showing 56 changed files with 7,542 additions and 1,066 deletions.
35 changes: 35 additions & 0 deletions functions/files_and_folders/CFF_file_extension.m
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
%% CFF_file_extension.m
%
% Get extension of file
%
%% Help
%
% *USE*
%
% CFF_file_extension(filename) returns the extension of filename.
%
% *INPUT VARIABLES*
%
% * |filename|: Required. String filename.
%
% *OUTPUT VARIABLES*
%
% * |ext|: String filename extension
%
% *DEVELOPMENT NOTES*
%
% *NEW FEATURES*
%
% * 2018-10-11: added header
% * YYYY-MM-DD: first version. XXX
%
% *EXAMPLE*
%
% ext = CFF_file_extension('test.mat'); % returns 'mat'
%
% *AUTHOR, AFFILIATION & COPYRIGHT*
%
% Alexandre Schimel, Waikato University, Deakin University, NIWA.

%% Function
function ext = CFF_file_extension(filename)

[~,~,ext] = fileparts(filename);
37 changes: 37 additions & 0 deletions functions/files_and_folders/CFF_file_name.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%% CFF_file_name.m
%
% Get name of file (without path or extension
%
%% Help
%
% *USE*
%
% CFF_file_extension(filename) returns the extension of filename.
%
% *INPUT VARIABLES*
%
% * |filename|: Required. String filename.
%
% *OUTPUT VARIABLES*
%
% * |ext|: String filename extension
%
% *DEVELOPMENT NOTES*
%
% *NEW FEATURES*
%
% * 2018-10-11: added header
% * YYYY-MM-DD: first version. XXX
%
% *EXAMPLE*
%
% ext = CFF_file_extension('test.mat'); % returns 'mat'
%
% *AUTHOR, AFFILIATION & COPYRIGHT*
%
% Alexandre Schimel, Waikato University, Deakin University, NIWA.

%% Function
function name = CFF_file_name(filename)

[~,name,~] = fileparts(filename);
108 changes: 63 additions & 45 deletions functions/geodesy/CFF_ll2tm.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
function [E, N, gridConv, pointScaleFactor, utmzone] = CFF_ll2tm(lon, lat, ellips, tmproj)
% -------------------------------------------------------------------------
% [E, N, gridConv, pointScaleFactor, utmzone] = CFF_ll2tm(lon, lat, ellipsoid, tmproj)
%%% CFF_ll2tm.m
%
% Converts geographic coordinates (Latitude, Longitude) to Transverse
% Mercator Projections coordinates (Northing, Easting). Also provides grid
% convergence (angle between true north and grid north), point scale factor
% and UTM zone if not specified in input. Different ellipsoids or
% projections can be specified.
%
%% Help
%
% *USE*
%
% _This section contains a more detailed description of what the function
% does and how to use it, for the interested user to have an overall
% understanding of its function. Example below to replace. Delete these
% lines XXX._
%
% Description:
% Converts geographic coordinates (Latitude, Longitude) to Transverse
% Mercator Projections coordinates (Northing, Easting). Also provides
% grid convergence (angle between true north and grid north), point
% scale factor and UTM zone if not specified in input. Different
% ellipsoids or projections can be specified.
% This is a text file containing the basic comment template to add at the
% start of any new ESP3 function to serve as function help. XXX
%
% Input:
% - lat: Latitude scalar or vector in decimal degrees.
% - lon: Longitude scalar or vector in decimal degrees.
% - ellips: code string for the input coordinates' ellipsoid.
% supported codes: 'wgs84', 'grs80'
% - tmproj: code string for the ouptut transverse mercator projection.
% supported codes:
% *INPUT VARIABLES*
%
% * |lon: Required. Longitude scalar or vector in decimal degrees.
% * |lat|: Required. Latitude scalar or vector in decimal degrees.
% * |ellips|: Required. code string for the input coordinates' ellipsoid.
% Supported codes: 'wgs84', 'grs80'
% * |tmproj|: Required. Code string for the ouptut transverse mercator
% projection. Supported codes:
% 'utm' -> Universal Transvere Mercator projection without zone
% specified. The function computes the longitudinal zone for input
% coordinates and returns the result in variable utmzone. Note: UTM
Expand Down Expand Up @@ -64,42 +73,51 @@
% 'taietm2000' -> "North Taieri 2000".
% 'bluftm2000' -> "Bluff 2000".
%
% Output:
% - E: projection easting scalar or vector
% - N: projection northing scalar or vector
% - gridConv: grid convergence in degrees. Grid convergence is the angle
% at a point between true and grid North. It is positive when grid north
% lies to the West of the true North.
% - pointScaleFactor: Point scale factor. The scale factor at a point
% away from the central meridian.
% - utmzone: UTM longitudinal zone (ouput if zone was not specified in
% input, i.e. ellips = 'utm')
% *OUTPUT VARIABLES*
%
% Notes:
% * |E|: Projection easting scalar or vector
% * |N|: Projection northing scalar or vector
% * |gridConv|: Grid convergence in degrees. Grid convergence is the angle
% at a point between true and grid North. It is positive when grid north
% lies to the West of the true North.
% * |pointScaleFactor|: Point scale factor. The scale factor at a point
% away from the central meridian.
% * |utmzone|: UTM longitudinal zone (ouput if zone was not specified in
% input, i.e. ellips = 'utm').
%
% - The GRS80 and WGS84 ellipsoids are so close that the differences in
% Lat/Long are usually considered insignificant for most applications.
% This function makes this assumption too, even though a fair conversion
% from say, WGS84 lat/long to a NZ projection based on GRS80 would
% require a datum transformation. If this function is ever extended to
% different ellipsoids, a datum transformation will be required.
% *DEVELOPMENT NOTES*
%
% Author notes:
% This function is based on "LINZS25002. Standard for New Zealand
% Geodetic Datum 2000 Projections: version 2." and original code from
% "ll2tm.m" by David Johnson and Brett Beamsley (Metocean Solutions LTD).
% * The GRS80 and WGS84 ellipsoids are so close that the differences in
% Lat/Long are usually considered insignificant for most applications. This
% function makes this assumption too, even though a fair conversion from
% say, WGS84 lat/long to a NZ projection based on GRS80 would require a
% datum transformation. If this function is ever extended to different
% ellipsoids, a datum transformation will be required.
% * This function is based on "LINZS25002. Standard for New Zealand
% Geodetic Datum 2000 Projections: version 2." and original code from
% "ll2tm.m" by David Johnson and Brett Beamsley (Metocean Solutions LTD).
%
% Example:
% *NEW FEATURES*
%
% Author:
% Alexandre Schimel
% Coastal Marine Group - University of Waikato
% Hamilton, New Zealand
% * 2018-10-11: new header
% * 2010-06: first version.
%
% Version:
% June 2010
% -------------------------------------------------------------------------
% *EXAMPLE*
%
% _This section contains examples of valid function calls. Note that
% example lines start with 3 white spaces so that the publish function
% shows them correctly as matlab code. Example below to replace. Delete
% these lines XXX._
%
% example_use_1; % comment on what this does. XXX
% example_use_2: % comment on what this line does. XXX
%
% *AUTHOR, AFFILIATION & COPYRIGHT*
%
% Alexandre Schimel, University of Waikato

%% Function
function [E, N, gridConv, pointScaleFactor, utmzone] = CFF_ll2tm(lon, lat, ellips, tmproj)


%% ellipsoid parameters:
Expand Down
22 changes: 14 additions & 8 deletions functions/gis_raster/CFF_grid.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,31 @@
XX = [floor(minX):res:ceil(maxX)];
YY = [floor(minY):res:ceil(maxY)]';

% initialize ZZ and WW arrays
ZZ = -999.*ones(length(YY),length(XX)); % remove NaNs to allow averaging
% initialize the running count, the running weighted sum, and the running
% sum of weights:
% N = zeros(length(YY),length(XX));
WS = zeros(length(YY),length(XX));
WW = zeros(length(YY),length(XX));

% weight gridding
for ii = 1:length(x(:))

if ~isnan(x(ii))

% get grid cell index
% get grid cell index to which this data point will contribute
iR = round(((y(ii)-YY(1))./res)+1);
iC = round(((x(ii)-XX(1))./res)+1);

% add new point to grid, updating based on weight
ZZ(iR,iC) = ((ZZ(iR,iC).*WW(iR,iC))+z(ii).*w(ii))./(WW(iR,iC)+w(ii));
WW(iR,iC) = WW(iR,iC)+w(ii);
% calculate new values with added point
% N(iR,iC) = N(iR,iC) + 1;
WS(iR,iC) = WS(iR,iC) + w(ii).*z(ii);
WW(iR,iC) = WW(iR,iC) + w(ii);

end
end

% put NaNs back in ZZ
ZZ(ZZ==-999) = NaN;
% at the end, divide the weighted sum by the sum of weights to get the
% weighted average values
ZZ = WS./WW;


Loading

0 comments on commit 3a05264

Please sign in to comment.