Skip to main content

ncBuilder

Project description

ncBuilder

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

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

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')
# nc_file = ncBuilder.initialize_nc('file_name_here', '/path/to/file', '_suffix.nc')

# creating dimensions
ncBuilder.create_nc(nc_file, lat, lon, time=times)

# 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()

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.5.tar.gz (6.4 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.5-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncBuilder-0.0.5.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.3

File hashes

Hashes for ncBuilder-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a68dbc9001c81127836a6347be0b4a6b5ed764fc8404fe2b72d8be0b7e318d04
MD5 b428fe0aff09e672cff6c4cf088cf559
BLAKE2b-256 d5033f1609e32ce7c8dbda4e84bc440cb306f074d29fa3cb00add6d7a6de7484

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ncBuilder-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.3

File hashes

Hashes for ncBuilder-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8ec30a48ef63a710d096a507eb39a139e7a78cdbd93616d08a8529c744163efa
MD5 46f2134df16588c643da5a9be8ddb150
BLAKE2b-256 0c7212ca434b4a88a9316a594eacdfb3da5b993e22942a770aa48546ef876ebf

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