首页 > 解决方案 > 用python掩盖非经典nc文件的纬度和经度区域变量

问题描述

我正在尝试了解来自卫星的气候数据。如果您想在此处查看文件的 ncdump:

netcdf NSS.AMBX.NK.D08214.S0740.E0931.B5312324.WI {
dimensions:
    nscan = 2495 ;
    npixel = 90 ;
    nchar = 19 ;
    nchan = 5 ;

// global attributes:
        :Conventions = "CF-1.6" ;
        :Metadata_Conventions = "CF-1.6, Unidata Dataset Discovery v1.0, NOAA CDR v1.0, GDS v2.0" ;
        :standard_name_vocabulary = "CF Standard Name Table (Version 34, 13 June 2016)" ;
        :id = "NSS.AMBX.NK.D08214.S0740.E0931.B5312324.WI.nc" ;
        :naming_authority = "gov.noaa.ncdc" ;
        :metadata_link = "gov.noaa.ncdc:C00981" ;
        :title = "CICS Version-1 AMSU-B/MHS FCDR" ;
        :product_version = "v00r02" ;
        :date_issued = "TBD" ;
        :summary = "CDRs for AMSU/MHS water vapor channels and corresponding hydrological products are vital for the climate community. The corrections applied to the CDRs include geolocation correction and intersatellte calibration." ;
        :keywords = "EARTH SCIENCE > SPECTRAL/ENGINEERING > MICROWAVE > BRIGHTNESS TEMPERATURE" ;
        :keywords_vocabulary = "NASA Global Change Master Directory (GCMD) Earth Science Keywords, Version 8.1" ;
        :platform = "NOAA-15 > National Oceanic and Atmospheric Administration - 15" ;
        :sensor = "AMSU-B > Advanced Microwave Sounding Unit - B" ;
        :cdm_data_type = "Swath" ;
        :cdr_program = "NOAA Climate Data Record Program for satellites, FY 2016" ;
        :cdr_variable = "fcdr_brightness_temperature_1, fcdr_brightness_temperature_2, fcdr_brightness_temperature_3, fcdr_brightness_temperature_4, fcdr_brightness_temperature_5" ;
        :source = "NSS.AMBX.NK.D08214.S0740.E0931.B5312324.WI" ;
        :refrences = "Original level 1b data are from NOAA archive, they are also available at NOAA Comprehensive Large Array-data Stewardship System (CLASS)" ;
        :history = "TBD" ;
        :date_created = "2016-09-20T22:36:15" ;
        :creator_name = "Ralph R Ferraro" ;
        :creator_url = "http://cics.umd.edu/AMSU-CDR/home.html" ;
        :creator_email = "Ralph.R.Ferraro@noaa.gov" ;
        :institution = "DOC/NOAA/NESDIS/STAR/CoRP > Cooperative Research Program, Center for Satellite Applications and Research, NESDIS, NOAA, U.S. Department of Commerce" ;
        :processing_level = "NOAA level 2" ;
        :geospatial_lat_min = -89.86956f ;
        :geospatial_lat_max = 89.89485f ;
        :geospatial_lon_min = -179.9902f ;
        :geospatial_lon_max = 179.9998f ;
        :geospatial_lat_units = "degrees_north" ;
        :geospatial_lon_units = "degrees_east" ;
        :spatial_resolution = "16km X 16km at nadir, 50km X 27km at limb" ;
        :time_coverage_start = "2008-08-01T07:40:51" ;
        :time_coverage_end = "2008-08-01T09:31:42" ;
        :time_coverage_duration = "P6651S" ;
        :license = "No restrictions on access or use" ;
        :contributor_name = "TBD" ;
        :contributor_role = "TBD" ;

group: Geolocation_Time_Fields {
  variables:
    char scan_time(nscan, nchar) ;
        scan_time:long_name = "Scan start time (UTC) in ISO8601 date/time (YYYY-MM-DDTHH-MM-SS) format" ;
        scan_time:_FillValue = "0" ;
    double scan_time_since98(nscan) ;
        scan_time_since98:standard_name = "time" ;
        scan_time_since98:long_name = "Scan start time (UTC) in a referenced or elapsed time format" ;
        scan_time_since98:_FillValue = 0. ;
        scan_time_since98:units = "seconds since 1998-01-01T00:00:00" ;
    float latitude(nscan, npixel) ;
        latitude:standard_name = "latitude" ;
        latitude:long_name = "Latitude for AMSU-B/MHS" ;
        latitude:valid_min = -90.f ;
        latitude:valid_max = 90.f ;
        latitude:_FillValue = -999.f ;
        latitude:units = "degrees_north" ;
    float longitude(nscan, npixel) ;
        longitude:standard_name = "longitude" ;
        longitude:long_name = "Longitude for AMSU-B/MHS" ;
        longitude:valid_min = -180.f ;
        longitude:valid_max = 180.f ;
        longitude:_FillValue = -999.f ;
        longitude:units = "degrees_east" ;
  } // group Geolocation_Time_Fields

group: Data_Fields {
  variables:
    ubyte orbital_mode(nscan) ;
        orbital_mode:long_name = "satellite direction" ;
        orbital_mode:flag_values = 0UB, 1UB ;
        orbital_mode:flag_meanings = "northbound southbound" ;
        orbital_mode:_FillValue = 255UB ;
    ubyte surface_type(nscan, npixel) ;
        surface_type:long_name = "surface type" ;
        surface_type:coordinates = "latitude longitude" ;
        surface_type:flag_values = 0b, 1b, 2b ;
        surface_type:flag_meanings = "ocean land coast" ;
    float earth_angle_of_incidence(nscan, npixel) ;
        earth_angle_of_incidence:long_name = "earth_angle_of_incidence for AMSU-B/MHS" ;
        earth_angle_of_incidence:_FillValue = -999.f ;
        earth_angle_of_incidence:units = "degree" ;
        earth_angle_of_incidence:coordinates = "latitude longitude" ;
    float solar_zenith_angle(nscan, npixel) ;
        solar_zenith_angle:standard_name = "solar zenith angle" ;
        solar_zenith_angle:long_name = "solar zenith angle for all AMSU-B/MHS" ;
        solar_zenith_angle:_FillValue = -999.f ;
        solar_zenith_angle:units = "degree" ;
    float fcdr_brightness_temperature_1(nscan, npixel) ;
        fcdr_brightness_temperature_1:standard_name = "brightness_temperature" ;
        fcdr_brightness_temperature_1:long_name = "NOAA FCDR of 89 GHz brightness temperature" ;
        fcdr_brightness_temperature_1:valid_min = 10.f ;
        fcdr_brightness_temperature_1:valid_max = 400.f ;
        fcdr_brightness_temperature_1:_FillValue = -99.f ;
        fcdr_brightness_temperature_1:units = "kelvin" ;
        fcdr_brightness_temperature_1:coordinates = "latitude longitude" ;
    float fcdr_brightness_temperature_2(nscan, npixel) ;
        fcdr_brightness_temperature_2:standard_name = "brightness_temperature" ;
        fcdr_brightness_temperature_2:long_name = "NOAA FCDR of 150 GHz brightness temperature" ;
        fcdr_brightness_temperature_2:valid_min = 10.f ;
        fcdr_brightness_temperature_2:valid_max = 400.f ;
        fcdr_brightness_temperature_2:_FillValue = -99.f ;
        fcdr_brightness_temperature_2:units = "kelvin" ;
        fcdr_brightness_temperature_2:coordinates = "latitude longitude" ;
    float fcdr_brightness_temperature_3(nscan, npixel) ;
        fcdr_brightness_temperature_3:standard_name = "brightness_temperature" ;
        fcdr_brightness_temperature_3:long_name = "NOAA FCDR of 183+-1 GHz brightness temperature" ;
        fcdr_brightness_temperature_3:valid_min = 10.f ;
        fcdr_brightness_temperature_3:valid_max = 400.f ;
        fcdr_brightness_temperature_3:_FillValue = -99.f ;
        fcdr_brightness_temperature_3:units = "kelvin" ;
        fcdr_brightness_temperature_3:coordinates = "latitude longitude" ;
    float fcdr_brightness_temperature_4(nscan, npixel) ;
        fcdr_brightness_temperature_4:standard_name = "brightness_temperature" ;
        fcdr_brightness_temperature_4:long_name = "NOAA FCDR of 183+-3 GHz brightness temperature" ;
        fcdr_brightness_temperature_4:valid_min = 10.f ;
        fcdr_brightness_temperature_4:valid_max = 400.f ;
        fcdr_brightness_temperature_4:_FillValue = -99.f ;
        fcdr_brightness_temperature_4:units = "kelvin" ;
        fcdr_brightness_temperature_4:coordinates = "latitude longitude" ;
    float fcdr_brightness_temperature_5(nscan, npixel) ;
        fcdr_brightness_temperature_5:standard_name = "brightness_temperature" ;
        fcdr_brightness_temperature_5:long_name = "NOAA FCDR of 183+-7 GHz brightness temperature" ;
        fcdr_brightness_temperature_5:valid_min = 10.f ;
        fcdr_brightness_temperature_5:valid_max = 400.f ;
        fcdr_brightness_temperature_5:_FillValue = -99.f ;
        fcdr_brightness_temperature_5:units = "kelvin" ;
        fcdr_brightness_temperature_5:coordinates = "latitude longitude" ;
    ubyte flag_brightness_temperature(nscan, nchan) ;
        flag_brightness_temperature:long_name = "instrument/channel quality flag" ;
        flag_brightness_temperature:comment = "The 8-bit quality flags are channel-specific. Users are advised not to use any scans for which the highest bit (bit 7) is set to 1. The lowest two bits (bits 0 and 1) are not used. The meanings of the bits are: bit 7 = Do not use scan for product generation; bit 6 = Calibration error; bit 5 = Time sequence error; bit 4 = Earth location questionable; bit 3 = Brightness temperature out of range; bit 2 = Lunar contamination warning; bit 1~0 = zero fill;" ;
        flag_brightness_temperature:flag_masks = 0UB, 1UB ;
        flag_brightness_temperature:flag_meanings = "good problematic" ;
  } // group Data_Fields
}

我使用 panopoly 进行绘图,您可以在这里找到它。当我尝试使用 matplotlib 进行绘图时,我得到了相同的结果,但是当我尝试获取特定位置时无法确定它是否正确。这是我获取特定位置的代码:

from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma

file = './sample_data/NSS.AMBX.NK.D08214.S0740.E0931.B5312324.WI.nc'
data = Dataset(file,mode='r')

latlar = np.asarray(lats[:]) #Lati
lonlar = np.asarray(lons[:]) #Long
ar = np.asarray(fcdBT[:]) #Brigthness Temp

lo = ma.masked_outside(lonlar,105,110)
la = ma.masked_outside(latlar,30,35)
merged = ~ma.mask_or(la,lo)
ar[merged]

试图在合并值中逻辑合并两个掩码数组,但它给出了空数组,但全景图说有值。我无法理解这里有什么问题。另外,当我尝试到特定位置时,如何确保达到正确的值?Panopoly 不支持掩蔽坐标。或者我不知道该怎么做。CDO 不起作用,因为此 nc 文件包含组给出此错误消息:

$ cdo -info sample_data/NSS.AMBX.NK.D08214.S0740.E0931.B5312324.WI.nc
Warning (cdfInqContents): NetCDF4 groups not supported! Found 2 root groups.
Warning (cdfInqContents): No arrays found!

标签: pythonnumpymaskingnetcdf4

解决方案


merged = ~ma.mask_or(la,lo)应该是类型错误merged = ~ma.mask_or(la.mask,lo.mask)


推荐阅读