Skip to content

Undefined local variable with regrid2.crossSection.get_latitude_wts_bnds #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zshaheen opened this issue Aug 8, 2017 · 10 comments · Fixed by #154
Closed

Undefined local variable with regrid2.crossSection.get_latitude_wts_bnds #153

zshaheen opened this issue Aug 8, 2017 · 10 comments · Fixed by #154
Assignees
Labels
Milestone

Comments

@zshaheen
Copy link
Contributor

zshaheen commented Aug 8, 2017

@chengzhuzhang Uncovered this error.

A quick glance at the get_latitude_wts_bnds() function shows that wts is only declared in the if statements, thus an error on the line return (wts, bnds).
Maybe we need to initialize wts to None?

Your thoughts @dnadeau4

Traceback (most recent call last):
  File "acme_diags_driver.py", line 79, in <module>
    run_diag(parameter)
  File "/Users/zhang40/anaconda2/envs/acme_diags_env/lib/python2.7/site-packages/acme_diags-0.1-py2.7.egg/acme_diags/driver/zonal_mean_2d_driver.py", line 199, in run_diag
    mv1_reg = mv1_p.crossSectionRegrid(lev_out, lat_out)
  File "/Users/zhang40/anaconda2/envs/acme_diags_env/lib/python2.7/site-packages/cdms2/avariable.py", line 1217, in crossSectionRegrid
    fromlat, newLatitude, fromlevel, newLevel)
  File "/Users/zhang40/anaconda2/envs/acme_diags_env/lib/python2.7/site-packages/regrid2/crossSection.py", line 116, in __init__
    lat_wts_bndsIn = get_latitude_wts_bnds(latIn)
  File "/Users/zhang40/anaconda2/envs/acme_diags_env/lib/python2.7/site-packages/regrid2/crossSection.py", line 678, in get_latitude_wts_bnds
    return (wts, bnds)
UnboundLocalError: local variable 'wts' referenced before assignment
@doutriaux1 doutriaux1 added the bug label Aug 8, 2017
@doutriaux1 doutriaux1 added this to the 2.12 milestone Aug 8, 2017
@doutriaux1
Copy link
Contributor

@zshaheen can you provide the in and out files please? (link to file is enough)

@zshaheen
Copy link
Contributor Author

zshaheen commented Aug 8, 2017

This is the model file on aims4 that breaks it:

/export_2/zhang40/tests/acme_output_test/20161118.beta0.F1850COSP.ne30_ne30.edison_ANN_climo.nc

Here's one that we've been using forever that works:

/space/golaz1/ACME_simulations/20160520.A_WCYCL1850.ne30_oEC.edison.alpha6_01/pp/clim_rgr/0070-0099/20160520.A_WCYCL1850.ne30_oEC.edison.alpha6_01_ANN_climo.nc

Let me know if you want me to try and rerun any changes to cdms in acme diags.

Thanks guys :)

@doutriaux1
Copy link
Contributor

thhanks @zshaheen do you know what the target grid is?

@zshaheen
Copy link
Contributor Author

zshaheen commented Aug 8, 2017

We're regridding the model to the level and latitude of the obs. So we're doing:

model.crossSectionRegrid(obs.getLevel(), obs.getLatitude())

The observation data is located here on aims4:

/space1/test_data/obs_data_20140804/

@zshaheen zshaheen closed this as completed Aug 8, 2017
@zshaheen zshaheen reopened this Aug 8, 2017
@zshaheen
Copy link
Contributor Author

zshaheen commented Aug 8, 2017

@doutriaux1
We also see that for the working model data (20160520.A_WCYCL1850.ne30_oEC.edison.alpha6_01_ANN_climo.nc) we have the dimensions for T to be 1:

        float T(time, lev, lat, lon) ;
                T:mdims = 1 ;
                T:units = "K" ;
                T:long_name = "Temperature" ;
                T:cell_methods = "time: mean" ;

While for the non-working model data (20161118.beta0.F1850COSP.ne30_ne30.edison_ANN_climo.nc), we have the dimensions for T to be 9:

        float T(time, lev, lat, lon) ;
                T:mdims = 9 ;
                T:units = "K" ;
                T:long_name = "Temperature" ;
                T:cell_methods = "time: mean" ;
                T:cell_measures = "area: area" ;

This is the ncdump of the obs we're using (/space1/test_data/obs_data_20140804/MERRA_ANN_climo.nc):

	float T(time, lev, lat, lon) ;
		T:info = "function clmMonLLLT: contributed.ncl" ;
		T:time_op_ncl = "Climatology: 20 years: 1990-2009" ;
		T:missing_value = 1.e+20f ;
		T:valid_range = 250.4688f, 251.875f ;
		T:missing_value_original = -32767s ;
		T:_FillValue_original = -32767s ;
		T:units = "K" ;
		T:long_name = "Air Temperature" ;
		T:_FillValue = 1.e+20f ;

@golaz
Copy link

golaz commented Aug 8, 2017

What is mdims? Is CDMS actually reading mdims? mdims is definitely not the dimensions of the variable 'T'; they are given by the dimensions time, lev, lat, lon.

@doutriaux1
Copy link
Contributor

@golaz I agree, I wonder what mdims is. @dnadeau4 is that something you use internally?

@doutriaux1
Copy link
Contributor

doutriaux1 commented Aug 9, 2017

I'm getting closer, any gaussian grid with an odd number of latitudes seems to fail. seems like _regrid.gridattr(nlat, grid_type) expects even number of latitudes

@doutriaux1
Copy link
Contributor

ok both odd gaussian axes and generic latitude axes are now fixed at: #154
As soon as @zshaheen and jill confirmed it fixes things for them, i will merge.

@zshaheen
Copy link
Contributor Author

@doutriaux1 It's all good to merge into master.
Thanks again for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants