Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Reading netcdf files #67

Open
carleyjmartin opened this issue Jun 9, 2023 · 0 comments
Open

New Feature: Reading netcdf files #67

carleyjmartin opened this issue Jun 9, 2023 · 0 comments
Assignees

Comments

@carleyjmartin
Copy link
Collaborator

New Feature

Name: read_netcdf

module: in superdarn.py

package: superdarn

Scope

Will read netcdf files produced at APL into dictionary to use with pyDARN.

Code to work from:

"""
Demo read SuperDARN netCDF files available from https://superdarn.jhuapl.edu/download/
nc_utils available from github.com/alexchartier/nc_utils
Alex Chartier, 2023
"""
try:
    import nc_utils
except:
    print('Get nc_utils from github.com/alexchartier/nc_utils')
import sys

def main(fit_fn, grid_fn):
    # Read the whole file using load_nc() (provides access to header info)
    grid_file = nc_utils.load_nc(grid_fn)
    fit_file = nc_utils.load_nc(fit_fn)

    # Read the variables (a little easier to use)
    grid_vars = nc_utils.ncread_vars(grid_fn)
    fit_vars = nc_utils.ncread_vars(fit_fn)

    """ Print the details of the fit file """
    print('\n*****')
    print(fit_fn)
    print(fit_file.description)  # Note the grid_file (and other python objects) can be interrogated on the commandline using dir()
    print('Lat: %s' % fit_file.lat)
    print('Lon: %s' % fit_file.lon)
    print('Boresight: %s\n' % fit_file.boresight)
    for k, v in fit_vars.items():
        print('%s: %i entries, e.g. %1.1f' % (k, len(v), v[0]) )
    print('*****\n')

    """ Print the details of the grid file """
    print('\n*****')
    print(grid_fn)
    print(grid_file.description)  # Note the grid_file (and other python objects) can be interrogated on the commandline using dir()
    print('Lat: %s' % grid_file.lat)
    print('Lon: %s' % grid_file.lon)
    print('Boresight: %s\n' % grid_file.boresight)
    for k, v in grid_vars.items():
        print('%s: %i entries, e.g. %1.1f' % (k, len(v), v[0]) )
    print('*****\n')


if __name__ == '__main__':
    args = sys.argv
    demo_fit_fn = "~/Downloads/19940701.gbr.v3.0.despeckled.nc"
    demo_grid_fn = "~/Downloads/20150317.cly.v3.0.grid.nc"
    assert len(args) == 3, 'Should have 2 args, e.g.:\n python3 read_nc.py %s %s' % (demo_fit_fn, demo_grid_fn)
    fit_fn = sys.argv[1]
    grid_fn = sys.argv[2]
    main(fit_fn, grid_fn)
@JWiker JWiker self-assigned this Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants