Skip to content

utility

latlon_2modis_tile(lat, lon)

Find the latitude and longitude of a given modis tile

Parameters:

Name Type Description Default
lat float

Description of parameter lat.

required
lon float

Description of parameter lon.

required

Returns:

Type Description
(int, int)

H and V

Source code in monetio/sat/utility.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def latlon_2modis_tile(lat, lon):
    """Find the latitude and longitude of a given modis tile

    Parameters
    ----------
    lat : float
        Description of parameter `lat`.
    lon : float
        Description of parameter `lon`.

    Returns
    -------
    (int, int)
        H and V

    """
    from pyproj import Proj

    # reference: https://code.env.duke.edu/projects/mget/wiki/SinusoidalMODIS
    p_modis_grid = Proj("+proj=sinu +R=6371007.181 +nadgrids=@null +wktext")
    x, y = p_modis_grid(lon, lat)
    # or the inverse, from x, y to lon, lat
    # lat, lon = p_modis_grid(x, y, inverse=True)
    tileWidth = 1111950.5196666666
    ulx = -20015109.354
    uly = -10007554.677
    H = int(x - ulx) / tileWidth
    V = 18 - (int(y - uly) / tileWidth)
    return int(V), int(H)

write_array_tif(data, crs, transform, output_filename)

Write a tiff from a numpy array given the crs and transform

Parameters:

Name Type Description Default
data numpy array

Description of parameter data.

required
crs type

Description of parameter crs.

required
transform type

Description of parameter transform.

required
output_filename type

Description of parameter output_filename.

required

Returns:

Type Description
type

Description of returned object.

Source code in monetio/sat/utility.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def write_array_tif(data, crs, transform, output_filename):
    """Write a tiff from a numpy array given the crs and transform

    Parameters
    ----------
    data : numpy array
        Description of parameter `data`.
    crs : type
        Description of parameter `crs`.
    transform : type
        Description of parameter `transform`.
    output_filename : type
        Description of parameter `output_filename`.

    Returns
    -------
    type
        Description of returned object.

    """
    import rasterio

    new_dataset = rasterio.open(
        output_filename,
        "w",
        driver="GTiff",
        height=data.shape[0],
        width=data.shape[1],
        count=1,
        dtype=data.dtype,
        crs=crs,
        transform=transform,
    )
    new_dataset.write(data, 1)
    new_dataset.close()
    return None