Location functions

Some generally helpful location control functions for base QC.

marine_qc.location_control.fill_missing_vals(q11, q12, q21, q22)[source]

Fill missing values.

For a group of four neighbouring grid boxes which form a square, with values q11, q12, q21, q22, fill gaps using means of neighbours.

Parameters:
  • q11 (float) – Value of first gridbox.

  • q12 (float) – Value of second gridbox.

  • q21 (float) – Value of third gridbox.

  • q22 (float) – Value of fourth gridbox.

Return type:

tuple[float | None, float | None, float | None, float | None]

Returns:

tuple of float – A tuple of four floats representing neighbour means.

marine_qc.location_control.filler(value_to_fill, neighbour1, neighbour2, opposite)[source]

Fill invalid values.

If the value_to_fill is invalid it is replaced with the mean of the neighbours and if it is still invalid then it is replaced with the value from the opposite member.

Parameters:
  • value_to_fill (float) – The value to fill.

  • neighbour1 (float) – The first neighbour.

  • neighbour2 (float) – The second neighbour.

  • opposite (float) – The opposite member.

Return type:

float | None

Returns:

float – Filled invalid input values.

marine_qc.location_control.get_four_surrounding_points(lat, lon, res, max90=True)[source]

Get the four surrounding points of a specified latitude and longitude point.

Parameters:
  • lat (float) – Latitude of point.

  • lon (float) – Longitude of point.

  • res (int) – Resolution of the grid in degrees.

  • max90 (bool, default: True) – If True then cap latitude at 90.0, otherwise don’t cap latitude.

Return type:

tuple[float, float, float, float]

Returns:

tuple of floats – A tuple of floats representing the longitudes of the leftmost and rightmost pairs of points, and the latitudes of the topmost and bottommost pairs of points.

marine_qc.location_control.lat_to_yindex(lat, res)[source]

For a given latitude return the y index in a 1x1x5-day global grid.

Parameters:
  • lat (float) – Latitude of the point.

  • res (float) – Resolution of grid in degrees.

Return type:

int

Returns:

int – Grid box index.

Notes

The routine assumes that the structure of the SST array is a grid that is 360 x 180 x 73 i.e. one year of 1degree lat x 1degree lon data split up into pentads. The west-most box is at 180degrees with index 0 and the northernmost box also has index zero. Inputs on the border between grid cells are pushed south.

In previous versions, res had the default value 1.0.

marine_qc.location_control.lon_to_xindex(lon, res)[source]

For a given longitude return the x index in a 1x1x5-day global grid.

Parameters:
  • lon (float) – Longitude of the point.

  • res (float) – Resolution of grid in degrees.

Return type:

int

Returns:

int – Grid box index.

Notes

The routine assumes that the structure of the SST array is a grid that is 360 x 180 x 73 i.e. one year of 1degree lat x 1degree lon data split up into pentads. The west-most box is at 180degrees W with index 0 and the northernmost box also has index zero. Inputs on the border between grid cells are pushed east.

In previous versions, res had the default value 1.0.

marine_qc.location_control.mds_lat_to_yindex(lat, res)[source]

For a given latitude return the y-index as it was in MDS2/3 in a 1x1 global grid.

Parameters:
  • lat (float) – Latitude of the point.

  • res (float) – Resolution of grid in degrees.

Return type:

int

Returns:

int – Grid box index.

Notes

In the northern hemisphere, borderline latitudes which fall on grid boundaries are pushed north, except 90 which goes south. In the southern hemisphere, they are pushed south, except -90 which goes north. At 0 degrees they are pushed south.

Expects that latitudes run from 90N to 90S

In previous versions, res had the default value 1.0.

marine_qc.location_control.mds_lat_to_yindex_fast(lat, res)[source]

For a given latitude return the y-index as it was in MDS2/3 in a 1x1 global grid.

Parameters:
  • lat (np.ndarray) – Latitude(s) of observation in degrees.

  • res (float) – Resolution of grid in degrees.

Return type:

ndarray

Returns:

np.ndarray – Grid box indexes.

Notes

In the northern hemisphere, borderline latitudes which fall on grid boundaries are pushed north, except 90 which goes south. In the southern hemisphere, they are pushed south, except -90 which goes north. At 0 degrees they are pushed south.

Expects that latitudes run from 90N to 90S

In previous versions, res had the default value 1.0.

marine_qc.location_control.mds_lon_to_xindex(lon, res)[source]

For a given longitude return the x-index as it was in MDS2/3 in a 1x1 global grid.

Parameters:
  • lon (float) – Longitude of the point.

  • res (float) – Resolution of grid in degrees.

Return type:

int

Returns:

int – Grid box index.

Notes

In the western hemisphere, borderline longitudes which fall on grid boundaries are pushed west, except -180 which goes east. In the eastern hemisphere, they are pushed east, except 180 which goes west. At 0 degrees they are pushed west.

In previous versions, res had the default value 1.0.

marine_qc.location_control.mds_lon_to_xindex_fast(lon, res)[source]

For a given longitude return the x-index as it was in MDS2/3 in a 1x1 global grid.

Parameters:
  • lon (np.ndarray) – Longitude(s) of observation in degrees.

  • res (float) – Resolution of grid in degrees.

Return type:

ndarray

Returns:

np.ndarray – Grid box indexes.

Notes

In the western hemisphere, borderline longitudes which fall on grid boundaries are pushed west, except -180 which goes east. In the eastern hemisphere, they are pushed east, except 180 which goes west. At 0 degrees they are pushed west.

In previous versions, res had the default value 1.0.

marine_qc.location_control.xindex_to_lon(xindex, res)[source]

Convert xindex to longitude.

Parameters:
  • xindex (int) – Index of the longitude.

  • res (float) – Resolution of grid in degrees.

Return type:

float

Returns:

float – Longitude (degrees).

Notes

In previous versions, res had the default value 1.0.

marine_qc.location_control.yindex_to_lat(yindex, res)[source]

Convert yindex to latitude.

Parameters:
  • yindex (int) – Index of the latitude.

  • res (float) – Resolution of grid in degrees.

Return type:

float

Returns:

float – Latitude (degrees).

Notes

In previous versions, res had the default value 1.0.