barronh / pseudonetcdf

PseudoNetCDF like NetCDF except for many scientific format backends
GNU Lesser General Public License v3.0
76 stars 35 forks source link

camx7+ netcdf format to camx uam-iv format? #138

Closed yosukefk closed 1 year ago

yosukefk commented 1 year ago

Hi Barron,

Do you know if I can convert CAMx generated netcdf avrg conc file to equivalent of traditional fortran binary format? I have old fortran code written for fortran binary and want to reuse it for camx runs in v7+.

Thanks,

barronh commented 1 year ago

Yosuke,

You can. It may take some extra properties. The core function is part of save.

newf.save(path, format='uamiv')

On Monday, I’ll try to post a real example.

barronh commented 1 year ago

The writer isn't particularly robust, so you have to massage the original file to match its expectations. The expectations are generally based on the pseudo-code from the manual, but with an all caps rule for attributes. So, the file being used to write must have NAME, NOTE, PLON, PLAT, TLAT1, TLAT2 attributes -- and the strings must be of the expected length (10 and 60).

The safest thing to do is make a copy in memory and modify the attributes before output.

import PseudoNetCDF as pnc

newrawf = pnc.pncopen('/path/to/new/avrg.nc', format='netcdf')
newf = newrawf.copy()
newf.NAME = 'AVERAGE'.ljust(10)
newf.NOTE = newrawf.NOTE.ljust(60)
newf.PLON = newrawf.XCENT
newf.PLAT = newrawf.YCENT
newf.TLAT1 = newrawf.P_ALP
newf.TLAT2 = newrawf.P_BET
newf.save('test2.bin', format='uamiv')

I have also added a branch that should be able to write the file without modification (https://github.com/barronh/pseudonetcdf/tree/enhancement/uamiv-robust-write). Obviously, you should do some checks on the output of either of these.

yosukefk commented 1 year ago

Thanks Barron, i will test out the branch + your instructions