Skip to content

Commit

Permalink
Merge pull request #259 from NASA-Openscapes/tidy-matlab
Browse files Browse the repository at this point in the history
remove old approach, noted by Cedric
  • Loading branch information
jules32 authored Nov 6, 2023
2 parents a79d657 + 26266e1 commit bc6a501
Showing 1 changed file with 0 additions and 99 deletions.
99 changes: 0 additions & 99 deletions in-development/matlab.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -310,105 +310,6 @@ This isn't included in the numbered prereq list above because it is a bit more i
3. Login with your MATLAB credentials
4. You are in!
##
1. Search NASA Earthdata and find the S3 link you want to access
2. Set AWS Environment Variables - Go to the link above for the Access key, secret access key and token.
3. Copy and past those variables into the code below
`setenv('AWS_ACCESS_KEY_ID', 'REPLACE WITH PODAAC ACCESS KEY');`
`setenv('AWS_SECRET_ACCESS_KEY', 'REPLACE WITH PODAAC SECRET KEY');`
`setenv('AWS_SESSION_TOKEN', 'REPLACE WITH PODAAC SESSION TOKEN');`
`setenv('AWS_DEFAULT_REGION', 'us-west-2');`
NOTE: These expire ever 30 mins or so and this step needs to be done. We are searching for a better method.
4. In MATLAB on AWS only the HDF commands work
`FILE_NAME = 's3://podaac-ops-cumulus-protected/MODIS_A-JPL-L2P-v2019.0/20100619062008-JPL-L2P_GHRSST-SSTskin-MODIS_A-N-v02.0-fv01.0.nc';`
`file_id = H5F.open(FILE_NAME, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');`
5. This code works to read the file - Copy each section into the MATLAB command\
NOTE: We need a way to find all variables in a given netcdf file. I used the python code to find variables and then brought it here.
`DATAFIELD_NAME='sea_surface_temperature_4um';`
`data_id = H5D.open(file_id, DATAFIELD_NAME);`
`data=H5D.read(data_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT');`
`% Read units.`
`ATTRIBUTE = 'units';`
`attr_id = H5A.open_name(data_id, ATTRIBUTE);`
`units = H5A.read(attr_id, 'H5ML_DEFAULT');`
`H5A.close(attr_id);`
`% Read long_name.`
`ATTRIBUTE = 'long_name';`
`attr_id = H5A.open_name (data_id, ATTRIBUTE);`
`long_name=H5A.read (attr_id, 'H5ML_DEFAULT');`
`H5A.close(attr_id);`
`% Read the fill value.`
`ATTRIBUTE = '_FillValue';`
`attr_id = H5A.open_name(data_id, ATTRIBUTE);`
`fillvalue=H5A.read(attr_id, 'H5T_NATIVE_DOUBLE');`
`H5A.close(attr_id);`
`% Read latitude data.`
`LAT_NAME='lat';`
`lat_id=H5D.open(file_id, LAT_NAME);`
`lat=H5D.read(lat_id, 'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT');`
`% Read longitude data.`
`LON_NAME='lon';`
`lon_id=H5D.open(file_id, LON_NAME);`
`lon=H5D.read(lon_id, 'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT');`
`% Close and release resources.`
`H5D.close(data_id);`
`H5D.close(lat_id);`
`H5D.close(lon_id);`
`H5F.close(file_id);`
`% Replace the fill value with NaN.`
`data(data==fillvalue) = NaN;`
6. Create an image
`contour(data);`
![](images/Screen%20Shot%202022-05-30%20at%207.00.01%20PM.png)
### Shutdown your AWS Stack
After each session you need to turn off the AWS Stack. If you forget this step and leave it running it is like keeping a computer on for the month. For the large instance it costs \$0.5/day so it's a few dollars a month.
Expand Down

0 comments on commit bc6a501

Please sign in to comment.