dtcenter / METdataio

https://metdataio.readthedocs.io/en/latest/index.html
Apache License 2.0
5 stars 3 forks source link

Bugfix METreadnc does support reading netCDF data that only has level and latitude (rather than longitude and latitude and level) #247

Closed bikegeek closed 10 months ago

bikegeek commented 11 months ago

Describe the Problem

When reading in the following netCDF data (remove the .txt extension), which DOES NOT have a longitude, only latitude: sa_test.nc.txt

The resulting pandas dataframe does not capture the level and latitude data into separate columns but instead creates an index comprised of the latitude and level:

xarray_to_dataframe

The Xarray method to_dataframe() does not correctly handle this input data.

Expected Behavior

When using the METdataio.METreadnc.util.read_netcdf package to reformat netCDF data with only latitude (and no corresponding longitude), no errors are produced but the resulting data frame does not have the expected data columns corresponding to the level and latitude.

On 'cheyenne', you will observe an AttributeError: 'DataFrame' object has no attribute 'append'. Did you mean: '_append'? while running the read_netcdf.py script. Note: the append method has been deprecated in later versions of pandas, so this should be replaced with concat.

Environment

Describe your runtime environment: 1. Machine: (e.g. HPC name, Linux Workstation, Mac Laptop) cheyenne 2. OS: (e.g. RedHat Linux, MacOS) GNU/ Linux 3. Software version number(s) Linux cheyenne5 4.12.14-95.51-default #1 SMP Fri Apr 17 08:14:12 UTC 2020 (c6bab98) x86_64 x86_64 x86_64 GNU/Linux (output from uname -a)

To Reproduce

Describe the steps to reproduce the behavior: Clone the METcalcpy and METdataio source code Set up a Python environment 1. Go to 'METdataio/METreadnc/util 2. Copy the netcdf file to a data directory and set the CALCPY_DATA env variable 3. Set the PYTHONPATH to PATH-TO/METdataio/METreadnc:PATH-TO/METcalcpy:PATH-TO/METcalcpy/metcalcpy 4. From the METdataio/METreadnc/util directory run the following: python Post relevant sample data following these instructions: sa_test.nc.txt

Relevant Deadlines

List relevant project deadlines here or state NONE.

Funding Source

Define the source of funding and account keys here or state NONE.

Define the Metadata

Assignee

Labels

Projects and Milestone

Define Related Issue(s)

Consider the impact to the other METplus components.

Bugfix Checklist

See the METplus Workflow for details.

bikegeek commented 11 months ago

resetting the index of the resulting data frame seems to produce the expected data frame:

df = df.append(file_data.to_dataframe().reset_index(), sort=False)