2

I tried to convert my text file into NetCDF (nc) file with the help of the youtube link I shared here. I cannot open this nc file in GrADS. I guess the reason is that I cannot add metadata or something into nc file with these lines of codes.

I would therefore like to improve the code in my hand so that I can open it up in other platforms. I need to open this NetCDF file in RCMES so I can carry out quantile mapping bias correction operations.

I am also open to suggestion for other ways/programming languages/platforms to perform this conversion task.

Below is the code I used.

import netCDF4 as nc
import numpy as np
import panda
import numpy as np
import pandas as pd
import xarray

# here csv file is converted into pandas dataframe
df = pd.read_csv('C:/Users/Asus/Documents/ArcGIS/ArcGIS Copy/evaporation/Downscaling Files/netcdfye dönecek csvler/Aydin_cnrm_Prec_rcp451.txt')
df

#converting pandas dataframe into xarray
xr = df.to_xarray()
xr

#lastly from xarray to nc file conversion
xr.to_nc('Aydin_cnrm_Prec_rcp451.nc')
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86

1 Answers1

3

Instead of using Python for creating a Netcdf file from a ASCII/txt file I tried using cdo that I installed on Ubuntu.

The following lines of code solved the problem

cdo -f nc input,r1x1 tmp.nc < Aydin_cnrm_Prec_rcp45.txt

cdo -r -chname,var1,prec -settaxis,1980-01-01,00:00:00,1mon tmp.nc prec.nc
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86