Jun-27-2019, 10:22 PM
Hi all.
I'm using Python to process climate data and use it in a weather model. To do this, there was a script in Python2, which I modified to adapt it to Python3. I have a part of the code, which when I execute it gives me the following error:
I'm using Python to process climate data and use it in a weather model. To do this, there was a script in Python2, which I modified to adapt it to Python3. I have a part of the code, which when I execute it gives me the following error:
Error: File "./preprocess.py", line 223, in calc
grbout.write('msg', 'utf-8')
TypeError: write() takes exactly one argument (2 given)
The part of the code to which it refers is the following:#logger.info("Calculating soil moisture and filling skintemp for %s" % ffile) logger.info("Calculating soil moisture for %s" % ffile) smfile = prefix + "calc_" + infix + suffix if os.path.isfile(smfile): os.remove(smfile) grbout = open(smfile, "w") grbs = pygrib.open(os.path.join(DATADIR, ffile)) grbs.seek(0) #have_sst = False #have_skt = False for grb in grbs: if grb.indicatorOfParameter == 140: sm_values = grb.values/sm_at_field_capacity grb.indicatorOfParameter = 142 grb.indicatorOfTypeOfLevel = 'sfc' grb.typeOfLevel = 'depthBelowLand' for level in SM_LEVELS.keys(): grb.level = level grb.values = sm_values*SM_LEVELS[level] msg = grb.tostring() grbout.write(msg) #elif grb.indicatorOfParameter == 139: # skt_grb = grb # have_skt = True #elif grb.indicatorOfParameter == 103: # sst_grb = grb # have_sst = True #if have_sst and have_skt: # values = skt_grb.values*sea_land_mask + sst_grb.values*(1-sea_land_mask) # skt_grb.values = values # skt_grb.indicatorOfParameter = 143 # msg = skt_grb.tostring() # grbout.write(msg) # del sst_grb # del skt_grb # have_sst = False # have_skt = False grbs.close() grbout.close()I searched for the solution, but I'm not sure what coding to use.