super(type, obj): obj must be an instance or subtype of type [closed]











up vote
-2
down vote

favorite












Im trying to run a short climate model in Python, but get the error: TypeError: super(type, obj): obj must be an instance or subtype of type. can somebody advise please?



# Import libraries
import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt

# import the coordinate reference system from cartopyy
import cartopy.crs as ccrs

# import the mutils library
# import mplotutils as mp


#--------------------------------------------------------------------------
# Load in netcdf files from simulation
#--------------------------------------------------------------------------

fN='control2_latent_heat.nc'
print(fN)

# opening the dataset
ncf = nc.Dataset(fN)

# print all variables
print(ncf.variables.keys())

# get a variable
ncf.variables['lon']

# check the units of the variable (in the netCDF4.variable structure)
ncf.variables['time'].units

# load actual data (as a numpy array): longitude and latitude
lon = ncf.variables['lon'][:]
lat = ncf.variables['lat'][:]

# example to convert the masked array to a np array
lon_nm = np.asarray(lon)
lat_nm = np.asarray(lat)

# load evaporation
var_orig = ncf.variables['variables'][:]


#--------------------------------------------------------------------------
# Manipulate variables
#--------------------------------------------------------------------------

# remove first dimension of variable (to have 2D var)
rows = var_orig.shape[1]
cols = var_orig.shape[2]
var_masked = np.reshape(var_orig,(rows,cols))


# extract the mask from the variable and convert to a nan mask
mask_bool = np.logical_not(np.ma.getmask(var_masked))
mask = 1*mask_bool.astype(float)
mask[~mask_bool] = np.nan

# convert the masked variable to a numpy array and apply the nan mask
var_nomask = np.asarray(var_masked)
var = var_nomask*mask



#-----------------------------------------------------------------------------
# Plot the netCDF file (map)
# ----------------------------------------------------------------------------

# define the projection
projection = ccrs.PlateCarree()

# initiate the figure
ax = plt.axes(projection=projection)

# add the coastlines to the plot
ax.coastlines()

# the original cesm lon and lat assumes center of gridcel. pcolormesh assumes border.
# this function transforms lon and lat to represent gridcel edges.
# only necessary for the cesm grid! (not for the observational data)

LON = np.arange(0, 361, 2.5)
LAT = np.arange(-90, 91, 1.9)


# add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
h = ax.pcolormesh(LON,LAT,var, cmap='GnBu',rasterized=True)

# set the extent of the cartopy geoAxes to "global"
ax.set_global()

# or alternatively, if you want to plot a certain region, use (example: Europe)
#ax.set_extent([-13, 43, 35, 70], ccrs.PlateCarree())

# plot the colorbar
cbar = plt.colorbar(h, ax=ax, label='label', orientation='horizontal', extend='max')

# adjust colorbar extent to axes extent
ax.set_aspect('auto')

# add title
plt.title('your title')

# save the figure, adjusting the resolution
plt.savefig('yourfigure.png', dpi=300)









share|improve this question













closed as off-topic by Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк Dec 12 at 21:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк

If this question can be reworded to fit the rules in the help center, please edit the question.

















    up vote
    -2
    down vote

    favorite












    Im trying to run a short climate model in Python, but get the error: TypeError: super(type, obj): obj must be an instance or subtype of type. can somebody advise please?



    # Import libraries
    import netCDF4 as nc
    import numpy as np
    import matplotlib.pyplot as plt

    # import the coordinate reference system from cartopyy
    import cartopy.crs as ccrs

    # import the mutils library
    # import mplotutils as mp


    #--------------------------------------------------------------------------
    # Load in netcdf files from simulation
    #--------------------------------------------------------------------------

    fN='control2_latent_heat.nc'
    print(fN)

    # opening the dataset
    ncf = nc.Dataset(fN)

    # print all variables
    print(ncf.variables.keys())

    # get a variable
    ncf.variables['lon']

    # check the units of the variable (in the netCDF4.variable structure)
    ncf.variables['time'].units

    # load actual data (as a numpy array): longitude and latitude
    lon = ncf.variables['lon'][:]
    lat = ncf.variables['lat'][:]

    # example to convert the masked array to a np array
    lon_nm = np.asarray(lon)
    lat_nm = np.asarray(lat)

    # load evaporation
    var_orig = ncf.variables['variables'][:]


    #--------------------------------------------------------------------------
    # Manipulate variables
    #--------------------------------------------------------------------------

    # remove first dimension of variable (to have 2D var)
    rows = var_orig.shape[1]
    cols = var_orig.shape[2]
    var_masked = np.reshape(var_orig,(rows,cols))


    # extract the mask from the variable and convert to a nan mask
    mask_bool = np.logical_not(np.ma.getmask(var_masked))
    mask = 1*mask_bool.astype(float)
    mask[~mask_bool] = np.nan

    # convert the masked variable to a numpy array and apply the nan mask
    var_nomask = np.asarray(var_masked)
    var = var_nomask*mask



    #-----------------------------------------------------------------------------
    # Plot the netCDF file (map)
    # ----------------------------------------------------------------------------

    # define the projection
    projection = ccrs.PlateCarree()

    # initiate the figure
    ax = plt.axes(projection=projection)

    # add the coastlines to the plot
    ax.coastlines()

    # the original cesm lon and lat assumes center of gridcel. pcolormesh assumes border.
    # this function transforms lon and lat to represent gridcel edges.
    # only necessary for the cesm grid! (not for the observational data)

    LON = np.arange(0, 361, 2.5)
    LAT = np.arange(-90, 91, 1.9)


    # add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
    h = ax.pcolormesh(LON,LAT,var, cmap='GnBu',rasterized=True)

    # set the extent of the cartopy geoAxes to "global"
    ax.set_global()

    # or alternatively, if you want to plot a certain region, use (example: Europe)
    #ax.set_extent([-13, 43, 35, 70], ccrs.PlateCarree())

    # plot the colorbar
    cbar = plt.colorbar(h, ax=ax, label='label', orientation='horizontal', extend='max')

    # adjust colorbar extent to axes extent
    ax.set_aspect('auto')

    # add title
    plt.title('your title')

    # save the figure, adjusting the resolution
    plt.savefig('yourfigure.png', dpi=300)









    share|improve this question













    closed as off-topic by Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк Dec 12 at 21:53


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк

    If this question can be reworded to fit the rules in the help center, please edit the question.















      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      Im trying to run a short climate model in Python, but get the error: TypeError: super(type, obj): obj must be an instance or subtype of type. can somebody advise please?



      # Import libraries
      import netCDF4 as nc
      import numpy as np
      import matplotlib.pyplot as plt

      # import the coordinate reference system from cartopyy
      import cartopy.crs as ccrs

      # import the mutils library
      # import mplotutils as mp


      #--------------------------------------------------------------------------
      # Load in netcdf files from simulation
      #--------------------------------------------------------------------------

      fN='control2_latent_heat.nc'
      print(fN)

      # opening the dataset
      ncf = nc.Dataset(fN)

      # print all variables
      print(ncf.variables.keys())

      # get a variable
      ncf.variables['lon']

      # check the units of the variable (in the netCDF4.variable structure)
      ncf.variables['time'].units

      # load actual data (as a numpy array): longitude and latitude
      lon = ncf.variables['lon'][:]
      lat = ncf.variables['lat'][:]

      # example to convert the masked array to a np array
      lon_nm = np.asarray(lon)
      lat_nm = np.asarray(lat)

      # load evaporation
      var_orig = ncf.variables['variables'][:]


      #--------------------------------------------------------------------------
      # Manipulate variables
      #--------------------------------------------------------------------------

      # remove first dimension of variable (to have 2D var)
      rows = var_orig.shape[1]
      cols = var_orig.shape[2]
      var_masked = np.reshape(var_orig,(rows,cols))


      # extract the mask from the variable and convert to a nan mask
      mask_bool = np.logical_not(np.ma.getmask(var_masked))
      mask = 1*mask_bool.astype(float)
      mask[~mask_bool] = np.nan

      # convert the masked variable to a numpy array and apply the nan mask
      var_nomask = np.asarray(var_masked)
      var = var_nomask*mask



      #-----------------------------------------------------------------------------
      # Plot the netCDF file (map)
      # ----------------------------------------------------------------------------

      # define the projection
      projection = ccrs.PlateCarree()

      # initiate the figure
      ax = plt.axes(projection=projection)

      # add the coastlines to the plot
      ax.coastlines()

      # the original cesm lon and lat assumes center of gridcel. pcolormesh assumes border.
      # this function transforms lon and lat to represent gridcel edges.
      # only necessary for the cesm grid! (not for the observational data)

      LON = np.arange(0, 361, 2.5)
      LAT = np.arange(-90, 91, 1.9)


      # add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
      h = ax.pcolormesh(LON,LAT,var, cmap='GnBu',rasterized=True)

      # set the extent of the cartopy geoAxes to "global"
      ax.set_global()

      # or alternatively, if you want to plot a certain region, use (example: Europe)
      #ax.set_extent([-13, 43, 35, 70], ccrs.PlateCarree())

      # plot the colorbar
      cbar = plt.colorbar(h, ax=ax, label='label', orientation='horizontal', extend='max')

      # adjust colorbar extent to axes extent
      ax.set_aspect('auto')

      # add title
      plt.title('your title')

      # save the figure, adjusting the resolution
      plt.savefig('yourfigure.png', dpi=300)









      share|improve this question













      Im trying to run a short climate model in Python, but get the error: TypeError: super(type, obj): obj must be an instance or subtype of type. can somebody advise please?



      # Import libraries
      import netCDF4 as nc
      import numpy as np
      import matplotlib.pyplot as plt

      # import the coordinate reference system from cartopyy
      import cartopy.crs as ccrs

      # import the mutils library
      # import mplotutils as mp


      #--------------------------------------------------------------------------
      # Load in netcdf files from simulation
      #--------------------------------------------------------------------------

      fN='control2_latent_heat.nc'
      print(fN)

      # opening the dataset
      ncf = nc.Dataset(fN)

      # print all variables
      print(ncf.variables.keys())

      # get a variable
      ncf.variables['lon']

      # check the units of the variable (in the netCDF4.variable structure)
      ncf.variables['time'].units

      # load actual data (as a numpy array): longitude and latitude
      lon = ncf.variables['lon'][:]
      lat = ncf.variables['lat'][:]

      # example to convert the masked array to a np array
      lon_nm = np.asarray(lon)
      lat_nm = np.asarray(lat)

      # load evaporation
      var_orig = ncf.variables['variables'][:]


      #--------------------------------------------------------------------------
      # Manipulate variables
      #--------------------------------------------------------------------------

      # remove first dimension of variable (to have 2D var)
      rows = var_orig.shape[1]
      cols = var_orig.shape[2]
      var_masked = np.reshape(var_orig,(rows,cols))


      # extract the mask from the variable and convert to a nan mask
      mask_bool = np.logical_not(np.ma.getmask(var_masked))
      mask = 1*mask_bool.astype(float)
      mask[~mask_bool] = np.nan

      # convert the masked variable to a numpy array and apply the nan mask
      var_nomask = np.asarray(var_masked)
      var = var_nomask*mask



      #-----------------------------------------------------------------------------
      # Plot the netCDF file (map)
      # ----------------------------------------------------------------------------

      # define the projection
      projection = ccrs.PlateCarree()

      # initiate the figure
      ax = plt.axes(projection=projection)

      # add the coastlines to the plot
      ax.coastlines()

      # the original cesm lon and lat assumes center of gridcel. pcolormesh assumes border.
      # this function transforms lon and lat to represent gridcel edges.
      # only necessary for the cesm grid! (not for the observational data)

      LON = np.arange(0, 361, 2.5)
      LAT = np.arange(-90, 91, 1.9)


      # add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
      h = ax.pcolormesh(LON,LAT,var, cmap='GnBu',rasterized=True)

      # set the extent of the cartopy geoAxes to "global"
      ax.set_global()

      # or alternatively, if you want to plot a certain region, use (example: Europe)
      #ax.set_extent([-13, 43, 35, 70], ccrs.PlateCarree())

      # plot the colorbar
      cbar = plt.colorbar(h, ax=ax, label='label', orientation='horizontal', extend='max')

      # adjust colorbar extent to axes extent
      ax.set_aspect('auto')

      # add title
      plt.title('your title')

      # save the figure, adjusting the resolution
      plt.savefig('yourfigure.png', dpi=300)






      python numpy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 12 at 20:39









      gall

      1




      1




      closed as off-topic by Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк Dec 12 at 21:53


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк

      If this question can be reworded to fit the rules in the help center, please edit the question.




      closed as off-topic by Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк Dec 12 at 21:53


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Sᴀᴍ Onᴇᴌᴀ, 200_success, Gerrit0, яүυк

      If this question can be reworded to fit the rules in the help center, please edit the question.



























          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар