Skip to main content

ncBuilder

Project description

ncBuilder

netCDF4 tool to help creating new files from scratch, and loading variables from existing ones.

example

from ncBuilder import (
    ncBuilder,
    ncHelper,
)
import datetime as dt
import numpy as np
import pandas as pd

dtNow = dt.datetime.now()
times = pd.date_range('2021-01-01', periods=10).to_pydatetime()
lat = np.arange(-30., 10. + 0.05, 0.05)
lon = np.arange(-60., -30 + 0.05, 0.05)
temp = np.random.rand(times.size, lat.size, lon.size)

nc_file = ncBuilder.initialize_nc(dtNow, '/path/to/file', '_suffix.nc')
# or
nc_file = nc.Dataset('your_nc_file.nc', 'w')
# nc_file = ncBuilder.initialize_nc('file_name_here', '/path/to/file', '_suffix.nc')

# creating dimensions
ncBuilder.create_nc(nc_file,
                    lat,
                    lon,
                    time=times)
# or create variables while creating dimensions
ncBuilder.create_nc(nc_file,
                    lat,
                    lon,
                    time=times, 
                    vars={'temp': {'dims': ('time', 'latitude', 'longitude'),
                                   'units': 'ºC',
                                   'standard_name': 'temperature in ºC',
                                   },
                          })

# creating a single variable
ncBuilder.create_nc_variable(nc_file,
                             'temp',
                             comp_lvl=6,
                             dims=('time',
                                   'latitude',
                                   'longitude'),
                             dtype=np.float64,
                             units='°C',
                             standard_name='temperature in °C')

# updating a variable
ncBuilder.update_nc(nc_file, 'temp', temp)

# updating partially a variable
ncBuilder.update_nc(nc_file, 'temp', temp[:, 5:, :-5], dims=(slice(None), 
                                                             slice(5, None),
                                                             slice(None, -5)))

# loading time
times = ncHelper.load_time(nc_file.variables['time'])

# getting lats and lons
lats, lons = ncHelper.get_lats_lons(nc_file)

# getting nearest point
idx, jdx = ncHelper.get_idx_pos(lat0, lon0, lats, lons)

# closing the nc_file
nc_file.close()

version 0.0.7

  • Added create_nc_dimension, so new custom dimensions can be easily added.
  • Minor modifications to the inner creation of dimensions to accomodate the new function.

version 0.0.6

  • Added zlib, fill_value and variable_kw when creating a new variable, so it's more customizable
  • Changed the way dimension variables are created for more consistency of the process

version 0.0.5

  • Added ncHelper, which contains load_time, get_lats_lons and get_idx_pos

version 0.0.3

  • Modified function names to use snake_style pattern
  • Comments added to the main functions
  • Example updated to follow the new patterns

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ncBuilder-0.0.7.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ncBuilder-0.0.7-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file ncBuilder-0.0.7.tar.gz.

File metadata

  • Download URL: ncBuilder-0.0.7.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.11

File hashes

Hashes for ncBuilder-0.0.7.tar.gz
Algorithm Hash digest
SHA256 ed6f78e9a7867ffdbe5239b5887ba252558fcc191061697297e0694026803da8
MD5 fa8ab468bbf2ba0e4615f814a1f1d4e7
BLAKE2b-256 9cbefe02114e82a454bc0c00e0601d4664063fa4e4cb8abde046c8329115c70d

See more details on using hashes here.

File details

Details for the file ncBuilder-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: ncBuilder-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.11

File hashes

Hashes for ncBuilder-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e44fd51076eec15a9cd2788d0566dd4921e858faae8f6f3ea29dc6bababcce99
MD5 dc72a439a79a6a3cdcdb6a1346d12836
BLAKE2b-256 8ba504c9b8ee1a89adafc364cf0e065ae85ed4532b505d42467069f5f0625c5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page