netcdf4

Extracting values for specific lat long from netcdf

穿精又带淫゛_ 提交于 2020-05-14 09:02:19
问题 I'm trying to read into R a netCDF file. The netcdf chirps-v2.0.1981.days_p05.nc is downloaded from here: ftp://ftp.chg.ucsb.edu/pub/org/chg/products/CHIRPS-2.0/global_daily/netcdf/p05/ This netCDF file describes daily rainfall globally as a function of longitude, latitude and has size of 1.1 GB I also have a set of lon lat dat <- structure(list(locatioID = paste0('ID', 1:16), lon = c(73.73, 86, 73.45, 86.41, 85.36, 81.95, 82.57, 75.66, 82.03, 81.73, 85.66, 85.31, 81.03, 81.70, 87.03, 73.38),

Take maximum rainfall value for each season over a time period (xarray)

…衆ロ難τιáo~ 提交于 2020-04-18 06:08:42
问题 I'm trying to find the maximum rainfall value for each season (DJF, MAM, JJA, SON) over a 10 year period. I am using netcdf data and xarray to try and do this. The data consists of rainfall (recorded every 3 hours), lat, and lon data. Right now I have the following code: ds.groupby('time.season).max('time') However, when I do it this way the output has a shape of (4,145,192) indicating that it's taking the maximum value for each season over the entire period. I would like the maximum for each

How to extract all levels from a netcdf file using the raster package?

喜夏-厌秋 提交于 2020-01-06 07:12:58
问题 Related to this question Plotting netcdf file with levels in R But I would like to know how to extract all levels from a netcdf file automatically, without going through one at a time. Do I have to write a custom function or is there a function in raster package that does that? 来源: https://stackoverflow.com/questions/52893780/how-to-extract-all-levels-from-a-netcdf-file-using-the-raster-package

Python: How to use MFdataset in netCDF4

百般思念 提交于 2020-01-01 19:55:12
问题 I am trying to read multiple NetCDF files and my code returns the error: ValueError: MFNetCDF4 only works with NETCDF3_* and NETCDF4_CLASSIC formatted files, not NETCDF4. I looked up the documentation and MFdataset is not supported by NetCDF4, so I'm confused where to go from here. 回答1: I think the error is pretty clear, but there are ways to avoid it. 1/ You could convert the NetCDF files from NetCDF4 to the classic format using e.g. nccopy: nccopy -k classic nc4_file.nc ncclassic_file.nc 2/

NCO cropping a netcdf file using dimension values rather than indices

自古美人都是妖i 提交于 2020-01-01 19:20:32
问题 CDO can crop a netcdf file in terms of latitude and longitude as long as they are defined in a standard way, and I know that NCO can cut out a subset of a netcdf file along any dimension if you know the range of indices that you want, as stated in the answers to this related question: Is there a way to crop a NETCDF file? However, I was wondering if the ncks hyperslabber can work directly on the values of the dimension, rather than the index values? 回答1: Yes, using a decimal indicates the

Fortran NetCDF - added new dimension need to fill it with zeroes

时间秒杀一切 提交于 2019-12-25 07:59:56
问题 I added a new dimension to an existing netCDF file in fortran using the following code - retval = nf_open(cfn,NF_WRITE,ncid) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_redef(ncid) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_def_dim(ncid,"xyz",len,dimid_xyz) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_enddef(ncid) Now I want to be able to fill this dimension with values of zero. The cardinality of this set is equal to the cardinality of

Aggregating seasonal means with the raster package in r

给你一囗甜甜゛ 提交于 2019-12-13 14:05:24
问题 I am attempting to aggregate daily data (35 years) to monthly then calculate seasonal mean using the raster package in R (I know how to do it with CDO). Below is my code, which outputs 4 seasonal means for all years (140 layers). How can I loop to output only 4 layers ( for the 4 seasons)?. I appreciate your help. dailydata <- brick ("dailyrain.nc") dates <- seq(as.Date("1981-01-01"), as.Date("2015-12-31"), by="day") months <- format(dates, "%Y-%m") Aggregate2Monthly <- function(x) { agg <-

\[Errno -101\] NetCDF: HDF error when opening netcdf file

狂风中的少年 提交于 2019-12-13 02:00:48
问题 I have this error when opening my netcdf file. The code was working before. How do I fix this ? Traceback (most recent call last): File "", line 1, in ... File "file.py", line 71, in gather_vgt return xr.open_dataset(filename) File "/.../lib/python3.6/site-packages/xarray/backends/api.py", line 286, in open_dataset autoclose=autoclose) File "/.../lib/python3.6/site-packages/xarray/backends/netCDF4_.py", line 275, in open ds = opener() File "/.../lib/python3.6/site-packages/xarray/backends

Convert NetCDF file to CSV or text using Python

我怕爱的太早我们不能终老 提交于 2019-12-12 07:06:53
问题 I'm trying to convert a netCDF file to either a CSV or text file using Python. I have read this post but I am still missing a step (I'm new to Python). It's a dataset including latitude, longitude, time and precipitation data. This is my code so far: import netCDF4 import pandas as pd precip_nc_file = 'file_path' nc = netCDF4.Dataset(precip_nc_file, mode='r') nc.variables.keys() lat = nc.variables['lat'][:] lon = nc.variables['lon'][:] time_var = nc.variables['time'] dtime = netCDF4.num2date

mysql.connector.errors.ProgrammingError: Failed processing format-parameters;Python 'list' cannot be converted to a MySQL type

你。 提交于 2019-12-12 04:22:15
问题 I am trying to store some data in MYSQL database using python script, but i got the following error. mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'list' cannot be converted to a MySQL type Actually I am extracting variables from netCDF file and trying to store them in MYSQL db. my code is import sys import collections import os import netCDF4 import calendar from netCDF4 import Dataset import mysql.connector from mysql.connector import errorcode table =