barronh / cmaqsatproc

Satellite Processors Designed for CMAQ
GNU General Public License v3.0
7 stars 5 forks source link

Data conversion error from satellite to cmaq and vice versa #6

Closed manishsoni0291 closed 2 years ago

manishsoni0291 commented 2 years ago

I am getting this error when trying to invoke command

overf = satreader.cmaq_process(qf, l3)

elif isinstance(obj, tuple): 125 if isinstance(obj[1], DataArray): --> 126 raise TypeError( 127 "Using a DataArray object to construct a variable is" 128 " ambiguous, please extract the data using the .data property."

TypeError: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property.

barronh commented 2 years ago

This sounds like some sort of version issue. Run the command below, and send me the result.

python -c " import xarray as xr xr.show_versions() "

Also, please include the whole traceback. Right now, you are only showing the last 7 lines and the line that triggered it. There is a lot of code in between that I need to see to understand where this originates.

manishsoni0291 commented 2 years ago

Hi @barronh The output of xarray version is given below:-

commit: None python: 3.9.6 (default, Jul 28 2021, 12:38:21) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] python-bits: 64 OS: Linux OS-release: 3.10.0-1160.2.2.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.0 libnetcdf: 4.7.4

xarray: 2022.11.0 pandas: 1.3.1 numpy: 1.21.1 scipy: 1.7.0 netCDF4: 1.5.7 pydap: None h5netcdf: 1.0.2 h5py: 3.3.0 Nio: None zarr: None cftime: 1.5.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2021.07.1 distributed: None matplotlib: 3.4.2 cartopy: None seaborn: None numbagg: None fsspec: 2021.07.0 cupy: None pint: None sparse: None flox: None numpy_groupies: 0.9.13 setuptools: 56.0.0 pip: 21.3.1 conda: None pytest: 6.2.4 IPython: 7.25.0 sphinx: 4.1.2

manishsoni0291 commented 2 years ago

@barronh

complete traceback result:- ______________________________________ TypeError Traceback (most recent call last) in 1 # Create satellite according to CMAQ, and CMAQ according to satellite ----> 2 overf = satreader.cmaq_process(qf, l3) 3 overf.to_netcdf(f'{readername}_{date}_{GDNAM}_CMAQ.nc') ~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_process(cls, qf, satl3f, key) 678 overf['NO2_PER_M2'].attrs['units'] = 'mole/m**2'.ljust(16) 679 --> 680 ak = overf['NO2_AK_CMAQ'] = cls.cmaq_ak(overf, satl3f) 681 overf['NO2_SW_CMAQ'] = cls.cmaq_sw(overf, satl3f) 682 # uses AK for tropopause ~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_ak(cls, overf, satl3f, amfkey) 635 Averaging kernel on the CMAQ grid 636 """ --> 637 q_sw_trop = cls.cmaq_sw(overf, satl3f, amfkey=amfkey) 638 q_ak = q_sw_trop / satl3f['air_mass_factor_troposphere'] 639 q_ak.attrs.update(q_sw_trop.attrs) ~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_sw(cls, overf, satl3f, amfkey, tropopausekey) 578 Tropospheric scattering Weights on the CMAQ grid 579 """ --> 580 return TropOMI.cmaq_sw( 581 overf, satl3f, amfkey=amfkey, tropopausekey=tropopausekey 582 ) ~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_sw(cls, overf, satl3f, amfkey, tropopausekey) 318 tm5_b = tm5_b.mean('vertices') 319 else: --> 320 tm5_b = xr.DataArray( 321 tm5_constant_b.mean(1), dims=('layer',), 322 coords=[('layer', satl3f['layer'])] ~/.local/lib/python3.9/site-packages/xarray/core/dataarray.py in __init__(self, data, coords, dims, name, attrs, indexes, fastpath) 416 data = _check_data_shape(data, coords, dims) 417 data = as_compatible_data(data) --> 418 coords, dims = _infer_coords_and_dims(data.shape, coords, dims) 419 variable = Variable(dims, data, attrs, fastpath=True) 420 indexes, coords = _create_indexes_from_coords(coords) ~/.local/lib/python3.9/site-packages/xarray/core/dataarray.py in _infer_coords_and_dims(shape, coords, dims) 146 elif coords is not None: 147 for dim, coord in zip(dims, coords): --> 148 var = as_variable(coord, name=dim) 149 var.dims = (dim,) 150 new_coords[dim] = var.to_index_variable() ~/.local/lib/python3.9/site-packages/xarray/core/variable.py in as_variable(obj, name) 124 elif isinstance(obj, tuple): 125 if isinstance(obj[1], DataArray): --> 126 raise TypeError( 127 "Using a DataArray object to construct a variable is" 128 " ambiguous, please extract the data using the .data property." TypeError: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property.
barronh commented 2 years ago

I just pushed an update version 0.2.3 that updates the code as follows:

tm5_b = xr.DataArray(
    tm5_constant_b.mean(1), dims=('layer',),
    coords=[('layer', satl3f['layer'])]
)

to

tm5_b = xr.DataArray(
    tm5_constant_b.mean(1), dims=('layer',),
    coords=dict(layer=satl3f['layer'])
)

The dictionary form is not ambiguous, while the sequence of sequences is. I have verified that the old form raises an error with newer xarray versions (e.g., 0.20.0), and that the new code does not. I've also confirmed that it is backward compatible.

Can you confirm that the new version solves this problem?

manishsoni0291 commented 2 years ago

@barronh The problem is solved. Now it is facing another error in terms of TSTEP and Date and time found. It is not able to find the TSTEP in netcdf file

header of TropOMINO2_2019-07-25_12US1_CMAQ.nc .............................................................................................................. netcdf TropOMINO2_2019-07-25_12US1_CMAQ { dimensions: LAY = 35 ; ROW = 299 ; COL = 459 ; variables: float NO2(LAY, ROW, COL) ; NO2:_FillValue = NaNf ; NO2:long_name = "NO2 " ; NO2:units = "ppmV " ; NO2:var_desc = "Variable NO2 " ; NO2:coordinates = "TSTEP" ;

................................................... header of ncdump -h CCTM_CONC_v52_noDDM_gcc_TRECH2_BOSTON_12km_base_20170725.nc

netcdf CCTM_CONC_v52_noDDM_gcc_TRECH2_BOSTON_12km_base_20170725 { dimensions: TSTEP = UNLIMITED ; // (25 currently) DATE-TIME = 2 ; LAY = 35 ; VAR = 179 ; ROW = 299 ; COL = 459 ; variables: int TFLAG(TSTEP, VAR, DATE-TIME) ; TFLAG:units = "<YYYYDDD,HHMMSS>" ; TFLAG:long_name = "TFLAG " ; TFLAG:var_desc = "Timestep-valid flags: (1) YYYYDDD or (2) HHMMSS " ; float NO2(TSTEP, LAY, ROW, COL) ; NO2:long_name = "NO2 " ; NO2:units = "ppmV " ; NO2:var_desc = "Variable NO2

Both are different.

barronh commented 2 years ago

I see that they are different, but that is different than there being an error. Is there an error?

manishsoni0291 commented 2 years ago

Yep @barronh this is an error coz it doesn't find the TSTEP in the TropOMINO2_2019-07-25_12US1_CMAQ.nc i am supplying full header now. Can u check again the output by using your files.

CDL Header of files in full ncdump -h TropOMINO2_2019-07-25_12US1_CMAQ.nc netcdf TropOMINO2_2019-07-25_12US1_CMAQ { dimensions: LAY = 35 ; ROW = 299 ; COL = 459 ; variables: float NO2(LAY, ROW, COL) ; NO2:_FillValue = NaNf ; NO2:long_name = "NO2 " ; NO2:units = "ppmV " ; NO2:var_desc = "Variable NO2 " ; NO2:coordinates = "TSTEP" ; float DENS(LAY, ROW, COL) ; DENS:_FillValue = NaNf ; DENS:long_name = "DENS " ; DENS:units = "KG/M**3 " ; DENS:var_desc = "density of air: MM5-total density, WRF-dry density " ; DENS:coordinates = "TSTEP" ; float ZF(LAY, ROW, COL) ; ZF:_FillValue = NaNf ; ZF:long_name = "ZF " ; ZF:units = "M " ; ZF:var_desc = "full-layer height above ground " ; ZF:coordinates = "TSTEP" ; float PRES(LAY, ROW, COL) ; PRES:_FillValue = NaNf ; PRES:long_name = "PRES " ; PRES:units = "Pa " ; PRES:var_desc = "pressure " ; PRES:coordinates = "TSTEP" ; float LAY(LAY) ; LAY:_FillValue = NaNf ; double ROW(ROW) ; ROW:_FillValue = NaN ; double COL(COL) ; COL:_FillValue = NaN ; int64 TSTEP ; TSTEP:units = "days since 2017-07-25 00:00:00" ; TSTEP:calendar = "proleptic_gregorian" ; float MOL_PER_M2(LAY, ROW, COL) ; MOL_PER_M2:_FillValue = NaNf ; MOL_PER_M2:long_name = "MOL_PER_M2 " ; MOL_PER_M2:var_desc = "air areal density " ; MOL_PER_M2:units = "mole/m**2 " ; MOL_PER_M2:coordinates = "TSTEP" ; float NO2_PER_M2(LAY, ROW, COL) ; NO2_PER_M2:_FillValue = NaNf ; NO2_PER_M2:long_name = "NO2 " ; NO2_PER_M2:units = "mole/m**2 " ; NO2_PER_M2:var_desc = "Variable NO2 " ; NO2_PER_M2:coordinates = "TSTEP" ; double NO2_AK_CMAQ(ROW, COL, LAY) ; NO2_AK_CMAQ:_FillValue = NaN ; NO2_AK_CMAQ:units = "1" ; NO2_AK_CMAQ:long_name = "Averaging kernel" ; NO2_AK_CMAQ:ancillary_variables = "tm5_constant_a tm5_constant_b tm5_tropopause_layer_index /PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_pressure" ; NO2_AK_CMAQ:origname = "averaging_kernel" ; NO2_AK_CMAQ:fullnamepath = "/PRODUCT/averaging_kernel" ; NO2_AK_CMAQ:coordinates = "PRODUCT_longitude PRODUCT_latitude" ; NO2_AK_CMAQ:var_desc = "AK * AMF " ; double NO2_SW_CMAQ(ROW, COL, LAY) ; NO2_SW_CMAQ:_FillValue = NaN ; NO2_SW_CMAQ:units = "1" ; NO2_SW_CMAQ:long_name = "Averaging kernel" ; NO2_SW_CMAQ:ancillary_variables = "tm5_constant_a tm5_constant_b tm5_tropopause_layer_index /PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_pressure" ; NO2_SW_CMAQ:origname = "averaging_kernel" ; NO2_SW_CMAQ:fullnamepath = "/PRODUCT/averaging_kernel" ; NO2_SW_CMAQ:coordinates = "PRODUCT_longitude PRODUCT_latitude" ; NO2_SW_CMAQ:var_desc = "AK * AMF " ; double VCDNO2_CMAQ(ROW, COL) ; VCDNO2_CMAQ:_FillValue = NaN ; VCDNO2_CMAQ:long_name = "NO2 " ; VCDNO2_CMAQ:units = "mole/m**2 " ; VCDNO2_CMAQ:var_desc = "Variable NO2 " ; VCDNO2_CMAQ:coordinates = "TSTEP" ; double VCDNO2_CMAQ_TOMI(ROW, COL) ; VCDNO2_CMAQ_TOMI:_FillValue = NaN ; VCDNO2_CMAQ_TOMI:long_name = "NO2 " ; VCDNO2_CMAQ_TOMI:units = "mole/m**2 " ; VCDNO2_CMAQ_TOMI:var_desc = "Variable NO2 " ; VCDNO2_CMAQ_TOMI:coordinates = "TSTEP" ; double AMF_CMAQ(ROW, COL) ; AMF_CMAQ:_FillValue = NaN ; AMF_CMAQ:units = "1" ; AMF_CMAQ:long_name = "Averaging kernel" ; AMF_CMAQ:ancillary_variables = "tm5_constant_a tm5_constant_b tm5_tropopause_layer_index /PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_pressure" ; AMF_CMAQ:origname = "averaging_kernel" ; AMF_CMAQ:fullnamepath = "/PRODUCT/averaging_kernel" ; AMF_CMAQ:coordinates = "PRODUCT_longitude PRODUCT_latitude" ; AMF_CMAQ:var_desc = "AK * AMF " ; double VCDNO2_TOMI_CMAQ(ROW, COL) ; VCDNO2_TOMI_CMAQ:_FillValue = NaN ; VCDNO2_TOMI_CMAQ:units = "mol m-2" ; VCDNO2_TOMI_CMAQ:standard_name = "troposphere_mole_content_of_nitrogen_dioxide" ; VCDNO2_TOMI_CMAQ:long_name = "Tropospheric vertical column of nitrogen dioxide" ; VCDNO2_TOMI_CMAQ:ancillary_variables = "nitrogendioxide_tropospheric_column_precision air_mass_factor_troposphere air_mass_factor_total averaging_kernel" ; VCDNO2_TOMI_CMAQ:multiplication_factor_to_convert_to_molecules_percm2 = 6.02214e+19f ; VCDNO2_TOMI_CMAQ:origname = "nitrogendioxide_tropospheric_column" ; VCDNO2_TOMI_CMAQ:fullnamepath = "/PRODUCT/nitrogendioxide_tropospheric_column" ; VCDNO2_TOMI_CMAQ:coordinates = "longitude latitude" ; VCDNO2_TOMI_CMAQ:var_desc = "TropOMI_NO2 x TropOMI_AMF / CMAQ_AMF " ; // global attributes: :IOAPI_VERSION = "ioapi-3.2: $Id: init3.F90 136 2019-10-16 13:57:49Z coats $ " ; :EXEC_ID = "CCTM_v52_noDDM.exe " ; :FTYPE = 1 ; :CDATE = 2022155 ; :CTIME = 130524 ; :WDATE = 2022155 ; :WTIME = 130524 ; :SDATE = 2017206 ; :STIME = 0 ; :TSTEP = 10000 ; :NTHIK = 1 ; :NCOLS = 459 ; :NROWS = 299 ; :NLAYS = 35 ; :NVARS = 179 ; :GDTYP = 2 ; :P_ALP = 33. ; :P_BET = 45. ; :P_GAM = -97. ; :XCENT = -97. ; :YCENT = 40. ; :XORIG = -2556000. ; :YORIG = -1728000. ; :XCELL = 12000. ; :YCELL = 12000. ; :VGTYP = 7 ; :VGTOP = 5000.f ; :VGLVLS = 1.f, 0.9975f, 0.995f, 0.99f, 0.985f, 0.98f, 0.97f, 0.96f, 0.95f, 0.94f, 0.93f, 0.92f, 0.91f, 0.9f, 0.88f, 0.86f, 0.84f, 0.82f, 0.8f, 0.77f, 0.74f, 0.7f, 0.65f, 0.6f, 0.55f, 0.5f, 0.45f, 0.4f, 0.35f, 0.3f, 0.25f, 0.2f, 0.15f, 0.1f, 0.05f, 0.f ; :GDNAM = "12US1_459X299 " ; :UPNAM = "OPCONC " ; :VAR-LIST = "NO2 NO O O3 NO3 O1D OH HO2 H2O2 N2O5 HNO3 HONO PNA SO2 SULF C2O3 MEO2 RO2 PAN PACD AACD CXO3 ALD2 XO2H PANX FORM MEPX MEOH ROOH XO2 XO2N XPAR XPRP NTR1 NTR2 FACD CO HCO3 ALDX GLYD GLY MGLY ETHA ETOH KET PAR ACET PRPA ROR ETHY ETH OLE IOLE ISOP ISO2 ISPD INTR ISPX HPLD OPO3 EPOX EPX2 TERP BENZENE CRES BZO2 OPEN BENZRO2 TOL TO2 TOLRO2 XOPN XYLMN XLO2 XYLRO2 NAPH PAHRO2 CRO CAT1 CRON OPAN ECH4 CL2 CL HOCL CLO FMCL HCL CLNO2 SESQ SOAALK H2NO3PIJ H2NO3PK ASO4J ASO4I ANH4J ANH4I ANO3J ANO3I AALK1J AALK2J AXYL1J AXYL2J AXYL3J ATOL1J ATOL2J ATOL3J ABNZ1J ABNZ2J ABNZ3J APAH1J APAH2J APAH3J ATRP1J ATRP2J AISO1J AISO2J ASQTJ AORGCJ APOCJ APOCI APNCOMJ APNCOMI AECJ AECI AOTHRJ AOTHRI AFEJ AALJ ASIJ ATIJ ACAJ AMGJ AKJ AMNJ ACORS ASOIL NUMATKN NUMACC NUMCOR SRFATKN SRFACC SRFCOR AH2OJ AH2OI AH3OPJ AH3OPI ANAJ ANAI ACLJ ACLI ASEACAT ACLK ASO4K ANH4K ANO3K AH2OK AH3OPK AISO3J AOLGAJ AOLGBJ AGLYJ NH3 SV_ALK1 SV_ALK2 SV_XYL1 SV_XYL2 SV_TOL1 SV_TOL2 SV_BNZ1 SV_BNZ2 SV_PAH1 SV_PAH2 SV_TRP1 SV_TRP2 SV_ISO1 SV_ISO2 SV_SQT W_VEL " ; :FILEDESC = "Concentration file output From CMAQ model dyn alloc version CTM Set of variables (possibly) reduced from CGRID For next scenario continuation runs, use the \"one-step\" CGRID file Layer 1 to 1 Layer 2 to 2 Layer 3 to 3 Layer 4 to 4 Layer 5 to 5 Layer 6 to 6 Layer 7 to 7 Layer 8 to 8 Layer 9 to 9 Layer 10 to 10 Layer 11 to 11 Layer 12 to 12 Layer 13 to 13 Layer 14 to 14 Layer 15 to 15 Layer 16 to 16 Layer 17 to 17 Layer 18 to 18 Layer 19 to 19 Layer 20 to 20 Layer 21 to 21 Layer 22 to 22 Layer 23 to 23 Layer 24 to 24 Layer 25 to 25 Layer 26 to 26 Layer 27 to 27 Layer 28 to 28 Layer 29 to 29 Layer 30 to 30 Layer 31 to 31 Layer 32 to 32 Layer 33 to 33 Layer 34 to 34 Layer 35 to 35 " ; :HISTORY = "" ; :crs = "+proj=lcc +lat_0=40.0 +lon_0=-97.0 +lat_1=33.0 +lat_2=45.0 +x_0=2556000.0 +y_0=1728000.0 +R=6370000.0 +to_meter=12000.0 +no_defs" ; :_NCProperties = "version=2,netcdf=4.7.4,hdf5=1.12.0," ; header file of CCTMncdump -h CCTM_CONC_v52_noDDM_gcc_TRECH2_BOSTON_12km_base_20170725.nc netcdf CCTM_CONC_v52_noDDM_gcc_TRECH2_BOSTON_12km_base_20170725 { dimensions: TSTEP = UNLIMITED ; // (25 currently) DATE-TIME = 2 ; LAY = 35 ; VAR = 179 ; ROW = 299 ; COL = 459 ; variables: int TFLAG(TSTEP, VAR, DATE-TIME) ; TFLAG:units = "" ; TFLAG:long_name = "TFLAG " ; TFLAG:var_desc = "Timestep-valid flags: (1) YYYYDDD or (2) HHMMSS " ; float NO2(TSTEP, LAY, ROW, COL) ; NO2:long_name = "NO2 " ; NO2:units = "ppmV " ; NO2:var_desc = "Variable NO2 " ; float NO(TSTEP, LAY, ROW, COL) ; NO:long_name = "NO " ; NO:units = "ppmV " ; NO:var_desc = "Variable NO " ; float O(TSTEP, LAY, ROW, COL) ; O:long_name = "O " ; O:units = "ppmV " ; O:var_desc = "Variable O " ; float O3(TSTEP, LAY, ROW, COL) ; O3:long_name = "O3 " ; O3:units = "ppmV " ; O3:var_desc = "Variable O3 " ; float NO3(TSTEP, LAY, ROW, COL) ; NO3:long_name = "NO3 " ; NO3:units = "ppmV " ; NO3:var_desc = "Variable NO3 ..... ,,,,, global attributes: :IOAPI_VERSION = "ioapi-3.2: $Id: init3.F90 136 2019-10-16 13:57:49Z coats $ " ; :EXEC_ID = "CCTM_v52_noDDM.exe " ; :FTYPE = 1 ; :CDATE = 2022155 ; :CTIME = 130524 ; :WDATE = 2022155 ; :WTIME = 130524 ; :SDATE = 2017206 ; :STIME = 0 ; :TSTEP = 10000 ; :NTHIK = 1 ; :NCOLS = 459 ; :NROWS = 299 ; :NLAYS = 35 ; :NVARS = 179 ; :GDTYP = 2 ; :P_ALP = 33. ; :P_BET = 45. ; :P_GAM = -97. ; :XCENT = -97. ; :YCENT = 40. ; :XORIG = -2556000. ; :YORIG = -1728000. ; :XCELL = 12000. ; :YCELL = 12000. ; :VGTYP = 7 ; :VGTOP = 5000.f ; :VGLVLS = 1.f, 0.9975f, 0.995f, 0.99f, 0.985f, 0.98f, 0.97f, 0.96f, 0.95f, 0.94f, 0.93f, 0.92f, 0.91f, 0.9f, 0.88f, 0.86f, 0.84f, 0.82f, 0.8f, 0.77f, 0.74f, 0.7f, 0.65f, 0.6f, 0.55f, 0.5f, 0.45f, 0.4f, 0.35f, 0.3f, 0.25f, 0.2f, 0.15f, 0.1f, 0.05f, 0.f ; ..
barronh commented 2 years ago

this is an error coz it doesn't find the TSTEP

Just because it doesn't have a TSTEP does not mean there is an error. This file is not intended to be IOAPI compliant. So, it does not have a TSTEP dimension, nor does it have a TFLAG variable.

The file looks fine.

manishsoni0291 commented 2 years ago

@barronh I tried opening the file in panoply and verdi it is giving error.

Figures showing Panoply cannot open file ![image](https://user-images.githubusercontent.com/10591068/203157926-7087acf1-0bd1-4fbc-a1a1-ba009fb10332.png) verdi error ![image](https://user-images.githubusercontent.com/10591068/203158063-facb3572-6b8a-4421-b5ea-11cb87c7c28d.png)
barronh commented 2 years ago

Manish,

Panoply support would be ideal, and I may look into improving compatibility with Panoply. Right now, Panoply is inferring that this is an IOAPI file and failing to read the time. The file is not intended to fully support IOAPI for many reasons. For example, the vertical structure is inherited from the satellite. The satellites can have vertical structures that are not supported by IOAPI.

So, I think your question is how can I make a figure? You can make a figure pretty easily without Panoply using xarray.

The commands below should make a nice little plot. I've chosen to visualize the CMAQ VCD and the TropOMI VCD processed with the CMAQ AMF. An alternative is to use the VCD from TropOMI and visualize CMAQ with the TropOMI averaging kernel. Either comparison is better than comparing CMAQ's VCD directly to TropOMI's.

import xarray as xr
import cmaqsatproc as csp
import matplotlib.pyplot as plt

# Open a GRIDDESC and a CMAQ processed TropOMI file
cg = csp.open_griddesc('12US1')
qf = xr.open_dataset('TropOMINO2_2019-07-25_12US1_CMAQ.nc')

# Make a figure to hold two panels.
fig, axx = plt.subplots(1, 2, figsize=(12, 4))
opts = dict(
    norm=plt.Normalize(vmin=0),
    cmap='viridis'
)
# Add CMAQ raw VCD
qf['VCDNO2_CMAQ'].plot(ax=axx[0], **opts)
# Add TropOMI VCD recalculated with CMAQ AMF
qf['VCDNO2_TOMI_CMAQ'].plot(ax=axx[1], **opts)
# add maps with states
for ax in axx.ravel():
    cg.csp.cno.drawstates(ax=ax)

# Save the figure to disk
fig.savefig('vcd_no2.png')
manishsoni0291 commented 2 years ago

@barronh Hi Barron First of all thank for your assistance.

When i use the script to plot the figure. There is no difference coming. values are also very less. vcd_no2

When i use the same dimension plotting of figure completed successfully. When the CMAQ concentration file have lesser dimension (spatial reference) It gives error. it is shown below

Script run (CLICK ME)
import numpy
import pandas
import geopandas
import netCDF4
import h5netcdf
import pyproj

import cmaqsatproc as csp
import xarray as xr

GDNAM = '12NE3'
date='2018-07-01'
readername = 'TropOMINO2'

satreader = csp.reader_dict[readername]
l3 = xr.open_dataset(f'{readername}_{date}_{GDNAM}.nc')

qf = csp.open_ioapi(f'CCTM_CONC_4.454_Bench_2018_12NE3_20180701.nc')[['NO2']]
mf = csp.open_ioapi(f'MET_CRO_3D_4.454_Bench_2018_12NE3_20180701.nc')
qf['DENS'] = mf['DENS']
qf['ZF'] = mf['ZF']
qf['PRES'] = mf['PRES']
# Create satellite according to CMAQ, and CMAQ according to satellite
overf = satreader.cmaq_process(qf, l3)
Error Log (CLICK ME) that shows files were not aligned
ValueError                                Traceback (most recent call last)
 in 
     22 qf['PRES'] = mf['PRES']
     23 # Create satellite according to CMAQ, and CMAQ according to satellite
---> 24 overf = satreader.cmaq_process(qf, l3)

~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_process(cls, qf, satl3f, key)
    678         overf['NO2_PER_M2'].attrs['units'] = 'mole/m**2'.ljust(16)
    679
--> 680         ak = overf['NO2_AK_CMAQ'] = cls.cmaq_ak(overf, satl3f)
    681         overf['NO2_SW_CMAQ'] = cls.cmaq_sw(overf, satl3f)
    682         # uses AK for tropopause

~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_ak(cls, overf, satl3f, amfkey)
    635             Averaging kernel on the CMAQ grid
    636         """
--> 637         q_sw_trop = cls.cmaq_sw(overf, satl3f, amfkey=amfkey)
    638         q_ak = q_sw_trop / satl3f['air_mass_factor_troposphere']
    639         q_ak.attrs.update(q_sw_trop.attrs)

~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_sw(cls, overf, satl3f, amfkey, tropopausekey)
    578             Tropospheric scattering Weights on the CMAQ grid
    579         """
--> 580         return TropOMI.cmaq_sw(
    581             overf, satl3f, amfkey=amfkey, tropopausekey=tropopausekey
    582         )

~/cmaqsatproc/cmaqsatproc/readers/tropomi/__init__.py in cmaq_sw(cls, overf, satl3f, amfkey, tropopausekey)
    339         sw_trop = ak * satl3f[amfkey]
    340
--> 341         q_sw_trop = coord_interp(
    342             overf['PRES'], pres, sw_trop,
    343             indim='layer', outdim='LAY', ascending=False

~/cmaqsatproc/cmaqsatproc/utils.py in coord_interp(coordout, coordin, varin, verbose, interp, outdim, indim, ascending, **kwds)
    276     XP = coordin.sortby(indim, ascending=ascending)
    277     FP = varin.sortby(indim, ascending=ascending)
--> 278     interped = xr.apply_ufunc(
    279         interp1d,
    280         FP,

~/.local/lib/python3.9/site-packages/xarray/core/computation.py in apply_ufunc(func, input_core_dims, output_core_dims, exclude_dims, vectorize, join, dataset_join, dataset_fill_value, keep_attrs, kwargs, dask, output_dtypes, output_sizes, meta, dask_gufunc_kwargs, *args)
   1202     # feed DataArray apply_variable_ufunc through apply_dataarray_vfunc
   1203     elif any(isinstance(a, DataArray) for a in args):
-> 1204         return apply_dataarray_vfunc(
   1205             variables_vfunc,
   1206             *args,

~/.local/lib/python3.9/site-packages/xarray/core/computation.py in apply_dataarray_vfunc(func, signature, join, exclude_dims, keep_attrs, *args)
    297
    298     if len(args) > 1:
--> 299         args = deep_align(
    300             args, join=join, copy=False, exclude=exclude_dims, raise_on_invalid=False
    301         )

~/.local/lib/python3.9/site-packages/xarray/core/alignment.py in deep_align(objects, join, copy, indexes, exclude, raise_on_invalid, fill_value)
    833             out.append(variables)
    834
--> 835     aligned = align(
    836         *targets,
    837         join=join,

~/.local/lib/python3.9/site-packages/xarray/core/alignment.py in align(join, copy, indexes, exclude, fill_value, *objects)
    770         fill_value=fill_value,
    771     )
--> 772     aligner.align()
    773     return aligner.results
    774

~/.local/lib/python3.9/site-packages/xarray/core/alignment.py in align(self)
    557         self.find_matching_unindexed_dims()
    558         self.assert_no_index_conflict()
--> 559         self.align_indexes()
    560         self.assert_unindexed_dim_sizes_equal()
    561

~/.local/lib/python3.9/site-packages/xarray/core/alignment.py in align_indexes(self)
    402                 if need_reindex:
    403                     if self.join == "exact":
--> 404                         raise ValueError(
    405                             "cannot align objects with join='exact' where "
    406                             "index/labels/sizes are not equal along "

ValueError: cannot align objects with join='exact' where index/labels/sizes are not equal along these coordinates (dimensions): 'ROW' ('ROW',)
```
barronh commented 2 years ago

When the CMAQ concentration file have lesser dimension (spatial reference) It gives error. it is shown below

I do not understand this. What do you mean when the CMAQ concentration have lesser dimension?

The TropOMI file you make for 12NE3 must also be 12NE3 and the CONC file must be 3 dimensional.

If this does not clarify your question, can you post your files some where so that I can test it?

manishsoni0291 commented 2 years ago

@barronh The problem was i haven't included the GRIDDESC in ~/cmaqsatproc/cmaqsatproc/cmaq.py
I also think this can also be included into documentation file for other users to tell the users to specify the GRIDDESC in cmaq.py. The comparison is not good in terms there is large underestimation. This is CMAQ benchmark case output taken from CMAQ site only using CMAQ 5.4. I have included the nc file as file as png file. vcd_no2_01072018 TropOMINO2_2018-07-01_2018_12NE3_CMAQ.nc.gz

barronh commented 2 years ago

I also think this can also be included into documentation file for other users to tell the users to specify the GRIDDESC in cmaq.py.

You don't need to include the GRIDDESC in the code. csp.open_griddesc has an optional keyword gdpath where you can point to your own custom file. I have, just now, improved the documentation on open_griddesc and other functions in cmaqsatproc.cmaq to make this obvious.

gf = csp.open_griddesc('12NE3', gdpath='/path/to/your/GRIDDESC')

I think I know why your totals are low. It looks like your CONC file is just 1 layer tall. As a result, your vertical column density is only integrating one layer. You would need to re-run CMAQ with the full vertical structure.

p.s., I am going to make some edits to make this thread shorter and more readable for others in the future.

barronh commented 2 years ago

I am going to close this issue, since it was originally related to the xarray version compatibility. If you have more questions, please open a new issue.