'How to correctly define the crs of a raster brick of a Netcdf file in R?

I was trying to open my nc file using the raster package on R, but got errors while trying to change the projection of my data.

The information of my fyle is the following:

File C:/Users/fisica/Downloads/data_sensit01.nc (NC_FORMAT_64BIT):

     6 variables (excluding dimension variables):
        double time_bnds[bnds,time]   
        float xlon[jx,iy]   
            standard_name: longitude
            long_name: Longitude on Cross Points
            units: degrees_east
            _CoordinateAxisType: Lon
        float xlat[jx,iy]   
            standard_name: latitude
            long_name: Latitude on Cross Points
            units: degrees_north
            _CoordinateAxisType: Lat
        char crs[]   
            proj4_params: +proj=omerc +lat_0=-21.11 +alpha=89.999999 +lonc=-60.30 +x_0=-15000. +y_0=-15000. +ellps=sphere +a=6371229. +b=6371229. +units=m +no_defs
            grid_mapping_name: rotated_mercator
            latitude_of_projection_origin: -21.11
            longitude_of_projection_origin: -60.3
            scale_factor_at_projection_origin: 1
            semi_major_axis: 6371229
            inverse_flattening: 0
            false_easting: -15000
            false_northing: -15000
            CoordinateTransformType: Projection
            CoordinateAxisTypes: GeoX GeoY
        float ts[jx,iy,time]   
            standard_name: surface_temperature
            long_name: Surface Temperature
            units: K
            grid_mapping: crs
            coordinates: xlat xlon
            cell_methods: time: point
        float pr[jx,iy,time]   
            standard_name: precipitation_flux
            long_name: Precipitation
            units: kg m-2 s-1
            grid_mapping: crs
            coordinates: xlat xlon
            cell_methods: time: mean

     4 dimensions:
        time  Size:32128   *** is unlimited *** 
            standard_name: time
            long_name: time
            bounds: time_bnds
            units: hours since 1949-12-01 00:00:00 UTC
            calendar: gregorian
            axis: T
        bnds  Size:2 (no dimvar)
        jx  Size:240 
            standard_name: projection_x_coordinate
            long_name: x-coordinate in Cartesian system
            units: m
            axis: X
        iy  Size:275 
            standard_name: projection_y_coordinate
            long_name: y-coordinate in Cartesian system
            units: m
            axis: Y

    146 global attributes:
        CDI: Climate Data Interface version 2.0.0rc1 (https://mpimet.mpg.de/cdi)
        Conventions: CF-1.7
        source: RegCM Model output file
        institution: ICTP
        title: ICTP Regional Climatic model V4
        references: http://gforge.ictp.it/gf/project/regcm
        model_revision: tag-4.7.0
        history: Tue Apr 19 11:47:29 2022: cdo select,name=ts,pr sensit01_SRF.2005010100.nc sensit01_SRF.2005020100.nc sensit01_SRF.2005030100.nc sensit01_SRF.2005040100.nc sensit01_SRF.2005050100.nc sensit01_SRF.2005060100.nc sensit01_SRF.2005070100.nc sensit01_SRF.2005080100.nc sensit01_SRF.2005090100.nc sensit01_SRF.2005100100.nc sensit01_SRF.2005110100.nc sensit01_SRF.2005120100.nc sensit01_SRF.2006010100.nc sensit01_SRF.2006020100.nc sensit01_SRF.2006030100.nc sensit01_SRF.2006040100.nc sensit01_SRF.2006050100.nc sensit01_SRF.2006060100.nc sensit01_SRF.2006070100.nc sensit01_SRF.2006080100.nc sensit01_SRF.2006090100.nc sensit01_SRF.2006100100.nc sensit01_SRF.2006110100.nc sensit01_SRF.2006120100.nc sensit01_SRF.2007010100.nc sensit01_SRF.2007020100.nc sensit01_SRF.2007030100.nc sensit01_SRF.2007040100.nc sensit01_SRF.2007050100.nc sensit01_SRF.2007060100.nc sensit01_SRF.2007070100.nc sensit01_SRF.2007080100.nc sensit01_SRF.2007090100.nc sensit01_SRF.2007100100.nc sensit01_SRF.2007110100.nc sensit01_SRF.2007120100.nc sensit01_SRF.2008010100.nc sensit01_SRF.2008020100.nc sensit01_SRF.2008030100.nc sensit01_SRF.2008040100.nc sensit01_SRF.2008050100.nc sensit01_SRF.2008060100.nc sensit01_SRF.2008070100.nc sensit01_SRF.2008080100.nc sensit01_SRF.2008090100.nc sensit01_SRF.2008100100.nc sensit01_SRF.2008110100.nc sensit01_SRF.2008120100.nc sensit01_SRF.2009010100.nc sensit01_SRF.2009020100.nc sensit01_SRF.2009030100.nc sensit01_SRF.2009040100.nc sensit01_SRF.2009050100.nc sensit01_SRF.2009060100.nc sensit01_SRF.2009070100.nc sensit01_SRF.2009080100.nc sensit01_SRF.2009090100.nc sensit01_SRF.2009100100.nc sensit01_SRF.2009110100.nc sensit01_SRF.2009120100.nc sensit01_SRF.2010010100.nc sensit01_SRF.2010020100.nc sensit01_SRF.2010030100.nc sensit01_SRF.2010040100.nc sensit01_SRF.2010050100.nc sensit01_SRF.2010060100.nc sensit01_SRF.2010070100.nc sensit01_SRF.2010080100.nc sensit01_SRF.2010090100.nc sensit01_SRF.2010100100.nc sensit01_SRF.2010110100.nc sensit01_SRF.2010120100.nc sensit01_SRF.2011010100.nc sensit01_SRF.2011020100.nc sensit01_SRF.2011030100.nc sensit01_SRF.2011040100.nc sensit01_SRF.2011050100.nc sensit01_SRF.2011060100.nc sensit01_SRF.2011070100.nc sensit01_SRF.2011080100.nc sensit01_SRF.2011090100.nc sensit01_SRF.2011100100.nc sensit01_SRF.2011110100.nc sensit01_SRF.2011120100.nc sensit01_SRF.2012010100.nc sensit01_SRF.2012020100.nc sensit01_SRF.2012030100.nc sensit01_SRF.2012040100.nc sensit01_SRF.2012050100.nc sensit01_SRF.2012060100.nc sensit01_SRF.2012070100.nc sensit01_SRF.2012080100.nc sensit01_SRF.2012090100.nc sensit01_SRF.2012100100.nc sensit01_SRF.2012110100.nc sensit01_SRF.2012120100.nc sensit01_SRF.2013010100.nc sensit01_SRF.2013020100.nc sensit01_SRF.2013030100.nc sensit01_SRF.2013040100.nc sensit01_SRF.2013050100.nc sensit01_SRF.2013060100.nc sensit01_SRF.2013070100.nc sensit01_SRF.2013080100.nc sensit01_SRF.2013090100.nc sensit01_SRF.2013100100.nc sensit01_SRF.2013110100.nc sensit01_SRF.2013120100.nc sensit01_SRF.2014010100.nc sensit01_SRF.2014020100.nc sensit01_SRF.2014030100.nc sensit01_SRF.2014040100.nc sensit01_SRF.2014050100.nc sensit01_SRF.2014060100.nc sensit01_SRF.2014070100.nc sensit01_SRF.2014080100.nc sensit01_SRF.2014090100.nc sensit01_SRF.2014100100.nc sensit01_SRF.2014110100.nc sensit01_SRF.2014120100.nc sensit01_SRF.2015010100.nc sensit01_SRF.2015020100.nc sensit01_SRF.2015030100.nc sensit01_SRF.2015040100.nc sensit01_SRF.2015050100.nc sensit01_SRF.2015060100.nc sensit01_SRF.2015070100.nc sensit01_SRF.2015080100.nc sensit01_SRF.2015090100.nc sensit01_SRF.2015100100.nc sensit01_SRF.2015110100.nc sensit01_SRF.2015120100.nc data_sensit01.nc
2021-09-13 11:23:59 : Created by RegCM RegCM Model program
        experiment: sensit01
        projection: ROTMER
        grid_size_in_meters: 30000
        latitude_of_projection_origin: -21.11
        longitude_of_projection_origin: -60.3
        grid_north_pole_latitude: -21.11
        grid_north_pole_longitude: -60.3
        grid_factor: 0
        landsurface_model: bats1e
        model_icbc_data_source: EIN15
        model_sst_data_source: OI_WK
        boundary_nspgx: 12
        boundary_nspgd: 12
        boundary_high_nudge: 3
        boundary_medium_nudge: 2
        boundary_low_nudge: 1
        boundary_nm: -1
        boundary_dm: -1
        model_is_restarted: No
        model_simulation_initial_start:  2005-01-01 00:00:00 UTC
        model_simulation_start:  2005-01-01 00:00:00 UTC
        model_simulation_end:  2015-12-31 00:00:00 UTC
        atmosphere_time_step_in_seconds: 30
        surface_interaction_time_step_in_seconds: 600
        convection_time_step_in_seconds: 300
        radiation_scheme_time_step_in_seconds: 1800
        absorption_emission_time_step_in_seconds: 64800
        dynamical_core: 1
        asselin_filter_nu_1: 0.0625
        asselin_filter_nu_2: 0.0625
        diffusion_hgt_factor: 1
        upstream_mode: Yes
        off_centering_max: 0.25
        stability_enhance: Yes
        temperature_extreme_gradient: 5
        cloud_extreme_gradient_fraction: 0.5
        vapor_extreme_gradient_fraction: 0.2
        tracer_extreme_gradient_fraction: 0.5
        lateral_boundary_condition_scheme: 5
        semi_lagrangian_advection_scheme: 0
        boundary_layer_scheme: 1
        cumulus_convection_scheme_lnd: 2
        cumulus_convection_scheme_ocn: 4
        moisture_scheme: 1
        ocean_flux_scheme: 2
        zeng_ocean_roughness_formula: 1
        zeng_ocean_roughness_method: 1
        pressure_gradient_scheme: 0
        surface_emissivity_factor_computed: 0
        lake_model_activated: 0
        chemical_aerosol_scheme_activated: 0
        ipcc_scenario_code: A1B
        diurnal_cycle_sst_scheme: 0
        ocean_precipitaion_cooling_effect: 0
        ocean_albedo_from_whitecapping: 0
        simple_sea_ice_scheme: 0
        seasonal_desert_albedo: 0
        convective_lwp_as_large_scale: 0
        large_scale_cloud_fraction_scheme: 0
        ocean_stratiform_clouds_scheme: 1
        rrtm_radiation_scheme_activated: 0
        climatic_ozone_input_dataset: 0
        climatic_aerosol_input_dataset: 0
        static_solar_constant_used: 0
        cumulus_cloud_model: 1
        sun_year_offset: 0
        fix_solar_parameters: 0
        cloud_bottom_level_with_no_clouds: 1
        cloud_rh_with_fcc_one: 1.01
        cloud_rh_threshold_for_land: 0.8
        cloud_rh_threshold_for_ocean: 0.9
        cloud_rh1_limit_temperature: 238
        cloud_cloud_fraction_maximum: 0.75
        cloud_condensation_threshold: 1
        cloud_cloud_fraction_max_for_convection: 0.75
        cloud_cloud_liqwat_max_for_convection: 3e-04
        cloud_shallow_convective_cf_param: 0.07
        cloud_deep_convective_cf_param: 0.14
        cloud_k2_convective_cf_param: 500
        cloud_surface_radiation_hack: No
        cloud_arctic_cloud_correction: Yes
        subex_auto_conversion_rate_for_land: 5e-04
        subex_auto_conversion_rate_for_ocean: 5e-04
        subex_gultepe_factor_when_rain_for_land: 0.65
        subex_gultepe_factor_when_rain_for_ocean: 0.3
        subex_land_raindrop_evaporation_rate: 1e-05
        subex_ocean_raindrop_evaporation_rate: 1e-05
        subex_land_raindrop_accretion_rate: 6
        subex_ocean_raindrop_accretion_rate: 4
        grell_scheme_closure: 1
        grell_cloud_conversion_rate: 0.002
        grell_min_shear_on_precip: 0.3
        grell_max_shear_on_precip: 0.9
        grell_min_precip_efficiency: 0.2
        grell_max_precip_efficiency: 0.8
        grell_min_precip_efficiency_o: 0.2
        grell_max_precip_efficiency_o: 0.8
        grell_min_precip_efficiency_x: 0.2
        grell_max_precip_efficiency_x: 0.8
        grell_min_shear_on_precip_on_ocean: 0.3
        grell_max_shear_on_precip_on_ocean: 0.9
        grell_min_precip_efficiency_on_ocean: 0.2
        grell_max_precip_efficiency_on_ocean: 0.8
        grell_min_precip_efficiency_o_on_ocean: 0.2
        grell_max_precip_efficiency_o_on_ocean: 0.8
        grell_min_precip_efficiency_x_on_ocean: 0.2
        grell_max_precip_efficiency_x_on_ocean: 0.8
        grell_max_depth_of_stable_layer: 50
        grell_min_depth_of_cloud: 150
        grell_min_convective_heating: -250
        grell_max_convective_heating: 500
        grell_max_cloud_base_height: 0.4
        grell_FC_ABE_removal_timescale: 30
        mit_lowest_convection_sigma: 0.95
        mit_autoconversion_threshold_mixing_over_ocean: 0.0011
        mit_autoconversion_threshold_mixing_over_land: 0.0011
        mit_autoconversion_threshold_temperature: -55
        mit_mixing_coefficient_in_entrainment: 1.5
        mit_fractional_area_unsaturated_downdraft: 0.05
        mit_fractional_precip_outside_cloud: 0.12
        mit_pressure_velocity_of_rain: 50
        mit_pressure_velocity_of_snow: 5.5
        mit_rain_evaporation_coefficient: 1
        mit_snow_evaporation_coefficient: 0.8
        mit_momentum_transport_coefficient: 0.7
        mit_downdraft_velocity_coefficient: 10
        mit_max_parcel_neg_temp_perturbation: 0.9
        mit_approach_rate_quasi_eq_coeff_a: 0.2
        mit_approach_rate_quasi_eq_coeff_d: 0.1
        mit_maximum_land_precipitation_efficiency: 0.999
        mit_maximum_ocean_precipitation_efficiency: 0.999
        holtslag_critical_ocean_richardson: 0.25
        holtslag_critical_land_richardson: 0.25
        holtslag_zhnew_factor: 0.25
        holtslag_th10_estimate: 1
        holtslag_th10_maximize: 1
        holtslag_th10_niteration: 1
        CDO: Climate Data Operators version 2.0.0rc1 (https://mpimet.mpg.de/cdo)

In order to open the file, I tried running the following:

dummie_raster <- raster::brick(file)

And got the following errors:

proj_create: Error -5 (unknown projection id)
proj_create: Error -5 (unknown projection id)
Warning messages:
1: In .varName(nc, varname, warn = warn) : varname used is: ts
If that is not correct, you can set it to one of: ts, pr
2: In .getCRSfromGridMap4(atts) : cannot process these parts of the crs:
proj4_params=+proj=omerc +lat_0=-21.11 +alpha=89.999999 +lonc=-60.30 +x_0=-15000. +y_0=-15000. +ellps=sphere +a=6371229. +b=6371229. +units=m +no_defs
CoordinateTransformType=Projection
CoordinateAxisTypes=GeoX GeoY
3: In .getCRSfromGridMap4(atts) : cannot create a valid crs
grid_mapping_name; false_easting; false_northing; scale_factor_at_projection_origin; scale_factor_at_central_meridian; standard_parallel; standard_parallel1; standard_parallel2; longitude_of_central_meridian; longitude_of_projection_origin; latitude_of_projection_origin; straight_vertical_longitude_from_pole; longitude_of_prime_meridian; semi_major_axis; semi_minor_axis; inverse_flattening; earth_radius; +proj; +x_0; +y_0; +k_0; +k_0; +lat_1; +lat_1; +lat_2; +lon_0; +lon_0; +lat_0; +lon_0; +pm; +a; +b; +rf; +a

So in the information of my raster brick, I get that crs is NA.

In order to define the crs, I tried to use :

proj4string(dummie_raster)=CRS("+=omerc +lat_0=-21.11 +alpha=89.999999 +lon0=-60.30 +x_0=-15000. +y_0=-15000. +ellps=sphere +a=6371229. +b=6371229. +units=m")

Only to get a similar error.

I would really appreciate any insights on how to solve this, since I'm trying to reproject this data to WGS84.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source