Menu

problem with a where statement in a conditional expression ncap2

Help
2023-10-04
2023-10-04
  • francesco maicu

    francesco maicu - 2023-10-04

    Dear all,
    I am not able to run a ncap2 command.
    First I calculate a 1D variable from an L3 mask like this:

     ncap2 -h -s 'data_occ=sst_mask.sum($lon,$lat); sst_diff=votemper' myfile
    

    I want to make some calculation along the time axis, based on a threshold value of the occurrence of observed data, like this:

    ncap2 -h -s 'for(*t=0;t<=time.size();t++){ if(data_occ(t)>5000) {mask_t=sst_mask(:,:,t);where(mask_t==1)sst_diff(:,:,t)=votemper(:,:,t)-adjusted_sea_surface_temperature(:,:,t)-273.15;elsewhere sst_diff(:,:,t)=votemper.get_miss();} else{sst_diff(:,:,t)=votemper.get_miss();};}' myfile
    

    The error messagge is quite straighforward:

    ncap2: ERROR where_assign(): the "where statement" cannot handle a variable with limits on the Left-Hand-Side of an assign statement. Please remove the limts and try again

    Unfortunately I don't know how to solve. It looks like the where statement doesn't like to manage a 2D variable (mask_t) and a 3D variable (sst_diff) even at a specific fixed time.
    Do you have any suggestion?

     
  • francesco maicu

    francesco maicu - 2023-10-04

    I just realized that I missed the diemnsion order in the script(:,:,t) instead of the correct (t,:,:). But unfortunately, this doesn't change the result.

     
  • francesco maicu

    francesco maicu - 2023-10-04

    Finally I managed to make it working.
    I degraded from 3D to 2D arrays to work with the where condition, like this:
    ncap2 -h -s ' for(*t=0;t<time.size();t++) { if(data_occ(t)>5000) {maskt=sst_mask(t,:,:); sst_difft=votemper(t,:,:); where(maskt == 1)sst_difft=votemper(t,:,:)-adjusted_sea_surface_temperature(t,:,:)-273.15;elsewhere sst_difft=votemper.get_miss();sst_diff(t,:,:)=sst_difft;} else{sst_diff(t,:,:)=votemper.get_miss();}; }'
    It works but it seems to me a workaroud.
    Any suggestion?
    Thank you

     

Log in to post a comment.

MongoDB Logo MongoDB