GithubHelp home page GithubHelp logo

nsidc / nsidc0756-scripts Goto Github PK

View Code? Open in Web Editor NEW
3.0 6.0 1.0 167 KB

Scripts related to NSIDC-0756

Home Page: https://nsidc.org/data/nsidc-0756

License: Other

MATLAB 44.21% Python 55.79%
bedmachine nsidc-0756 nsidc0756 interpolation coordinate-conversion

nsidc0756-scripts's Introduction

NSIDC logo NSIDC DAAC Logo NASA logo

nsidc0756-scripts

Scripts related to NSIDC-0756: MEaSUREs BedMachine Antarctica, Version 2. This repository is a work in progress!

The scripts that are currently in this repository can be used to convert between geographic lat/lon and polar stereographic coordinates, and for interpolating BedMachine Antarctica data onto user-defined coordinates.

For example, one could interpolate bedrock elevation values from BedMachine Antarctica onto a latitude/longitude grid. First, use the ll2xy script to convert lat/lon coordinates to polar stereographic coordinates. Then these coordinates can be used as input for the interpBedmachineantarctica script which will interpolate BedMachine Antarctica values onto the input coordinates. The scripts are available both as Matlab and python scripts, for further details please see below.

Level of Support

  • This repository is fully supported by NSIDC. If you discover any problems or bugs, please submit an Issue. If you would like to contribute to this repository, you may fork the repository and submit a pull request.

See the LICENSE for details on permissions and warranties. Please contact [email protected] for more information.

Scripts

xy2ll.m | xy2ll.py

Converts polar stereographic (x, y) coodinates to geodetic (latitude, longitude) coordinates.

Usage example for xy2ll.py:

from netCDF4 import Dataset

from xy2ll import xy2ll

ds = Dataset('BedMachineAntarctica_2019-11-05_v01.nc')
xs = ds.variables['x'][:]
ys = ds.variables['y'][:]

# cast xs and ys as float. `xy2ll` will not return correct results
# otherwise.
xs = xs.astype(float)
ys = ys.astype(float)

lats, lons = xy2ll(
    xs,
    ys,
    -1,  # -1 is a flag indicating the southern hemisphere.
)

ll2xy.m | ll2xy.py

Converts geodetic (latitude, longitude) coordinates to polar sterographic (x, y) coordinates.

interpBedmachineantarctica.m | interp_bedmachine_antarctica.py

Interpolates values from the BedMachineAntarctica netcdf file onto requested (x, y) polar stereographic coordinates.

NOTE:

interp_bedmachine_antarctica.py does not provide a perfect re-implementation of interpBedMachineAntarctica.m! When used with a to_x array of <1000, this code should perform in roughly the same way. When interpolating onto larger grids, interpBedMachineAntarctica.m uses a custom interpolation algorithm that has not yet been implemented in Python.

Outputs from interpBedMachineAntarctica.m have not been directly compared to interp_bedmachine_antarctica.py yet. Results may differ.

Setup

To use interp_bedmachine_antarctica.py, the requirements listed under environment.yml must be installed.

To create an environment with conda:

$ conda env create -f environment.yml
$ conda activate interp_bedmachine

Example usage (Python):

$ python
>>> from interp_bedmachine_antarctica import interp_bedmachine_antarctica
>>> import numpy as np
>>> to_x = np.linspace(-1666500.0, 1666500.0, 13332)
>>> to_y = np.linspace(-1666500.0, 1666500.0, 13332)
>>> variable = 'bed'
>>> bedmachine_nc_path = './BedMachineAntarctica_2019-11-05_v01.nc'
>>> interpolated = interp_bedmachine_antarctica(
        to_x,
        to_y,
        variable,
        bedmachine_nc_path=bedmachine_nc_path
)
>>> interpolated
array([[-4442.84863281, -4442.40963504, -4441.97063731, ...,
          386.82238055,   388.31525668,   389.80810547],
       [-4442.15570974, -4441.8033949 , -4441.45106056, ...,
          385.1755937 ,   386.62244517,   388.06926655],
       [-4441.46270859, -4441.19708971, -4440.93143181, ...,
          383.52890537,   384.92973833,   386.33053843],
       ...,
       [-4019.93213131, -4021.66220741, -4023.39202323, ...,
          241.79977309,   241.0239085 ,   240.24799334],
       [-4018.98273722, -4020.62648272, -4022.27007854, ...,
          264.8464815 ,   262.60142472,   260.35621881],
       [-4018.03344727, -4019.59069298, -4021.14789963, ...,
          287.89288765,   284.17862334,   280.46411133]])

Example usage (MATLAB):

% Input lat. and lon. and they can be an array or a list.
lat = [-84.72, -82.03; -83.96, -79.07];
lon = [92.41 ,85.11; 65.65, 77.67];

% For each lat., lon. calculate the stereographic coordinates
[x,y] = ll2xy(lat, lon, -1);

% Interpolate the Bedmachine values onto the coordinates
bed = interpBedmachineAntarctica(x,y,'bed');

disp(bed)

License

See LICENSE.

Code of Conduct

See Code of Conduct.

Credit

This software was developed by the National Snow and Ice Data Center with funding from multiple sources.

nsidc0756-scripts's People

Contributors

trey-stafford avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

alextbradley

nsidc0756-scripts's Issues

xy2ll error in solving for rho

I attempted to use the xy2ll for both MATLAB and python. I used the x and y data from the BedMachine .nc file. In both instances of running the script I ran into the errors
For Python:
ufunc 'square' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

For MATLAB:
Check for incorrect argument data type or missing argument in call to function 'sqrt'.
rho=sqrt(x.^2+y.^2);

In Python I was able to fix the issue by importing the x and y values as a dtype='int64' numpy array. Some stackoverflow searchers made it seem like the error was an integer overflow issue. However the output longitude values only varied from -45 to 135 and not -180 to 180.

Any help would be much appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.