In [1]:
from netCDF4 import Dataset
import numpy as np
df = Dataset("/Users/brodzik/projects/PMESDR/CSU_FCDR/F08/8710/871022/CSU_SSMI_FCDR_V01R00_F08_D19871022_S2219_E0001_R01763.nc", "r", 'NETCDF4' )

In [2]:
ndf = Dataset("/Users/brodzik/projects/PMESDR/CSU_FCDR/F08/8710/871022/CSU_SSMI_FCDR_V01R00_F08_D19871022_S1855_E2037_R01761.nc", "r", 'NETCDF4' )

In [3]:
print df


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    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 (v20, 11 September 2012)
    id: CSU_SSMI_FCDR_V01R00_F08_D19871022_S2219_E0001_R01763.nc
    naming_authority: gov.noaa.ncdc
    metadata_link: gov.noaa.ncdc:C00827
    title: CSU SSM/I FCDR
    product_version: V01R00
    revision_date: 2013-02-01
    summary: Colorado State University Special Sensor Microwave/Imager (SSM/I) Fundamental Climate Data Record (FCDR) of intercalibrated brightness temperatures
    keywords: EARTH SCIENCE > SPECTRAL/ENGINEERING > MICROWAVE > BRIGHTNESS TEMPERATURE
    keywords_vocabulary: NASA Global Change Master Directory (GCMD) Earth Science Keywords, Version 6.0
    platform: DMSP 5D-2/F08 > Defense Meteorological Satellite Program-F08
    sensor: SSM/I > Special Sensor Microwave/Imager
    cdm_data_type: Swath
    cdr_program: NOAA Climate Data Record Program for satellites, FY 2013
    cdr_variable: fcdr_tb19v, fcdr_tb19h, fcdr_tb22v, fcdr_tb37v, fcdr_tb37h, fcdr_tb85v, fcdr_tb85h
    source: SSMI_TDRBASE_V01R03_F08_D19871022_S2219_E0001_R01763.nc
    date_created: 2013-02-01T16:07MST
    creator_name: Wesley Berg
    creator_url: http://rain.atmos.colostate.edu/FCDR
    creator_email: fcdr@atmos.colostate.edu
    institution: Colorado State University, Dept. of Atmospheric Science, Kummerow research group
    processing_level: NOAA Level 2
    geospatial_lat_min:  -87.71
    geospatial_lat_max:   87.68
    geospatial_lon_min: -180.00
    geospatial_lon_max:  179.99
    geospatial_lat_units: degrees_north
    geospatial_lon_units: degrees_east
    spatial_resolution: 19 V/H GHz: 43km X 69km, 22 V GHz: 40km X 50km, 37 V/H GHz: 28km X 37km, 85 V/H GHz: 13km X 15km
    time_coverage_start: 1987-10-22T22:19:25Z
    time_coverage_end: 1987-10-23T00:01:23Z
    time_coverage_duration: PT1H41M58S
    license: No restrictions on access or use
    contributor_name: Christian Kummerow, Wesley Berg, Mathew Sapiano
    contributor_role: Principal investigator, Co-Investigator and developer with overall responsibility for FCDR data software and documentation, Responsible for intercalibration geolocation and cross-track bias adjustments including associated software and documentation
    orbit_number: 01763
    dimensions(sizes): npixel_lores(64), npixel_hires(128), nscan_lores(1591), nscan_hires(3182), ntest(9), numchar(23)
    variables(dimensions): float64 orbit_lores(nscan_lores), float64 scan_time_lores(nscan_lores), |S1 scan_datetime_lores(nscan_lores,numchar), float32 spacecraft_lat_lores(nscan_lores), float32 spacecraft_lon_lores(nscan_lores), float32 spacecraft_alt_lores(nscan_lores), float32 lat_lores(nscan_lores,npixel_lores), float32 lon_lores(nscan_lores,npixel_lores), float32 fcdr_tb19v(nscan_lores,npixel_lores), float32 fcdr_tb19h(nscan_lores,npixel_lores), float32 fcdr_tb22v(nscan_lores,npixel_lores), float32 fcdr_tb37v(nscan_lores,npixel_lores), float32 fcdr_tb37h(nscan_lores,npixel_lores), float32 eia_lores(nscan_lores,npixel_lores), int8 sun_glint_lores(nscan_lores,npixel_lores), int8 quality_lores(nscan_lores,npixel_lores), float64 orbit_hires(nscan_hires), float64 scan_time_hires(nscan_hires), |S1 scan_datetime_hires(nscan_hires,numchar), float32 spacecraft_lat_hires(nscan_hires), float32 spacecraft_lon_hires(nscan_hires), float32 spacecraft_alt_hires(nscan_hires), float32 lat_hires(nscan_hires,npixel_hires), float32 lon_hires(nscan_hires,npixel_hires), float32 fcdr_tb85v(nscan_hires,npixel_hires), float32 fcdr_tb85h(nscan_hires,npixel_hires), float32 eia_hires(nscan_hires,npixel_hires), int8 sun_glint_hires(nscan_hires,npixel_hires), int8 quality_hires(nscan_hires,npixel_hires), int32 quality_tests(ntest), float32 nominal_elevation_angle(), float32 delta_elevation_angle(), float32 spacecraft_roll(), float32 spacecraft_pitch(), float32 spacecraft_yaw(), |S1 crs()
    groups: 


In [4]:
print ndf


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    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 (v20, 11 September 2012)
    id: CSU_SSMI_FCDR_V01R00_F08_D19871022_S1855_E2037_R01761.nc
    naming_authority: gov.noaa.ncdc
    metadata_link: gov.noaa.ncdc:C00827
    title: CSU SSM/I FCDR
    product_version: V01R00
    revision_date: 2013-02-01
    summary: Colorado State University Special Sensor Microwave/Imager (SSM/I) Fundamental Climate Data Record (FCDR) of intercalibrated brightness temperatures
    keywords: EARTH SCIENCE > SPECTRAL/ENGINEERING > MICROWAVE > BRIGHTNESS TEMPERATURE
    keywords_vocabulary: NASA Global Change Master Directory (GCMD) Earth Science Keywords, Version 6.0
    platform: DMSP 5D-2/F08 > Defense Meteorological Satellite Program-F08
    sensor: SSM/I > Special Sensor Microwave/Imager
    cdm_data_type: Swath
    cdr_program: NOAA Climate Data Record Program for satellites, FY 2013
    cdr_variable: fcdr_tb19v, fcdr_tb19h, fcdr_tb22v, fcdr_tb37v, fcdr_tb37h, fcdr_tb85v, fcdr_tb85h
    source: SSMI_TDRBASE_V01R03_F08_D19871022_S1855_E2037_R01761.nc
    date_created: 2013-02-01T16:07MST
    creator_name: Wesley Berg
    creator_url: http://rain.atmos.colostate.edu/FCDR
    creator_email: fcdr@atmos.colostate.edu
    institution: Colorado State University, Dept. of Atmospheric Science, Kummerow research group
    processing_level: NOAA Level 2
    geospatial_lat_min:   90.00
    geospatial_lat_max:  -90.00
    geospatial_lon_min:  180.00
    geospatial_lon_max: -180.00
    geospatial_lat_units: degrees_north
    geospatial_lon_units: degrees_east
    spatial_resolution: 19 V/H GHz: 43km X 69km, 22 V GHz: 40km X 50km, 37 V/H GHz: 28km X 37km, 85 V/H GHz: 13km X 15km
    time_coverage_start: 1987-10-22T18:55:28Z
    time_coverage_end: 1987-10-22T20:37:27Z
    time_coverage_duration: PT1H41M59S
    license: No restrictions on access or use
    contributor_name: Christian Kummerow, Wesley Berg, Mathew Sapiano
    contributor_role: Principal investigator, Co-Investigator and developer with overall responsibility for FCDR data software and documentation, Responsible for intercalibration geolocation and cross-track bias adjustments including associated software and documentation
    orbit_number: 01761
    dimensions(sizes): npixel_lores(64), npixel_hires(128), nscan_lores(0), nscan_hires(0), ntest(9), numchar(23)
    variables(dimensions): 
    groups: 


In [8]:
Rdf = Dataset("/Users/brodzik/disks/archive/nsidc0588_RSS_TBs/v7_netcdf/F08/1987/10/RSS_SSMI_FCDR_V07R00_F08_D19871022_S2148_E2340_R01763.nc", "r", "NETCDF4" )

In [9]:
print Rdf


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    Conventions: CF-1.5
    Metadata_Conventions: CF-1.5, Unidata Dataset Discovery v1.0, NOAA CDR v1.0, GDS v2.0
    standard_name_vocabulary: CF Standard Name Table (v16, 11 October 2010)
    id: RSS_SSMI_FCDR_V07R00_F08_D19871022_S2148_E2340_R01763.nc
    naming_authority: gov.noaa.ncdc
    metadata_link: gov.noaa.ncdc:C00810
    title: RSS Version-7 SSM/I FCDR
    product_version: v07r00
    date_issued: 2011-09-30
    summary: Remote Sensing Systems (RSS) Version-7 Special Sensor Microwave/Imager (SSM/I) Fundamental Climate Data Record (FCDR); intercalibrated and homogenized brightness temperature polar-orbiting product with quality flags starting from July 1987
    keywords: EARTH SCIENCE > SPECTRAL/ENGINEERING > MICROWAVE > BRIGHTNESS TEMPERATURE
    keywords_vocabulary: NASA Global Change Master Directory (GCMD) Earth Science Keywords, Version 6.0
    platform: DMSP 5D-2/F08 > Defense Meteorological Satellite Program-F08
    sensor: SSM/I > Special Sensor Microwave/Imager
    cdm_data_type: Swath
    cdr_program: CICS-NC supported Climate Data Record Program for satellites, FY 2011
    cdr_variable: fcdr_brightness_temperature_19V, fcdr_brightness_temperature_19H, fcdr_brightness_temperature_22V, fcdr_brightness_temperature_37V, fcdr_brightness_temperature_37H, fcdr_brightness_temperature_85V, fcdr_brightness_temperature_85H
    source: F08_r01763.dat
    date_created: 2012-05-24 23:35:45Z
    creator_name: Carl Mears
    creator_url: http://www.remss.com/
    creator_email: mears@remss.com
    institution: Remote Sensing Systems
    processing_level: NOAA Level 2
    references: doi:10.1175/2007JAMC1635.1, doi:10.1126/science.1140746, SSM/I Users Interpretation Guide UG32268-900 Rev C 29 Nov 2000
    history: 1) 2011-09-30, Carl Mears, Remote Sensing Systems, created initial netCDF file converted from the original RSS data format
    geospatial_lat_min: -87.77
    geospatial_lat_max: 87.73
    geospatial_lon_min: -180.0
    geospatial_lon_max: 179.99
    geospatial_lat_units: degrees_north
    geospatial_lon_units: degrees_east
    spatial_resolution: 19 V/H GHz: 45km X 70km, 22 V GHz: 40km X 60km, 37 V/H GHz: 30km X 38km, 85 V/H GHz: 14km X 16km
    time_coverage_start: 1987-10-22 21:48:49Z
    time_coverage_end: 1987-10-22 23:40:57Z
    time_coverage_duration: PT6728S
    license: No restrictions on access or use
    contributor_name: Frank Wentz, Carl Mears
    contributor_role: Principal investigator and originator of input/source or antenna temperature data, Processor and author of entire driver routine (write_ssmi_tbs_netcdf.pro) which converts RSS native brightness temperature format to netCDF-4.
    dimensions(sizes): scan_number_hires(3600), footprint_number_hires(128), scan_number_lores(1800), footprint_number_lores(64), fourteen_flags(14), numchar(20)
    variables(dimensions): int32 iorbit(), float64 scan_time_hires(scan_number_hires), float64 scan_time_lores(scan_number_hires), float64 orbit_position(scan_number_hires), float32 sc_lat(scan_number_hires), float32 sc_lon(scan_number_hires), float32 sc_alt(scan_number_hires), int8 iqual_flag_hires(fourteen_flags,scan_number_hires), int8 iqual_flag_lores(fourteen_flags,scan_number_lores), int16 latitude_hires(scan_number_hires,footprint_number_hires), int16 longitude_hires(scan_number_hires,footprint_number_hires), int16 earth_incidence_angle_hires(scan_number_hires,footprint_number_hires), int16 earth_azimuth_angle_hires(scan_number_hires,footprint_number_hires), int16 sun_glitter_angle_hires(scan_number_hires,footprint_number_hires), int16 land_percentage_hires(scan_number_hires,footprint_number_hires), int16 ice_flag_hires(scan_number_hires,footprint_number_hires), float32 fcdr_brightness_temperature_85V(scan_number_hires,footprint_number_hires), float32 fcdr_brightness_temperature_85H(scan_number_hires,footprint_number_hires), int16 latitude_lores(scan_number_lores,footprint_number_lores), int16 longitude_lores(scan_number_lores,footprint_number_lores), int16 earth_incidence_angle_lores(scan_number_lores,footprint_number_lores), int16 earth_azimuth_angle_lores(scan_number_lores,footprint_number_lores), int16 sun_glitter_angle_lores(scan_number_lores,footprint_number_lores), int16 land_percentage_lores(scan_number_lores,footprint_number_lores), int16 ice_flag_lores(scan_number_lores,footprint_number_lores), float32 fcdr_brightness_temperature_19V(scan_number_lores,footprint_number_lores), float32 fcdr_brightness_temperature_19H(scan_number_lores,footprint_number_lores), float32 fcdr_brightness_temperature_22V(scan_number_lores,footprint_number_lores), float32 fcdr_brightness_temperature_37V(scan_number_lores,footprint_number_lores), float32 fcdr_brightness_temperature_37H(scan_number_lores,footprint_number_lores)
    groups: 


In [11]:
tbs = Rdf.variables["fcdr_brightness_temperature_37V"]
print tbs

#Rdf.close()


<type 'netCDF4.Variable'>
float32 fcdr_brightness_temperature_37V(scan_number_lores, footprint_number_lores)
    standard_name: brightness_temperature
    long_name: RSS FCDR of 37.0 GHz vertically polarized brightness temperature
    units: kelvin
    valid_range: [  50.  350.]
    _FillValue: -100.0
    coordinates: longitude_lores latitude_lores
unlimited dimensions: 
current shape = (1800, 64)
filling on

In [30]:
bgifil = Dataset("/Users/brodzik/Desktop/test_bgi_diffs.nc", "w", 'NETCDF4' )
bgifil.createDimension( "rows", 3 )
bgifil.createDimension( "columns", 2 )


Out[30]:
<netCDF4.Dimension at 0x10dcbdbe0>

In [31]:
bgifil.createVariable( "bgi_image", float64, ( "rows", "columns" ) )


Out[31]:
<netCDF4.Variable at 0x10dce5b90>

In [32]:
fil = Dataset("/Users/brodzik/Desktop/test.nc", "r", 'NETCDF4' )
print fil


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    dimensions(sizes): rows(3), columns(2)
    variables(dimensions): float64 a_image(rows,columns), float64 ave_image(rows,columns)
    groups: 


In [33]:
origdata = fil.variables['a_image'][:]
print origdata


[[ 150.  200.]
 [ 201.  325.]
 [ 278.  285.]]

In [34]:
origdata[0][1] = 500.
print origdata


[[ 150.  500.]
 [ 201.  325.]
 [ 278.  285.]]

In [35]:
bgifil.variables["bgi_image"][:] = origdata

In [36]:
bgifil.close()

In [45]:
otherfil = Dataset("/Users/brodzik/Desktop/test_bgi_diffs.nc", "r", 'NETCDF4' )
print otherfil
bad_bgi = otherfil.variables["bgi_image"][:]
print bad_bgi


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    dimensions(sizes): rows(3), columns(2)
    variables(dimensions): float64 bgi_image(rows,columns)
    groups: 

[[ 150.  500.]
 [ 201.  325.]
 [ 278.  285.]]

In [41]:
otherfil.close()

In [44]:
otherfil = Dataset("/Users/brodzik/projects/PMESDR/PMESDR_daily_regression_test/python/test_cetb_utilities_data/bgi_data/test_bgi.nc", "r", 'NETCDF4' )
print otherfil
good_bgi = otherfil.variables["bgi_image"][:]
print good_bgi


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    dimensions(sizes): rows(3), columns(2)
    variables(dimensions): float64 bgi_image(rows,columns)
    groups: 

[[ 150.  200.]
 [ 201.  325.]
 [ 278.  285.]]

In [63]:
print good_bgi
print bad_bgi
diff = bad_bgi - good_bgi
print diff
print diff[ np.where( np.logical_and( np.logical_and( 50. < bad_bgi, bad_bgi < 350. ), 
                                np.logical_and( 50. < good_bgi, good_bgi < 350. ) ) ) ]
print diff[ ( 50. < bad_bgi ) & ( bad_bgi < 350. ) & ( 50. < good_bgi ) & ( good_bgi < 350. ) ]


[[ 150.  200.]
 [ 201.  325.]
 [ 278.  285.]]
[[ 150.  500.]
 [ 201.  325.]
 [ 278.  285.]]
[[   0.  300.]
 [   0.    0.]
 [   0.    0.]]
[ 0.  0.  0.  0.  0.]
[ 0.  0.  0.  0.  0.]

In [75]:
new = bad_bgi.copy()
new[2][0] = -10.
print new
print bad_bgi
diff = new - bad_bgi
print diff
print diff[ ( 50. < bad_bgi ) & ( bad_bgi < 350. ) & ( 50. < new ) & ( new < 350. ) ]
indx = ( 50. < bad_bgi ) & ( bad_bgi < 350. ) & ( 50. < new ) & ( new < 350. )
print indx


[[ 150.  500.]
 [ 201.  325.]
 [ -10.  285.]]
[[ 150.  500.]
 [ 201.  325.]
 [ 278.  285.]]
[[   0.    0.]
 [   0.    0.]
 [-288.    0.]]
[ 0.  0.  0.  0.]
[[ True False]
 [ True  True]
 [False  True]]

In [21]:
fil.createVariable( "ave_image", float64, ( "rows", "columns" ) )


Out[21]:
<netCDF4.Variable at 0x10dce54d0>

In [22]:
fil.close()

In [24]:
fil = Dataset("/Users/brodzik/Desktop/test.nc", "r", 'NETCDF4' )
print fil
keys = fil.variables.keys()
print keys


<type 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format UNDEFINED):
    dimensions(sizes): rows(3), columns(2)
    variables(dimensions): float64 a_image(rows,columns), float64 ave_image(rows,columns)
    groups: 

[u'a_image', u'ave_image']

In [25]:
for key in keys: print key


a_image
ave_image

In [5]:
print len(x)


2

In [73]:
def test(x):
    x = 5
y = 8
test( y )
print y


8

In [ ]: