PseudoNetCDF.camxfiles.uamiv package

Submodules

PseudoNetCDF.camxfiles.uamiv.Memmap module

Memmap – uamiv Memmap interface

class PseudoNetCDF.camxfiles.uamiv.Memmap.uamiv(*args, **kwds)[source]

Bases: ioapi_base

uamiv provides a PseudoNetCDF interface for CAMx uamiv files. Where possible, the inteface follows IOAPI conventions (see www.baronams.com).

ex:
>>> uamiv_path = 'camx_uamiv.bin'
>>> uamivfile = uamiv(uamiv_path)
>>> uamivfile.variables.keys()
['TFLAG', 'O3', 'NO', 'NO2', ...]
>>> tflag = uamivfile.variables['TFLAG']
>>> tflag.dimensions
('TSTEP', 'VAR', 'DATE-TIME')
>>> tflag[0,0,:]
array([2005185,       0])
>>> tflag[-1,0,:]
array([2005185,  240000])
>>> v = uamivfile.variables['O3']
>>> v.dimensions
('TSTEP', 'LAY', 'ROW', 'COL')
>>> v.shape
(25, 28, 65, 83)
>>> uamivfile.dimensions
{'TSTEP': 25, 'LAY': 28, 'ROW': 65, 'COL': 83}
Parameters:
  • rf (string or RecordFile) – usually a path to a CAMx formatted file, can be a FortranFileUtil RecordFile object.

  • mode (string) – file open mode read (‘r’), write (‘w’), append (‘a’, ‘r+’)

  • P_ALP (float) – see IOAPI GRIDDESC documentation

  • P_BET (float) – see IOAPI GRIDDESC documentation

  • P_GAM (float) – see IOAPI GRIDDESC documentation

  • XCENT (float) – see IOAPI GRIDDESC documentation

  • YCENT (float) – see IOAPI GRIDDESC documentation

  • GDTYP (float) – see IOAPI GRIDDESC documentation

  • endian (string) – ‘big’ or ‘little’ usually only if mistaken compile

  • chemparam (None or string) – used to identify gases and aerosols

Returns:

outf – PseudoNetCDFFile populated from file

Return type:

uamiv

classmethod isMine(path)[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.

PseudoNetCDF.camxfiles.uamiv.Read module

Read – uamiv Read interface

class PseudoNetCDF.camxfiles.uamiv.Read.uamiv(*args, **kwds)[source]

Bases: PseudoNetCDFFile

uamiv provides a PseudoNetCDF interface for CAMx uamiv files. Where possible, the inteface follows IOAPI conventions (see www.baronams.com).

ex:
>>> uamiv_path = 'camx_uamiv.bin'
>>> rows,cols = 65,83
>>> uamivfile = uamiv(uamiv_path,rows,cols)
>>> uamivfile.variables.keys()
['TFLAG', 'O3', 'NO', 'NO2', ...]
>>> tflag = uamivfile.variables['TFLAG']
>>> tflag.dimensions
('TSTEP', 'VAR', 'DATE-TIME')
>>> tflag[0,0,:]
array([2005185,       0])
>>> tflag[-1,0,:]
array([2005185,  240000])
>>> v = uamivfile.variables['O3']
>>> v.dimensions
('TSTEP', 'LAY', 'ROW', 'COL')
>>> v.shape
(25, 28, 65, 83)
>>> uamivfile.dimensions
{'TSTEP': 25, 'LAY': 28, 'ROW': 65, 'COL': 83}

Initialization included reading the header and learning about the format.

see __readheader and __gettimestep() for more info

cell_hdr_fmt = 'iiii'
close()[source]

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

data_fmt = 'f'
emiss_hdr_fmt = '10i60i3ifif'
getArray(krange=slice(1, None, None), nspec=slice(None, None, None), nx=slice(None, None, None), ny=slice(None, None, None))[source]

Method takes slice arguments. Alternatively, takes a hashable object with 2 values (e.g., the list: [0,3]). Arguments: krange vertical slice (1 indexed) nspec species slice (0 indexed) nx column slice (0 indexed) ny row slice (0 indexed)

grid_hdr_fmt = 'ffiffffiiiiifff'
header()[source]
id_fmt = 'i10i'
id_size = 44
idum = 0
ione = 1
items()[source]
keys()[source]
rdum = 0.0
read()[source]

Provide direct access to record file read

read_into(dest)[source]

Transfer values from current record to dest dest - numeric or numpy array

seek(date=None, time=None, spc=-1, k=0, chkvar=True)[source]

Move file cursor to the beginning of the specified record see __recordposition for parameter definitions

seekandread(date=None, time=None, spc=1, k=1)[source]

see seek and read

seekandreadinto(dest, date=None, time=None, spc=1, k=1)[source]

see seek and read_into

spc_fmt = '10i'
time_hdr_fmt = 'ifif'
timerange()[source]
values()[source]

PseudoNetCDF.camxfiles.uamiv.Transforms module

Write – CAMx uamiv variable transformations

class PseudoNetCDF.camxfiles.uamiv.Transforms.osat(*args, **kwds)[source]

Bases: PseudoNetCDFFile

OSAT provides a way of slicing and summing tagged species.

sources - dictionary of name and id for CAMx source codes

(i.e. {‘SOURCES1-5’: ‘001’,’002’,’003’,’004’,’005’})

regions - dictionary of name and id for CAMx region codes

(i.e. {‘REGIONS1-5’: ‘001’,’002’,’003’,’004’,’005’})

Example

# Source and regions definitions sources={‘SOURCES1-5’: (‘001’,’002’,’003’,’004’,’005’)} regions={‘REGIONS1-5’: (‘001’,’002’,’003’,’004’,’005’)} # File initiation osatfile=osat(‘path’,sources,regions) # Variable (v) would return the sum of all O3V for all five # sources and all five regions v=osatfile.variables[‘O3V_SOURCES1-5_REGIONS1-5’]

PseudoNetCDF.camxfiles.uamiv.Write module

Write – CAMx uamiv writer

PseudoNetCDF.camxfiles.uamiv.Write.ncf2uamiv(ncffile, outpath)[source]

ncf2uamiv converts a ncffile to a uamiv file

Parameters:
  • ncffile (PseudoNetCDF-like object) –

    Must be open and have all properties of a uamiv file as produced by PseudoNetCDF.camxfiles 1) IOAPI conventions 2) UAMIV specific properties: PLON PLAT IUTM CPROJ

    TLAT1 TLAT2 ISTAG

  • outpath (string) – path to create a uamiv file output

Returns:

outfile – File object is in write binary mode and has the uamiv file as its contents

Return type:

file object

Examples

$ # test.uamiv must be a file in uamiv format $ pncgen -f uamiv test.uamiv test.uamiv.nc $ python -c ” ncpath = ‘test.uamiv.nc’ uamivpath = ‘test.uamiv.nc.uamiv’ from netCDF4 import Dataset from PseudoNetCDF.camxfiles.uamiv.Write import ncf2uamiv inncf = Dataset(ncpath) ncf2uamiv(inncf, uamivpath) ” # If uamivpath does not include EOD, the diff will be perfect diff test.uamiv test.uamiv.nc.uamiv

# If uamivpath includes EOD, the diff may yield difference. # The ONLY difference will be time flags for the end of a day. # Most time software agrees – there is no such thing as 2002154T24:00. # Some CAMx files, however, have a 2400 time. # PseudoNetCDF interprets this equivalently as 2002155T00:00 $ python -c “from PseudoNetCDF.camxfiles.Memmaps import uamiv import numpy as np old = uamiv(‘test.uamiv’) new = uamiv(‘test.uamiv.nc.uamiv’) for k in old.variables.keys():

check = (old.variables[k][…] == new.variables[k][…]) if not check.all():

print(k) if k == ‘ETFLAG’:

diffidx = np.where(~check)[:2]

else:

diffidx = np.where(~check)

print(old.variables[k][diffidx]) print(new.variables[k][diffidx])

PseudoNetCDF.camxfiles.uamiv.Write.write_emissions(start_date, start_time, time_step, hdr, vals)[source]
PseudoNetCDF.camxfiles.uamiv.Write.write_emissions_ncf(infile, outfile)[source]

Module contents

uamiv – UAM-IV File Interfaces