Skip to content

Commit

Permalink
Merge pull request #2 from NVlabs/review
Browse files Browse the repository at this point in the history
Respond to reviews
  • Loading branch information
nbren12 authored May 31, 2024
2 parents f9d84d4 + 60ce89f commit e66f4fe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ pip install --no-build-isolation earth2-grid

```
>>> import earth2grid
>>> import torch
... # level is the resolution
... level = 6
... hpx = earth2grid.healpix.Grid(level=level, pixel_order=earth2grid.healpix.PixelOrder.XY)
... hpx = earth2grid.healpix.Grid(level=level, pixel_order=earth2grid.healpix.XY())
... src = earth2grid.latlon.equiangular_lat_lon_grid(32, 64)
... z_torch = torch.as_tensor(z)
... z_torch = torch.as_tensor(z)
... z_torch = torch.cos(torch.deg2rad(torch.tensor(src.lat)))
... z_torch = z_torch.broadcast_to(src.shape)
>>> regrid = earth2grid.get_regridder(src, hpx)
>>> z_hpx = regrid(z_torch)
>>> z_hpx.shape
Expand Down
27 changes: 4 additions & 23 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
# Installation

## Stable release

To install Earth2 Grid Utilities, run this command in your
terminal:

``` console
$ pip install earth2-grid
```

This is the preferred method to install Earth2 Grid Utilities, as it will always install the most recent stable release.

If you don't have [pip][] installed, this [Python installation guide][]
can guide you through the process.

## From source

The source for Earth2 Grid Utilities can be downloaded from
the [Github repo][].

You can either clone the public repository:

``` console
$ git clone git://github.com/waynerv/earth2-grid
$ git clone git@github.com:NVlabs/earth2grid.git
```

Or download the [tarball][]:

``` console
$ curl -OJL https://github.com/waynerv/earth2-grid/tarball/master
$ curl -OJL https://github.com/NVlabs/earth2-grid/tarball/master
```

Once you have a copy of the source, you can install it with:

``` console
$ pip install .
$ pip install --no-build-isolation .
```

[pip]: https://pip.pypa.io
[Python installation guide]: http://docs.python-guide.org/en/latest/starting/installation/
[Github repo]: https://github.com/%7B%7B%20cookiecutter.github_username%20%7D%7D/%7B%7B%20cookiecutter.project_slug%20%7D%7D
[tarball]: https://github.com/%7B%7B%20cookiecutter.github_username%20%7D%7D/%7B%7B%20cookiecutter.project_slug%20%7D%7D/tarball/master
[Github repo]: https://github.com/NVlabs/earth2grid
30 changes: 18 additions & 12 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
To use Earth2 Grid Utilities in a project

```
import earth2grid
# level is the resolution
level = 6
hpx = earth2grid.healpix.Grid(level=level, pixel_order=earth2grid.healpix.PixelOrder.XY)
src = earth2grid.latlon.equiangular_lat_lon_grid(32, 64)
z_torch = torch.as_tensor(z)
z_torch = torch.as_tensor(z)
regrid = earth2grid.get_regridder(src, hpx)
z_hpx = regrid(z_torch)
z_hpx.shape
nside = 2**level
reshaped = z_hpx.reshape(12, nside, nside)
>>> import earth2grid
>>> import torch
... # level is the resolution
... level = 6
... hpx = earth2grid.healpix.Grid(level=level, pixel_order=earth2grid.healpix.XY())
... src = earth2grid.latlon.equiangular_lat_lon_grid(32, 64)
... z_torch = torch.cos(torch.deg2rad(torch.tensor(src.lat)))
... z_torch = z_torch.broadcast_to(src.shape)
>>> regrid = earth2grid.get_regridder(src, hpx)
>>> z_hpx = regrid(z_torch)
>>> z_hpx.shape
torch.Size([49152])
>>> nside = 2**level
... reshaped = z_hpx.reshape(12, nside, nside)
... lat_r = hpx.lat.reshape(12, nside, nside)
... lon_r = hpx.lon.reshape(12, nside, nside)
>>> reshaped.shape
torch.Size([12, 64, 64])
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "earth2-grid"
version = "2024.5.1"
version = "2024.5.2"
description = "Utilities for working with geographic data defined on various grids."
readme = "README.md"
license = { file="LICENSE.txt" }
Expand Down
14 changes: 14 additions & 0 deletions tests/test_latlon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.import torch
import torch

from earth2grid.latlon import equiangular_lat_lon_grid
Expand Down

0 comments on commit e66f4fe

Please sign in to comment.