X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 23 Jan 2018 11:36 AM by  David Starbuck
read netcdf file with python
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Simone Colella



New Member


Posts:
New Member


--
17 Jan 2018 01:45 PM
    Hi,
    I would like to read a netcdf4 file using python bridge.
    I imported netCDF4 module and then I read the file:

    rd=python.import('netCDF4')
    data=rd.Dataset('/tmp/A2007235-chl-med-hr.nc')

    now with help,data I obtain the information:

    <class 'netCDF4._netCDF4.Dataset'>
    root group (NETCDF4 data model, file format HDF5):
    Conventions: CF-1.4
    title: dataset-oc-med-chl-modis-l3-chl_1km_daily-rt-v02
    netcdf_version: v4
    grid_mapping: Equirectangular
    parameter: chlorophyll-a concentration
    platform: Aqua (EOS PM) satellites
    sensor_name: MODIS
    sensor: Moderate Resolution Imaging Spectroradiometer
    history:
    source: surface observation
    start_time: 08:00:00 UTC
    stop_time: 14:00:00 UTC
    file_quality_index: 0
    Citation:
    start_date: 2007-08-23
    stop_date: 2007-08-23
    creation_date: Wed May 03 2017
    creation_time: 18:05:58 UTC
    westernmost_longitude: -6.0
    easternmost_longitude: 36.5
    southernmost_latitude: 30.0
    northernmost_latitude: 46.0
    grid_resolution: 1 Km
    product_version:
    site_name:
    dimensions(sizes): time(1), lat(1580), lon(3308)
    variables(dimensions): int32 time(time), float32 lat(lat), float32 lon(lon), float32 CHL(time,lat,lon), float32 WTM(time,lat,lon)
    groups:

    Now I would like select lat or lon variables and import the data array.

    I select the "lat" variable with:
    latitude=data.variables['lat']

    but I don't know how I can get the data.

    I tried with data.variables['lat'][:] (as in python ambient) but it doesn't work.

    Can you help me?

    thanks in advance.

    ciao
    S

    David Starbuck



    Basic Member


    Posts:143
    Basic Member


    --
    23 Jan 2018 11:36 AM
    I've never read a netcdf file using python. It looks you are able to get the netcdf dataset object into IDL from Python. I think that it would be helpful to know the data type of the variables property of this object. Could you perhaps enter the following command and post the output:

    variables = data.variables
    help, variables
    You are not authorized to post a reply.