1

I have a nc file retrieved from the following link https://www.globsnow.info/swe/nrt/2020/data/GlobSnow_SWE_L3A_20200110_v.1.0.nc.gz. I am trying to convert this file to geotiff in wgs 1984 coordinate reference system using python. following is the code i have tried:

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

nc_file = Dataset('path/to/your/nc/file.nc', 'r')
snow_depth = nc_file.variables['snow_depth'][:]
lat = nc_file.variables['latitude'][:]
lon = nc_file.variables['longitude'][:]
lat_attrs = nc_file.variables['latitude'].ncattrs()
lon_attrs = nc_file.variables['longitude'].ncattrs()
transform = rasterio.transform.from_origin(lon[0], lat[0], lon[1]-lon[0], lat[1]-lat[0])
width = int(round((lon[-1] - lon[0]) / transform[0]))
height = int(round((lat[-1] - lat[0]) / transform[4]))
meta = {
    'count': 1,
    'crs': 'EPSG:4326',
    'transform': transform,
    'width': width,
    'height': height,
    'driver': 'GTiff',
    'dtype': rasterio.float32,
    'nodata': -9999
}
with rasterio.open('path/to/your/output/geotiff/file.tif', 'w', **meta) as dst:
    dst.write(snow_depth, 1)

However, I am getting the error that is: "MaskedArray doesn't define round method".

I am looking to convert this file to geotiff, then reproject it to wgs1984.

1
  • You are trying to round an array - I suspect you are missing a max and/or a min
    – Ian Turton
    Mar 7 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.