barronh / pseudonetcdf

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

pncopen griddesc file error #135

Closed Lina312 closed 1 year ago

Lina312 commented 1 year ago

When I try the example case "Make CMAQ Emissions from a CSV File", I receive an error about reading the griddesc file (looks like related to the GDNAME) and have no idea why this error happens.

create a GRIDDESC

with open('GRIDDESC', 'w') as gf: gf.write( "' '\n'LamCon_40N_97W'\n 2 33.000 45.000 -97.000 -97.000 40.000\n" + "' '\n'12US1'\n'LamCon_40N_97W' " + "-2556000.0 -1728000.0 12000.0 12000.0 459 299 1\n' '" )

Create a Template

gf = pnc.pncopen('GRIDDESC', format='griddesc')

Error:

TypeError Traceback (most recent call last) /var/folders/ws/9mzn_sf91kgbcf_20yvdl4pr0000gn/T/ipykernel_17228/3819481324.py in 10 11 # Create a Template ---> 12 pnc.pncopen('GRIDDESC', format='griddesc')

~/opt/anaconda3/lib/python3.8/site-packages/PseudoNetCDF/_getreader.py in pncopen(*args, *kwds) 151 return help(reader) 152 --> 153 outfile = reader(args, **kwds) 154 if addcf: 155 try:

~/opt/anaconda3/lib/python3.8/site-packages/PseudoNetCDF/cmaqfiles/_griddesc.py in init(self, path, GDNAM, VGLVLS, VGTOP, FTYPE, VGTYP, SDATE, STIME, TSTEP, var_kwds, nsteps, withcf, **prop_kw) 131 self.FTYPE = FTYPE 132 self.VGTYP = VGTYP --> 133 self.GDNAM = GDNAM 134 self.VGTOP = np.float32(VGTOP) 135 self.VGLVLS = np.array(VGLVLS, dtype='f')

~/opt/anaconda3/lib/python3.8/site-packages/PseudoNetCDF/cmaqfiles/_ioapi.py in setattr(self, k, v) 81 v = v.ljust(4800) 82 elif k in ('GDNAM', 'UPNAM'): ---> 83 if len(v) > 16: 84 warn(f'Truncating {k} to 16') 85 v = v[:16]

TypeError: object of type 'NoneType' has no len()

barronh commented 1 year ago

I’ll look at making the newer version default to the first. That’s what used to happen. For now, explicitly setting the GDNAM in the pncopen call as shown below.

gf = pnc.pncopen('GRIDDESC', format='griddesc', GDNAM='12US1')

thanks for finding this.

barronh commented 1 year ago

Does that solve your issue?

Lina312 commented 1 year ago

It solved. Sorry, I missed this email. Thanks so much for your help.

On Sep 23, 2022, at 9:02 PM, Barron H. Henderson @.***> wrote:

Does that solve your issue?

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/barronh/pseudonetcdf/issues/135*issuecomment-1256833052__;Iw!!BuQPrrmRaQ!lDqQZEvAXvg2U4QlBYgNAmYPR1RVATfZKyAAG5UBIIp_7hqbaihefdhHdh9lRIaVECSV9Fwp0E5VAFb7_EOrILJv0tF-9Py5ow$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/APRWZT2NQUSVAUY5UNTUNBTV7ZOJTANCNFSM6AAAAAAQTQ66OU__;!!BuQPrrmRaQ!lDqQZEvAXvg2U4QlBYgNAmYPR1RVATfZKyAAG5UBIIp_7hqbaihefdhHdh9lRIaVECSV9Fwp0E5VAFb7_EOrILJv0tEotfExgQ$. You are receiving this because you authored the thread.