Replies: 16 comments 17 replies
-
Hi Matt, |
Beta Was this translation helpful? Give feedback.
-
Hi Max,That sounds great. SEBFLUX is a logical place to start. You could write your own script that calls SEBFLUX to test it out. You could use the saved PHYSCONS.mat (see near the top of icemodel.m) or type them in yourself to get aquatinted with the physical constants that are used. You could also run icemodel and save the output, then load ice1.m and use the values as inputs to SEBFLUX, or you could make up dummy values, or whatever you want. Any questions feel free to ask. Have fun!
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Couple of quick comments, Max - you’re actually due to TA my Python course next quarter since there was no else qualified. I’ll make sure you’re well prepared. In regards to package managers, we recently decided to migrate to venv so you can ignore the conda stuff for now. I agree that more tinkering with the model code in matlab is a good idea. It will be a great learning experience converting it to Python but only worth starting that when you are a little more familiar with the model. Lastly writing of course is one the more important skills to have in this world. You’ll get plenty of practice next quarter. I’d like you to submit a FINSST proposal which is due in Feb 11. We should discuss some ideas next time we all meet. |
Beta Was this translation helpful? Give feedback.
-
Hey Matt, I'm a bit stuck (with downloading data) and want to get clarification (on variables) My current task is to download the reanalysis data (specifically, M2T1NXFLX from here). Johnny gave me really good details on the directions (attached), but there are 2 points that I need help clearing up. The former is more directed for you, Matt. Preamble: The penultimate step before downloading the reanalysis data is to pick out which variables I'd like to extract, and the list is extensive. I took that list and pasted them into the excel file that also has some of the main icemodel vars. The goal is to compare which variables from merra2 match those in icemodel.
|
Beta Was this translation helpful? Give feedback.
-
Hi Max,
Glad to see you are organizing this information. I have a similar spreadsheet attached here. It is not well organized. The most relevant sheets are ‘Greenland’ and ‘Forcing’. The Forcing sheet has the variables needed for forcing icemodel (not evaluating the output). There is a note that the incoming longwave is missing from the table. In the past I used LWGNT. I also made some notes on your spreadsheet.
The ‘Greenland and Global’ sheet lists additional variables useful for evaluating the model. I think this is what you want. Note that Merra2 has “instantaneous” and “time averaged” values. You want time averaged. Download the Merra2 technical document and compare the filename definitions with the ones in my spreadsheet. That will clarify which variables are useful in general (which “collections” as they’re called).
I attached a script to help download the data. It doesn’t actually download the data, it builds a shell script ‘wget_list.sh’ that does. It actually builds four scripts b/c there are four “collections”. The final step is to put those sh scripts wherever you want to save the data and then run them. I attached one of the sh scripts as an example, compare it to the text file you got and you should see how it works, but the scripts won’t work anymore b/c Merra2 filenames change over time when revisions are made.
There is a better way you could do it though. Instead of writing the wget_list.sh scripts, you could just execute the lines that are written to that script in the loop using the matlab ‘system’ command or in python I think it’s called ‘subprocess’. So in summary you would just read in that text file and loop over each line, compose the wget command, and send it to ‘system’ or ‘subprocess’ (each line downloads one file, so your just writing a loop to download all the files). This is a good skill set to have so I suggest spending some time figuring it out.
Good luck!
From: max ***@***.***>
Date: Saturday, November 5, 2022 at 9:53 PM
To: mgcooper/icemodel ***@***.***>
Cc: mgcooper ***@***.***>, Author ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
Hey Matt,
I'm a bit stuck (with downloading data) and want to get clarification (on variables)
My current task is to download the reanalysis data (specifically, M2T1NXFLX from here<https://disc.gsfc.nasa.gov/>). Johnny gave me really good details on the directions (attached), but there are 2 points that I need help clearing up. The former is more directed for you, Matt.
merra2-notes.txt<https://github.com/mgcooper/icemodel/files/9945172/merra2-notes.txt>
Preamble: The penultimate step before downloading the reanalysis data is to pick out which variables I'd like to extract, and the list is extensive. I took that list and pasted them into the excel file that also has some of the main icemodel vars. The goal is to compare which variables from merra2 match those in icemodel.
vars_compare.xlsx<https://github.com/mgcooper/icemodel/files/9945146/vars_compare.xlsx>
1. Matt, can you take a quick glance at the excel file and see if the green "matches" and yellow "maybe worth matching up" are accurate?
Later, I realized that there are waaay more variables in icemodel that are loaded in, e.g., PHYSCONS. For many of those constants, I'm not sure where to look in order to get their definition. Do I need to account for them?
The ultimate question is which of those variables in the reanalysis data match with icemodel variables // which ones should I tick?
2. I decided to skip ahead and just select 5 variables (green ones in excel sheet). I then wanted to download the data but found the only output to be netCDF (a large .txt file with lines of individual .nc files). Although there are directions<https://disc.gsfc.nasa.gov/data-access#mac_linux_wget> on how to read the data, I am not sure how to approach this. The given directions – although for Mac – are meant to be executed in... Unix/shell (aka just the terminal?)? I tried running some of their lines and got an error at step 2 (type touch.netrc). Am i supposed to do it in Python? Can I find similar codes in matlab? Am i not looking hard enough in your code how you dealt with this? I saw some of your "ncread" commands but couldn't quite understand which variables/values you extracted, Matt.
—
Reply to this email directly, view it on GitHub<#2 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKRV6GE5GREWWOCFKCEF53WG42UJANCNFSM6AAAAAAQ2QPN64>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hey Matt, quick question: |
Beta Was this translation helpful? Give feedback.
-
Interpolated. The 15 m is for numerical stability in the model … topic for another discussion.
From: max ***@***.***>
Date: Monday, December 5, 2022 at 11:27 AM
To: mgcooper/icemodel ***@***.***>
Cc: mgcooper ***@***.***>, Author ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
Hey Matt, quick question:
For your input weather station data, you have options for 15min and 1hr data. Based on some info<https://essd.copernicus.org/articles/13/3819/2021/> I found, AWSs provide hourly data.
So, did you have to interpolate the hourly data to create a 15min subset or did you just download it as 15min data?
—
Reply to this email directly, view it on GitHub<#2 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKRV6C5A4H76WGI5CQFG3DWLY6ZLANCNFSM6AAAAAAQ2QPN64>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I won’t be able to answer until Wednesday, but just a few ideas:
* Johnny’s explanation sounds like the answer – you may be comparing a watershed-average to point-scale values
* My forcing files are watershed-averages for the watershed files, and point-scale values for the met station files
* Take some time to study the README.md and what happens in METINIT.m (also icemodel_opts where the met file name is built) to understand the forcing files because there are two types – “Met” files, and “Data” files
* To understand that last part, pay attention to the file-naming convention in the README and the ‘swapvar’ concept and how it’s implemented in METINIT
* Also try putting a debug stop in icemdoel_opts prior to the part where the filenames are built and/or in METINIT then step through one line at a time and see how the vars get swapped out, you can pass in your merra albedo as an extra variable to the function so you can have it in your workspace and you can plot it against the values in my files to see how they compare, but probably easier to do this outside of the model
* Overall I think Johnny may be right but I need to read through your email more carefully
This is a good exercise to see how the model works. I am a little confused by the instability in the KAN-M output. The runoff should be smooth like the others. But we’ll have to revisit that. Also, I think Johnny’s explanation is right as far as why the albedo timeseries are different, but the reason the runoff is so different must be related to something else since your m2a matches my merra kanm albedo. Again, you will have to study the way the swapvar concept works to understand what’s going on. Depending on your setup, you may be using KAN-M forcing data with MERRA albedo, or you may be running MERRA forcing. It is hard to know exactly what is going into the forcing file without seeing the full setup and/or stepping through the initialization.
From: Johnny Ryan ***@***.***>
Date: Monday, December 5, 2022 at 4:17 PM
To: mgcooper/icemodel ***@***.***>
Cc: mgcooper ***@***.***>, Author ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
I can have a go at answering these... I think it's likely that Behar is the average MERRA albedo for a 60km2 watershed upstream of KAN-M. Since most of these grid cells are higher elevation than KAN-M, they are slightly brighter, hence slightly less runoff than your single MERRA grid cell. There could be a number of reasons why m2a does not exactly equal merra_kanm. It could be older version of MERRA2, there could also be some smoothing applied to remove the spikes. I wouldn't worry too much about it. Overall this is good progress and I'm glad you're getting some runoff outputs.
—
Reply to this email directly, view it on GitHub<#2 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKRV6DMFZHN564XJTEKNTTWL2AYTANCNFSM6AAAAAAQ2QPN64>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hey @mgcooper , I have an odd problem. I forced the icemodel with merra2 albedo and i was able to run the model just fine, seeing the increase in runoff over the years. However, when I tried forcing it with modis albedo, the model ran but showed just a fat zero for the runoff change. I was able to determine that the error happens within icemodel.m, before the POSTPROC function. So, somewhere in the loop. Specifically, I noticed that the variables k_eff and T, by the end of the loop running, were all zero. I tried running the first iteration and comparing it simultanesouly with the successful merra2 albedo run, and the first iteration's answers were identical. So, it must be something wrong in the further iterations. |
Beta Was this translation helpful? Give feedback.
-
Hi Max,
To read merra2 data files, you can use the function linked below. It depends on ‘ncparse’ which is linked below that. If you’re just reading albedo, you can ignore the comments in readMerra2.m regarding unit conversions.
Getting the data for a particular location is slightly more complicated, especially using matlab. I recommend using a tool designed to work with netcdf files such as nco. Another option is cdo, but I am less familiar with it. I also suggest to download Panoply for quickly viewing netcdf data. There’s a bit of a learning curve with nco but well worth it. I am sure rasterio or xarray would also work if you want to use python. I always used to use the ‘raster’ package in R and loved it, but nowadays not so much. If you’re committed to using matlab, I can provide some tools but they’re not very user friendly. Basically, I read in the merra lat/lon variables and use the ‘inpolygon’ function to figure out which lat/lon values are inside a closed area, then I read in the entire data grid, and mask out the data using the result from inpolygon. Don’t be dumb like me though! Instead use nco, or xarray.
https://github.com/mgcooper/matfunclib/blob/main/libhydro/readMerra2.m
https://github.com/mgcooper/matfunclib/tree/main/libdata/readfiles/ncparse
From: max ***@***.***>
Date: Wednesday, January 25, 2023 at 5:43 PM
To: mgcooper/icemodel ***@***.***>
Cc: Matt Cooper ***@***.***>, Mention ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
On another note, @mgcooper<https://github.com/mgcooper> any tips on extracting albedo data for a specific lat/lon from a 4D double? I tried looking at your scripts like scripts/preproc/met/mk_metfile_MAR_point.m and you have some kind of magical projfwd and projsipsn commands that turn your lat lons to x/y? Not usre if that will help but I remember you mentioning being cautious with reading nc files and how my loops are constructed but back then i just either 3d or 2d doubles.
—
Reply to this email directly, view it on GitHub<#2 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKRV6ABTPKIBRDM34UQPRDWUHJDBANCNFSM6AAAAAAQ2QPN64>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
PS here’s a good set of tips on nco. The linked example may do what you want.
http://research.jisao.washington.edu/data_sets/nco/#example10
From: Matt Cooper ***@***.***>
Date: Monday, January 30, 2023 at 7:02 PM
To: mgcooper/icemodel ***@***.***>, mgcooper/icemodel ***@***.***>
Cc: Mention ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
Hi Max,
To read merra2 data files, you can use the function linked below. It depends on ‘ncparse’ which is linked below that. If you’re just reading albedo, you can ignore the comments in readMerra2.m regarding unit conversions.
Getting the data for a particular location is slightly more complicated, especially using matlab. I recommend using a tool designed to work with netcdf files such as nco. Another option is cdo, but I am less familiar with it. I also suggest to download Panoply for quickly viewing netcdf data. There’s a bit of a learning curve with nco but well worth it. I am sure rasterio or xarray would also work if you want to use python. I always used to use the ‘raster’ package in R and loved it, but nowadays not so much. If you’re committed to using matlab, I can provide some tools but they’re not very user friendly. Basically, I read in the merra lat/lon variables and use the ‘inpolygon’ function to figure out which lat/lon values are inside a closed area, then I read in the entire data grid, and mask out the data using the result from inpolygon. Don’t be dumb like me though! Instead use nco, or xarray.
https://github.com/mgcooper/matfunclib/blob/main/libhydro/readMerra2.m
https://github.com/mgcooper/matfunclib/tree/main/libdata/readfiles/ncparse
From: max ***@***.***>
Date: Wednesday, January 25, 2023 at 5:43 PM
To: mgcooper/icemodel ***@***.***>
Cc: Matt Cooper ***@***.***>, Mention ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
On another note, @mgcooper<https://github.com/mgcooper> any tips on extracting albedo data for a specific lat/lon from a 4D double? I tried looking at your scripts like scripts/preproc/met/mk_metfile_MAR_point.m and you have some kind of magical projfwd and projsipsn commands that turn your lat lons to x/y? Not usre if that will help but I remember you mentioning being cautious with reading nc files and how my loops are constructed but back then i just either 3d or 2d doubles.
—
Reply to this email directly, view it on GitHub<#2 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKRV6ABTPKIBRDM34UQPRDWUHJDBANCNFSM6AAAAAAQ2QPN64>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
also see: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi Max,
The ice1.Tsfc variable is the surface temperature simulated by icemodel. The met.Tsfc variable is the Tsfc variable from the met data source. For example, if a MAR metfile is used, then met.Tsfc is the surface temperature simulated by MAR. It isn’t used in the model, it is included for comparison with the icemodel simulated surface temperature in ice1.
Matt
From: max ***@***.***>
Date: Tuesday, April 25, 2023 at 11:28 AM
To: mgcooper/icemodel ***@***.***>
Cc: Matt Cooper ***@***.***>, Mention ***@***.***>
Subject: Re: [mgcooper/icemodel] Python conversion stuff (Discussion #2)
Hey Matt,
What is the difference between Ice1 and met Tsfc? I tried to look at the POSTPROC.m function to understand how the two differ, but i'm not sure which would be better for me to use. For context, I want to juxtapose summer temperature and runoffs. Here's a screenshot of POSTPROC where the Tsfc of ice1 and met get updated (the highlighted lines 39 and [order] 66) for convenience.
[Screen Shot 2023-04-25 at 11 24 22]<https://user-images.githubusercontent.com/89253609/234367943-be4e5d60-5be7-4efa-ac98-c5fccbb28812.png>
I also tried plotting them against one another and the difference seems to be minuscule. I'm guessing that I don't need Tair and that Tf is the freezing temperature
[Screen Shot 2023-04-25 at 11 03 52]<https://user-images.githubusercontent.com/89253609/234368356-a6efe69c-de41-41de-80aa-d27bef0e3175.png>
—
Reply to this email directly, view it on GitHub<#2 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKRV6GEAEXRKFDKOZMDON3XDAJVHANCNFSM6AAAAAAQ2QPN64>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Starting a general list of ideas related to the python conversion.
Indents are currently three spaces. This is a holdover from a time when all my code was written on an eleven inch laptop. Plus three is way better than four. But we’ll need four for python. Use an autoformatter for this. Probably best to format the m files first, because formatting the py files may not be possible until they’re debugged.
Can try matlab to python conversion utilities such as smop and matlab2python. I tried both. They won’t work out of the box, but they might accelerate the process. A simple find and replace, keeping track of idiosyncrasies, might be faster. Start with one function, delete all ‘end’ statements, replace all ‘function’ statements with ‘def’ and so on. Patterns will emerge and soon you’ll have a list of conversions that can be applied to other functions.
The input met files are in a high level file format known as a timetable. I will convert them to flat binary files.
Another option is to first get it running in octave. This will reveal idiosyncratic issues like the met files, because octave is closer to python in terms of not being compatible with matlabic stuff like timetables.
Beta Was this translation helpful? Give feedback.
All reactions