Project

General

Profile

Convert the command line to a Python script

Added by Sean Shi almost 3 years ago

I want to know if {cdo.remap('target_grid_world_0125.txt,weights_icogl2world_0125.nc', input='./alb_rad/icon_global_icosahedral_single-level_2021120900_000_ALB_RAD.grib2', output='2020_1.grib', option='-f grb2')} is equivalent to {time cdo -f grb2 remap,target_grid_world_0125.txt,weights_icogl2world_0125.nc ./alb_rad/icon_global_icosahedral_single-level_2021120900_000_ALB_RAD.grib2 '2020_1.grib'}.


Replies (8)

RE: Convert the command line to a Python script - Added by Karin Meier-Fleischer almost 3 years ago

Hi Sean,

to make it more readable:

cdo.remap('target_grid_world_0125.txt,weights_icogl2world_0125.nc', input='./alb_rad/icon_global_icosahedral_single-level_2021120900_000_ALB_RAD.grib2', output='2020_1.grib', option='-f grb2')

is equal to

cdo -f grb2 remap,target_grid_world_0125.txt,weights_icogl2world_0125.nc ./alb_rad/icon_global_icosahedral_single-level_2021120900_000_ALB_RAD.grib2 2020_1.grib

RE: Convert the command line to a Python script - Added by Sean Shi almost 3 years ago

Thank you, karin.
I think I already know the answer. These two commands are not equal.

RE: Convert the command line to a Python script - Added by Sean Shi almost 3 years ago

karin, I try:

from cdo import *
import os
cdo = Cdo()
cdo.remap('target_grid_world_0125.txt,weights_icogl2world_0125.nc', input='icon_global_icosahedral_single-level_2021121300_000_ALB_RAD.grib2', output='2020_2.nc', option='-f grb2')

But I get that:
Traceback (most recent call last):
File "transH5.py", line 22, in <module>
cdo.remap('target_grid_world_0125.txt,weights_icogl2world_0125.nc', input='icon_global_icosahedral_single-level_2021121300_000_ALB_RAD.grib2', output='2020_2.nc', option='-f grb2')
File "/home/tode12/miniconda3/lib/python3.7/site-packages/cdo.py", line 494, in call
raise CDOException(**retvals)
cdo.CDOException: (returncode:134) cdo remap: Processed 1 variable over 1 timestep [0.72s 459MB].

RE: Convert the command line to a Python script - Added by Ralf Mueller almost 3 years ago

when you call this in python, you can set

cdo.debug = True
before and it will print the command line, which is used internally.

I think both calls use the identical CDO command.

RE: Convert the command line to a Python script - Added by Sean Shi almost 3 years ago

Thank you, Ralf.
I printed out the command line the way you told me. There seems to be a slight difference between the two methods. Strangely, an error message is printed and an available file is generated at the same time. I can ignore this error message, but I still want to know why it appears.

I try :

from cdo import *
import os
cdo = Cdo()
cdo.debug = True
cdo.remap('target_grid_world_0125.txt,weights_icogl2world_0125.nc', input='icon_global_icosahedral_single-level_2021121300_000_ALB_RAD.grib2', output='2020_2.nc', option='-f grb2')

then I get that:
found method:remap
  1. DEBUG - start =============================================================
    CALL :cdo -O -f grb2 -remap,target_grid_world_0125.txt,weights_icogl2world_0125.nc icon_global_icosahedral_single-level_2021121300_000_ALB_RAD.grib2 2020_4.nc
    STDOUT:
    STDERR:
    cdo remap: Processed 1 variable over 1 timestep [0.69s 460MB].
    free(): invalid pointer
    Aborted (core dumped)
  1. DEBUG - end ===============================================================
    RETURNCODE:134
    Error in calling operator remap with:

cdo -O -f grb2 -remap,target_grid_world_0125.txt,weights_icogl2world_0125.nc icon_global_icosahedral_single-level_2021121300_000_ALB_RAD.grib2 2020_4.nc<<<

STDOUT:
STDERR:cdo remap: Processed 1 variable over 1 timestep [0.69s 460MB].
free(): invalid pointer
Aborted (core dumped)

Traceback (most recent call last):
File "transH5.py", line 23, in <module>
cdo.remap('target_grid_world_0125.txt,weights_icogl2world_0125.nc', input='icon_global_icosahedral_single-level_2021121300_000_ALB_RAD.grib2', output='2020_4.nc', options='-f grb2')
File "/home/tode12/miniconda3/lib/python3.7/site-packages/cdo.py", line 494, in call
raise CDOException(**retvals)
cdo.CDOException: (returncode:134) cdo remap: Processed 1 variable over 1 timestep [0.69s 460MB].

RE: Convert the command line to a Python script - Added by Ralf Mueller almost 3 years ago

This error is a segmentation fault:

free(): invalid pointer
Aborted (core dumped)
This error is thrown by CDO itself. so no matter if you do call CDO by python or on the shell command line you should get this error. For further investigation you might upload the input files.

RE: Convert the command line to a Python script - Added by Sean Shi almost 3 years ago

Ralf, your help was very much appreciated. My input file is attached.‘arget_grid_world_0125.txt' and 'weights_icogl2world_0125.nc' are in 'ICON_GLOBAL2WORLD_0125_EASY.tar(1).bz2'.

    (1-8/8)