def main():

    plt.close('all')

    shp_file = '/Users/mpim/Desktop/ben/TP/TibeatanPlateau'  # specify name of shapefile; note that it should be done WITHOUT the file extension

    # set a array as masked array: x.data = np.ma.array(arr, mask=arr!=arr)
    #set the region for masking
    r = RegionBboxLatLon(777, 70., 105., 25., 40., label='testregion')
    r.mask = None

    #Read files
    filename_Landevl = '/Users/mpim/Desktop/ben/chen_sebs_wgs84_n_0.13x0.13.nc'  #'/data/share/mpiles/TRS/m300157/land_eval/LandFluxEVAL.merged.89-05.monthly.diagnostic.nc'
    Landevl = Data(filename_Landevl, 'ETmon', read=True)  #'lat','lon', ET_mean

    #get aoi
    Landevl.get_aoi_lat_lon(r)
    Landevl.cut_bounding_box()

    # read regions from shapefile
    # This gives an object which contains all regions stored in the shapefile

    RS = RegionShape(shp_file)

    # just print the region keys for illustration
    for k in RS.regions.keys():
        print k

    # if you now want to generate a particular mask we can do that
    # in the following example we mask the airt temperature for the
    # Tibetean plateau

    # and then mask it
    r_tibet = RS.regions[1]  # gives a Region object

    # mask with region

    Landevl.mask_region(r_tibet)
    Landevl.save('/Users/mpim/Desktop/ben/chen_sebs_recut2.nc')

    plt.show()
Example #2
0
# read some data as Data object
filename = download.get_sample_file(name='air', return_object=False)
air = Data(filename, 'air', read=True)

# generate some plot BEFORE the masking
map_plot(air, title='before', use_basemap=True)

# now mask the data ...
air.get_aoi_lat_lon(r)

# generate some plot AFTER the masking
map_plot(air, title='after', use_basemap=True)

#... o.k., so far so good, but the dataset "air" still contains data for the entire domain.
# even if it is masked it will eat some of your memory. You can see this by plotting the size of the matrix
print(air.shape)

# wouldn't it be nice to just remove everything which is not needed?
# Here you go ...
air.cut_bounding_box()
map_plot(air, title='after cutting', use_basemap=True)

# still looks the same, isn't  it? No it isn't, look at the size!
print(air.shape)

# To illustrate what happens, you can plot WITHOUT using a map projection
map_plot(air, title='after cutting (no projection)')

plt.show()
Example #3
0
# read some data as Data object
filename = download.get_sample_file(name="air", return_object=False)
air = Data(filename, "air", read=True)

# generate some plot BEFORE the masking
map_plot(air, title="before", use_basemap=True)

# now mask the data ...
air.get_aoi_lat_lon(r)

# generate some plot AFTER the masking
map_plot(air, title="after", use_basemap=True)

# ... o.k., so far so good, but the dataset "air" still contains data for the entire domain.
# even if it is masked it will eat some of your memory. You can see this by plotting the size of the matrix
print(air.shape)

# wouldn't it be nice to just remove everything which is not needed?
# Here you go ...
air.cut_bounding_box()
map_plot(air, title="after cutting", use_basemap=True)

# still looks the same, isn't  it? No it isn't, look at the size!
print(air.shape)

# To illustrate what happens, you can plot WITHOUT using a map projection
map_plot(air, title="after cutting (no projection)")

plt.show()