GEOS-Chem

class PseudoNetCDF.geoschemfiles.bpch(*args, **kwds)[source]

bpch_path: path to binary punch file tracerinfo: path to ascii file with tracer definitions diaginfo: path to ascii file with diagnostic group definitions mode : {‘r+’, ‘r’, ‘w+’, ‘c’}, optional

The file is opened in this mode:

+——+———————————————————–+
| ‘r’ | Open existing file for reading only. |
+——+———————————————————–+
| ‘r+’ | Open existing file for reading and writing. |
+——+———————————————————–+
| ‘w+’ | Create or overwrite existing file for reading and writing.|
+——+———————————————————–+
| ‘c’ | Copy-on-write: assignments affect data in memory, but |
| | changes are not saved to disk. The file on disk is |
| | read-only. |
+——+———————————————————–+
timeslice: If the file is larger than 2GB, timeslice provides a way

to subset results. The subset requested depends on the data type of timeslice:

  • int: return the a part of the file if it was broken

    into 2GB chunks (0..N-1)

  • slice: return the times that correspond to that slice

    (i.e., range(ntimes)[timeslice])

  • list/tuple/set: return specified times where each

    time is in the set (0..N-1)

noscale: Do not apply scaling factors vertgrid: vertical coordinate system (options: ‘GEOS-5-REDUCED’,

‘GEOS-5-NATIVE’, ‘MERRA-REDUCED’, ‘MERRA-NATIVE’, ‘GEOS-4-REDUCED’, ‘GEOS-4-NATIVE’, default ‘GEOS-5-REDUCED’)

nogroup: False - use all groups, True - use no groups, list of groups

to ignore

apply(verbose=0, **dimfuncs)

Similar to numpy.apply_along_axis, but for damed dimensions and processes dimensions as well as variables

Parameters
  • dimfuncs (dictionary) – key value pairs where the key is a dimensions and the value is a 1D function (func1d) or a dictionary. If the value is a dictionary it must include func1d as a function and any keyword arguments as additional options

  • verbose (integer) – 0 silent, 1 show variable, 2 show dimensions and variables

Returns

outf – instance with variables and dimensions after processing

Return type

PseudoNetCDFFile

applyAlongDimensions(verbose=0, **dimfuncs)

Similar to numpy.apply_along_axis, but for damed dimensions and processes dimensions as well as variables

Parameters
  • dimfuncs (dictionary) – key value pairs where the key is a dimensions and the value is a 1D function (func1d) or a dictionary. If the value is a dictionary it must include func1d as a function and any keyword arguments as additional options

  • verbose (integer) – 0 silent, 1 show variable, 2 show dimensions and variables

Returns

outf – instance with variables and dimensions after processing

Return type

PseudoNetCDFFile

close()

Does nothing. Implemented for continuity with Scientific.IO.NetCDF

copy(props=True, dimensions=True, variables=True, data=True)

Function for making copies of the same type

Parameters
  • props (boolean) – include properties (default: True)

  • dimensions (boolean) – include dimensions (default: True)

  • variables (boolean) – include variable structures (default: True)

  • data (boolean) – include variable data (default: True)

Returns

outf

Return type

PseudoNetCDFFile instance

copyVariable(var, key=None, dtype=None, dimensions=None, fill_value=None, withdata=True)

Copy var into self as vark

Parameters
  • var (PseudoNetCDFVariable) – netCDF4.Variable-like object (must have ncattrs and setncatts)

  • key (string) – key for variable in self (can be omitted if var has name, standard_name, or long_name)

  • dtype (string or numpy.dtype) – change the data type to dtype

  • dimensions (iterable of strings) – change the dimensions to dimensions

  • fill_value (integer or flaot) – change the fill_value to this values

  • withdata (boolean) – default True, copies data

Returns

myvar – copy of var in this file

Return type

PseuodNetCDFVairable

createDimension(name, length)

Create a dimension

Parameters
  • name (string) – name for dimension

  • length (integer) – maximum length of dimension

Returns

dim – new dimension

Return type

PseudoNetCDFDimensions

createVariable(name, type, dimensions, fill_value=None, **properties)

Create a variable

Parameters
  • name (string) – name for new variable

  • type (string or numpy dtype) – code (e.g., ‘f’, ‘i’, ‘d’)

  • dimensions (tuple of strigns) – dimension keys that can be found in objects’ dimensions dictionary

Returns

var

Return type

new variable

date2num(time, timekey='time')
Parameters
  • time (array-like) – array of datetime.datetime objects

  • timekey (str) – time variable key which requires units and should have calendar. If calendar is missing, standard is the default. default ‘time’

Returns

num – time in relative time as defined by units of time variable (i.e., timekey) which defaults to ‘time’

Return type

array-like

eval(expr, inplace=False, copyall=False)

Evaluate expr and return a PseudoNetCDFFile object with resutl

Parameters
  • expr (string) – expression to evaluate

  • inplace (boolean) – create the new variable in this netcdf file (default False)

  • copyall (boolean) – if not inplace, should all variables be copied to new file

Returns

outf – instance with renamed variable (this file if inplace = True)

Return type

PseudoNetCDFFile

flush()

Does nothing. Implemented for continuity with Scientific.IO.NetCDF

classmethod from_ncf(infile)
Parameters

infile (PseudoNetCDF-like file) –

Returns

outf

Return type

PseudoNetcdf-like file

classmethod from_ncvs(*invars, **invarkw)
Parameters
  • invars (list) – NetCDF-like variable must have standard_name, long_name or name

  • invarkw (kwds) – NetCDF-like variables

Returns

outf

Return type

PseudoNetcdf-like file

getCoords()

Return a list of coordkeys

getMap(maptype='basemap_auto', **kwds)

Description

Parameters
  • maptype (string) –

    choices ‘basemap’, ‘basemap_auto’, ‘cartopy’ (not yet) basemap : attempts to open a basemap with only supplied kwds basemap_auto : automatically adds llcrnrlon,llcrnrlat,u

    rcrnrlon,urcrnrlat based on longitude_bounds

  • **kwds (keywords) – for basemap or cartopy

Returns

map

Return type

basemap or cartopy axis

getTimes(bounds=False)

Get an array of datetime objects

Parameters
  • datetype (string or numpy.dtype) – ‘datetime’ or datetime64 dtype

  • bounds (boolean) – get time boundaries

Returns

out – datetime objects or array of numpy’s datetype type

Return type

array

Notes

self must have a time or TFLAG variable

get_dest()
Returns

path – path where a new file is created on some action

Return type

str

Notes

If None, a file is created in memory. Else, a netcdf file is created on disk.

get_varopt()

Get options

Parameters

None

Returns

options

Return type

dictionary of options

getncatts()

Return all ncattrs keys and values as a dictionary

Returns

attdict – key/value pairs of properties

Return type

dictionary

getproj(withgrid=False, projformat='pyproj')

Description

Parameters
  • withgrid (boolean) – use grid units instead of meters

  • projformat (string) – ‘pyproj’ (default), ‘proj4’ or ‘wkt’ allows function to return a pyproj projection object or a string in the format of proj4 or WKT

Returns

proj – (wkt, proj4) or pyprojProj (pyproj)

Return type

string pyproj.Proj

ij2ll(i, j)

i, j to center lon, lat

insertDimension(newonly=True, multionly=False, before=None, after=None, inplace=False, **newdims)

Insert dimensions with keys and lengths from newdims

Parameters
  • **newdims (dictionary) – where key is the new dimension and value is the length

  • newonly (boolean) – Only add dimension to variables that do not already have it, default True

  • multionly (boolean) – Only add dimension if there are already more than one (good for ignoring coordinate dimensions)

  • before (string) – if variable has this dimension, insert the new dimension before it. Otherwise, add to the beginning. (before takes precedence)

  • after (string) – if variable has this dimension, insert the new dimension after it. Otherwise, add to the beginning.

  • inplace (boolean) – create the new variable in this netcdf file (default False)

Returns

outf – instance will new dimension in dimensions and variables

Return type

PseudoNetCDFFile

Notes

  1. Adding a non unity dimension will cause the data to be repeated along the new axis.

  2. If order of addition matters, use multiple calls. newdimsuse will be a non-ordered dictionary

interpDimension(dimkey, newdimvals, coordkey=None, **interpkwds)
Parameters
  • dimkey (string) – the new dimension for interpolation

  • newdimvals (iterable) – the new values to interpolate to

  • coordkey (string) – the variable to use as the old coordinate values

  • interptype (string) –

    ‘linear’ or ‘conserve’. linear uses a linear interpolation

    conserve uses a mass conserving interpolation

  • extrapolate (boolean) – allow extrapolation beyond bounds with linear, default False

  • fill_value (numeric value) – set fill value (e.g, nan) to prevent extrapolation or edge continuation

Returns

outf – instance with all variables interpolated

Return type

PseudoNetCDFFile

Notes

When extrapolate is false, the edge values are used for points beyond the inputs.

interpSigma(vglvls, vgtop=None, interptype='linear', extrapolate=False, fill_value='extrapolate', layerdims=None, approach='eta', verbose=0)
Parameters
  • self (the file to interpolate from must have VGLVLS) –

  • vglvls (the new vglvls (edges)) –

  • vgtop (Converting to new vgtop (Pascals)) –

  • interptype ('linear' or 'conserve') – linear : uses a linear interpolation conserve : uses a mass conserving interpolation

  • extrapolate (allow extrapolation beyond bounds with linear,) – default False

  • fill_value (set fill value (e.g, nan) to prevent extrapolation or edge) – continuation

  • layerdims (specify layer dimension, None will apply to all dimensions) – named layer*

  • approach

    etause simple eta coordinates to calculate sigma and

    interpolate

    pressure : requires surface pressure

  • verbose (0-inf show more) –

Returns

Return type

outf - ioapi_base PseudoNetCDFFile with al variables interpolated

Notes

When extrapolate is false, the edge values are used for points beyond the inputs.

classmethod isMine(*args, **kwds)[source]

True if this file or object can be identified for use by this class. Useful to override for classes that can be initialized from disk.

ll2ij(lon, lat, bounds='error')

Converts lon/lat to 0-based indicies (0,M), (0,N)

Parameters
  • lon (scalar or iterable of longitudes in decimal degrees) –

  • lat (scalar or iterable of latitudes in decimal degrees) –

  • bounds (ignore, error, warn if i,j are out of domain) –

Returns

i, j

Return type

indices (0-based) for variables

ll2xy(lon, lat)

lon and lat are converted to local lon and lat (-180,180) (-90, 90)

mask(where=None, less=None, less_equal=None, greater=None, greater_equal=None, values=None, equal=None, invalid=False, mask=None, dims=None, fill_value=- 999, coords=False, verbose=0)

Apply mask to all variables of same shape or just where dimensions match.

Parameters
  • where (array-like) – boolean array to use as a mask see numpy.ma.masked_where

  • greater (scalar) – mask when values are greater than this value see numpy.ma.masked_greater

  • less (scalar) – mask when values are less than this value see numpy.ma.masked_less

  • greater_equal (scalar) – mask when values are greater than or equal to this value see numpy.ma.masked_greater

  • less_equal (scalar) – mask when values are less than or equal to this value see numpy.ma.masked_less

  • values (scalar) – mask when values are equal to this value within standard floating point see numpy.ma.masked_values

  • equal (scalar) – mask when values are exactly this value (i.e., integers) see numpy.ma.masked_equal

  • invalid (boolean) – mask when values are invalid, see numpy.ma.masked_invalid

  • mask (array-like) – alias for where

  • dims (iterable of strings) – only apply “mask” or “where” to variables with these dimensions no effet on other masks

  • fill_value (scalar) – value to use as the fill_value for new arrays

  • coords (boolean) – if True, apply masks to coordinate variables. Default, False

  • verbose (int) – level of verbosity for function, mostly for debugging

Returns

outf – instance with masked variables

Return type

PseudoNetCDFFile

See also

numpy.ma()

all masks are passing throught to numpy.ma.masked_

Notes

mask options are not mutually exclusive. the order is where, greater, greater_equal, less, less_equal, values, equal, invalid

plot(varkey, plottype='longitude-latitude', ax_kw=None, plot_kw=None, cbar_kw=None, map_kw=None, dimreduction='mean', laykey=None)
Parameters
  • self (the bpch file) –

  • varkey (the variable to plot) –

  • plottype (longitude-latitude, latitude-pressure, longitude-pressure,) – vertical-profile, time-longitude, time-latitude, time-pressure, default, longitude-latitude

  • ax_kw (keywords for the axes to be created) –

  • plot_kw (keywords for the plot (plot, scatter, or pcolormesh) to be) – created

  • cbar_kw (keywords for the colorbar) –

  • map_kw (keywords for the getMap routine, which is only used with) – plottype=’longitude-latitude’

  • dimreduction (dimensions not being used in the plot are removed) – using applyAlongDimensions(dimkey=dimreduction) where each dimenions

  • laykey (name of the layer dimension (e.g., layer47)) –

removeSingleton(dimkey=None)

Return a netcdflike object with dimensions sliced

Parameters

dimkey (string) – key of dimension to be evaluated for removal; if None, evaluate all. only singleton dimensions will be removed.

Returns

outf – instance with dimensions removed

Return type

PseudoNetCDFFile

renameDimension(oldkey, newkey, inplace=False)

Rename dimension (oldkey) in dimensions and in all variables

Parameters
  • oldkey (string) – dimension to be renamed

  • newkey (string) – new dame for dimension

  • inplace (boolean) – create the new variable in this netcdf file (default False)

Returns

outf – instance with renamed variable (this file if inplace = True)

Return type

PseudoNetCDFFile

renameDimensions(inplace=False, **newkeys)

Rename dimension (oldkey) in dimensions and in all variables

Parameters
  • **newkeys (dictionary) – where key is the oldkey and value is the newkey

  • inplace (boolean) – create the new variable in this netcdf file (default False)

Returns

outf – instance with renamed variable (this file if inplace = True)

Return type

PseudoNetCDFFile

renameVariable(oldkey, newkey, inplace=False, copyall=True)

Rename variable (oldkey)

Parameters
  • oldkey (string) – variable to be renamed

  • newkey (string) – new dame for variable

  • inplace (boolean) – create the new variable in this netcdf file (default False)

  • copyall (boolean) – if not inplace, should all variables be copied to new file

Returns

outf – instance with renamed variable (this file if inplace = True)

Return type

PseudoNetCDFFile

renameVariables(inplace=False, copyall=True, **newkeys)

Rename variables for each oldkey: newkey dictionary item

Parameters
  • **newkeys (dictionary) – where key is the oldkey and value is the newkey

  • inplace (boolean) – create the new variable in this netcdf file (default False)

  • copyall (boolean) – if not inplace, should all variables be copied to new file

Returns

outf – instance with renamed variable (this file if inplace = True)

Return type

PseudoNetCDFFile

reorderDimensions(oldorder, neworder, inplace=False)

Evaluate expr and return a PseudoNetCDFFile object with resutl

Parameters
  • oldorder (iterable of strings) – dimension names in existing order

  • neworder (iterable of strings) – dimension names in new order

Returns

outf – instance with dimensions reordered in variables

Return type

PseudoNetCDFFile

save(*args, **kwds)

Provides access to pncwrite for self

Parameters

Help pncwrite (see) –

Returns

Return type

see Help pncwrite

setCoords(keys, missing='ignore')

Set a variable as a coordinate variable

Parameters
  • keys (iterable of strings) – keys for coord variables

  • missing (string) – action if missing ‘ignore’, ‘skip’ or ‘error’ ignore - add in case used later skip - do not add error - raise an error

Returns

Return type

None

Notes

Coordinate variables are excluded from math

set_dest(path, **options)

Sets the path where a new file is created on some action

Parameters
  • path (str) – path for new file

  • **options (keywords for constructor) – options for new file creation

Returns

Return type

None

set_varopt(**options)

Set options to be used when creating any Variable

Parameters

**options (options for createVariable) – optional keywords to be supplied when creating new variables in destination file

Returns

Return type

None

setncatts(attdict)

Set ncattrs from attdict keys and values

Parameters

attdict (dictionary) – key/value pairs of properties

Returns

Return type

None

slice(newdims='POINTS', verbose=0, **dimslices)

Return a netcdflike object with dimensions sliced

Parameters
  • newdims (iterable of strings) – names for new dimensions. When more than one iterable applies to a variable slice, fancy indexing removes both dimensions and creates a new one of the iterable lengths

  • **dimslices (dictionary) – key value pairs where the key is a dimension and the value is a valid slice object (slices, ints or iterables) if iterables are provided, all iterables must be the same size and shape. If the arrays are not 1D, newdims must have ndim names

Returns

outf – instance with variables and dimensions sliced

Return type

PseudoNetCDFFile

sliceDimensions(newdims='POINTS', verbose=0, **dimslices)

Return a netcdflike object with dimensions sliced

Parameters
  • newdims (iterable of strings) – names for new dimensions. When more than one iterable applies to a variable slice, fancy indexing removes both dimensions and creates a new one of the iterable lengths

  • **dimslices (dictionary) – key value pairs where the key is a dimension and the value is a valid slice object (slices, ints or iterables) if iterables are provided, all iterables must be the same size and shape. If the arrays are not 1D, newdims must have ndim names

Returns

outf – instance with variables and dimensions sliced

Return type

PseudoNetCDFFile

stack(other, stackdim)

Concatenates all variables on stackdim

Parameters
  • other (instance or list of PseudoNetCDFFiles) – files to add to this file along stackdim

  • stackdim (str) – dimension name

Returns

outf – instance with stacked variables and dimension equal to new length

Return type

PseudoNetCDFFile

subset(varkeys, inplace=False, exclude=False, keepcoords=True)

Return a PseudoNetCDFFile with only varkeys

Parameters
  • varkeys (iterable of strings) – keys to keep

  • inplace (boolean) – if true (default false), then remove other variable from this file

  • exclude (boolean) – if True (default False), then remove just these variables

  • keepcoords (boolean) – if True (default True), keep coordinate variables

Returns

outf – instance with variables

Return type

PseudoNetCDFFile

subsetVariables(varkeys, inplace=False, keepcoords=True, exclude=False)

Return a PseudoNetCDFFile with only varkeys

Parameters
  • varkeys (iterable of strings) – keys to keep

  • inplace (boolean) – if true (default false), then remove other variable from this file

  • exclude (boolean) – if True (default False), then remove just these variables

  • keepcoords (boolean) – if True (default True), keep coordinate variables

Returns

outf – instance with variables

Return type

PseudoNetCDFFile

sync()

Does nothing. Implemented for continuity with Scientific.IO.NetCDF

time2idx(time, dim='time', timekey=None, **kwds)

Convert datetime objects to dimension indices

Parameters
  • time (array-like) – array of datetime.datetime objects

  • dim (str) – dimension name for val2idx

  • timekey (str) – time variable key. None defaults to dim

  • kwds (mappable) – see val2idx

Returns

idx – time index (0-based)

Return type

array-like

time2t(time, ttype='nearest', index=True)
Parameters
  • time (array of datetime.datetime objects) –

  • interp ('nearest', 'bounds', 'bounds_close') –

  • index (return index) –

Returns

t

Return type

fractional time or if index, integers for indexing

val2idx(dim, val, method='nearest', bounds='warn', left=None, right=None, clean='mask')

Convert coordinate values to indices

Parameters
  • dim (str) – name of dimensions, which must have a coordinate variable

  • val (array-like) – value in coordinate space

  • method (str) –

    nearest, bounds, exact - each calculates the index differently
    • nearest : uses interp with coord values and rounds

    • bounds : uses interp between bounding values and truncates

    • exactreturns indices for exact coord values with other

      indices masked (clean keyword has no effect)

  • bounds (str) – ignore, error, warn if i,j are out of domain

  • left (scalar) – see np.interp

  • right (scalar) – see np.interp

  • clean ({'none', 'mask'}) –

    none - return values regardless of bounds; mask - mask invalid values (use with left/right=np.nan);

    has no affect with method exact

Returns

i – indices (0-based) for variables

Return type

array-like

xy2ll(x, y)

see ll2xy

#.. autoclass:: PseudoNetCDF.geoschemfiles.bpch_base # :members: # :inherited-members: