Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • Python_ToolBox Python_ToolBox
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Create a new issue
  • Issue Boards
Collapse sidebar
  • Marie Brunel
  • Python_ToolBoxPython_ToolBox
  • Wiki
  • Data treatment

Last edited by Marie Brunel Feb 04, 2022
Page history

Data treatment

Monthly runoff

  • convert monthly runoff to annual by summing :
if file_name == "mrunoff.nc":
        #convert number of months to years
        nb_year = int(len(years)/12) #years in months here
        tmp = np.zeros([nb_year,len(latitudes),len(longitudes)])
        #calculation of the sum over each year
        for k in range(0,nb_year,1):
            tmp[k] = np.sum(data[k*12:k*12+12],axis=0)
        data = tmp  #[months,latitudes,longitudes]

Harvest

  • Convert harvest to yield :
#gC/m2 -> tDM/ha (dry matter)
harvests_tdm = np.multiply(harvests,0.02222222)
#tDM/ha -> tFM/ha (fresh matter)
harvests_tfm = np.multiply(harvests_tdm,1.14) #tonne / ha
#production = harvest * surface  [years 101; latitude 30; longitude 33]
yields = np.multiply(harvests_tfm,cft_surface) #tonne

Convert latitude and longitude into lpjml 30 minutes system

pts = [ 
(-43.42368753718026, -12.682038634410734), (-42.71628164452376, -10.559820956441273), (-41.70570179787164, -9.549241109789147), (-42.81733962918898, -15.71377817436711)]
for pt in pts :
    new_pt = []
    for i in [1,0]:
        p = pt[i]
        if round(p) > p :
            p = round(p)-0.25
        else : 
            p = round(p)+0.25
        new_pt.append(p)
    print(new_pt)  

Cell fraction to area

30 minutes resolution

gridhectares = np.zeros((len(latitudes),len(longitudes)))
for lat,latitude in enumerate(latitudes) :
     gridhectares[lat,:] = 110 * 110 * math.cos(math.pi*latitude/180) * 1/2 * 1/2 * 100

5 minutes resolution

surfaces = np.zeros_like(cftfracs)
for lat,latitude in enumerate(latitudes) :
    surfaces[:,:,lat,:] = 110 * 110 * math.cos(math.pi*latitude/180) * 0.083 * 0.083 * 100

Moving average

ma_harvest = []
window = 10
for y,year in enumerate(years[window:]):
    ma_harvest.append(np.average(harvests_regions[id_region][y-window:y]))
ma_harvest = np.asarray(ma_harvest)

Regional selection (biome in brazil)

def region_selection (latitudes,longitudes,region):
    nc = Dataset("/home/marie/ownCloud/Documents/spitfire grassland paper/visualization/python_toolbox/brazil_biomes/brazilian_biomes_newversion.nc", mode='r')
    lat = nc.variables['latitude'][:]
    lon = nc.variables['longitude'][:]
    biomes = nc.variables['biome'][:]
    nc.close()

    new_latitudes,new_longitudes = np.where(region==biomes)

    return (new_latitudes,new_longitudes)
biomes =  ["amazon","caatinga","cerrado","mataatlantica","pampas","pantanal"]
Clone repository
  • Binary file
  • Brazil
  • C balance abnormally high in LPJmL 5 running @LAM
  • Cluster
  • Color and ColorMap
  • Data treatment
  • Link shelf
  • Morocco
  • NetCDF format and file
  • Numpy array
  • Plot graph and map
  • Python script
  • Run CNRM and HADgem LPJmL5 (30 minutes)
  • Home