Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to write to a netcdf file using xarray

#import xarray
import xarray as xr

ds = xr.open_dataset(file_name.nc)

#by now you may have performed some computations and ds is a new dataset

ds.to_netcdf('/directory_to_file/file_name.nc', format='NETCDF4_CLASSIC')
Comment

using xarray to open netcdf data

# Reading and writing netCDF files with xarray requires scipy or the netCDF4-Python library
# to be installed (the latter is required to read/write netCDF V4 files and use the
# compression options described below).


# 1) We can load netCDF files to create a new Dataset using open_dataset():

ds_disk = xr.open_dataset("saved_on_disk.nc")

# print data information
ds_disk
    
    
# 2) We can save a Dataset to disk using the Dataset.to_netcdf() method:
ds.to_netcdf("saved_on_disk.nc")


# Datasets have a Dataset.close() method to close the associated netCDF file.
# However, it’s often cleaner to use a with statement:

# this automatically closes the dataset after use
with xr.open_dataset("saved_on_disk.nc") as ds:
     print(ds.keys())
    
    
  
Comment

PREVIOUS NEXT
Code Example
Python :: python with file 
Python :: concatenate directories python 
Python :: tkmessagebox not found 
Python :: json filter python 
Python :: how to find total no of nan values in pandas 
Python :: pandas shift all columns 
Python :: how to define a constant in python 
Python :: relu function python 
Python :: clahe opencv 
Python :: how to sort tuples in list python 
Python :: accessing index of dataframe python 
Python :: sorted vs sort python 
Python :: clear text box tkinter python 
Python :: check if camera is being used python 
Python :: sum of any numbers in python 
Python :: how to read xlsx file in jupyter notebook 
Python :: pandas drop duplicates from column 
Python :: generate random number from range python 
Python :: python insert on a specific line from file 
Python :: separate path python 
Python :: python capture desktop as video source 
Python :: write a list into csv python 
Python :: python numphy how to use fractions 
Python :: how to sum certain columns row wise in python 
Python :: merge two dictionaries in a single expression 
Python :: creating a virtual environment with django on windows 
Python :: pandas name of day 
Python :: python printing to a file 
Python :: python exit for loop 
Python :: python unzip list of tuples 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =