Re: [R-sig-Geo] Merge dataframe with NetCDF file

2023-05-20 Thread Roy Mendelssohn - NOAA Federal via R-sig-Geo
You have it  what sense?  Is it your R workspace?  If so,  assume what you have 
is called "obj",  what is the result of str(obj).  Also have you googled 
writing netcdf files from R?  There are any number of online tutorials.  Have 
you looked at the packages ncdf4 or RNetCDF?  Also,  who is your target 
audience?  Just dumping data to netcdf is not that hard,  creating netcdf files 
that others can understand by following a convention,  like the CF convention,  
takes some thought and work,  As I said in my first reply,  you are likely to 
get more help when you can show the effort you have put into solving this,  and 
where you got stuck.

-Roy

> On May 20, 2023, at 1:51 PM, Miluji Sb  wrote:
> 
> What I have is data for 49 years at grid cells (0.5°×0.5°) which I would
> like to write as a NetCDF file. Any help will be greatly appreciated.
> Thanks!

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: [email protected] www: https://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

___
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Merge dataframe with NetCDF file

2023-05-20 Thread Miluji Sb
Apologies. I actually do not have a raster yet.

I have created a rasterlayer but when I want to import by data (wide format
and 49 variables), I get the following error.

Error in setValues(x, v) : values must be numeric, logical or factor
In addition: Warning message:
In v[] <- value :
  number of items to replace is not a multiple of replacement length
Error in .local(x, i = i, j = j, ..., value) :

cannot replace values on this raster (it is too large

class  : RasterLayer
dimensions : 360, 720, 259200  (nrow, ncol, ncell)
resolution : 0.5, 0.5  (x, y)
extent : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
crs: +proj=longlat +datum=WGS84 +no_defs


What I have is data for 49 years at grid cells (0.5°×0.5°) which I would
like to write as a NetCDF file. Any help will be greatly appreciated.
Thanks!

Best,

Milu


On Sat, May 20, 2023 at 2:27 AM Alexander Ilich  wrote:

> The WriteRaster should be able to do it (
> https://stackoverflow.com/questions/50026442/writing-r-raster-stack-to-netcdf).
> Also, if practical, I'd recommend switching from the raster package to the
> terra package which has replaced it and is written by the same author. The
> syntax is almost identical so it's an easy transition. terra has a writeCDF
> function which may work (https://rdrr.io/cran/terra/man/writeCDF.html).
>
> Best Regards,
> Alex
>
> --
> *From:* R-sig-Geo  on behalf of Miluji
> Sb 
> *Sent:* Friday, May 19, 2023 7:19 PM
> *To:* R-sig-geo mailing list 
> *Subject:* [R-sig-Geo] Merge dataframe with NetCDF file
>
> [You don't often get email from [email protected]. Learn why this is
> important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Dear all,
>
> I am struggling to convert a dataframe with 49 years of data for 259,200
> coordinates. How can I convert this dataset into a NetCDF file with the
> following attributes;
>
> class  : RasterBrick
> dimensions : 360, 720, 259200, 10  (nrow, ncol, ncell, nlayers)
> resolution : 0.5, 0.5  (x, y)
> extent : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
> crs: +proj=longlat +datum=WGS84 +no_defs
> year (): 1971, 1972, ..., 2019
> varname: fs
>
> Any help will be highly appreciated.
>
> Best,
>
> Milu
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> [email protected]
>
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=05%7C01%7Cailich%40usf.edu%7C0f7d47bd46514adffc8408db58bf9b44%7C741bf7dee2e546df8d6782607df9deaa%7C0%7C0%7C638201387342113041%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4%2FySAN%2BWpf4VPnWpJ464WBHBud2bZ0vVz4aV3k1pLHI%3D&reserved=0
> 
> [EXTERNAL EMAIL] DO NOT CLICK links or attachments unless you recognize
> the sender and know the content is safe.
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Merge dataframe with NetCDF file

2023-05-19 Thread Alexander Ilich
The WriteRaster should be able to do it 
(https://stackoverflow.com/questions/50026442/writing-r-raster-stack-to-netcdf).
 Also, if practical, I'd recommend switching from the raster package to the 
terra package which has replaced it and is written by the same author. The 
syntax is almost identical so it's an easy transition. terra has a writeCDF 
function which may work (https://rdrr.io/cran/terra/man/writeCDF.html).

Best Regards,
Alex


From: R-sig-Geo  on behalf of Miluji Sb 

Sent: Friday, May 19, 2023 7:19 PM
To: R-sig-geo mailing list 
Subject: [R-sig-Geo] Merge dataframe with NetCDF file

[You don't often get email from [email protected]. Learn why this is important 
at https://aka.ms/LearnAboutSenderIdentification ]

Dear all,

I am struggling to convert a dataframe with 49 years of data for 259,200
coordinates. How can I convert this dataset into a NetCDF file with the
following attributes;

class  : RasterBrick
dimensions : 360, 720, 259200, 10  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
crs: +proj=longlat +datum=WGS84 +no_defs
year (): 1971, 1972, ..., 2019
varname: fs

Any help will be highly appreciated.

Best,

Milu

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
[email protected]
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=05%7C01%7Cailich%40usf.edu%7C0f7d47bd46514adffc8408db58bf9b44%7C741bf7dee2e546df8d6782607df9deaa%7C0%7C0%7C638201387342113041%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4%2FySAN%2BWpf4VPnWpJ464WBHBud2bZ0vVz4aV3k1pLHI%3D&reserved=0
[EXTERNAL EMAIL] DO NOT CLICK links or attachments unless you recognize the 
sender and know the content is safe.

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Merge dataframe with NetCDF file

2023-05-19 Thread Roy Mendelssohn - NOAA Federal via R-sig-Geo
Hi Milu:

One of the best ways to get help is to give some description of what you have 
tried and what it was that had you stuck.  It looks like you already have the 
data in a raster brick,  have you Googled "writing RasterBrick to netcdf"?

 I assume nrow is latitude, ncol is longitude,  but what is ncell and nlayers?  
 I can't match up either of those values with the number of years you show  And 
what is actual name of the other dimension,  and does it have units?  ls what 
is the long name of "fs" and what are its units?

Thanks,

-Roy

> On May 19, 2023, at 4:19 PM, Miluji Sb  wrote:
> 
> Dear all,
> 
> I am struggling to convert a dataframe with 49 years of data for 259,200
> coordinates. How can I convert this dataset into a NetCDF file with the
> following attributes;
> 
> class  : RasterBrick
> dimensions : 360, 720, 259200, 10  (nrow, ncol, ncell, nlayers)
> resolution : 0.5, 0.5  (x, y)
> extent : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
> crs: +proj=longlat +datum=WGS84 +no_defs
> year (): 1971, 1972, ..., 2019
> varname: fs
> 
> Any help will be highly appreciated.
> 
> Best,
> 
> Milu
> 
>   [[alternative HTML version deleted]]
> 
> ___
> R-sig-Geo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: [email protected] www: https://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

___
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo