GithubHelp home page GithubHelp logo

era5-roms's Introduction

Build status CodeBeat CodeCov

Download ERA5 and convert to ROMS format

update 15.01.2022 All tests successful This latest version of the toolbox has now been tested for both the Rutgers and Kate Hedstroms versions of the code. For both versions, the correct forcing files are created and are read correctly by the ROMS source code. In both tests cases the results show an improvement in vertical mixing of heat in the water column due to the higher time frequency compared to ERA INTERIM.

The toolbox has also been tested for an Arctic model that covers 40-90N and -180 to 180E. Initially, ROMS did not accept the ERA5 data as the maximum longitude of the ERA5 data was slightly less than the model grid.

          Gridded:  LonMin = -180.0000 LonMax =  179.7500
                    LatMin =   40.0000 LatMax =   90.0000
          Model:    LonMin = -179.9848 LonMax =  179.9680
                    LatMin =   45.0081 LatMax =   89.9205

To resolve this issue you can pply a brillian CDO command called sethalo which basically replicates the last index value (-180E) at the maximum longitude (180E) to wrap the globe. To repeat this command on all files generated by this toolbox run(also new file added to repository here:

for file in era5*.nc
do
 name=${file##*/}
 base=${name%.nc}
 echo "$file" new file "${base}_halo.nc"
 cdo sethalo,0,1 "$file" "${base}_halo.nc"
done

After runnning the CDO commands (add_halo.sh) you may need to update the attributes of the .nc files by running add_attributes_to_netcdf4.sh found here

A new option to reduce the memory footprint of the result files has been implemented. The option extract_data_every_6_hours (defined as True/False in ECMWF_query.py) allow you to specify 6 hourly, instead of hourly, output to file frequency. For forcing files that cover large regions such as the entire Northern Hemisphere, this drastically reduces the total file size. The option can be used to specify other output frequency through the list of timesteps required (ECMWF:tools.py):

if self.config_ecmwf.extract_data_every_6_hours is True:
			times = ['00:00', '06:00', '12:00', '18:00']

update 12.11.2021 - resolved Believe that the issue with ROMS reading ERA5 generated files using ERA5-ROMs has been resolved by inverting the latitude (and data array) of ERA5. Apparently ROMS is not able to read the ERA5 in the ECMWF standard way of representing latitude. Please create an issue if this is still a problem!

update 10.08.2020 After conversations with ECMWF support I changed the code to only use ERA5 parameter names and not parameter IDs as these did not result in stable downloads (some parameter IDs seems to be missing for some months while the parameter names are consistent).

This toolbox enables you to download ERA5 atmospheric forcing data for your model domain for a specified period. The toolbox uses the [Climate Data Store] Python API to connect and download specific variables required by ROMS to perform simulations with atmospheric forcing. These variables are included in the list below:

   'Specific_humidity',
   '10m_u_component_of_wind',
   '10m_v_component_of_wind',
   '2m_temperature',
   '2m_dewpoint_temperature',
   'Mean_sea_level_pressure',
   'Total_cloud_cover',
   'Total_precipitation',
   'Mean_surface_net_short-wave_radiation_flux',
   'Mean_surface_net_long-wave_radiation_flux',
   'Mean_surface_downward_long-wave_radiation_flux',
   'Mean_surface_latent_heat_flux',
   'Mean_surface_sensible_heat_flux',
   'Evaporation',
   'Mean surface downward short-wave radiation flux'

Details of the ERA5 variables can be found here To see the details for how ROMS requires naming convention etc.

Install API

To start signup and get necessary credentials at the [Climate Data Store]. Store the credentials in a file called .cdsapircin you root $HOME directory. It should look something like this:

url: https://cds.climate.copernicus.eu/api/v2 key: 28122:f85a4564-8895-498d-ad8a-gf274ba38d2r ls -lrt

Edit the toolbox settings

Edit the file ECMWF_query.pyto define the start and end period you want to download data. If you want you can edit the months, days, and time steps of the day data will be downloaded in the file ECMWF_tools.py but by default the program downloads data for all available reanalysis time steps of the day for all days for all months of the year. Each result file contains data for one variable for one year.

Note: If you are using Kate Hedstroms ROMS version with sea-ice you need to download 'mean_surface_downward_short_wave_radiation_flux' while the regular Rutgers ROMS version uses 'mean_surface_net_short_wave_radiation_flux'. This can be defined in the option self.ROMS_version = "Kate"in ECMWF_query.py.

The request API can be tested here: ECMWF ERA5 API requests and the Python cdsapi is described cdsapi. Data availability from Copernicus available here https://cp-availability.ceda.ac.uk/.

The region for where you extract the data is defined by the variable self.area = "80/0/50/25"found in ECMWF_query.py. The area is constrained by North/West/South/East.

The time units in the resulting ROMS files are converted from the ERA5 units (1900-01-01) to the standard ROMS reference time 1948-01-01. The toolbox uses the netCDF4 date2numand num2date functions for this conversion.

Main query

The main query for the call for data is found in ECMWF_tools.py

		def submit_request(self, parameter, year, out_filename):

		options = {
			'product_type': 'reanalysis',
			"year": year,
			"month": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"],
			'day': [
				'01', '02', '03',
				'04', '05', '06',
				'07', '08', '09',
				'10', '11', '12',
				'13', '14', '15',
				'16', '17', '18',
				'19', '20', '21',
				'22', '23', '24',
				'25', '26', '27',
				'28', '29', '30',
				'31',
			],
			'time': [
				'00:00', '01:00', '02:00',
				'03:00', '04:00', '05:00',
				'06:00', '07:00', '08:00',
				'09:00', '10:00', '11:00',
				'12:00', '13:00', '14:00',
				'15:00', '16:00', '17:00',
				'18:00', '19:00', '20:00',
				'21:00', '22:00', '23:00',
			],
			"variable": [parameter],
			'format': "netcdf",
			"area": self.config_ecmwf.area,
			"verbose": self.config_ecmwf.debug,
		}
		# Add more specific options for variables on pressure surfaces
		if parameter == "specific_humidity":
			self.config_ecmwf.reanalysis = "reanalysis-era5-pressure-levels"
			options["levtype"] = 'pl'
			options["pressure_level"] = '1000'
		else:
			self.config_ecmwf.reanalysis = 'reanalysis-era5-single-levels'

		try:
			# Do the request
			self.server.retrieve(self.config_ecmwf.reanalysis, options, out_filename)
		except Exception as e:
			print(e)
			print("[!] -------------------------- PROBLEMS WITH {0}".format(out_filename))

		metadata = self.config_ecmwf.get_parameter_metadata(parameter)
		converter = ECMWF_convert_to_ROMS.ECMWF_convert_to_ROMS()
		converter.convert_to_ROMS_units_standards(out_filename, metadata, parameter, self.config_ecmwf)

Run the toolbox

To run the toolbox after editing the settings simply run python ECMWF_tools.py

Global data

If your model domain covers the entire Arctic, or northern hemisphere and reaches from -180 to 180 you have to convert the ERA5 data to be connected. This is done by introducing a fake point at 180 which is identical to point 0. This makes the data across the meridian line consistent and ROMS wont choke on it. This step requires CDO installed.

Run make_files_fully_global-sh:

for filename in results/*.nc; do
		echo "Converting: " "$filename" " to" "halo/$(basename "$filename" .nc)_halo.nc"
    cdo sethalo,0,1 "$filename" "halo/$(basename "$filename" .nc)_halo.nc"
done

####Unittest A few simple unittests are included in test_ERA5.py.

era5-roms's People

Contributors

alaurent101 avatar trondactea avatar trondkr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

era5-roms's Issues

Regarding location where output file shall be saved

Hello sir,
I am trying to use your script ERA5-ROMS. Thanks a lot for your such a generous contribution. Although I had an issue. After running the toolbox using according to Run the toolbox section of Readme.md file, I am not sure where the file is being saved(i mean its location and filename). May be it's a bug or maybe I am unable to use it in a proper way. Also is there a way that I can use this script to create forcing on my own grid present in netcdf format ?

Thanks a lot for your help in advance @trondkr

Issue with ERA5 download data

Hi Trondkr. I'm using your script to download the ERA5 data to use in my ROMS domain. However, the download is apparently doing very slowly, and after some time the process is killed unexpectedly, at different times (in my failed attempts to download and process the data). It can be something wrong with the solicitation? do you know if we have a limit of downloads of ERA5 data?

I am trying to download:

  • 'reanalysis-era5-single-levels'
  • 3hourly data from 1998 to 2018. (10m u,v wind, 2m temperature, mean sea level pressure, mean surface downward long and short wave radiation fluxes, total cloud cover, total precipitation, specific humidity)
  • domain: -30/-140/-85/40

The download starts, it is downloaded 1998 u_wind, v_wind, they are converted to ROMS, but it stops when it finishes the 2m-temperature, or before...

Download speed is slow

Great code!But I had a problem when I ran it: the download was too slow (20~100kb/s). I simply modified the code, now I can call Internet Download Manager (IDM) for multi-threaded download, the speed can reach 8mb/s. But the whole process of data download and processing is not elegant enough (need to run twice and comment out some statements). I wonder if the author has any plans to add a multi-threaded download module to the code. Thanks.

Problem to use this code

I try to download data for ROMS Rutgers. I can use it but I can download 10 variables. My other problem is the code does not change the time properly and my header file is for 1900. When I start running the model, I faced a problem.
netcdf era5_msnlwrf_year_2014 {
dimensions:
longitude = 36 ;
latitude = 29 ;
time = 4380 ;
variables:
float longitude(longitude) ;
longitude:units = "degrees_east" ;
longitude:long_name = "longitude" ;
float latitude(latitude) ;
latitude:units = "degrees_north" ;
latitude:long_name = "latitude" ;
int time(time) ;
time:units = "hours since 1948-01-01 00:00:00.0" ;
time:long_name = "time" ;
time:calendar = "gregorian" ;
short msnlwrf(time, latitude, longitude) ;
msnlwrf:scale_factor = 0.00339088604676628 ;
msnlwrf:add_offset = -91.074113655914 ;
msnlwrf:_FillValue = -32767s ;
msnlwrf:missing_value = -32767s ;
msnlwrf:units = "W m**-2" ;
msnlwrf:long_name = "Mean surface net long-wave radiation flux" ;

// global attributes:
:Conventions = "CF-1.6" ;
:history = "2022-06-04 09:23:44 GMT by grib_to_netcdf-2.24.3: /opt/ecmwf/mars-client/bin/grib_to_netcdf -S param -o /cache/data1/adaptor.mars.internal-1654334612.669915-11911-5-14831270-9472-4c48-9faf-6bc9abe5ac36.nc /cache/tmp/14831270-9472-4c48-9faf-6bc9abe5ac36-adaptor.mars.internal-1654334292.9382155-11911-7-tmp.grib" ;
data:

longitude = 12, 12.25, 12.5, 12.75, 13, 13.25, 13.5, 13.75, 14, 14.25, 14.5,
14.75, 15, 15.25, 15.5, 15.75, 16, 16.25, 16.5, 16.75, 17, 17.25, 17.5,
17.75, 18, 18.25, 18.5, 18.75, 19, 19.25, 19.5, 19.75, 20, 20.25, 20.5,
20.75 ;

latitude = 45.9, 45.65, 45.4, 45.15, 44.9, 44.65, 44.4, 44.15, 43.9, 43.65,
43.4, 43.15, 42.9, 42.65, 42.4, 42.15, 41.9, 41.65, 41.4, 41.15, 40.9,
40.65, 40.4, 40.15, 39.9, 39.65, 39.4, 39.15, 38.9 ;

time = 999312, 999314, 999316, 999318, 999320, 999322, 999324, 999326,
999328, 999330, 999332, 999334, 999336, 999338, 999340, 999342, 999344,
999346, 999348, 999350, 999352, 999354, 999356, 999358, 999360, 999362,
999364, 999366, 999368, 999370, 999372, 999374, 999376, 999378, 999380,
999382, 999384, 999386, 999388, 999390, 999392, 999394, 999396, 999398,
999400, 999402, 999404, 999406, 999408, 999410, 999412, 999414, 999416,
999418, 999420, 999422, 999424, 999426, 999428, 999430, 999432, 999434,
999436, 999438, 999440, 999442, 999444, 999446, 999448, 999450, 999452,

False is not of type string

Hello @trondkr sorry for the bother.

I don't understand what is happening, I am setting

        self.start_year = 2017
        self.end_year = 2020
        self.project = "IEA"

with

        return {'IEA': '80/-40/45/15',
                'A20': '90/-180/40/180'}[project]

and I am getting the following:

2023-02-10 12:52:12,079 INFO Request is failed
2023-02-10 12:52:12,079 ERROR Message: the request you have submitted is not valid
2023-02-10 12:52:12,080 ERROR Reason:
request['verbose'][0]: False is not of type 'string'
2023-02-10 12:52:12,080 ERROR Traceback (most recent call last):
2023-02-10 12:52:12,080 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 59, in handle_request
2023-02-10 12:52:12,080 ERROR result = cached(context.method, proc, context, context.args, context.kwargs)
2023-02-10 12:52:12,080 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
2023-02-10 12:52:12,080 ERROR result = proc(context, *context.args, **context.kwargs)
2023-02-10 12:52:12,080 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 124, in call
2023-02-10 12:52:12,080 ERROR return p(*args, **kwargs)
2023-02-10 12:52:12,080 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 60, in call
2023-02-10 12:52:12,080 ERROR return self.proc(context, *args, **kwargs)
2023-02-10 12:52:12,080 ERROR File "/home/cds/cdsservices/services/mars/mars.py", line 48, in internal
2023-02-10 12:52:12,080 ERROR return mars(context, request, **kwargs)
2023-02-10 12:52:12,080 ERROR File "/home/cds/cdsservices/services/mars/mars.py", line 18, in mars
2023-02-10 12:52:12,080 ERROR **kwargs)
2023-02-10 12:52:12,080 ERROR File "/home/cds/cdsservices/services/mars/preprocess_request.py", line 24, in preprocess_request
2023-02-10 12:52:12,080 ERROR requests = enforce_minimal_schema(requests, context)
2023-02-10 12:52:12,080 ERROR File "/home/cds/cdsservices/services/mars/request_checking.py", line 54, in enforce_minimal_schema
2023-02-10 12:52:12,080 ERROR return enforce_schema(requests, schema, context)
2023-02-10 12:52:12,080 ERROR File "/opt/cdstoolbox/cds-common/cds_common/request_schemas/enforce_schema.py", line 29, in enforce_schema
2023-02-10 12:52:12,080 ERROR from None
2023-02-10 12:52:12,080 ERROR cdsinf.exceptions.BadRequestException:
2023-02-10 12:52:12,080 ERROR request['verbose'][0]: False is not of type 'string'

The funny thing is that this very same code was working very well last December.
Any help and suggestion you could provide?

Thank you very much in advance.

Problem with using output to run ROMS

When testing the current output of this package for an Arctic ROMS model it seems that ROMS has either 1) a problem with one of the variables that prevent seasonality to emerge in the ROMS solution 2) the internal interpolation in ROMS is broken.. This needs to be further investigated

There may exist a bug in ECMWF_convert_to_ROMS.py

Thanks for this great project, but I encountered a small issue while using the code.
In the ECMWF_convert_to_ROMS.py, line 99, function write_to_ROMS_netcdf_file is defined and netcdf_file is used as a parameter, which gives the name of the netcdf file to be written in line 120.
However, in line 120,the code is netcdf_roms_filename = f"{out_filename[0:-3]}_roms.nc", which use out_filename instead of netcdf_file, causing the problem: NameError: name 'out_filename' is not defined.
I wonder if the code may need to be modified. Looking for reply. Thanks

Bug in ECMWF_tools.py?

Hi Trond,
Could you please check whether there's a bug in ECMWF_tools.py. I specified both the start and end dates to be 2015 in ECMWF_querry.py, but when the download completed it started to grab data for 2016. Thanks again for this tool!

Regards,
Joseph K. Ansong

wrong order for latitude?

Hi Trond,

Thanks for this great piece of code, but I came into some issue that ROMS model (I'm using COAWST actually) can't read the forcing data. It seems ROMS doesn't like the latitude to be from 90 to -90, I modified "ECMWF_convert_to_ROMS.py" with following:

vnc = f1.createVariable('lat', 'd', 'lat', fill_value=fill_val)
vnc.long_name = 'Latitude'
vnc.units = 'degree_north'
vnc.standard_name = 'latitude'
vnc[:] = latitude[::-1]



vnc = f1.createVariable(metadata['roms_name'], 'd', (metadata['time_name'], 'lat', 'lon'), fill_value=fill_val)
vnc.long_name = metadata["name"]
vnc.standard_name = metadata["short_name"]
vnc.coordinates = "lon lat {}".format(metadata['time_name'])
vnc.units = var_units
vnc.missing_value = fill_val
vnc[:, :, :] = data_array[:,::-1,:]

and ROMS is running. Not sure if it's an error with ROMS or COAWST, but I think it may be worth bringing it to you.

Cheers,
Yi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.